1 /* Copyright Google, Inc. 2017
2 * Author: Zach Zimmerman
3 * mmap_vmm_test: tests mmap with fd's with access from
14 #include <parlib/parlib.h>
15 #include <parlib/timing.h>
16 #include <parlib/ros_debug.h>
18 #include <sys/types.h>
23 #include <vmm/vthread.h>
25 static struct virtual_machine vm = {.mtx = UTH_MUTEX_INIT};
33 static void mmap_testz(void)
36 for (char *i = addr; (void*)i < addr + nr_pgs * PGSIZE; i += STRIDE)
40 static void mmap_testy(void)
43 for (char *i = addr; (void*)i < addr + nr_pgs * PGSIZE; i += STRIDE)
47 void *worker_thread(void *arg)
51 for (i = 0; i < NUM_ITERS; ++i)
55 __asm__ __volatile__("hlt\n\t");
65 sprintf(inputfile, "/tmp/mmap-test-%d", pid);
67 fd = open(inputfile, O_RDWR | O_CREAT, 0666);
69 perror("Unable to open file");
73 ret = unlink(inputfile);
75 perror("UNLINK error");
79 //Increase the file size with ftruncate
80 ret = ftruncate(fd, nr_pgs * PGSIZE);
82 perror("FTRUNCATE error");
87 void *loc = (void*) 0x1000000;
89 addr = mmap(loc, nr_pgs * PGSIZE, PROT_WRITE | PROT_READ | PROT_EXEC,
91 if (addr == MAP_FAILED) {
92 perror("mmap failed");
96 printf("MMap got addr %p\n", addr);
97 printf("Spawning worker vmthread thread, etc...\n");
98 vthread_create(&vm, 0, (void*)&worker_thread, NULL);
100 while (!safe_to_exit)
103 for (char *i = addr; (void*)i < addr + nr_pgs * PGSIZE; i += STRIDE)
106 printf("mmap_file_vmm: test finished, doing teardown\n");
108 ret = munmap(addr, nr_pgs * PGSIZE);
110 perror("mmap_file_vmm: problem unmapping memory after test\n");
116 perror("mmap_file_vmm: problem closing file after test\n");
120 printf("mmap_file_vmm: PASSED\n");