sigaction tests: does normal / siglongjmp return from sighandler work?
MODIFY
bin/utest/Makefile
bin/utest/Makefile
@@ -14,6 +14,7 @@ SOURCES = \
signal.c \
stat.c \
setjmp.c \
+ sigaction.c \
utest.c
PROGRAM = utest

MODIFY
bin/utest/main.c
bin/utest/main.c
@@ -51,6 +51,8 @@ int main(int argc, char **argv) {
CHECKRUN_TEST(exc_sigsys);
CHECKRUN_TEST(syscall_in_bds);
CHECKRUN_TEST(setjmp);
+ CHECKRUN_TEST(sigaction_with_setjmp);
+ CHECKRUN_TEST(sigaction_handler_returns);
CHECKRUN_TEST(fpu_fcsr);
CHECKRUN_TEST(fpu_gpr_preservation);

MODIFY
bin/utest/setjmp.c
bin/utest/setjmp.c
static jmp_buf jump_buffer;
-noreturn void do_longjmp(int count) {
+noreturn static void do_longjmp(int count) {
longjmp(jump_buffer, count);
+ assert(0); /* Shouldn't reach here. */
}
int test_setjmp(void) {

ADD
bin/utest/sigaction.c
+#include <assert.h>
+#include <signal.h>
+#include <string.h>
+#include <setjmp.h>
+#include <stdnoreturn.h>
+
+static sigjmp_buf jump_buffer;
+
+noreturn static void sigint_handler(int signo) {
+ siglongjmp(jump_buffer, 42);
+ assert(0); /* Shouldn't reach here. */
+}
+
+int test_sigaction_with_setjmp(void) {
+ struct sigaction sa;
+
+ memset(&sa, 0, sizeof(sa));
+ sa.sa_handler = sigint_handler;
+ assert(sigaction(SIGINT, &sa, NULL) == 0);
+
+ if (sigsetjmp(jump_buffer, 1) != 42) {
+ raise(SIGINT);
+ assert(0); /* Shouldn't reach here. */
+ }
+
+ return 0;
+}
+
+static volatile int sigusr1_handled;
+
+static void sigusr1_handler(int signo) {
+ sigusr1_handled = 1;
+}
+
+int test_sigaction_handler_returns(void) {
+ struct sigaction sa;
+
+ memset(&sa, 0, sizeof(sa));
+ sa.sa_handler = sigusr1_handler;
+ assert(sigaction(SIGUSR1, &sa, NULL) == 0);
+
+ assert(sigusr1_handled == 0);
+ raise(SIGUSR1);
+ assert(sigusr1_handled == 1);
+
+ return 0;
+}

MODIFY
bin/utest/utest.h
bin/utest/utest.h
@@ -55,4 +55,7 @@ int test_syscall_in_bds(void);
int test_setjmp(void);
+int test_sigaction_with_setjmp(void);
+int test_sigaction_handler_returns(void);
+
#endif /* __UTEST_H__ */

MODIFY
sys/tests/utest.c
sys/tests/utest.c
@@ -94,6 +94,9 @@ UTEST_ADD_SIMPLE(fstat);
UTEST_ADD_SIMPLE(setjmp);
+UTEST_ADD_SIMPLE(sigaction_with_setjmp);
+UTEST_ADD_SIMPLE(sigaction_handler_returns);
+
#if 0
UTEST_ADD_SIMPLE(fpu_fcsr);
UTEST_ADD_SIMPLE(fpu_gpr_preservation);

sigaction tests: does normal / siglongjmp return from sighandler work? (#566)