Clarification.
[pintos-anon] / grading / filesys / random.inc
index e821a599e41a9a96579623b422718c866020f1bf..895b65884694b41061b79996093add1fa49d1550 100644 (file)
 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;
 }