summaryrefslogtreecommitdiffstats
path: root/tests/vm/mmap-lazy-seq.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/vm/mmap-lazy-seq.c')
-rw-r--r--tests/vm/mmap-lazy-seq.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/vm/mmap-lazy-seq.c b/tests/vm/mmap-lazy-seq.c
new file mode 100644
index 0000000..b8f07bd
--- /dev/null
+++ b/tests/vm/mmap-lazy-seq.c
@@ -0,0 +1,52 @@
1/* Create a large file, and mmap it several times, writing to
2 different pages. Then unmaps the file, and reads the data back
3 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/* Offset needs to be larger or equal to page size */
12#define OFFSET(i) (8192*(i))
13/* Number of times file is mmapped */
14#define N (8)
15/* Size of file */
16#define FILE_SIZE (1024*1024)
17/* Address for mmap */
18#define ACTUAL(i) ((void *) (0x10000000 + (i)*FILE_SIZE))
19
20
21void
22test_main (void)
23{
24 int i;
25 int handle;
26 mapid_t map[N];
27 char buf[1024];
28 /* create file */
29 CHECK (create ("sample.txt", FILE_SIZE), "create \"sample.txt\"");
30 CHECK ((handle = open ("sample.txt")) > 1, "open \"sample.txt\"");
31 /* mmap */
32 for (i = 0; i < N; i++) {
33 CHECK ((map[i] = mmap (handle, ACTUAL(i))) != MAP_FAILED, "mmap \"sample.txt\"");
34 }
35 /* write */
36 for (i = 0; i < N; i++) {
37 memcpy (buf, ACTUAL(i)+OFFSET(i+N), 1024); /* not checked */
38 memcpy (ACTUAL(i)+OFFSET(i), sample, strlen (sample));
39 }
40 /* munmap */
41 for (i = 0; i < N; i++) {
42 munmap (map[i]);
43 }
44 /* Read back via read(). */
45 for (i = 0; i < N; i++) {
46 seek (handle, OFFSET(i));
47 read (handle, buf, strlen (sample));
48 CHECK (!memcmp (buf, sample, strlen (sample)),
49 "compare read data against written data");
50 }
51 close (handle);
52}