aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/embind/shell.html6
-rwxr-xr-xtests/fuzz/creduce_tester.py54
-rwxr-xr-xtests/fuzz/csmith_driver.py30
-rw-r--r--tests/hello_world_gles_shell.html3
-rwxr-xr-xtests/runner.py181
5 files changed, 116 insertions, 158 deletions
diff --git a/tests/embind/shell.html b/tests/embind/shell.html
index 6664ec78..c3655e03 100644
--- a/tests/embind/shell.html
+++ b/tests/embind/shell.html
@@ -85,10 +85,6 @@
};
Module.setStatus('Downloading...');
</script>
- <script type='text/javascript'>
-
- {{{ SCRIPT_CODE }}}
-
- </script>
+ <script type='text/javascript'>{{{ SCRIPT_CODE }}}</script>
</body>
</html>
diff --git a/tests/fuzz/creduce_tester.py b/tests/fuzz/creduce_tester.py
index c3460e9d..d5618c2e 100755
--- a/tests/fuzz/creduce_tester.py
+++ b/tests/fuzz/creduce_tester.py
@@ -1,53 +1,53 @@
#!/usr/bin/python
'''
-Runs csmith, a C fuzzer, and looks for bugs
+Usage: creduce ./creduce_tester.py newfail1.c
'''
-import os, sys, difflib
+import os, sys
from subprocess import Popen, PIPE, STDOUT
sys.path += [os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'tools')]
-import shared
+import shared, jsrun
+
+# creduce will only pass the filename of the C file as the first arg, so other
+# configuration options will have to be hardcoded.
+CSMITH_CFLAGS = ['-I', os.path.join(os.environ['CSMITH_PATH'], 'runtime')]
+ENGINE = shared.JS_ENGINES[0]
+EMCC_ARGS = ['-O2', '-s', 'ASM_JS=1', '-s', 'PRECISE_I64_MATH=1', '-s',
+ 'PRECISE_I32_MUL=1']
filename = sys.argv[1]
+obj_filename = os.path.splitext(filename)[0]
+js_filename = obj_filename + '.js'
print 'testing file', filename
-print '2) Compile natively'
-shared.try_delete(filename)
-shared.execute([shared.CLANG_CC, '-O2', filename + '.c', '-o', filename] + CSMITH_CFLAGS, stderr=PIPE)
-assert os.path.exists(filename)
-print '3) Run natively'
try:
- correct = shared.timeout_run(Popen([filename], stdout=PIPE, stderr=PIPE), 3)
+ print '2) Compile natively'
+ shared.check_execute([shared.CLANG_CC, '-O2', filename, '-o', obj_filename] + CSMITH_CFLAGS)
+ print '3) Run natively'
+ correct = jsrun.timeout_run(Popen([obj_filename], stdout=PIPE, stderr=PIPE), 3)
except Exception, e:
print 'Failed or infinite looping in native, skipping', e
- notes['invalid'] += 1
- os.exit(0) # boring
+ sys.exit(1) # boring
print '4) Compile JS-ly and compare'
def try_js(args):
- shared.try_delete(filename + '.js')
- shared.execute([shared.EMCC, '-O2', '-s', 'ASM_JS=1', '-s', 'PRECISE_I64_MATH=1', '-s', 'PRECISE_I32_MUL=1', filename + '.c', '-o', filename + '.js'] + CSMITH_CFLAGS + args, stderr=PIPE)
- assert os.path.exists(filename + '.js')
- js = shared.run_js(filename + '.js', stderr=PIPE, engine=engine1)
- assert correct == js, ''.join([a.rstrip()+'\n' for a in difflib.unified_diff(correct.split('\n'), js.split('\n'), fromfile='expected', tofile='actual')])
+ shared.check_execute([shared.EMCC] + EMCC_ARGS + CSMITH_CFLAGS + args +
+ [filename, '-o', js_filename])
+ js = shared.run_js(js_filename, stderr=PIPE, engine=ENGINE)
+ assert correct == js
# Try normally, then try unaligned because csmith does generate nonportable code that requires x86 alignment
-ok = False
-normal = True
-for args, note in [([], None), (['-s', 'UNALIGNED_MEMORY=1'], 'unaligned')]:
+# If you are sure that alignment is not the cause, disable it for a faster reduction
+for args in [[]]:
try:
try_js(args)
- ok = True
- if note:
- notes[note] += 1
break
except Exception, e:
- print e
- normal = False
-if not ok: sys.exit(1)
-
-sys.exit(0) # boring
+ pass
+else:
+ sys.exit(0)
+sys.exit(1) # boring
diff --git a/tests/fuzz/csmith_driver.py b/tests/fuzz/csmith_driver.py
index b60e67f7..c987a3be 100755
--- a/tests/fuzz/csmith_driver.py
+++ b/tests/fuzz/csmith_driver.py
@@ -1,11 +1,14 @@
#!/usr/bin/python
'''
-Runs csmith, a C fuzzer, and looks for bugs
+Runs csmith, a C fuzzer, and looks for bugs.
+
+CSMITH_PATH should be set to something like /usr/local/include/csmith
'''
import os, sys, difflib, shutil
-from subprocess import Popen, PIPE, STDOUT
+from distutils.spawn import find_executable
+from subprocess import check_call, Popen, PIPE, STDOUT, CalledProcessError
sys.path += [os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'tools')]
import shared
@@ -15,8 +18,11 @@ engine2 = eval('shared.' + sys.argv[2]) if len(sys.argv) > 2 else None
print 'testing js engines', engine1, engine2
-CSMITH = os.path.expanduser('~/Dev/csmith/src/csmith')
-CSMITH_CFLAGS = ['-I' + os.path.expanduser('~/Dev/csmith/runtime/')]
+CSMITH = os.environ.get('CSMITH') or find_executable('csmith')
+assert CSMITH, 'Could not find CSmith on your PATH. Please set the environment variable CSMITH.'
+CSMITH_PATH = os.environ.get('CSMITH_PATH')
+assert CSMITH_PATH, 'Please set the environment variable CSMITH_PATH.'
+CSMITH_CFLAGS = ['-I', os.path.join(CSMITH_PATH, 'runtime')]
filename = os.path.join(shared.CANONICAL_TEMP_DIR, 'fuzzcode')
@@ -31,7 +37,7 @@ fails = 0
while 1:
print 'Tried %d, notes: %s' % (tried, notes)
print '1) Generate C'
- shared.execute([CSMITH, '--no-volatiles', '--no-math64', '--no-packed-struct'],# +
+ check_call([CSMITH, '--no-volatiles', '--no-math64', '--no-packed-struct'],# +
#['--max-block-depth', '2', '--max-block-size', '2', '--max-expr-complexity', '2', '--max-funcs', '2'],
stdout=open(filename + '.c', 'w'))
#shutil.copyfile(filename + '.c', 'testcase%d.c' % tried)
@@ -41,11 +47,11 @@ while 1:
print '2) Compile natively'
shared.try_delete(filename)
- shared.execute([shared.CLANG_CC, '-O2', filename + '.c', '-o', filename + '1'] + CSMITH_CFLAGS, stderr=PIPE) # + shared.EMSDK_OPTS
- shared.execute([shared.CLANG_CC, '-O2', '-emit-llvm', '-c', '-Xclang', '-triple=i386-pc-linux-gnu', filename + '.c', '-o', filename + '.bc'] + CSMITH_CFLAGS + shared.EMSDK_OPTS, stderr=PIPE)
- shared.execute([shared.path_from_root('tools', 'nativize_llvm.py'), filename + '.bc'], stdout=PIPE, stderr=PIPE)
+ shared.check_execute([shared.CLANG_CC, '-O2', filename + '.c', '-o', filename + '1'] + CSMITH_CFLAGS) # + shared.EMSDK_OPTS
+ shared.check_execute([shared.CLANG_CC, '-O2', '-emit-llvm', '-c', '-Xclang', '-triple=i386-pc-linux-gnu', filename + '.c', '-o', filename + '.bc'] + CSMITH_CFLAGS + shared.EMSDK_OPTS)
+ shared.check_execute([shared.path_from_root('tools', 'nativize_llvm.py'), filename + '.bc'])
shutil.move(filename + '.bc.run', filename + '2')
- shared.execute([shared.CLANG_CC, filename + '.c', '-o', filename + '3'] + CSMITH_CFLAGS, stderr=PIPE)
+ shared.check_execute([shared.CLANG_CC, filename + '.c', '-o', filename + '3'] + CSMITH_CFLAGS)
print '3) Run natively'
try:
correct1 = shared.jsrun.timeout_run(Popen([filename + '1'], stdout=PIPE, stderr=PIPE), 3)
@@ -65,7 +71,7 @@ while 1:
def try_js(args):
shared.try_delete(filename + '.js')
print '(compile)'
- shared.execute([shared.EMCC, '-O2', '-s', 'ASM_JS=1', filename + '.c', '-o', filename + '.js'] + CSMITH_CFLAGS + args, stderr=PIPE)
+ shared.check_execute([shared.EMCC, '-O2', '-s', 'ASM_JS=1', filename + '.c', '-o', filename + '.js'] + CSMITH_CFLAGS + args)
assert os.path.exists(filename + '.js')
print '(run)'
js = shared.run_js(filename + '.js', stderr=PIPE, engine=engine1, check_timeout=True)
@@ -91,7 +97,7 @@ while 1:
print "EMSCRIPTEN BUG"
notes['embug'] += 1
fails += 1
- shutil.copyfile('fuzzcode.c', 'newfail%d.c' % fails)
+ shutil.copyfile(filename + '.c', 'newfail%d.c' % fails)
continue
#if not ok:
# try: # finally, try with safe heap. if that is triggered, this is nonportable code almost certainly
@@ -118,7 +124,7 @@ while 1:
print "ODIN VALIDATION BUG"
notes['embug'] += 1
fails += 1
- shutil.copyfile('fuzzcode.c', 'newfail%d.c' % fails)
+ shutil.copyfile(filename + '.c', 'newfail%d.c' % fails)
continue
js2 = js2.replace('\nwarning: Successfully compiled asm.js code\n', '')
diff --git a/tests/hello_world_gles_shell.html b/tests/hello_world_gles_shell.html
index 4abee90c..2459d755 100644
--- a/tests/hello_world_gles_shell.html
+++ b/tests/hello_world_gles_shell.html
@@ -48,9 +48,8 @@
}
Module.postRun = doTest;
- // The compiled code
- {{{ SCRIPT_CODE }}}
</script>
+ <script>{{{ SCRIPT_CODE }}}</script>
</body>
</html>
diff --git a/tests/runner.py b/tests/runner.py
index 46dc5e11..2ce72240 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -230,11 +230,11 @@ process(sys.argv[1])
os.remove(f + '.o')
except:
pass
- args = [PYTHON, EMCC] + Building.COMPILER_TEST_OPTS + \
+ args = [PYTHON, EMCC] + Building.COMPILER_TEST_OPTS + Settings.serialize() + \
['-I', dirname, '-I', os.path.join(dirname, 'include')] + \
map(lambda include: '-I' + include, includes) + \
['-c', f, '-o', f + '.o']
- output = Popen(args, stdout=PIPE, stderr=self.stderr_redirect).communicate()[0]
+ output = Popen(args, stdout=PIPE, stderr=self.stderr_redirect if not DEBUG else None).communicate()[0]
assert os.path.exists(f + '.o'), 'Source compilation error: ' + output
# Link all files
@@ -435,7 +435,7 @@ process(sys.argv[1])
sys.argv = map(lambda arg: arg if not arg.startswith('test_') else 'default.' + arg, sys.argv)
-test_modes = ['default', 'o1', 'o2', 'asm1', 'asm2', 'asm2g', 'asm2x86', 's_0_0', 's_0_1', 's_1_0', 's_1_1']
+test_modes = ['default', 'o1', 'o2', 'asm1', 'asm2', 'asm2g', 'asm2x86', 's_0_0', 's_0_1']
test_index = 0
@@ -2104,12 +2104,12 @@ Succeeded!
}
return int(&x); // both for the number, and forces x to not be nativized
}
- int main()
+ int main(int argc, char **argv)
{
// We should get the same value for the first and last - stack has unwound
- int x1 = test(0);
+ int x1 = test(argc - 2);
int x2 = test(100);
- int x3 = test(0);
+ int x3 = test((argc - 2) / 4);
printf("*%d,%d*\\n", x3-x1, x2 != x1);
return 0;
}
@@ -4079,7 +4079,7 @@ def process(filename):
#include <assert.h>
#include "emscripten.h"
- int main()
+ int main(int argc, char **argv)
{
char *buf1 = (char*)malloc(100);
char *data1 = "hello";
@@ -4093,6 +4093,8 @@ def process(filename):
int totalMemory = emscripten_run_script_int("TOTAL_MEMORY");
char *buf3 = (char*)malloc(totalMemory+1);
+ buf3[argc] = (int)buf2;
+ if (argc % 7 == 6) printf("%d\n", memcpy(buf3, buf1, argc));
char *buf4 = (char*)malloc(100);
float *buf5 = (float*)malloc(100);
//printf("totalMemory: %d bufs: %d,%d,%d,%d,%d\n", totalMemory, buf1, buf2, buf3, buf4, buf5);
@@ -4230,6 +4232,8 @@ def process(filename):
''', args=['34962', '26214', '35040'])
def test_indirectbr(self):
+ Building.COMPILER_TEST_OPTS = filter(lambda x: x != '-g', Building.COMPILER_TEST_OPTS)
+
src = '''
#include <stdio.h>
int main(void) {
@@ -7550,11 +7554,11 @@ def process(filename):
return 0;
}
'''
- self.do_run(src, '''www.cheezburger.com : 1 : 4
+ self.do_run(src, '''www.cheezburger.com : 2 : 4
* -84.29.1.0.
-fail.on.this.never.work : 1 : 4
+fail.on.this.never.work : 2 : 4
* -84.29.2.0.
-localhost : 1 : 4
+localhost : 2 : 4
* -84.29.3.0.
''')
@@ -8217,7 +8221,7 @@ void*:16
if self.run_name == 'o2':
self.emcc_args += ['--closure', '1'] # Use closure here for some additional coverage
- Building.COMPILER_TEST_OPTS = [] # remove -g, so we have one test without it by default
+ Building.COMPILER_TEST_OPTS = filter(lambda x: x != '-g', Building.COMPILER_TEST_OPTS) # remove -g, so we have one test without it by default
if self.emcc_args is None: Settings.SAFE_HEAP = 0 # Has some actual loads of unwritten-to places, in the C++ code...
# Overflows happen in hash loop
@@ -8249,7 +8253,7 @@ void*:16
def test_gcc_unmangler(self):
Settings.NAMED_GLOBALS = 1 # test coverage for this
- Building.COMPILER_TEST_OPTS = ['-I' + path_from_root('third_party')]
+ Building.COMPILER_TEST_OPTS += ['-I' + path_from_root('third_party')]
self.do_run(open(path_from_root('third_party', 'gcc_demangler.c')).read(), '*d_demangle(char const*, int, unsigned int*)*', args=['_ZL10d_demanglePKciPj'])
@@ -8364,6 +8368,8 @@ def process(filename):
force_c=True)
def test_zlib(self):
+ if not Settings.USE_TYPED_ARRAYS == 2: return self.skip('works in general, but cached build will be optimized and fail, so disable this')
+
if Settings.ASM_JS:
self.banned_js_engines = [NODE_JS] # TODO investigate
@@ -8472,6 +8478,8 @@ def process(filename):
def test_openjpeg(self):
if self.emcc_args is None: return self.skip('needs libc for getopt')
+ Building.COMPILER_TEST_OPTS = filter(lambda x: x != '-g', Building.COMPILER_TEST_OPTS) # remove -g, so we have one test without it by default
+
if Settings.USE_TYPED_ARRAYS == 2:
Settings.CORRECT_SIGNS = 1
else:
@@ -8593,6 +8601,7 @@ def process(filename):
def test_python(self):
if self.emcc_args is None: return self.skip('requires emcc')
if Settings.QUANTUM_SIZE == 1: return self.skip('TODO: make this work')
+ if not self.is_le32(): return self.skip('fails on non-le32') # FIXME
#Settings.EXPORTED_FUNCTIONS += ['_PyRun_SimpleStringFlags'] # for the demo
@@ -8692,6 +8701,7 @@ def process(filename):
def test_autodebug(self):
if Building.LLVM_OPTS: return self.skip('LLVM opts mess us up')
+ Building.COMPILER_TEST_OPTS += ['--llvm-opts', '0']
# Run a test that should work, generating some code
self.test_structs()
@@ -8970,13 +8980,11 @@ def process(filename):
self.do_run(src, output)
shutil.move(self.in_dir('src.cpp.o.js'), self.in_dir('normal.js'))
- self.emcc_args.append('-s')
- self.emcc_args.append('ASM_JS=0')
+ Settings.ASM_JS = 0
Settings.PGO = 1
self.do_run(src, output)
+ Settings.ASM_JS = 1
Settings.PGO = 0
- self.emcc_args.append('-s')
- self.emcc_args.append('ASM_JS=1')
shutil.move(self.in_dir('src.cpp.o.js'), self.in_dir('pgo.js'))
pgo_output = run_js(self.in_dir('pgo.js')).split('\n')[1]
@@ -9699,7 +9707,9 @@ def process(filename):
if Settings.ASM_JS: return self.skip('asm always has corrections on')
if '-g' not in Building.COMPILER_TEST_OPTS: Building.COMPILER_TEST_OPTS.append('-g')
- if self.emcc_args: self.emcc_args += ['--llvm-opts', '0'] # llvm full opts make the expected failures here not happen
+ if self.emcc_args:
+ self.emcc_args += ['--llvm-opts', '0'] # llvm full opts make the expected failures here not happen
+ Building.COMPILER_TEST_OPTS += ['--llvm-opts', '0']
Settings.CHECK_SIGNS = 0
Settings.CHECK_OVERFLOWS = 0
@@ -10005,7 +10015,7 @@ finalizing 3 (global == 0)
''')
# Generate tests for everything
- def make_run(fullname, name=-1, compiler=-1, llvm_opts=0, embetter=0, quantum_size=0, typed_arrays=0, emcc_args=None, env='{}'):
+ def make_run(fullname, name=-1, compiler=-1, embetter=0, quantum_size=0, typed_arrays=0, emcc_args=None, env='{}'):
exec('''
class %s(T):
run_name = '%s'
@@ -10040,9 +10050,18 @@ class %s(T):
Building.LLVM_OPTS = 0
if '-O2' in self.emcc_args:
Building.COMPILER_TEST_OPTS = [] # remove -g in -O2 tests, for more coverage
+ #Building.COMPILER_TEST_OPTS += self.emcc_args
+ for arg in self.emcc_args:
+ if arg.startswith('-O'):
+ Building.COMPILER_TEST_OPTS.append(arg) # so bitcode is optimized too, this is for cpp to ll
+ else:
+ try:
+ key, value = arg.split('=')
+ Settings[key] = value # forward -s K=V
+ except:
+ pass
return
- llvm_opts = %d # 1 is yes, 2 is yes and unsafe
embetter = %d
quantum_size = %d
# TODO: Move much of these to a init() function in shared.py, and reuse that
@@ -10052,14 +10071,13 @@ class %s(T):
Settings.MICRO_OPTS = embetter
Settings.QUANTUM_SIZE = quantum_size
Settings.ASSERTIONS = 1-embetter
- Settings.SAFE_HEAP = 1-(embetter and llvm_opts)
- Building.LLVM_OPTS = llvm_opts
- Settings.CHECK_OVERFLOWS = 1-(embetter or llvm_opts)
- Settings.CORRECT_OVERFLOWS = 1-(embetter and llvm_opts)
+ Settings.SAFE_HEAP = 1-embetter
+ Settings.CHECK_OVERFLOWS = 1-embetter
+ Settings.CORRECT_OVERFLOWS = 1-embetter
Settings.CORRECT_SIGNS = 0
Settings.CORRECT_ROUNDINGS = 0
Settings.CORRECT_OVERFLOWS_LINES = CORRECT_SIGNS_LINES = CORRECT_ROUNDINGS_LINES = SAFE_HEAP_LINES = []
- Settings.CHECK_SIGNS = 0 #1-(embetter or llvm_opts)
+ Settings.CHECK_SIGNS = 0 #1-embetter
Settings.RUNTIME_TYPE_INFO = 0
Settings.DISABLE_EXCEPTION_CATCHING = 0
Settings.INCLUDE_FULL_LIBRARY = 0
@@ -10068,12 +10086,10 @@ class %s(T):
Settings.EMULATE_UNALIGNED_ACCESSES = int(Settings.USE_TYPED_ARRAYS == 2 and Building.LLVM_OPTS == 2)
Settings.DOUBLE_MODE = 1 if Settings.USE_TYPED_ARRAYS and Building.LLVM_OPTS == 0 else 0
Settings.PRECISE_I64_MATH = 0
- Settings.NAMED_GLOBALS = 0 if not (embetter and llvm_opts) else 1
-
- Building.pick_llvm_opts(3)
+ Settings.NAMED_GLOBALS = 0 if not embetter else 1
TT = %s
-''' % (fullname, fullname, env, fullname, fullname, compiler, str(emcc_args), llvm_opts, embetter, quantum_size, typed_arrays, fullname))
+''' % (fullname, fullname, env, fullname, fullname, compiler, str(emcc_args), embetter, quantum_size, typed_arrays, fullname))
return TT
# Make one run with the defaults
@@ -10092,16 +10108,14 @@ TT = %s
exec('''asm2x86 = make_run("asm2x86", compiler=CLANG, emcc_args=["-O2", "-g", "-s", "CHECK_HEAP_ALIGN=1"], env='{"EMCC_LLVM_TARGET": "i386-pc-linux-gnu"}')''')
# Make custom runs with various options
- for compiler, quantum, embetter, typed_arrays, llvm_opts in [
- (CLANG, 4, 0, 0, 0),
- (CLANG, 4, 0, 0, 1),
- (CLANG, 4, 1, 1, 0),
- (CLANG, 4, 1, 1, 1),
+ for compiler, quantum, embetter, typed_arrays in [
+ (CLANG, 4, 0, 0),
+ (CLANG, 4, 1, 1),
]:
- fullname = 's_%d_%d%s%s' % (
- llvm_opts, embetter, '' if quantum == 4 else '_q' + str(quantum), '' if typed_arrays in [0, 1] else '_t' + str(typed_arrays)
+ fullname = 's_0_%d%s%s' % (
+ embetter, '' if quantum == 4 else '_q' + str(quantum), '' if typed_arrays in [0, 1] else '_t' + str(typed_arrays)
)
- exec('%s = make_run(fullname, %r,%r,%d,%d,%d,%d)' % (fullname, fullname, compiler, llvm_opts, embetter, quantum, typed_arrays))
+ exec('%s = make_run(fullname, %r,%r,%d,%d,%d)' % (fullname, fullname, compiler, embetter, quantum, typed_arrays))
del T # T is just a shape for the specific subclasses, we don't test it itself
@@ -10235,23 +10249,25 @@ Options that are modified or new in %s include:
(['-o', 'something.js', '-O3', '-s', 'ASM_JS=0'], 3, None, 1, 1),
# and, test compiling to bitcode first
(['-o', 'something.bc'], 0, [], 0, 0),
- (['-o', 'something.bc'], 0, ['-O0'], 0, 0),
- (['-o', 'something.bc'], 1, ['-O1'], 0, 0),
- (['-o', 'something.bc'], 2, ['-O2'], 0, 0),
- (['-o', 'something.bc'], 3, ['-O3', '-s', 'ASM_JS=0'], 1, 0),
- (['-O1', '-o', 'something.bc'], 0, [], 0, 0), # -Ox is ignored and warned about
+ (['-o', 'something.bc', '-O0'], 0, [], 0, 0),
+ (['-o', 'something.bc', '-O1'], 1, ['-O1'], 0, 0),
+ (['-o', 'something.bc', '-O2'], 2, ['-O2'], 0, 0),
+ (['-o', 'something.bc', '-O3'], 3, ['-O3', '-s', 'ASM_JS=0'], 1, 0),
+ (['-O1', '-o', 'something.bc'], 1, [], 0, 0),
]:
print params, opt_level, bc_params, closure, has_malloc
self.clear()
keep_debug = '-g' in params
- output = Popen([PYTHON, compiler, path_from_root('tests', 'hello_world_loop' + ('_malloc' if has_malloc else '') + '.cpp')] + params,
+ args = [PYTHON, compiler, path_from_root('tests', 'hello_world_loop' + ('_malloc' if has_malloc else '') + '.cpp')] + params
+ print '..', args
+ output = Popen(args,
stdout=PIPE, stderr=PIPE).communicate()
assert len(output[0]) == 0, output[0]
if bc_params is not None:
- if '-O1' in params and 'something.bc' in params:
- assert '-Ox flags ignored, since not generating JavaScript' in output[1]
assert os.path.exists('something.bc'), output[1]
- output = Popen([PYTHON, compiler, 'something.bc', '-o', 'something.js'] + bc_params, stdout=PIPE, stderr=PIPE).communicate()
+ bc_args = [PYTHON, compiler, 'something.bc', '-o', 'something.js'] + bc_params
+ print '....', bc_args
+ output = Popen(bc_args, stdout=PIPE, stderr=PIPE).communicate()
assert os.path.exists('something.js'), output[1]
assert ('Applying some potentially unsafe optimizations!' in output[1]) == (opt_level >= 3), 'unsafe warning should appear in opt >= 3'
self.assertContained('hello, world!', run_js('something.js'))
@@ -11500,64 +11516,6 @@ seeked= file.
code = open('a.out.js').read()
assert 'SAFE_HEAP' in code, 'valid -s option had an effect'
- def test_optimize_normally(self):
- assert not os.environ.get('EMCC_OPTIMIZE_NORMALLY')
- assert not os.environ.get('EMCC_DEBUG')
-
- for optimize_normally in [0, 1]:
- print optimize_normally
- try:
- if optimize_normally: os.environ['EMCC_OPTIMIZE_NORMALLY'] = '1'
- os.environ['EMCC_DEBUG'] = '1'
-
- open(self.in_dir('main.cpp'), 'w').write(r'''
- extern "C" {
- void something();
- }
-
- int main() {
- something();
- return 0;
- }
- ''')
- open(self.in_dir('supp.cpp'), 'w').write(r'''
- #include <stdio.h>
-
- extern "C" {
- void something() {
- printf("yello\n");
- }
- }
- ''')
- out, err = Popen([PYTHON, EMCC, self.in_dir('main.cpp'), '-O2', '-o', 'main.o'], stdout=PIPE, stderr=PIPE).communicate()
- assert ("emcc: LLVM opts: ['-O3']" in err) == optimize_normally
- assert (' with -O3 since EMCC_OPTIMIZE_NORMALLY defined' in err) == optimize_normally
-
- out, err = Popen([PYTHON, EMCC, self.in_dir('supp.cpp'), '-O2', '-o', 'supp.o'], stdout=PIPE, stderr=PIPE).communicate()
- assert ("emcc: LLVM opts: ['-O3']" in err) == optimize_normally
- assert (' with -O3 since EMCC_OPTIMIZE_NORMALLY defined' in err) == optimize_normally
-
- out, err = Popen([PYTHON, EMCC, self.in_dir('main.o'), self.in_dir('supp.o'), '-O2', '-o', 'both.o'], stdout=PIPE, stderr=PIPE).communicate()
- assert "emcc: LLVM opts: ['-O3']" not in err
- assert ' with -O3 since EMCC_OPTIMIZE_NORMALLY defined' not in err
- assert ('despite EMCC_OPTIMIZE_NORMALLY since not source code' in err) == optimize_normally
-
- out, err = Popen([PYTHON, EMCC, self.in_dir('main.cpp'), self.in_dir('supp.cpp'), '-O2', '-o', 'both2.o'], stdout=PIPE, stderr=PIPE).communicate()
- assert ("emcc: LLVM opts: ['-O3']" in err) == optimize_normally
- assert (' with -O3 since EMCC_OPTIMIZE_NORMALLY defined' in err) == optimize_normally
-
- for last in ['both.o', 'both2.o']:
- out, err = Popen([PYTHON, EMCC, self.in_dir('both.o'), '-O2', '-o', last + '.js', '--memory-init-file', '0'], stdout=PIPE, stderr=PIPE).communicate()
- assert ("emcc: LLVM opts: ['-O3']" not in err) == optimize_normally
- assert ' with -O3 since EMCC_OPTIMIZE_NORMALLY defined' not in err
- output = run_js(last + '.js')
- assert 'yello' in output, 'code works ' + err
- assert open('both.o.js').read() == open('both2.o.js').read()
-
- finally:
- if optimize_normally: del os.environ['EMCC_OPTIMIZE_NORMALLY']
- del os.environ['EMCC_DEBUG']
-
def test_jcache_printf(self):
open(self.in_dir('src.cpp'), 'w').write(r'''
#include <stdio.h>
@@ -13481,9 +13439,10 @@ process(sys.argv[1])
try_delete(final_filename)
output = Popen([PYTHON, EMCC, filename, #'-O3',
'-O2', '-s', 'DOUBLE_MODE=0', '-s', 'PRECISE_I64_MATH=0',
- '--llvm-lto', '1', '--memory-init-file', '0', '--js-transform', 'python hardcode.py',
+ '--llvm-lto', '3', '--memory-init-file', '0', '--js-transform', 'python hardcode.py',
'-s', 'TOTAL_MEMORY=128*1024*1024',
'--closure', '1',
+ #'-g',
'-o', final_filename] + shared_args + emcc_args, stdout=PIPE, stderr=self.stderr_redirect).communicate()
assert os.path.exists(final_filename), 'Failed to compile file: ' + output[0]
@@ -13798,7 +13757,7 @@ process(sys.argv[1])
args = [path_from_root('tests', 'nbody-java', x) for x in os.listdir(path_from_root('tests', 'nbody-java')) if x.endswith('.c')] + \
['-I' + path_from_root('tests', 'nbody-java')]
self.do_benchmark('nbody_java', '', '''Time(s)''',
- force_c=True, emcc_args=args + ['-s', 'PRECISE_I64_MATH=1', '--llvm-lto', '0'], native_args=args + ['-lgc', '-std=c99', '-target', 'x86_64-pc-linux-gnu', '-lm'])
+ force_c=True, emcc_args=args + ['-s', 'PRECISE_I64_MATH=1', '--llvm-lto', '2'], native_args=args + ['-lgc', '-std=c99', '-target', 'x86_64-pc-linux-gnu', '-lm'])
def lua(self, benchmark, expected, output_parser=None, args_processor=None):
shutil.copyfile(path_from_root('tests', 'lua', benchmark + '.lua'), benchmark + '.lua')
@@ -14190,8 +14149,7 @@ fi
try_delete('a.out.js')
basebc_name = os.path.join(TEMP_DIR, 'emscripten_temp', 'emcc-0-basebc.bc')
- dcebc_name1 = os.path.join(TEMP_DIR, 'emscripten_temp', 'emcc-1-linktime.bc')
- dcebc_name2 = os.path.join(TEMP_DIR, 'emscripten_temp', 'emcc-2-linktime.bc')
+ dcebc_name = os.path.join(TEMP_DIR, 'emscripten_temp', 'emcc-1-linktime.bc')
ll_names = [os.path.join(TEMP_DIR, 'emscripten_temp', 'emcc-X-ll.ll').replace('X', str(x)) for x in range(2,5)]
# Building a file that *does* need dlmalloc *should* trigger cache generation, but only the first time
@@ -14199,7 +14157,6 @@ fi
for i in range(3):
print filename, libname, i
self.clear()
- dcebc_name = dcebc_name1 if i == 0 else dcebc_name2
try_delete(basebc_name) # we might need to check this file later
try_delete(dcebc_name) # we might need to check this file later
for ll_name in ll_names: try_delete(ll_name)
@@ -14216,9 +14173,9 @@ fi
assert os.path.exists(os.path.join(EMCC_CACHE, libname + '.bc'))
if libname == 'libcxx':
print os.stat(os.path.join(EMCC_CACHE, libname + '.bc')).st_size, os.stat(basebc_name).st_size, os.stat(dcebc_name).st_size
- assert os.stat(os.path.join(EMCC_CACHE, libname + '.bc')).st_size > 1800000, 'libc++ is big'
- assert os.stat(basebc_name).st_size > 1800000, 'libc++ is indeed big'
- assert os.stat(dcebc_name).st_size < 750000, 'Dead code elimination must remove most of libc++'
+ assert os.stat(os.path.join(EMCC_CACHE, libname + '.bc')).st_size > 1000000, 'libc++ is big'
+ assert os.stat(basebc_name).st_size > 1000000, 'libc++ is indeed big'
+ assert os.stat(dcebc_name).st_size < 500000, 'Dead code elimination must remove most of libc++'
# should only have metadata in -O0, not 1 and 2
if i > 0:
for ll_name in ll_names:
@@ -14305,7 +14262,7 @@ fi
(['--jcache'], 'hello_malloc.cpp', False, True, False, True, False, True, []),
([], 'hello_malloc.cpp', False, False, False, False, False, False, []),
# new, huge file
- ([], 'hello_libcxx.cpp', False, False, False, False, False, False, ('4 chunks',)),
+ ([], 'hello_libcxx.cpp', False, False, False, False, False, False, ('3 chunks',)),
(['--jcache'], 'hello_libcxx.cpp', True, False, True, False, True, False, []),
(['--jcache'], 'hello_libcxx.cpp', False, True, False, True, False, True, []),
([], 'hello_libcxx.cpp', False, False, False, False, False, False, []),