aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasilis Kalintiris <ehostunreach@gmail.com>2013-12-07 17:16:30 +0200
committerVasilis Kalintiris <ehostunreach@gmail.com>2013-12-07 19:36:02 +0200
commit179da486f99c85cb0d3d159d5eedf96f60cc6dcb (patch)
treef813183e4ab8f3bbc66d5afbeb0dd723c78d6252
parent98bb3dd7d7bb45eae92975a6f8ebf5ed4fc1ecab (diff)
Use do_run_from_file() for test_mmap
-rw-r--r--tests/core/test_mmap.in38
-rw-r--r--tests/core/test_mmap.out1
-rw-r--r--tests/test_core.py43
3 files changed, 43 insertions, 39 deletions
diff --git a/tests/core/test_mmap.in b/tests/core/test_mmap.in
new file mode 100644
index 00000000..46400278
--- /dev/null
+++ b/tests/core/test_mmap.in
@@ -0,0 +1,38 @@
+
+ #include <stdio.h>
+ #include <sys/mman.h>
+ #include <assert.h>
+
+ 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 00000000..f2fff68f
--- /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 01154605..242494b6 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 <stdio.h>
- #include <sys/mman.h>
- #include <assert.h>
-
- 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);
+ test_path = path_from_root('tests', 'core', 'test_mmap')
+ src, output = (test_path + s for s in ('.in', '.out'))
- 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')