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)
25 random_bytes (buf, sizeof buf);
27 for (i = 0; i < BLOCK_CNT; i++)
30 check (create ("bazzle", TEST_SIZE), "create \"bazzle\"");
31 check ((fd = open ("bazzle")) > 1, "open \"bazzle\"");
33 msg ("write \"bazzle\" in random order");
34 shuffle (order, BLOCK_CNT, sizeof *order);
35 for (i = 0; i < BLOCK_CNT; i++)
37 size_t ofs = BLOCK_SIZE * order[i];
39 if (write (fd, buf + ofs, BLOCK_SIZE) <= 0)
40 fail ("write %d bytes at offset %zu failed", (int) BLOCK_SIZE, ofs);
43 msg ("read \"bazzle\" in random order");
44 shuffle (order, BLOCK_CNT, sizeof *order);
45 for (i = 0; i < BLOCK_CNT; i++)
47 char block[BLOCK_SIZE];
48 size_t ofs = BLOCK_SIZE * order[i];
50 if (read (fd, block, BLOCK_SIZE) <= 0)
51 fail ("read %d bytes at offset %zu failed", (int) BLOCK_SIZE, ofs);
52 if (memcmp (block, buf + ofs, BLOCK_SIZE))
54 printf ("Expected data:\n");
55 hex_dump (ofs, buf + ofs, BLOCK_SIZE, false);
56 printf ("Actually read data:\n");
57 hex_dump (ofs, block, BLOCK_SIZE, false);
58 fail ("%d bytes at offset %zu differed from expected",
59 (int) BLOCK_SIZE, ofs);
63 fail ("close \"bazzle\"");