diff --git a/tests/core/test_mmap.in b/tests/core/test_mmap.in new file mode 100644 index 000000000..464002781 --- /dev/null +++ b/tests/core/test_mmap.in @@ -0,0 +1,38 @@ + + #include + #include + #include + + int main(int argc, char *argv[]) { + for (int i = 0; i < 10; i++) { + int* map = (int*)mmap(0, 5000, PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_ANON, -1, 0); + /* TODO: Should we align to 4k? + assert(((int)map) % 4096 == 0); // aligned + */ + assert(munmap(map, 5000) == 0); + } + + const int NUM_BYTES = 8 * 1024 * 1024; + const int NUM_INTS = NUM_BYTES / sizeof(int); + + int* map = (int*)mmap(0, NUM_BYTES, PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_ANON, -1, 0); + assert(map != MAP_FAILED); + + int i; + + for (i = 0; i < NUM_INTS; i++) { + map[i] = i; + } + + for (i = 0; i < NUM_INTS; i++) { + assert(map[i] == i); + } + + assert(munmap(map, NUM_BYTES) == 0); + + printf("hello,world"); + return 0; + } + \ No newline at end of file diff --git a/tests/core/test_mmap.out b/tests/core/test_mmap.out new file mode 100644 index 000000000..f2fff68f3 --- /dev/null +++ b/tests/core/test_mmap.out @@ -0,0 +1 @@ +hello,world \ No newline at end of file diff --git a/tests/test_core.py b/tests/test_core.py index 011546056..242494b68 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -4486,46 +4486,11 @@ return malloc(size); Settings.TOTAL_MEMORY = 128*1024*1024 - src = ''' - #include - #include - #include + test_path = path_from_root('tests', 'core', 'test_mmap') + src, output = (test_path + s for s in ('.in', '.out')) - int main(int argc, char *argv[]) { - for (int i = 0; i < 10; i++) { - int* map = (int*)mmap(0, 5000, PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_ANON, -1, 0); - /* TODO: Should we align to 4k? - assert(((int)map) % 4096 == 0); // aligned - */ - assert(munmap(map, 5000) == 0); - } - - const int NUM_BYTES = 8 * 1024 * 1024; - const int NUM_INTS = NUM_BYTES / sizeof(int); - - int* map = (int*)mmap(0, NUM_BYTES, PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_ANON, -1, 0); - assert(map != MAP_FAILED); - - int i; - - for (i = 0; i < NUM_INTS; i++) { - map[i] = i; - } - - for (i = 0; i < NUM_INTS; i++) { - assert(map[i] == i); - } - - assert(munmap(map, NUM_BYTES) == 0); - - printf("hello,world"); - return 0; - } - ''' - self.do_run(src, 'hello,world') - self.do_run(src, 'hello,world', force_c=True) + self.do_run_from_file(src, output) + self.do_run_from_file(src, output, force_c=True) def test_mmap_file(self): if self.emcc_args is None: return self.skip('requires emcc')