diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-01-07 12:54:29 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-01-07 12:54:29 -0800 |
commit | 578971453d4d1140486229bedc711f52b8e1948f (patch) | |
tree | 72f2371905d7d08a1a86641ccd977649088dcde9 /tests | |
parent | 904d9b751241bfa1e1a334877c8489a27e535892 (diff) |
reset the stack top when CATCH_EXIT_CODE
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/runner.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/runner.py b/tests/runner.py index e55a3f60..742ddf1f 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -2471,6 +2471,53 @@ setjmp exception execution path, level: 0, prev_jmp: -1 Exiting setjmp function, level: 0, prev_jmp: -1 ''') + def test_exit_stack(self): + if self.emcc_args is None: return self.skip('requires emcc') + if Settings.ASM_JS: return self.skip('uses report_stack without exporting') + + Settings.CATCH_EXIT_CODE = 1 + + src = r''' + #include <stdio.h> + #include <stdlib.h> + + extern "C" { + extern void report_stack(int x); + } + + char moar() { + char temp[125]; + for (int i = 0; i < 125; i++) temp[i] = i*i; + for (int i = 1; i < 125; i++) temp[i] += temp[i-1]/2; + if (temp[100] != 99) exit(1); + return temp[120]; + } + + int main(int argc, char *argv[]) { + report_stack((int)alloca(4)); + printf("*%d*\n", moar()); + return 0; + } + ''' + + open(os.path.join(self.get_dir(), 'pre.js'), 'w').write(''' + var initialStack = -1; + var _report_stack = function(x) { + Module.print('reported'); + initialStack = x; + } + var Module = { + postRun: function() { + Module.print('postRun'); + assert(initialStack == STACKTOP, [initialStack, STACKTOP]); + Module.print('ok.'); + } + }; + ''') + + self.emcc_args += ['--pre-js', 'pre.js'] + self.do_run(src, '''reported\npostRun\nok.\nExit Status: 1\n''') + def test_class(self): src = ''' #include <stdio.h> |