Make tests public. Rewrite most tests. Add tests.
[pintos-anon] / src / tests / vm / mmap-write.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 #define ACTUAL ((void *) 0x10000000)
8
9 void
10 test_main (void)
11 {
12   int handle;
13   mapid_t map;
14   char buf[1024];
15
16   /* Write file via mmap. */
17   CHECK (create ("sample.txt", strlen (sample)), "create \"sample.txt\"");
18   CHECK ((handle = open ("sample.txt")) > 1, "open \"sample.txt\"");
19   CHECK ((map = mmap (handle, ACTUAL)) != MAP_FAILED, "mmap \"sample.txt\"");
20   memcpy (ACTUAL, sample, strlen (sample));
21   munmap (map);
22
23   /* Read back via read(). */
24   read (handle, buf, strlen (sample));
25   CHECK (!memcmp (buf, sample, strlen (sample)),
26          "compare read data against written data");
27   close (handle);
28 }