diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/core/test_longjmp4.in | 44 | ||||
-rw-r--r-- | tests/core/test_longjmp4.out | 4 | ||||
-rw-r--r-- | tests/test_core.py | 51 |
3 files changed, 51 insertions, 48 deletions
diff --git a/tests/core/test_longjmp4.in b/tests/core/test_longjmp4.in new file mode 100644 index 00000000..ce27f751 --- /dev/null +++ b/tests/core/test_longjmp4.in @@ -0,0 +1,44 @@ + + #include <setjmp.h> + #include <stdio.h> + + typedef struct { + jmp_buf* jmp; + } jmp_state; + + void second_func(jmp_state* s); + + void first_func(jmp_state* s) { + jmp_buf* prev_jmp = s->jmp; + jmp_buf c_jmp; + volatile int once = 0; + + if (setjmp(c_jmp) == 0) { + printf("Normal execution path of first function!\n"); + + s->jmp = &c_jmp; + second_func(s); + } else { + printf("Exception execution path of first function! %d\n", once); + + if (!once) { + printf("Calling longjmp the second time!\n"); + once = 1; + longjmp(*(s->jmp), 1); + } + } + } + + void second_func(jmp_state* s) { + longjmp(*(s->jmp), 1); + } + + int main(int argc, char *argv[]) { + jmp_state s; + s.jmp = NULL; + + first_func(&s); + + return 0; + } +
\ No newline at end of file diff --git a/tests/core/test_longjmp4.out b/tests/core/test_longjmp4.out new file mode 100644 index 00000000..53fdd41b --- /dev/null +++ b/tests/core/test_longjmp4.out @@ -0,0 +1,4 @@ +Normal execution path of first function! +Exception execution path of first function! 0 +Calling longjmp the second time! +Exception execution path of first function! 1 diff --git a/tests/test_core.py b/tests/test_core.py index a31ef832..7e48e3a6 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1104,55 +1104,10 @@ class T(RunnerCore): # Short name, to make it more fun to use manually on the co self.do_run_from_file(src, output) def test_longjmp4(self): - src = r''' - #include <setjmp.h> - #include <stdio.h> - - typedef struct { - jmp_buf* jmp; - } jmp_state; - - void second_func(jmp_state* s); - - void first_func(jmp_state* s) { - jmp_buf* prev_jmp = s->jmp; - jmp_buf c_jmp; - volatile int once = 0; - - if (setjmp(c_jmp) == 0) { - printf("Normal execution path of first function!\n"); - - s->jmp = &c_jmp; - second_func(s); - } else { - printf("Exception execution path of first function! %d\n", once); - - if (!once) { - printf("Calling longjmp the second time!\n"); - once = 1; - longjmp(*(s->jmp), 1); - } - } - } - - void second_func(jmp_state* s) { - longjmp(*(s->jmp), 1); - } - - int main(int argc, char *argv[]) { - jmp_state s; - s.jmp = NULL; - - first_func(&s); + test_path = path_from_root('tests', 'core', 'test_longjmp4') + src, output = (test_path + s for s in ('.in', '.out')) - return 0; - } - ''' - self.do_run(src, '''Normal execution path of first function! -Exception execution path of first function! 0 -Calling longjmp the second time! -Exception execution path of first function! 1 -''') + self.do_run_from_file(src, output) def test_longjmp_funcptr(self): src = r''' |