Make tests public. Rewrite most tests. Add tests.
[pintos-anon] / src / tests / vm / mmap-read.c
1 #include <string.h>
2 #include <syscall.h>
3 #include "tests/vm/sample.inc"
4 #include "tests/lib.h"
5 #include "tests/main.h"
6
7 void
8 test_main (void)
9 {
10   char *actual = (char *) 0x10000000;
11   int handle;
12   mapid_t map;
13   size_t i;
14
15   CHECK ((handle = open ("sample.txt")) > 1, "open \"sample.txt\"");
16   CHECK ((map = mmap (handle, actual)) != MAP_FAILED, "mmap \"sample.txt\"");
17
18   /* Check that data is correct. */
19   if (memcmp (actual, sample, strlen (sample)))
20     fail ("read of mmap'd file reported bad data");
21
22   /* Verify that data is followed by zeros. */
23   for (i = strlen (sample); i < 4096; i++)
24     if (actual[i] != 0)
25       fail ("byte %zu of mmap'd region has value %02hhx (should be 0)",
26             i, actual[i]);
27
28   munmap (map);
29   close (handle);
30 }