Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EH/SjLj] Add tests for mixing exceptions and sjlj #14732

Merged
merged 6 commits into from Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions tests/core/test_exceptions_longjmp1.cpp
@@ -0,0 +1,21 @@
#include <stdio.h>
#include <setjmp.h>

static jmp_buf buf;

void foo() {
longjmp(buf, 1);
}

int main() {
int jmpval = setjmp(buf);
if (jmpval != 0) {
printf("setjmp returned for the second time\n");
return 0;
}
try {
foo();
} catch (...) {
}
return 0;
}
1 change: 1 addition & 0 deletions tests/core/test_exceptions_longjmp1.out
@@ -0,0 +1 @@
setjmp returned for the second time
25 changes: 25 additions & 0 deletions tests/core/test_exceptions_longjmp2.cpp
@@ -0,0 +1,25 @@
#include <stdio.h>
#include <setjmp.h>

static jmp_buf buf;

void foo() {
longjmp(buf, 1);
}

void test() {
try {
foo();
} catch (...) {
}
}

int main() {
int jmpval = setjmp(buf);
if (jmpval != 0) {
printf("setjmp returned for second time\n");
return 0;
}
test();
return 0;
}
1 change: 1 addition & 0 deletions tests/core/test_exceptions_longjmp2.out
@@ -0,0 +1 @@
setjmp returned for second time
26 changes: 26 additions & 0 deletions tests/core/test_exceptions_longjmp3.cpp
@@ -0,0 +1,26 @@
#include <stdio.h>
#include <setjmp.h>

static jmp_buf buf;

void foo() {
throw 3;
}

void test() {
int jmpval = setjmp(buf);
if (jmpval != 0) {
printf("setjmp returned for 2nd time\n");
return;
}
foo();
}

int main() {
try {
test();
} catch (int n) {
printf("caught: %d\n", n);
}
return 0;
}
1 change: 1 addition & 0 deletions tests/core/test_exceptions_longjmp3.out
@@ -0,0 +1 @@
caught: 3
15 changes: 15 additions & 0 deletions tests/test_core.py
Expand Up @@ -1413,6 +1413,21 @@ def test_iostream_ctors(self):
}
''', 'bugfree code')

def test_exceptions_longjmp1(self):
self.set_setting('SUPPORT_LONGJMP')
self.set_setting('DISABLE_EXCEPTION_CATCHING', 0)
self.do_core_test('test_exceptions_longjmp1.cpp')

def test_exceptions_longjmp2(self):
self.set_setting('SUPPORT_LONGJMP')
self.set_setting('DISABLE_EXCEPTION_CATCHING', 0)
self.do_core_test('test_exceptions_longjmp2.cpp')

def test_exceptions_longjmp3(self):
self.set_setting('SUPPORT_LONGJMP')
self.set_setting('DISABLE_EXCEPTION_CATCHING', 0)
self.do_core_test('test_exceptions_longjmp3.cpp')

# Marked as impure since the WASI reactor modules (modules without main)
# are not yet suppored by the wasm engines we test against.
@also_with_standalone_wasm(impure=True)
Expand Down