9 #if TEST_SIZE % BLOCK_SIZE != 0
10 #error TEST_SIZE must be a multiple of BLOCK_SIZE
13 #define BLOCK_CNT (TEST_SIZE / BLOCK_SIZE)
27 random_bytes (buf, sizeof buf);
29 for (i = 0; i < BLOCK_CNT; i++)
32 check (create ("bazzle", TEST_SIZE), "create \"bazzle\"");
33 check ((fd = open ("bazzle")) > 1, "open \"bazzle\"");
35 msg ("write \"bazzle\" in random order");
36 shuffle (order, BLOCK_CNT, sizeof *order);
37 for (i = 0; i < BLOCK_CNT; i++)
39 size_t ofs = BLOCK_SIZE * order[i];
41 if (write (fd, buf + ofs, BLOCK_SIZE) <= 0)
42 fail ("write %d bytes at offset %zu failed", (int) BLOCK_SIZE, ofs);
45 msg ("read \"bazzle\" in random order");
46 shuffle (order, BLOCK_CNT, sizeof *order);
47 for (i = 0; i < BLOCK_CNT; i++)
49 char block[BLOCK_SIZE];
50 size_t ofs = BLOCK_SIZE * order[i];
52 if (read (fd, block, BLOCK_SIZE) <= 0)
53 fail ("read %d bytes at offset %zu failed", (int) BLOCK_SIZE, ofs);
54 if (memcmp (block, buf + ofs, BLOCK_SIZE))
56 printf ("Expected data:\n");
57 hex_dump (ofs, buf + ofs, BLOCK_SIZE, false);
58 printf ("Actually read data:\n");
59 hex_dump (ofs, block, BLOCK_SIZE, false);
60 fail ("%d bytes at offset %zu differed from expected",
61 (int) BLOCK_SIZE, ofs);
65 fail ("close \"bazzle\"");