Skip to content

Commit 74d7271

Browse files
authored
Add a test for setjmp/longjmp in CI (#770)
This previously wasn't tested, so this add end-to-end testing of the whole shebang. Testing with the wasm exceptions proposal (latest version) requires Clang 20 so that's updated for the test matrix as well.
1 parent 724d866 commit 74d7271

File tree

3 files changed

+81
-15
lines changed

3 files changed

+81
-15
lines changed

.github/workflows/main.yml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,93 +60,93 @@ jobs:
6060
# but that can be expanded as necessary in the future too.
6161
- name: Test wasm32-wasi
6262
os: ubuntu-24.04
63-
clang_version: 19
63+
clang_version: 20
6464
test: true
6565
upload: wasm32-wasi
6666
args: -DTARGET_TRIPLE=wasm32-wasi
6767

6868
- name: Test wasm32-wasip1
6969
os: ubuntu-24.04
70-
clang_version: 19
70+
clang_version: 20
7171
test: true
7272
upload: wasm32-wasip1
7373
args: -DTARGET_TRIPLE=wasm32-wasip1
7474

7575
- name: Test wasm32-wasip2
7676
os: ubuntu-24.04
77-
clang_version: 19
77+
clang_version: 20
7878
test: true
7979
upload: wasm32-wasip2
8080
args: -DTARGET_TRIPLE=wasm32-wasip2
8181

8282
- name: Test wasm32-wasip1-threads
8383
os: ubuntu-24.04
84-
clang_version: 19
84+
clang_version: 20
8585
test: true
8686
upload: wasm32-wasip1-threads
8787
args: -DTARGET_TRIPLE=wasm32-wasip1-threads
8888

8989
- name: Test wasm32-wasip1 in V8
9090
os: ubuntu-24.04
91-
clang_version: 19
91+
clang_version: 20
9292
test: true
9393
test_with_v8: true
9494
args: -DTARGET_TRIPLE=wasm32-wasip1
9595

9696
- name: Test wasm32-wasip1-threads in V8
9797
os: ubuntu-24.04
98-
clang_version: 19
98+
clang_version: 20
9999
test: true
100100
test_with_v8: true
101101
args: -DTARGET_TRIPLE=wasm32-wasip1-threads
102102

103103
- name: Test wasm32-wasi-simd
104104
os: ubuntu-24.04
105-
clang_version: 19
105+
clang_version: 20
106106
test: true
107107
upload: wasm32-wasi-simd
108108
args: -DSIMD=ON -DCHECK_SYMBOLS=OFF
109109

110110
- name: Test wasm32-wasip1 (debug)
111111
os: ubuntu-24.04
112-
clang_version: 19
112+
clang_version: 20
113113
test: true
114114
args: -DCMAKE_BUILD_TYPE=Debug
115115

116116
- name: Test wasm32-wasip2 (debug)
117117
os: ubuntu-24.04
118-
clang_version: 19
118+
clang_version: 20
119119
test: true
120120
args: -DCMAKE_BUILD_TYPE=Debug -DTARGET_TRIPLE=wasm32-wasip2
121121

122122
- name: Test wasm32-wasip1-threads (debug)
123123
os: ubuntu-24.04
124-
clang_version: 19
124+
clang_version: 20
125125
test: true
126126
args: -DCMAKE_BUILD_TYPE=Debug -DTARGET_TRIPLE=wasm32-wasip1-threads
127127

128128
- name: Test wasm32-wasip3
129129
os: ubuntu-24.04
130-
clang_version: 19
130+
clang_version: 20
131131
test: true
132132
upload: wasm32-wasip3
133133
args: -DTARGET_TRIPLE=wasm32-wasip3
134134

135135
- name: Test wasm32-wasip3 (debug)
136136
os: ubuntu-24.04
137-
clang_version: 19
137+
clang_version: 20
138138
test: true
139139
args: -DCMAKE_BUILD_TYPE=Debug -DTARGET_TRIPLE=wasm32-wasip3
140140

141141
- name: Test emmalloc
142142
os: ubuntu-24.04
143-
clang_version: 19
143+
clang_version: 20
144144
test: true
145145
args: -DMALLOC=emmalloc
146146

147147
- name: Test LTO
148148
os: ubuntu-24.04
149-
clang_version: 19
149+
clang_version: 20
150150
test: true
151151
args: -DLTO=full -DTARGET_TRIPLE=wasm32-wasip2 -DCHECK_SYMBOLS=OFF
152152

test/CMakeLists.txt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,9 @@ endfunction()
110110
# * `NETWORK` - this test uses the network and sockets.
111111
# * `PASS_REGULAR_EXPRESSION` - a regex that must match the test output to pass
112112
# * `FAILP3` - this test fails on wasip3 targets
113+
# * `SETJMP` - this test requires setjmp/longjmp
113114
function(register_test test_name executable_name)
114-
set(options FS NETWORK FAILP3)
115+
set(options FS NETWORK FAILP3 SETJMP)
115116
set(oneValueArgs CLIENT PASS_REGULAR_EXPRESSION)
116117
set(multiValueArgs ARGV ENV LDFLAGS CFLAGS)
117118
cmake_parse_arguments(PARSE_ARGV 1 arg "${options}" "${oneValueArgs}" "${multiValueArgs}")
@@ -135,6 +136,18 @@ function(register_test test_name executable_name)
135136
list(APPEND wasmtime_args --wasm component-model-async)
136137
list(APPEND wasmtime_args --wasi p3)
137138
endif()
139+
if (arg_SETJMP)
140+
list(APPEND wasmtime_args --wasm exceptions)
141+
target_compile_options(${executable_name} PRIVATE
142+
"SHELL:-mllvm -wasm-enable-sjlj"
143+
"SHELL:-mllvm -wasm-use-legacy-eh=false"
144+
)
145+
target_link_options(${executable_name} PRIVATE
146+
-lsetjmp
147+
$<$<BOOL:LTO>:-Wl,-mllvm=-wasm-enable-sjlj>
148+
$<$<BOOL:LTO>:-Wl,-mllvm=-wasm-use-legacy-eh=false>
149+
)
150+
endif()
138151

139152
add_test(
140153
NAME "${test_name}"
@@ -311,6 +324,11 @@ add_wasilibc_test(sleep.c)
311324
add_wasilibc_test(write.c FS)
312325
add_wasilibc_test(wasi-defines.c)
313326

327+
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER 20.0)
328+
add_wasilibc_test(setjmp.c SETJMP)
329+
set_tests_properties(setjmp.wasm PROPERTIES LABELS v8fail)
330+
endif()
331+
314332
if (TARGET_TRIPLE MATCHES "-threads")
315333
add_wasilibc_test(busywait.c)
316334
add_wasilibc_test(pthread_cond_busywait.c)

test/src/setjmp.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include "test.h"
2+
#include <setjmp.h>
3+
#include <stdlib.h>
4+
5+
#define TEST(c) \
6+
do { \
7+
if (!(c)) \
8+
t_error("%s failed\n", #c); \
9+
} while (0)
10+
11+
static void test_a() {
12+
jmp_buf env;
13+
int val = setjmp(env);
14+
if (val == 0) {
15+
longjmp(env, 42);
16+
abort();
17+
} else {
18+
TEST(val == 42);
19+
}
20+
}
21+
22+
static jmp_buf b_env;
23+
24+
static void b_child2() {
25+
longjmp(b_env, 43);
26+
abort();
27+
}
28+
29+
static void b_child() {
30+
b_child2();
31+
abort();
32+
}
33+
34+
static void test_b() {
35+
int val = setjmp(b_env);
36+
if (val == 0) {
37+
b_child();
38+
abort();
39+
} else {
40+
TEST(val == 43);
41+
}
42+
}
43+
44+
int main() {
45+
test_a();
46+
test_b();
47+
return t_status;
48+
}

0 commit comments

Comments
 (0)