diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/core/test_longjmp_funcptr.in | 32 | ||||
-rw-r--r-- | tests/core/test_longjmp_funcptr.out | 2 | ||||
-rw-r--r-- | tests/test_core.py | 35 |
3 files changed, 37 insertions, 32 deletions
diff --git a/tests/core/test_longjmp_funcptr.in b/tests/core/test_longjmp_funcptr.in new file mode 100644 index 00000000..e699bae6 --- /dev/null +++ b/tests/core/test_longjmp_funcptr.in @@ -0,0 +1,32 @@ + + #include <stdio.h> + #include <setjmp.h> + + static jmp_buf buf; + + void (*fp)() = NULL; + + 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) { + fp(); + printf("first\n"); // does not print + } + + int main(int argc, char **argv) { + fp = argc == 200 ? NULL : second; + + volatile 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; + } +
\ No newline at end of file diff --git a/tests/core/test_longjmp_funcptr.out b/tests/core/test_longjmp_funcptr.out new file mode 100644 index 00000000..0e823e76 --- /dev/null +++ b/tests/core/test_longjmp_funcptr.out @@ -0,0 +1,2 @@ +second +main: 1 diff --git a/tests/test_core.py b/tests/test_core.py index 7e48e3a6..d16e02d3 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1110,39 +1110,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_longjmp_funcptr(self): - src = r''' - #include <stdio.h> - #include <setjmp.h> - - static jmp_buf buf; - - void (*fp)() = NULL; - - 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) { - fp(); - printf("first\n"); // does not print - } - - int main(int argc, char **argv) { - fp = argc == 200 ? NULL : second; - - volatile 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 - } + test_path = path_from_root('tests', 'core', 'test_longjmp_funcptr') + src, output = (test_path + s for s in ('.in', '.out')) - return 0; - } - ''' - self.do_run(src, 'second\nmain: 1\n') + self.do_run_from_file(src, output) def test_longjmp_repeat(self): Settings.MAX_SETJMPS = 1 |