diff options
Diffstat (limited to 'tests/runner.py')
-rwxr-xr-x | tests/runner.py | 134 |
1 files changed, 115 insertions, 19 deletions
diff --git a/tests/runner.py b/tests/runner.py index f7f6f17c..69ee3e86 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -27,6 +27,7 @@ Running the main part of the test suite. Don't forget to run the other parts! benchmark - run before and after each set of changes before pushing to master, verify no regressions browser - runs pages in a web browser + browser audio - runs audio tests in a web browser (requires human verification) To run one of those parts, do something like @@ -4521,6 +4522,22 @@ The current address of a is: 0x12345678 The current type of b is: 9 ''') + def test_functionpointer_libfunc_varargs(self): + src = r''' + #include <stdio.h> + #include <fcntl.h> + typedef int (*fp_t)(int, int, ...); + int main(int argc, char **argv) { + fp_t fp = &fcntl; + if (argc == 1337) fp = (fp_t)&main; + (*fp)(0, 10); + (*fp)(0, 10, 5); + printf("waka\n"); + return 0; + } + ''' + self.do_run(src, '''waka''') + def test_structbyval(self): Settings.INLINING_LIMIT = 50 @@ -6785,6 +6802,25 @@ Pass: 0.000012 0.000012''') ''' self.do_run(src, '2, , black\n2, ., #001100\n2, X, #111100'); + def test_sscanf_6(self): + src = r''' + #include <stdio.h> + + int main() + { + char *date = "18.07.2013w"; + char c[10]; + int y, m, d, i; + i = sscanf(date, "%d.%d.%4d%c", &d, &m, &y, c); + printf("date: %s; day %2d, month %2d, year %4d, extra: %c, %d\n", date, d, m, y, c[0], i); + i = sscanf(date, "%d.%d.%3c", &d, &m, c); + printf("date: %s; day %2d, month %2d, year %4d, extra: %s, %d\n", date, d, m, y, c, i); + } + ''' + self.do_run(src, '''date: 18.07.2013w; day 18, month 7, year 2013, extra: w, 4 +date: 18.07.2013w; day 18, month 7, year 2013, extra: 201, 3 +'''); + def test_sscanf_skip(self): if Settings.USE_TYPED_ARRAYS != 2: return self.skip("need ta2 for full i64") @@ -7377,18 +7413,8 @@ def process(filename): self.do_run(src, expected) def test_unistd_unlink(self): - add_pre_run = ''' -def process(filename): - import tools.shared as shared - src = open(filename, 'r').read().replace( - '// {{PRE_RUN_ADDITIONS}}', - open(shared.path_from_root('tests', 'unistd', 'unlink.js'), 'r').read() - ) - open(filename, 'w').write(src) -''' src = open(path_from_root('tests', 'unistd', 'unlink.c'), 'r').read() - expected = open(path_from_root('tests', 'unistd', 'unlink.out'), 'r').read() - self.do_run(src, expected, post_build=add_pre_run) + self.do_run(src, 'success', force_c=True) def test_unistd_links(self): add_pre_run = ''' @@ -10034,6 +10060,11 @@ finalizing 3 (global == 0) for k, v in self.env.iteritems(): del os.environ[k] + # clear global changes to Building + Building.COMPILER_TEST_OPTS = [] + Building.COMPILER = CLANG + Building.LLVM_OPTS = 0 + TT.tearDown = tearDown def setUp(self): @@ -10631,7 +10662,7 @@ f.close() Popen([PYTHON, EMLINK, 'main.js', 'side.js', 'together.js'], stdout=PIPE).communicate() assert os.path.exists('together.js') for engine in JS_ENGINES: - out = run_js('together.js', engine=SPIDERMONKEY_ENGINE, stderr=PIPE, full_output=True) + out = run_js('together.js', engine=engine, stderr=PIPE, full_output=True) self.assertContained(expected, out) if engine == SPIDERMONKEY_ENGINE: self.validate_asmjs(out) if first: @@ -10822,6 +10853,50 @@ f.close() args=['-I' + path_from_root('tests', 'bullet', 'src')]) + def test_outline(self): + def test(name, src, libs, expected, expected_ranges, args=[], suffix='cpp'): + print name + + def measure_funcs(filename): + i = 0 + start = -1 + curr = '?' + ret = {} + for line in open(filename): + i += 1 + if line.startswith('function '): + start = i + curr = line + elif line.startswith('}'): + size = i - start + if size > 100: ret[curr] = size + return ret + + for outlining_limit in [1000, 2000, 5000, 0]: + Popen([PYTHON, EMCC, src] + libs + ['-o', 'test.js', '-O2', '-g3', '-s', 'OUTLINING_LIMIT=%d' % outlining_limit] + args).communicate() + assert os.path.exists('test.js') + shutil.copyfile('test.js', '%d_test.js' % outlining_limit) + for engine in JS_ENGINES: + out = run_js('test.js', engine=engine, stderr=PIPE, full_output=True) + self.assertContained(expected, out) + if engine == SPIDERMONKEY_ENGINE: self.validate_asmjs(out) + low = expected_ranges[outlining_limit][0] + seen = max(measure_funcs('test.js').values()) + high = expected_ranges[outlining_limit][1] + print outlining_limit, ' ', low, '<=', seen, '<=', high + assert low <= seen <= high + + test('zlib', path_from_root('tests', 'zlib', 'example.c'), + self.get_library('zlib', os.path.join('libz.a'), make_args=['libz.a']), + open(path_from_root('tests', 'zlib', 'ref.txt'), 'r').read(), + { + 1000: (380, 390), + 2000: (395, 410), + 5000: (800, 1100), + 0: (1500, 1800) + }, + args=['-I' + path_from_root('tests', 'zlib')], suffix='c') + def test_symlink(self): if os.name == 'nt': return self.skip('Windows FS does not need to be tested for symlinks support, since it does not have them.') @@ -11546,11 +11621,11 @@ f.close() def test_js_optimizer(self): for input, expected, passes in [ (path_from_root('tools', 'test-js-optimizer.js'), open(path_from_root('tools', 'test-js-optimizer-output.js')).read(), - ['hoistMultiples', 'loopOptimizer', 'removeAssignsToUndefined', 'simplifyExpressionsPre', 'simplifyExpressionsPost']), + ['hoistMultiples', 'loopOptimizer', 'removeAssignsToUndefined', 'simplifyExpressions']), (path_from_root('tools', 'test-js-optimizer-t2c.js'), open(path_from_root('tools', 'test-js-optimizer-t2c-output.js')).read(), - ['simplifyExpressionsPre', 'optimizeShiftsConservative']), + ['simplifyExpressions', 'optimizeShiftsConservative']), (path_from_root('tools', 'test-js-optimizer-t2.js'), open(path_from_root('tools', 'test-js-optimizer-t2-output.js')).read(), - ['simplifyExpressionsPre', 'optimizeShiftsAggressive']), + ['simplifyExpressions', 'optimizeShiftsAggressive']), # Make sure that optimizeShifts handles functions with shift statements. (path_from_root('tools', 'test-js-optimizer-t3.js'), open(path_from_root('tools', 'test-js-optimizer-t3-output.js')).read(), ['optimizeShiftsAggressive']), @@ -11567,13 +11642,15 @@ f.close() (path_from_root('tools', 'test-js-optimizer-asm-regs-min.js'), open(path_from_root('tools', 'test-js-optimizer-asm-regs-min-output.js')).read(), ['asm', 'registerize']), (path_from_root('tools', 'test-js-optimizer-asm-pre.js'), open(path_from_root('tools', 'test-js-optimizer-asm-pre-output.js')).read(), - ['asm', 'simplifyExpressionsPre']), + ['asm', 'simplifyExpressions']), (path_from_root('tools', 'test-js-optimizer-asm-last.js'), open(path_from_root('tools', 'test-js-optimizer-asm-last-output.js')).read(), ['asm', 'last']), (path_from_root('tools', 'test-js-optimizer-asm-relocate.js'), open(path_from_root('tools', 'test-js-optimizer-asm-relocate-output.js')).read(), ['asm', 'relocate']), - #(path_from_root('tools', 'test-js-optimizer-asm-outline.js'), open(path_from_root('tools', 'test-js-optimizer-asm-outline-output.js')).read(), - # ['asm', 'outline']), + (path_from_root('tools', 'test-js-optimizer-asm-outline1.js'), open(path_from_root('tools', 'test-js-optimizer-asm-outline1-output.js')).read(), + ['asm', 'outline']), + (path_from_root('tools', 'test-js-optimizer-asm-outline2.js'), open(path_from_root('tools', 'test-js-optimizer-asm-outline2-output.js')).read(), + ['asm', 'outline']), ]: print input output = Popen(listify(NODE_JS) + [path_from_root('tools', 'js-optimizer.js'), input] + passes, stdin=PIPE, stdout=PIPE).communicate()[0] @@ -11810,6 +11887,24 @@ elif 'browser' in str(sys.argv): print 'Running the browser tests. Make sure the browser allows popups from localhost.' print + if 'audio' in sys.argv: + print + print 'Running the browser audio tests. Make sure to listen to hear the correct results!' + print + + i = sys.argv.index('audio') + sys.argv = sys.argv[:i] + sys.argv[i+1:] + i = sys.argv.index('browser') + sys.argv = sys.argv[:i] + sys.argv[i+1:] + sys.argv += [ + 'browser.test_sdl_audio', + 'browser.test_sdl_audio_mix_channels', + 'browser.test_sdl_audio_mix', + 'browser.test_sdl_audio_quickload', + 'browser.test_openal_playback', + 'browser.test_freealut' + ] + # Run a server and a web page. When a test runs, we tell the server about it, # which tells the web page, which then opens a window with the test. Doing # it this way then allows the page to close() itself when done. @@ -12820,8 +12915,9 @@ Press any key to continue.''' self.run_browser('page.html', 'Should print "(300, 150)" -- the size of the canvas in pixels', '/report_result?1') def test_freealut(self): - programs = self.get_library('freealut', os.path.join('examples', 'hello_world.bc'), make_args=['EXEEXT=.bc']) + programs = self.get_library('freealut', os.path.join('examples', '.libs', 'hello_world.bc'), make_args=['EXEEXT=.bc']) for program in programs: + assert os.path.exists(program) Popen([PYTHON, EMCC, '-O2', program, '-o', 'page.html']).communicate() self.run_browser('page.html', 'You should hear "Hello World!"') |