8 #include "tests/main.h"
10 #if TEST_SIZE % BLOCK_SIZE != 0
11 #error TEST_SIZE must be a multiple of BLOCK_SIZE
14 #define BLOCK_CNT (TEST_SIZE / BLOCK_SIZE)
22 const char *filename = "bazzle";
27 random_bytes (buf, sizeof buf);
29 for (i = 0; i < BLOCK_CNT; i++)
32 CHECK (create (filename, TEST_SIZE), "create \"%s\"", filename);
33 CHECK ((fd = open (filename)) > 1, "open \"%s\"", filename);
35 msg ("write \"%s\" in random order", filename);
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) != BLOCK_SIZE)
42 fail ("write %d bytes at offset %zu failed", (int) BLOCK_SIZE, ofs);
45 msg ("read \"%s\" in random order", filename);
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) != BLOCK_SIZE)
53 fail ("read %d bytes at offset %zu failed", (int) BLOCK_SIZE, ofs);
54 compare_bytes (block, buf + ofs, BLOCK_SIZE, ofs, filename);
57 msg ("close \"%s\"", filename);