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)
21 const char *filename = "bazzle";
26 random_bytes (buf, sizeof buf);
28 for (i = 0; i < BLOCK_CNT; i++)
31 CHECK (create (filename, TEST_SIZE), "create \"%s\"", filename);
32 CHECK ((fd = open (filename)) > 1, "open \"%s\"", filename);
34 msg ("write \"%s\" in random order", filename);
35 shuffle (order, BLOCK_CNT, sizeof *order);
36 for (i = 0; i < BLOCK_CNT; i++)
38 size_t ofs = BLOCK_SIZE * order[i];
40 if (write (fd, buf + ofs, BLOCK_SIZE) <= 0)
41 fail ("write %d bytes at offset %zu failed", (int) BLOCK_SIZE, ofs);
44 msg ("read \"%s\" in random order", filename);
45 shuffle (order, BLOCK_CNT, sizeof *order);
46 for (i = 0; i < BLOCK_CNT; i++)
48 char block[BLOCK_SIZE];
49 size_t ofs = BLOCK_SIZE * order[i];
51 if (read (fd, block, BLOCK_SIZE) <= 0)
52 fail ("read %d bytes at offset %zu failed", (int) BLOCK_SIZE, ofs);
53 compare_bytes (block, buf + ofs, BLOCK_SIZE, ofs, filename);
56 msg ("close \"%s\"", filename);