aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-01-27 16:55:44 -0800
committerAlon Zakai <alonzakai@gmail.com>2014-01-27 16:55:44 -0800
commiteb7c2b26f500609683e412c828a9d9a1c5c61374 (patch)
tree840a64e0a3be85b385c60f8836864539026cb9f1
parent25e736cbb791da970582666fcaf27b5f7450b3ef (diff)
add testcase with longjmp and c++ exception catching in the same function
-rw-r--r--tests/core/test_longjmp_throw.cpp38
-rw-r--r--tests/core/test_longjmp_throw.out4
-rw-r--r--tests/test_core.py10
3 files changed, 52 insertions, 0 deletions
diff --git a/tests/core/test_longjmp_throw.cpp b/tests/core/test_longjmp_throw.cpp
new file mode 100644
index 00000000..a5b658e8
--- /dev/null
+++ b/tests/core/test_longjmp_throw.cpp
@@ -0,0 +1,38 @@
+#include <stdio.h>
+#include <setjmp.h>
+
+static jmp_buf buf;
+volatile int x = 0;
+
+void second(void) {
+ printf("second\n");
+ if (x == 17) throw 5;
+ else longjmp(buf, -1);
+}
+
+void first(void) {
+ printf("first\n");
+ longjmp(buf, 1);
+}
+
+int main() {
+ int jmpval = setjmp(buf);
+ if (!jmpval) {
+ x++;
+ first();
+ printf("skipped\n");
+ } else if (jmpval == 1) {
+ printf("result: %d %d\n", x, jmpval);
+ x++;
+ try {
+ second();
+ } catch(int a) {
+ x--;
+ second();
+ }
+ } else if (jmpval == -1) {
+ printf("result: %d %d\n", x, jmpval);
+ }
+
+ return 0;
+}
diff --git a/tests/core/test_longjmp_throw.out b/tests/core/test_longjmp_throw.out
new file mode 100644
index 00000000..e9cc7525
--- /dev/null
+++ b/tests/core/test_longjmp_throw.out
@@ -0,0 +1,4 @@
+first
+result: 1 1
+second
+result: 2 -1
diff --git a/tests/test_core.py b/tests/test_core.py
index 97cba68f..aa3fd8c4 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -1157,6 +1157,16 @@ class T(RunnerCore): # Short name, to make it more fun to use manually on the co
src, output = (test_path + s for s in ('.in', '.out'))
self.do_run_from_file(src, output)
+ def test_longjmp_throw(self):
+ if self.run_name == 'asm3': return self.skip('issue 2069') # FIXME
+
+ for disable_throw in [0, 1]:
+ print disable_throw
+ Settings.DISABLE_EXCEPTION_CATCHING = disable_throw
+ test_path = path_from_root('tests', 'core', 'test_longjmp_throw')
+ src, output = (test_path + s for s in ('.cpp', '.out'))
+ self.do_run_from_file(src, output)
+
def test_setjmp_many(self):
if os.environ.get('EMCC_FAST_COMPILER') == '1': return self.skip('todo in fastcomp: make MAX_SETJMPS take effect')