X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=grading%2Ffilesys%2Frandom.inc;h=895b65884694b41061b79996093add1fa49d1550;hb=be193f8d945ee145b404e8b33fae7616a4b408f4;hp=e821a599e41a9a96579623b422718c866020f1bf;hpb=6ebce2100b371612b554bf17a3ce613a4093df37;p=pintos-anon diff --git a/grading/filesys/random.inc b/grading/filesys/random.inc index e821a59..895b658 100644 --- a/grading/filesys/random.inc +++ b/grading/filesys/random.inc @@ -15,24 +15,23 @@ char buf[TEST_SIZE]; int order[BLOCK_CNT]; -int -main (void) +void +test_main (void) { + const char *filename = "bazzle"; int fd; size_t i; - msg ("begin"); - random_init (57); random_bytes (buf, sizeof buf); for (i = 0; i < BLOCK_CNT; i++) order[i] = i; - check (create ("bazzle", TEST_SIZE), "create \"bazzle\""); - check ((fd = open ("bazzle")) > 1, "open \"bazzle\""); + CHECK (create (filename, TEST_SIZE), "create \"%s\"", filename); + CHECK ((fd = open (filename)) > 1, "open \"%s\"", filename); - msg ("write \"bazzle\" in random order"); + msg ("write \"%s\" in random order", filename); shuffle (order, BLOCK_CNT, sizeof *order); for (i = 0; i < BLOCK_CNT; i++) { @@ -42,7 +41,7 @@ main (void) fail ("write %d bytes at offset %zu failed", (int) BLOCK_SIZE, ofs); } - msg ("read \"bazzle\" in random order"); + msg ("read \"%s\" in random order", filename); shuffle (order, BLOCK_CNT, sizeof *order); for (i = 0; i < BLOCK_CNT; i++) { @@ -51,20 +50,9 @@ main (void) seek (fd, ofs); if (read (fd, block, BLOCK_SIZE) <= 0) fail ("read %d bytes at offset %zu failed", (int) BLOCK_SIZE, ofs); - if (memcmp (block, buf + ofs, BLOCK_SIZE)) - { - printf ("Expected data:\n"); - hex_dump (ofs, buf + ofs, BLOCK_SIZE, false); - printf ("Actually read data:\n"); - hex_dump (ofs, block, BLOCK_SIZE, false); - fail ("%d bytes at offset %zu differed from expected", - (int) BLOCK_SIZE, ofs); - } + compare_bytes (block, buf + ofs, BLOCK_SIZE, ofs, filename); } - fail ("close \"bazzle\""); + msg ("close \"%s\"", filename); close (fd); - - msg ("end"); - return 0; }