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>
24 static struct virtual_machine vm;
32 static void mmap_testz(void)
35 for (char *i = addr; (void*)i < addr + nr_pgs * PGSIZE; i += STRIDE)
39 static void mmap_testy(void)
42 for (char *i = addr; (void*)i < addr + nr_pgs * PGSIZE; i += STRIDE)
46 void *worker_thread(void *arg)
50 for (i = 0; i < NUM_ITERS; ++i)
54 __asm__ __volatile__("hlt\n\t");
64 sprintf(inputfile, "/tmp/mmap-test-%d", pid);
66 fd = open(inputfile, O_RDWR | O_CREAT, 0666);
68 perror("Unable to open file");
72 ret = unlink(inputfile);
74 perror("UNLINK error");
78 //Increase the file size with ftruncate
79 ret = ftruncate(fd, nr_pgs * PGSIZE);
81 perror("FTRUNCATE error");
85 ret = vthread_attr_init(&vm, 0);
87 fprintf(stderr, "vmm_init failed: %r\n");
91 fprintf(stderr, "Vthread attr init finished\n");
93 void *loc = (void*) 0x1000000;
95 addr = mmap(loc, nr_pgs * PGSIZE, PROT_WRITE | PROT_READ | PROT_EXEC,
97 if (addr == MAP_FAILED) {
98 perror("mmap failed");
102 printf("MMap got addr %p\n", addr);
103 printf("Spawning worker vmthread thread, etc...\n");
104 vthread_create(&vm, 0, (void*)&worker_thread, NULL);
106 while (!safe_to_exit)
109 for (char *i = addr; (void*)i < addr + nr_pgs * PGSIZE; i += STRIDE)
112 printf("mmap_file_vmm: test finished, doing teardown\n");
114 ret = munmap(addr, nr_pgs * PGSIZE);
116 perror("mmap_file_vmm: problem unmapping memory after test\n");
122 perror("mmap_file_vmm: problem closing file after test\n");
126 printf("mmap_file_vmm: PASSED\n");