diff options
Diffstat (limited to 'pintos-progos/tests/filesys/seq-test.c')
| -rw-r--r-- | pintos-progos/tests/filesys/seq-test.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/pintos-progos/tests/filesys/seq-test.c b/pintos-progos/tests/filesys/seq-test.c new file mode 100644 index 0000000..8ce222c --- /dev/null +++ b/pintos-progos/tests/filesys/seq-test.c | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | #include "tests/filesys/seq-test.h" | ||
| 2 | #include <random.h> | ||
| 3 | #include <syscall.h> | ||
| 4 | #include "tests/lib.h" | ||
| 5 | |||
| 6 | void | ||
| 7 | seq_test (const char *file_name, void *buf, size_t size, size_t initial_size, | ||
| 8 | size_t (*block_size_func) (void), | ||
| 9 | void (*check_func) (int fd, long ofs)) | ||
| 10 | { | ||
| 11 | size_t ofs; | ||
| 12 | int fd; | ||
| 13 | |||
| 14 | random_bytes (buf, size); | ||
| 15 | CHECK (create (file_name, initial_size), "create \"%s\"", file_name); | ||
| 16 | CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name); | ||
| 17 | |||
| 18 | ofs = 0; | ||
| 19 | msg ("writing \"%s\"", file_name); | ||
| 20 | while (ofs < size) | ||
| 21 | { | ||
| 22 | size_t block_size = block_size_func (); | ||
| 23 | if (block_size > size - ofs) | ||
| 24 | block_size = size - ofs; | ||
| 25 | |||
| 26 | if (write (fd, buf + ofs, block_size) != (int) block_size) | ||
| 27 | fail ("write %zu bytes at offset %zu in \"%s\" failed", | ||
| 28 | block_size, ofs, file_name); | ||
| 29 | |||
| 30 | ofs += block_size; | ||
| 31 | if (check_func != NULL) | ||
| 32 | check_func (fd, ofs); | ||
| 33 | } | ||
| 34 | msg ("close \"%s\"", file_name); | ||
| 35 | close (fd); | ||
| 36 | check_file (file_name, buf, size); | ||
| 37 | } | ||
