diff options
Diffstat (limited to 'pintos-progos/tests/userprog/read-boundary.c')
| -rw-r--r-- | pintos-progos/tests/userprog/read-boundary.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/pintos-progos/tests/userprog/read-boundary.c b/pintos-progos/tests/userprog/read-boundary.c new file mode 100644 index 0000000..9c19966 --- /dev/null +++ b/pintos-progos/tests/userprog/read-boundary.c | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | /* Reads data spanning two pages in virtual address space, | ||
| 2 | which must succeed. */ | ||
| 3 | |||
| 4 | #include <string.h> | ||
| 5 | #include <syscall.h> | ||
| 6 | #include "tests/userprog/boundary.h" | ||
| 7 | #include "tests/userprog/sample.inc" | ||
| 8 | #include "tests/lib.h" | ||
| 9 | #include "tests/main.h" | ||
| 10 | |||
| 11 | void | ||
| 12 | test_main (void) | ||
| 13 | { | ||
| 14 | int handle; | ||
| 15 | int byte_cnt; | ||
| 16 | char *buffer; | ||
| 17 | |||
| 18 | CHECK ((handle = open ("sample.txt")) > 1, "open \"sample.txt\""); | ||
| 19 | |||
| 20 | buffer = get_boundary_area () - sizeof sample / 2; | ||
| 21 | byte_cnt = read (handle, buffer, sizeof sample - 1); | ||
| 22 | if (byte_cnt != sizeof sample - 1) | ||
| 23 | fail ("read() returned %d instead of %zu", byte_cnt, sizeof sample - 1); | ||
| 24 | else if (strcmp (sample, buffer)) | ||
| 25 | { | ||
| 26 | msg ("expected text:\n%s", sample); | ||
| 27 | msg ("text actually read:\n%s", buffer); | ||
| 28 | fail ("expected text differs from actual"); | ||
| 29 | } | ||
| 30 | } | ||
