diff options
author | Vasilis Kalintiris <ehostunreach@gmail.com> | 2013-12-07 11:08:21 +0200 |
---|---|---|
committer | Vasilis Kalintiris <ehostunreach@gmail.com> | 2013-12-07 19:35:53 +0200 |
commit | 313a23e64c357260c660166f67d32d64601f164a (patch) | |
tree | afca4f585fc92f70f7bc5efca287348005c5e60e | |
parent | dca1ceb65a07c6d1a0bdbae1705ac5c90bacd929 (diff) |
Use do_run_from_file() for test_longjmp
-rw-r--r-- | tests/core/test_longjmp.in | 34 | ||||
-rw-r--r-- | tests/core/test_longjmp.out | 4 | ||||
-rw-r--r-- | tests/test_core.py | 37 |
3 files changed, 41 insertions, 34 deletions
diff --git a/tests/core/test_longjmp.in b/tests/core/test_longjmp.in new file mode 100644 index 00000000..4260ed15 --- /dev/null +++ b/tests/core/test_longjmp.in @@ -0,0 +1,34 @@ + + #include <stdio.h> + #include <setjmp.h> + + static jmp_buf buf; + + void second(void) { + printf("second\n"); + longjmp(buf,-1); + } + + void first(void) { + printf("first\n"); // prints + longjmp(buf,1); // jumps back to where setjmp was called - making setjmp now return 1 + } + + int main() { + volatile int x = 0; + int jmpval = setjmp(buf); + if (!jmpval) { + x++; // should be properly restored once longjmp jumps back + first(); // when executed, setjmp returns 1 + printf("skipped\n"); // does not print + } else if (jmpval == 1) { // when first() jumps back, setjmp returns 1 + printf("result: %d %d\n", x, jmpval); // prints + x++; + second(); // when executed, setjmp returns -1 + } else if (jmpval == -1) { // when second() jumps back, setjmp returns -1 + printf("result: %d %d\n", x, jmpval); // prints + } + + return 0; + } +
\ No newline at end of file diff --git a/tests/core/test_longjmp.out b/tests/core/test_longjmp.out new file mode 100644 index 00000000..4a412fef --- /dev/null +++ b/tests/core/test_longjmp.out @@ -0,0 +1,4 @@ +first +result: 1 1 +second +result: 2 -1
\ No newline at end of file diff --git a/tests/test_core.py b/tests/test_core.py index befd66ba..9646f09b 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1086,41 +1086,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(self): - src = r''' - #include <stdio.h> - #include <setjmp.h> - - static jmp_buf buf; - - void second(void) { - printf("second\n"); - longjmp(buf,-1); - } - - void first(void) { - printf("first\n"); // prints - longjmp(buf,1); // jumps back to where setjmp was called - making setjmp now return 1 - } - - int main() { - volatile int x = 0; - int jmpval = setjmp(buf); - if (!jmpval) { - x++; // should be properly restored once longjmp jumps back - first(); // when executed, setjmp returns 1 - printf("skipped\n"); // does not print - } else if (jmpval == 1) { // when first() jumps back, setjmp returns 1 - printf("result: %d %d\n", x, jmpval); // prints - x++; - second(); // when executed, setjmp returns -1 - } else if (jmpval == -1) { // when second() jumps back, setjmp returns -1 - printf("result: %d %d\n", x, jmpval); // prints - } + test_path = path_from_root('tests', 'core', 'test_longjmp') + src, output = (test_path + s for s in ('.in', '.out')) - return 0; - } - ''' - self.do_run(src, 'first\nresult: 1 1\nsecond\nresult: 2 -1') + self.do_run_from_file(src, output) def test_longjmp2(self): src = r''' |