diff options
-rw-r--r-- | tests/core/test_multiexception.in | 48 | ||||
-rw-r--r-- | tests/core/test_multiexception.out | 9 | ||||
-rw-r--r-- | tests/test_core.py | 60 |
3 files changed, 60 insertions, 57 deletions
diff --git a/tests/core/test_multiexception.in b/tests/core/test_multiexception.in new file mode 100644 index 00000000..93795388 --- /dev/null +++ b/tests/core/test_multiexception.in @@ -0,0 +1,48 @@ + +#include <stdio.h> + +static int current_exception_id = 0; + +typedef struct { +int jmp; +} jmp_state; + +void setjmp_func(jmp_state* s, int level) { +int prev_jmp = s->jmp; +int c_jmp; + +if (level == 2) { + printf("level is 2, perform longjmp!\n"); + throw 1; +} + +c_jmp = current_exception_id++; +try { + printf("setjmp normal execution path, level: %d, prev_jmp: %d\n", level, prev_jmp); + s->jmp = c_jmp; + setjmp_func(s, level + 1); +} catch (int catched_eid) { + printf("caught %d\n", catched_eid); + if (catched_eid == c_jmp) { + printf("setjmp exception execution path, level: %d, prev_jmp: %d\n", level, prev_jmp); + if (prev_jmp != -1) { + printf("prev_jmp is not empty, continue with longjmp!\n"); + s->jmp = prev_jmp; + throw s->jmp; + } + } else { + throw; + } +} + +printf("Exiting setjmp function, level: %d, prev_jmp: %d\n", level, prev_jmp); +} + +int main(int argc, char *argv[]) { +jmp_state s; +s.jmp = -1; + +setjmp_func(&s, 0); + +return 0; +} diff --git a/tests/core/test_multiexception.out b/tests/core/test_multiexception.out new file mode 100644 index 00000000..33efe46e --- /dev/null +++ b/tests/core/test_multiexception.out @@ -0,0 +1,9 @@ +setjmp normal execution path, level: 0, prev_jmp: -1 +setjmp normal execution path, level: 1, prev_jmp: 0 +level is 2, perform longjmp! +caught 1 +setjmp exception execution path, level: 1, prev_jmp: 0 +prev_jmp is not empty, continue with longjmp! +caught 0 +setjmp exception execution path, level: 0, prev_jmp: -1 +Exiting setjmp function, level: 0, prev_jmp: -1 diff --git a/tests/test_core.py b/tests/test_core.py index 0f70786d..c33bef18 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1311,65 +1311,11 @@ class T(RunnerCore): # Short name, to make it more fun to use manually on the co def test_multiexception(self): Settings.DISABLE_EXCEPTION_CATCHING = 0 - src = r''' -#include <stdio.h> - -static int current_exception_id = 0; - -typedef struct { -int jmp; -} jmp_state; - -void setjmp_func(jmp_state* s, int level) { -int prev_jmp = s->jmp; -int c_jmp; - -if (level == 2) { - printf("level is 2, perform longjmp!\n"); - throw 1; -} - -c_jmp = current_exception_id++; -try { - printf("setjmp normal execution path, level: %d, prev_jmp: %d\n", level, prev_jmp); - s->jmp = c_jmp; - setjmp_func(s, level + 1); -} catch (int catched_eid) { - printf("caught %d\n", catched_eid); - if (catched_eid == c_jmp) { - printf("setjmp exception execution path, level: %d, prev_jmp: %d\n", level, prev_jmp); - if (prev_jmp != -1) { - printf("prev_jmp is not empty, continue with longjmp!\n"); - s->jmp = prev_jmp; - throw s->jmp; - } - } else { - throw; - } -} - -printf("Exiting setjmp function, level: %d, prev_jmp: %d\n", level, prev_jmp); -} -int main(int argc, char *argv[]) { -jmp_state s; -s.jmp = -1; - -setjmp_func(&s, 0); + test_path = path_from_root('tests', 'core', 'test_multiexception') + src, output = (test_path + s for s in ('.in', '.out')) -return 0; -} -''' - self.do_run(src, '''setjmp normal execution path, level: 0, prev_jmp: -1 -setjmp normal execution path, level: 1, prev_jmp: 0 -level is 2, perform longjmp! -caught 1 -setjmp exception execution path, level: 1, prev_jmp: 0 -prev_jmp is not empty, continue with longjmp! -caught 0 -setjmp exception execution path, level: 0, prev_jmp: -1 -Exiting setjmp function, level: 0, prev_jmp: -1 -''') + self.do_run_from_file(src, output) def test_std_exception(self): if self.emcc_args is None: return self.skip('requires emcc') |