Skip to content

Commit 7691c22

Browse files
committed
Add default signal handler tests
1 parent 93b5adc commit 7691c22

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

test/test_core.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import random
1111
import re
1212
import shutil
13+
import signal
1314
import sys
1415
import time
1516
import unittest
@@ -6179,6 +6180,20 @@ def test_sigalrm(self):
61796180
def test_signals(self):
61806181
self.do_core_test(test_file('test_signals.c'))
61816182

6183+
@parameterized({
6184+
'sigint': (['sigint', signal.SIGINT, 128+signal.SIGINT, True]),
6185+
'sigtrap': (['sigtrap', signal.SIGTRAP, 7, False])
6186+
})
6187+
def test_sig_default(self, suffix, signal, exit_code, assert_identical):
6188+
self.do_run_from_file(
6189+
test_file('test_sig_default.c'),
6190+
test_file(f'test_sig_default_{suffix}.out'),
6191+
emcc_args=['-sEXIT_RUNTIME'],
6192+
args=[str(int(signal))],
6193+
assert_identical=assert_identical,
6194+
assert_returncode=exit_code
6195+
)
6196+
61826197
@no_windows('https://github.com/emscripten-core/emscripten/issues/8882')
61836198
@requires_node
61846199
def test_unistd_access(self):

test/test_sig_default.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2023 The Emscripten Authors. All rights reserved.
3+
* Emscripten is available under two separate licenses, the MIT license and the
4+
* University of Illinois/NCSA Open Source License. Both these licenses can be
5+
* found in the LICENSE file.
6+
*/
7+
8+
#include <stdio.h>
9+
#include <stdlib.h>
10+
#include <signal.h>
11+
#include <assert.h>
12+
13+
static void cleanExit() {
14+
puts("3");
15+
}
16+
17+
int main(int argc, char **argv) {
18+
atexit(cleanExit);
19+
puts("1");
20+
raise(atoi(argv[1]));
21+
puts("2");
22+
return 0;
23+
}

test/test_sig_default_sigint.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1

test/test_sig_default_sigtrap.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
RuntimeError: unreachable

0 commit comments

Comments
 (0)