summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasilis Kalintiris <ehostunreach@gmail.com>2013-12-07 11:16:18 +0200
committerVasilis Kalintiris <ehostunreach@gmail.com>2013-12-07 19:35:53 +0200
commit9635141fdd8aaa73657f7a6644d9dc200ea05332 (patch)
tree5b37bb40c86b8891f718d14aff1aaca53ed64854
parent205422ce0a76f4e7f6b1bed08b5abc20bf13430e (diff)
Use do_run_from_file() for test_longjmp_funcptr
-rw-r--r--tests/core/test_longjmp_funcptr.in32
-rw-r--r--tests/core/test_longjmp_funcptr.out2
-rw-r--r--tests/test_core.py35
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