git: e19be5b01eab - stable/14 - SIGSYS: add tests
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 09 Oct 2023 03:41:15 UTC
The branch stable/14 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=e19be5b01eabc5260011d97ae807e8d2410cf511 commit e19be5b01eabc5260011d97ae807e8d2410cf511 Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2023-09-25 18:40:28 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2023-10-09 03:24:31 +0000 SIGSYS: add tests (cherry picked from commit 0afcac3e37e911f7e387ebeb2aae19b2b00ca4cc) --- tests/sys/kern/Makefile | 1 + tests/sys/kern/sigsys.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/tests/sys/kern/Makefile b/tests/sys/kern/Makefile index f2fe9e7008d9..6396b22005c3 100644 --- a/tests/sys/kern/Makefile +++ b/tests/sys/kern/Makefile @@ -48,6 +48,7 @@ TEST_METADATA.unix_seqpacket_test+= timeout="15" ATF_TESTS_C+= unix_socketpair_test ATF_TESTS_C+= waitpid_nohang ATF_TESTS_C+= pdeathsig +ATF_TESTS_C+= sigsys ATF_TESTS_SH+= coredump_phnum_test ATF_TESTS_SH+= sonewconn_overflow diff --git a/tests/sys/kern/sigsys.c b/tests/sys/kern/sigsys.c new file mode 100644 index 000000000000..75e3816fc158 --- /dev/null +++ b/tests/sys/kern/sigsys.c @@ -0,0 +1,69 @@ +/*- + * Copyright (c) 2023 The FreeBSD Foundation + * + * SPDX-License-Identifier: BSD-2-Clause + * + * This software were developed by Konstantin Belousov <kib@FreeBSD.org> + * under sponsorship from the FreeBSD Foundation. + */ + +#include <sys/syscall.h> + +#include <atf-c.h> +#include <errno.h> +#include <signal.h> +#include <stdatomic.h> +#include <stdbool.h> + +static sig_atomic_t sigsys_cnt; + +static void +sigsys_handler(int signo, siginfo_t *si, void *ucp) +{ + sigsys_cnt++; +} + +ATF_TC(sigsys_test); + +ATF_TC_HEAD(sigsys_test, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Testing delivery of SIGSYS on invalid syscalls"); +} + +ATF_TC_BODY(sigsys_test, tc) +{ + struct sigaction sa; + + memset(&sa, 0, sizeof(sa)); + sa.sa_sigaction = sigsys_handler; + sa.sa_flags = SA_SIGINFO; + ATF_REQUIRE(sigaction(SIGSYS, &sa, NULL) == 0); + + ATF_REQUIRE(syscall(273) == -1); /* reserved */ + ATF_CHECK_ERRNO(ENOSYS, true); + atomic_signal_fence(memory_order_seq_cst); + ATF_CHECK_EQ(1, sigsys_cnt); + + ATF_REQUIRE(syscall(440) == -1); /* SYS_kse_switchin */ + ATF_CHECK_ERRNO(ENOSYS, true); + atomic_signal_fence(memory_order_seq_cst); + ATF_CHECK_EQ(2, sigsys_cnt); + + /* Hope this is enough for say next two months */ + ATF_REQUIRE(syscall(3000000) == -1); + ATF_CHECK_ERRNO(ENOSYS, true); + atomic_signal_fence(memory_order_seq_cst); + ATF_CHECK_EQ(3, sigsys_cnt); + + ATF_REQUIRE(syscall(SYS_afs3_syscall) == -1); + ATF_CHECK_ERRNO(ENOSYS, true); + atomic_signal_fence(memory_order_seq_cst); + ATF_CHECK_EQ(4, sigsys_cnt); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, sigsys_test); + return (atf_no_error()); +}