Make tests public. Rewrite most tests. Add tests.
[pintos-anon] / src / tests / vm / mmap-inherit.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 *) 0x54321000;
11   int handle;
12   pid_t child;
13
14   /* Open file, map, verify data. */
15   CHECK ((handle = open ("sample.txt")) > 1, "open \"sample.txt\"");
16   CHECK (mmap (handle, actual) != MAP_FAILED, "mmap \"sample.txt\"");
17   if (memcmp (actual, sample, strlen (sample)))
18     fail ("read of mmap'd file reported bad data");
19
20   /* Spawn child and wait. */
21   CHECK ((child = exec ("child-inherit")) != -1, "exec \"child-inherit\"");
22   quiet = true;
23   CHECK (wait (child) == -1, "wait for child (should return -1)");
24   quiet = false;
25
26   /* Verify data again. */
27   CHECK (!memcmp (actual, sample, strlen (sample)),
28          "checking that mmap'd file still has same data");
29 }