diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-12-30 12:49:24 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-12-30 12:49:43 -0800 |
commit | b500e12963793d7c297f9738637200d42baeb69c (patch) | |
tree | 18e15e2e4ee75709e1b87d80900923ee7353745c /tests | |
parent | a16fb0dcb7dc001646ffd792e47bfa46c875d0a1 (diff) |
fix mmap; fixes #769
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/runner.py | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/tests/runner.py b/tests/runner.py index 32f69781..b1852ff2 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -6239,7 +6239,7 @@ void*:16 } ''' self.do_run(src, '*10,22*') - + def test_mmap(self): Settings.TOTAL_MEMORY = 100*1024*1024 @@ -6282,6 +6282,33 @@ void*:16 self.do_run(src, 'hello,world') self.do_run(src, 'hello,world', force_c=True) + def test_mmap_file(self): + if self.emcc_args is None: return self.skip('requires emcc') + self.emcc_args += ['--embed-file', 'data.dat'] + + open(self.in_dir('data.dat'), 'w').write('data from the file ' + ('.' * 9000)) + + src = r''' + #include <stdio.h> + #include <sys/mman.h> + + int main() { + printf("*\n"); + FILE *f = fopen("data.dat", "r"); + char *m; + m = (char*)mmap(NULL, 9000, PROT_READ, MAP_PRIVATE, fileno(f), 0); + for (int i = 0; i < 20; i++) putchar(m[i]); + munmap(m, 9000); + printf("\n"); + m = (char*)mmap(NULL, 9000, PROT_READ, MAP_PRIVATE, fileno(f), 5); + for (int i = 0; i < 20; i++) putchar(m[i]); + munmap(m, 9000); + printf("\n*\n"); + return 0; + } + ''' + self.do_run(src, '*\ndata from the file .\nfrom the file ......\n*\n') + def test_cubescript(self): if self.emcc_args is not None and '-O2' in self.emcc_args: self.emcc_args += ['--closure', '1'] # Use closure here for some additional coverage |