summaryrefslogtreecommitdiffstats
path: root/pintos-progos/tests/vm/mmap-write.c
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2012-03-26 12:54:45 +0200
committermanuel <manuel@mausz.at>2012-03-26 12:54:45 +0200
commitb5f0874cd96ee2a62aabc645b9626c2749cb6a01 (patch)
tree1262e4bbe0634de6650be130c36e0538240f4cbf /pintos-progos/tests/vm/mmap-write.c
downloadprogos-b5f0874cd96ee2a62aabc645b9626c2749cb6a01.tar.gz
progos-b5f0874cd96ee2a62aabc645b9626c2749cb6a01.tar.bz2
progos-b5f0874cd96ee2a62aabc645b9626c2749cb6a01.zip
initial pintos checkin
Diffstat (limited to 'pintos-progos/tests/vm/mmap-write.c')
-rw-r--r--pintos-progos/tests/vm/mmap-write.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/pintos-progos/tests/vm/mmap-write.c b/pintos-progos/tests/vm/mmap-write.c
new file mode 100644
index 0000000..46e8043
--- /dev/null
+++ b/pintos-progos/tests/vm/mmap-write.c
@@ -0,0 +1,32 @@
1/* Writes to a file through a mapping, and unmaps the file,
2 then reads the data in the file back using the read system
3 call to verify. */
4
5#include <string.h>
6#include <syscall.h>
7#include "tests/vm/sample.inc"
8#include "tests/lib.h"
9#include "tests/main.h"
10
11#define ACTUAL ((void *) 0x10000000)
12
13void
14test_main (void)
15{
16 int handle;
17 mapid_t map;
18 char buf[1024];
19
20 /* Write file via mmap. */
21 CHECK (create ("sample.txt", strlen (sample)), "create \"sample.txt\"");
22 CHECK ((handle = open ("sample.txt")) > 1, "open \"sample.txt\"");
23 CHECK ((map = mmap (handle, ACTUAL)) != MAP_FAILED, "mmap \"sample.txt\"");
24 memcpy (ACTUAL, sample, strlen (sample));
25 munmap (map);
26
27 /* Read back via read(). */
28 read (handle, buf, strlen (sample));
29 CHECK (!memcmp (buf, sample, strlen (sample)),
30 "compare read data against written data");
31 close (handle);
32}