aboutsummaryrefslogtreecommitdiff
path: root/tests/test_other.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_other.py')
-rw-r--r--tests/test_other.py101
1 files changed, 77 insertions, 24 deletions
diff --git a/tests/test_other.py b/tests/test_other.py
index 86e0eadf..11b2dcb3 100644
--- a/tests/test_other.py
+++ b/tests/test_other.py
@@ -169,7 +169,7 @@ Options that are modified or new in %s include:
if keep_debug:
assert ('(label)' in generated or '(label | 0)' in generated) == (opt_level <= 0), 'relooping should be in opt >= 1'
assert ('assert(STACKTOP < STACK_MAX' in generated) == (opt_level == 0), 'assertions should be in opt == 0'
- assert 'var $i;' in generated or 'var $i_0' in generated or 'var $storemerge3;' in generated or 'var $storemerge4;' in generated or '$i_04' in generated or '$i_05' in generated or 'var $original = 0' in generated, 'micro opts should always be on'
+ assert '$i' in generated or '$storemerge' in generated or '$original' in generated, 'micro opts should always be on'
if opt_level >= 2 and '-g' in params:
assert re.search('HEAP8\[\$?\w+ ?\+ ?\(+\$?\w+ ?', generated) or re.search('HEAP8\[HEAP32\[', generated), 'eliminator should create compound expressions, and fewer one-time vars' # also in -O1, but easier to test in -O2
assert ('_puts(' in generated) == (opt_level >= 1), 'with opt >= 1, llvm opts are run and they should optimize printf to puts'
@@ -819,8 +819,12 @@ f.close()
}),
]:
Building.COMPILER_TEST_OPTS = test_opts
+ if WINDOWS:
+ zlib_library = self.get_library('zlib', os.path.join('libz.a'), configure=['emconfigure.bat'], configure_args=['cmake', '.', '-DBUILD_SHARED_LIBS=OFF'], make=['mingw32-make'], make_args=[])
+ else:
+ zlib_library = self.get_library('zlib', os.path.join('libz.a'), make_args=['libz.a'])
test('zlib', path_from_root('tests', 'zlib', 'example.c'),
- self.get_library('zlib', os.path.join('libz.a'), make_args=['libz.a']),
+ zlib_library,
open(path_from_root('tests', 'zlib', 'ref.txt'), 'r').read(),
expected_ranges,
args=['-I' + path_from_root('tests', 'zlib')], suffix='c')
@@ -1440,10 +1444,12 @@ f.close()
extern "C" {
void something();
+ void elsey();
}
int main() {
something();
+ elsey();
return 0;
}
''')
@@ -1451,26 +1457,24 @@ f.close()
def clear(): try_delete('a.out.js')
for args in [[], ['-O2']]:
- clear()
- print 'warn', args
- output = Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'main.cpp'), '-s', 'WARN_ON_UNDEFINED_SYMBOLS=1'] + args, stderr=PIPE).communicate()
- self.assertContained('unresolved symbol: something', output[1])
-
- clear()
- output = Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'main.cpp')] + args, stderr=PIPE).communicate()
- self.assertNotContained('unresolved symbol: something\n', output[1])
-
- for args in [[], ['-O2']]:
- clear()
- print 'error', args
- output = Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'main.cpp'), '-s', 'ERROR_ON_UNDEFINED_SYMBOLS=1'] + args, stderr=PIPE).communicate()
- self.assertContained('unresolved symbol: something', output[1])
- assert not os.path.exists('a.out.js')
-
- clear()
- output = Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'main.cpp')] + args, stderr=PIPE).communicate()
- self.assertNotContained('unresolved symbol: something\n', output[1])
- assert os.path.exists('a.out.js')
+ for action in ['WARN', 'ERROR', None]:
+ for value in ([0, 1] if action else [0]):
+ clear()
+ print 'warn', args, action, value
+ extra = ['-s', action + '_ON_UNDEFINED_SYMBOLS=%d' % value] if action else []
+ output = Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'main.cpp')] + extra + args, stderr=PIPE).communicate()
+ if action == None or (action == 'WARN' and value):
+ self.assertContained('unresolved symbol: something', output[1])
+ self.assertContained('unresolved symbol: elsey', output[1])
+ assert os.path.exists('a.out.js')
+ elif action == 'ERROR' and value:
+ self.assertContained('unresolved symbol: something', output[1])
+ self.assertContained('unresolved symbol: elsey', output[1])
+ self.assertNotContained('warning', output[1])
+ assert not os.path.exists('a.out.js')
+ elif action == 'WARN' and not value:
+ self.assertNotContained('unresolved symbol', output[1])
+ assert os.path.exists('a.out.js')
def test_toobig(self):
# very large [N x i8], we should not oom in the compiler
@@ -1909,7 +1913,8 @@ done.
out, err = Popen([PYTHON, EMCC, path_from_root('tests', 'hello_world.c'), '-E'], stdout=PIPE).communicate()
assert not os.path.exists('a.out.js')
- assert '''tests/hello_world.c"''' in out
+ assert '''#line 1 ''' in out
+ assert '''hello_world.c"''' in out
assert '''printf("hello, world!''' in out
def test_demangle(self):
@@ -1927,6 +1932,7 @@ done.
EM_ASM(Module.print(demangle('_main')));
EM_ASM(Module.print(demangle('__Z2f2v')));
EM_ASM(Module.print(demangle('__Z12abcdabcdabcdi')));
+ EM_ASM(Module.print(demangle('__ZL12abcdabcdabcdi')));
EM_ASM(Module.print(demangle('__Z4testcsifdPvPiPc')));
EM_ASM(Module.print(demangle('__ZN4test5moarrEcslfdPvPiPc')));
EM_ASM(Module.print(demangle('__ZN4Waka1f12a234123412345pointEv')));
@@ -1937,6 +1943,7 @@ done.
EM_ASM(Module.print(demangle('__Z9parsewordRPKciRi')));
EM_ASM(Module.print(demangle('__Z5multiwahtjmxyz')));
EM_ASM(Module.print(demangle('__Z1aA32_iPA5_c')));
+ EM_ASM(Module.print(demangle('__ZN21FWakaGLXFleeflsMarfooC2EjjjPKvbjj')));
one(17);
return 0;
}
@@ -1944,9 +1951,11 @@ done.
Popen([PYTHON, EMCC, 'src.cpp', '-s', 'LINKABLE=1']).communicate()
output = run_js('a.out.js')
- self.assertContained('''main
+ self.assertContained('''operator new()
+_main
f2()
abcdabcdabcd(int)
+abcdabcdabcd(int)
test(char, short, int, float, double, void*, int*, char*)
test::moarr(char, short, long, float, double, void*, int*, char*)
Waka::f::a23412341234::point()
@@ -1957,6 +1966,7 @@ __cxxabiv1::__si_class_type_info::search_below_dst(__cxxabiv1::__dynamic_cast_in
parseword(char*&, int, int&)
multi(wchar_t, signed char, unsigned char, unsigned short, unsigned int, unsigned long, long long, unsigned long long, ...)
a(int [32], char [5]*)
+FWakaGLXFleeflsMarfoo::FWakaGLXFleeflsMarfoo(unsigned int, unsigned int, unsigned int, void*, bool, unsigned int, unsigned int)
''', output)
# test for multiple functions in one stack trace
assert 'one(int)' in output
@@ -2010,6 +2020,49 @@ a(int [32], char [5]*)
try_delete(path_from_root('tests', 'Module-exports', 'test.js'))
try_delete(path_from_root('tests', 'Module-exports', 'test.js.map'))
+ def test_fs_stream_proto(self):
+ open('src.cpp', 'wb').write(r'''
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <string.h>
+
+int main()
+{
+ int file_size = 0;
+ int h = open("src.cpp", O_RDONLY, 0666);
+ if (0 != h)
+ {
+ FILE* file = fdopen(h, "rb");
+ if (0 != file)
+ {
+ fseek(file, 0, SEEK_END);
+ file_size = ftell(file);
+ fseek(file, 0, SEEK_SET);
+ }
+ else
+ {
+ printf("fdopen() failed: %s\n", strerror(errno));
+ return 10;
+ }
+ close(h);
+ printf("File size: %d\n", file_size);
+ }
+ else
+ {
+ printf("open() failed: %s\n", strerror(errno));
+ return 10;
+ }
+ return 0;
+}
+ ''')
+ Popen([PYTHON, EMCC, 'src.cpp', '--embed-file', 'src.cpp']).communicate()
+ for engine in JS_ENGINES:
+ out = run_js('a.out.js', engine=engine, stderr=PIPE, full_output=True)
+ self.assertContained('File size: 722', out)
+
def test_simd(self):
self.clear()
Popen([PYTHON, EMCC, path_from_root('tests', 'linpack.c'), '-O2', '-DSP', '--llvm-opts', '''['-O3', '-vectorize', '-vectorize-loops', '-bb-vectorize-vector-bits=128', '-force-vector-width=4']''']).communicate()