1 /* Grows two files in parallel and checks that their contents are
7 #include "tests/main.h"
10 static char buf_a[FILE_SIZE];
11 static char buf_b[FILE_SIZE];
14 write_some_bytes (const char *file_name, int fd, const char *buf, size_t *ofs)
18 size_t block_size = random_ulong () % (FILE_SIZE / 8) + 1;
20 if (block_size > FILE_SIZE - *ofs)
21 block_size = FILE_SIZE - *ofs;
23 ret_val = write (fd, buf + *ofs, block_size);
24 if (ret_val != block_size)
25 fail ("write %zu bytes at offset %zu in \"%s\" returned %zu",
26 block_size, *ofs, file_name, ret_val);
35 size_t ofs_a = 0, ofs_b = 0;
38 random_bytes (buf_a, sizeof buf_a);
39 random_bytes (buf_b, sizeof buf_b);
41 CHECK (create ("a", 0), "create \"a\"");
42 CHECK (create ("b", 0), "create \"b\"");
44 CHECK ((fd_a = open ("a")) > 1, "open \"a\"");
45 CHECK ((fd_b = open ("b")) > 1, "open \"b\"");
47 msg ("write \"a\" and \"b\" alternately");
48 while (ofs_a < FILE_SIZE || ofs_b < FILE_SIZE)
50 write_some_bytes ("a", fd_a, buf_a, &ofs_a);
51 write_some_bytes ("b", fd_b, buf_b, &ofs_b);
60 check_file ("a", buf_a, FILE_SIZE);
61 check_file ("b", buf_b, FILE_SIZE);