diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-02-18 12:01:57 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-02-18 12:01:57 -0800 |
commit | 52897895fb947665984a784555405ee0a806af18 (patch) | |
tree | f3bf5efac22ce12ddff4db971b4239c7c14ed5e6 /tests/runner.py | |
parent | c4e578be4cc6f5a6d801b8106422eb30de725b18 (diff) |
basic support for setjmp/longjmp
Diffstat (limited to 'tests/runner.py')
-rwxr-xr-x | tests/runner.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/runner.py b/tests/runner.py index 3d27d2c2..44fba344 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -1344,6 +1344,41 @@ if 'benchmark' not in str(sys.argv) and 'sanity' not in str(sys.argv): ''' self.do_run(src, 'Assertion failed: 1 == false') + def test_longjmp(self): + src = r''' + #include <stdio.h> + #include <setjmp.h> + + static jmp_buf buf; + + void second(void) { + printf("second\n"); // prints + longjmp(buf,1); // jumps back to where setjmp was called - making setjmp now return 1 + } + + void first(void) { + second(); + printf("first\n"); // does not print + } + + int main() { + int x = 0; + if ( ! setjmp(buf) ) { + x++; + first(); // when executed, setjmp returns 0 + } else { // when longjmp jumps back, setjmp returns 1 + printf("main: %d\n", x); // prints + } + + return 0; + } + ''' + # gcc -O0 and -O2 differ in what they do with the saved state of local vars - and we match that + if self.emcc_args is None or ('-O1' not in self.emcc_args and '-O2' not in self.emcc_args): + self.do_run(src, 'second\nmain: 1\n') + else: + self.do_run(src, 'second\nmain: 0\n') + def test_exceptions(self): if Settings.QUANTUM_SIZE == 1: return self.skip("we don't support libcxx in q1") |