summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorVasilis Kalintiris <ehostunreach@gmail.com>2013-12-07 11:23:49 +0200
committerVasilis Kalintiris <ehostunreach@gmail.com>2013-12-07 19:35:53 +0200
commit04955bb9f5daf898e12db11fe950aabb544cff6c (patch)
treef35627ff61303c6c781e2d4a57a6fcb8de3a6385 /tests
parentc5b55a9f04b6d0ee5506de9631a62bd351350799 (diff)
Use do_run_from_file() for test_longjmp_stacked
Diffstat (limited to 'tests')
-rw-r--r--tests/core/test_longjmp_stacked.in44
-rw-r--r--tests/core/test_longjmp_stacked.out13
-rw-r--r--tests/test_core.py59
3 files changed, 60 insertions, 56 deletions
diff --git a/tests/core/test_longjmp_stacked.in b/tests/core/test_longjmp_stacked.in
new file mode 100644
index 00000000..19539561
--- /dev/null
+++ b/tests/core/test_longjmp_stacked.in
@@ -0,0 +1,44 @@
+
+ #include <stdio.h>
+ #include <setjmp.h>
+ #include <stdlib.h>
+ #include <string.h>
+
+ int bottom, top;
+
+ int run(int y) {
+ // confuse stack
+ char *s = (char*)alloca(100);
+ memset(s, 1, 100);
+ s[y] = y;
+ s[y/2] = y*2;
+ volatile int x = s[y];
+ top = (int)alloca(4);
+ if (x <= 2) return x;
+ jmp_buf buf;
+ printf("setjmp of %d\n", x);
+ if (setjmp(buf) == 0) {
+ printf("going\n");
+ x += run(x/2);
+ longjmp(buf, 1);
+ }
+ printf("back\n");
+ return x/2;
+ }
+
+ int main(int argc, char **argv) {
+ int sum = 0;
+ for (int i = 0; i < argc*2; i++) {
+ bottom = (int)alloca(4);
+ sum += run(10);
+ // scorch the earth
+ if (bottom < top) {
+ memset((void*)bottom, 1, top - bottom);
+ } else {
+ memset((void*)top, 1, bottom - top);
+ }
+ }
+ printf("%d\n", sum);
+ return sum;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_longjmp_stacked.out b/tests/core/test_longjmp_stacked.out
new file mode 100644
index 00000000..d16a8e7d
--- /dev/null
+++ b/tests/core/test_longjmp_stacked.out
@@ -0,0 +1,13 @@
+setjmp of 10
+going
+setjmp of 5
+going
+back
+back
+setjmp of 10
+going
+setjmp of 5
+going
+back
+back
+12
diff --git a/tests/test_core.py b/tests/test_core.py
index 136016e5..07edda55 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -1124,64 +1124,11 @@ 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_stacked(self):
- src = r'''
- #include <stdio.h>
- #include <setjmp.h>
- #include <stdlib.h>
- #include <string.h>
+ test_path = path_from_root('tests', 'core', 'test_longjmp_stacked')
+ src, output = (test_path + s for s in ('.in', '.out'))
- int bottom, top;
-
- int run(int y) {
- // confuse stack
- char *s = (char*)alloca(100);
- memset(s, 1, 100);
- s[y] = y;
- s[y/2] = y*2;
- volatile int x = s[y];
- top = (int)alloca(4);
- if (x <= 2) return x;
- jmp_buf buf;
- printf("setjmp of %d\n", x);
- if (setjmp(buf) == 0) {
- printf("going\n");
- x += run(x/2);
- longjmp(buf, 1);
- }
- printf("back\n");
- return x/2;
- }
+ self.do_run_from_file(src, output)
- int main(int argc, char **argv) {
- int sum = 0;
- for (int i = 0; i < argc*2; i++) {
- bottom = (int)alloca(4);
- sum += run(10);
- // scorch the earth
- if (bottom < top) {
- memset((void*)bottom, 1, top - bottom);
- } else {
- memset((void*)top, 1, bottom - top);
- }
- }
- printf("%d\n", sum);
- return sum;
- }
- '''
- self.do_run(src, '''setjmp of 10
-going
-setjmp of 5
-going
-back
-back
-setjmp of 10
-going
-setjmp of 5
-going
-back
-back
-12
-''')
def test_longjmp_exc(self):
src = r'''