aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_core.py38
-rw-r--r--tests/test_other.py37
2 files changed, 74 insertions, 1 deletions
diff --git a/tests/test_core.py b/tests/test_core.py
index 015f65bf..26bb71ef 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -507,6 +507,7 @@ class T(RunnerCore): # Short name, to make it more fun to use manually on the co
def test_asmjs_unknown_emscripten(self):
if self.emcc_args == None: return self.skip('needs emcc')
if not self.is_emscripten_abi(): return self.skip('asmjs-unknown-emscripten needed for asmjs-unknown-emscripten target test')
+ if os.environ.get('EMCC_FAST_COMPILER') == '0': return self.skip('fastcomp needed for asmjs-unknonw-emscripten target')
self.do_run(open(path_from_root('tests', 'asmjs-unknown-emscripten.c')).read(), '')
def test_cube2md5(self):
@@ -4066,6 +4067,28 @@ def process(filename):
self.emcc_args += ['--embed-file', 'three_numbers.txt']
self.do_run(src, 'match = 3\nx = -1.0, y = 0.1, z = -0.1\n')
+ def test_fileno(self):
+ if self.emcc_args is None: return self.skip('requires emcc')
+ open(os.path.join(self.get_dir(), 'empty.txt'), 'w').write('')
+ src = r'''
+ #include <stdio.h>
+ #include <unistd.h>
+ int main()
+ {
+ FILE* fp = fopen("empty.txt", "r");
+ if (fp) {
+ printf("%d\n", fp);
+ printf("%d\n", fileno(fp));
+ printf("%d\n", fileno((FILE*)42)); // nonexistent stream
+ } else {
+ printf("failed to open empty.txt\n");
+ }
+ return 0;
+ }
+ '''
+ self.emcc_args += ['--embed-file', 'empty.txt']
+ self.do_run(src, '4\n3\n-1\n')
+
def test_readdir(self):
src = open(path_from_root('tests', 'dirent', 'test_readdir.c'), 'r').read()
self.do_run(src, 'success', force_c=True)
@@ -4520,10 +4543,20 @@ PORT: 3979
### 'Medium' tests
def test_fannkuch(self):
+ try:
+ if self.run_name == 'slow2' or self.run_name == 'slow2asm':
+ old_target = os.environ.get('EMCC_LLVM_TARGET') or ''
+ os.environ['EMCC_LLVM_TARGET'] = "asmjs-unknown-emscripten" # testing for asm-emscripten target on non-fastcomp
results = [ (1,0), (2,1), (3,2), (4,4), (5,7), (6,10), (7, 16), (8,22) ]
for i, j in results:
src = open(path_from_root('tests', 'fannkuch.cpp'), 'r').read()
self.do_run(src, 'Pfannkuchen(%d) = %d.' % (i,j), [str(i)], no_build=i>1)
+ finally:
+ if self.run_name == 'slow2' or self.run_name == 'slow2asm':
+ if old_target:
+ os.environ['EMCC_LLVM_TARGET'] = old_target
+ else:
+ del os.environ['EMCC_LLVM_TARGET']
def test_raytrace(self):
if self.emcc_args is None: return self.skip('requires emcc')
@@ -5181,7 +5214,10 @@ def process(filename):
for name in glob.glob(path_from_root('tests', 'fuzz', '*.c')) + glob.glob(path_from_root('tests', 'fuzz', '*.cpp')):
#if os.path.basename(name) != '4.c': continue
if 'newfail' in name: continue
- if os.path.basename(name) == '18.cpp' and not os.environ.get('EMCC_FAST_COMPILER') != '0': continue # works only in fastcomp
+ if os.environ.get('EMCC_FAST_COMPILER') == '0' and os.path.basename(name) in [
+ '18.cpp', '15.c'
+ ]:
+ continue # works only in fastcomp
print name
self.do_run(open(path_from_root('tests', 'fuzz', name)).read(),
diff --git a/tests/test_other.py b/tests/test_other.py
index 55cc5635..f5a4ebc9 100644
--- a/tests/test_other.py
+++ b/tests/test_other.py
@@ -2391,3 +2391,40 @@ int main() {
assert 'emcc: warning: unaligned store' in output[1]
assert '@line 9 "src.cpp"' in output[1]
+ def test_no_exit_runtime(self):
+ open('code.cpp', 'w').write(r'''
+#include <stdio.h>
+
+template<int x>
+struct Waste {
+ Waste() {
+ printf("coming around %d\n", x);
+ }
+ ~Waste() {
+ printf("going away %d\n", x);
+ }
+};
+
+Waste<1> w1;
+Waste<2> w2;
+Waste<3> w3;
+Waste<4> w4;
+Waste<5> w5;
+
+int main(int argc, char **argv) {
+ return 0;
+}
+''')
+
+ for no_exit in [0, 1]:
+ for opts in [0, 1]:
+ print no_exit, opts
+ Popen([PYTHON, EMCC, '-O' + str(opts), 'code.cpp', '-s', 'NO_EXIT_RUNTIME=' + str(no_exit)]).communicate()
+ output = run_js(os.path.join(self.get_dir(), 'a.out.js'), stderr=PIPE, full_output=True, engine=NODE_JS)
+ src = open('a.out.js').read()
+ exit = 1-no_exit
+ assert 'coming around' in output
+ assert ('going away' in output) == exit, 'destructors should not run if no exit'
+ assert ('_ZN5WasteILi2EED1Ev' in src) == exit, 'destructors should not appear if no exit'
+ assert ('atexit(' in src) == exit, 'atexit should not appear or be called'
+