diff options
| author | manuel <manuel@mausz.at> | 2012-03-26 12:54:45 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2012-03-26 12:54:45 +0200 |
| commit | b5f0874cd96ee2a62aabc645b9626c2749cb6a01 (patch) | |
| tree | 1262e4bbe0634de6650be130c36e0538240f4cbf /pintos-progos/tests/filesys/extended/grow-two-files.c | |
| download | progos-b5f0874cd96ee2a62aabc645b9626c2749cb6a01.tar.gz progos-b5f0874cd96ee2a62aabc645b9626c2749cb6a01.tar.bz2 progos-b5f0874cd96ee2a62aabc645b9626c2749cb6a01.zip | |
initial pintos checkin
Diffstat (limited to 'pintos-progos/tests/filesys/extended/grow-two-files.c')
| -rw-r--r-- | pintos-progos/tests/filesys/extended/grow-two-files.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/pintos-progos/tests/filesys/extended/grow-two-files.c b/pintos-progos/tests/filesys/extended/grow-two-files.c new file mode 100644 index 0000000..6a8fb1c --- /dev/null +++ b/pintos-progos/tests/filesys/extended/grow-two-files.c | |||
| @@ -0,0 +1,62 @@ | |||
| 1 | /* Grows two files in parallel and checks that their contents are | ||
| 2 | correct. */ | ||
| 3 | |||
| 4 | #include <random.h> | ||
| 5 | #include <syscall.h> | ||
| 6 | #include "tests/lib.h" | ||
| 7 | #include "tests/main.h" | ||
| 8 | |||
| 9 | #define FILE_SIZE 8143 | ||
| 10 | static char buf_a[FILE_SIZE]; | ||
| 11 | static char buf_b[FILE_SIZE]; | ||
| 12 | |||
| 13 | static void | ||
| 14 | write_some_bytes (const char *file_name, int fd, const char *buf, size_t *ofs) | ||
| 15 | { | ||
| 16 | if (*ofs < FILE_SIZE) | ||
| 17 | { | ||
| 18 | size_t block_size = random_ulong () % (FILE_SIZE / 8) + 1; | ||
| 19 | size_t ret_val; | ||
| 20 | if (block_size > FILE_SIZE - *ofs) | ||
| 21 | block_size = FILE_SIZE - *ofs; | ||
| 22 | |||
| 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); | ||
| 27 | *ofs += block_size; | ||
| 28 | } | ||
| 29 | } | ||
| 30 | |||
| 31 | void | ||
| 32 | test_main (void) | ||
| 33 | { | ||
| 34 | int fd_a, fd_b; | ||
| 35 | size_t ofs_a = 0, ofs_b = 0; | ||
| 36 | |||
| 37 | random_init (0); | ||
| 38 | random_bytes (buf_a, sizeof buf_a); | ||
| 39 | random_bytes (buf_b, sizeof buf_b); | ||
| 40 | |||
| 41 | CHECK (create ("a", 0), "create \"a\""); | ||
| 42 | CHECK (create ("b", 0), "create \"b\""); | ||
| 43 | |||
| 44 | CHECK ((fd_a = open ("a")) > 1, "open \"a\""); | ||
| 45 | CHECK ((fd_b = open ("b")) > 1, "open \"b\""); | ||
| 46 | |||
| 47 | msg ("write \"a\" and \"b\" alternately"); | ||
| 48 | while (ofs_a < FILE_SIZE || ofs_b < FILE_SIZE) | ||
| 49 | { | ||
| 50 | write_some_bytes ("a", fd_a, buf_a, &ofs_a); | ||
| 51 | write_some_bytes ("b", fd_b, buf_b, &ofs_b); | ||
| 52 | } | ||
| 53 | |||
| 54 | msg ("close \"a\""); | ||
| 55 | close (fd_a); | ||
| 56 | |||
| 57 | msg ("close \"b\""); | ||
| 58 | close (fd_b); | ||
| 59 | |||
| 60 | check_file ("a", buf_a, FILE_SIZE); | ||
| 61 | check_file ("b", buf_b, FILE_SIZE); | ||
| 62 | } | ||
