From nobody Tue Nov 23 20:41:48 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id E52CA18A3EE7; Tue, 23 Nov 2021 20:41:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HzGJr49jkz4dP3; Tue, 23 Nov 2021 20:41:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 702851D443; Tue, 23 Nov 2021 20:41:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1ANKfmcD034904; Tue, 23 Nov 2021 20:41:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1ANKfm92034903; Tue, 23 Nov 2021 20:41:48 GMT (envelope-from git) Date: Tue, 23 Nov 2021 20:41:48 GMT Message-Id: <202111232041.1ANKfm92034903@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: afc5ab870d86 - main - Basic signal tests: Can we deliver a signal? List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: afc5ab870d8661a7dacdbd65554c2f3533aecb8d Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1637700108; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=NGdv37V8+GlfybK5CWe+ijlxdPx1jeUUcPay9gujQLg=; b=QLnzB+xYb3EqiH4jMcfnhc0vOC9mbBbMvC0NOGioLdNoaEMYgYx4SQIXwyBVaIkLK+B3ck 6YTFG/ZJ0+Q+I9jlRNDl/EuWp4WSPkeBieGM6vZEA3wLTbdRoDW+ucuxiZhcqj87VkPz2R rf1AlzGezvyKgHGCEdhlSZpMZ/VVm18QMzXyeiT3SwKg2BOH0mPyx8MMX98Mk1NLwGcsW4 xKo1SSEy/sg74qpsxacZCpRp5sTlnXGIujtyCiy9SDOneBvIg1yTxugxfXxjZ+SB6966uG jOJwr5Aa9BV380GGsBCI6LLvTCfKNs3JZEc+/rrvcTHXrIFPKgGMY1GgbewBng== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1637700108; a=rsa-sha256; cv=none; b=rtcfPDii7o6rS4QeeXyTEcI1vBm7eTX5b6GVCXaAxi1EZins7M5ax1Cwzvs6Lgjx3S2vLk g04MBdL7xYksq36SCHVrZFUJQ4yOlOscQRWEFcY3484MWH0SIBPsgNsHoqWFxvF9a7+Luq X9ZWVqgManEAruKLSRpOSpq8+py9m3Lq2W/jEuJO7PaG8dRRfTBgs46lPY+kiqqVCGz3uR 6Qc0moY7GlVWU/kg45mpocN3A9cqH1zUI3hgGcWWOaQYBnWByF8YVOL/bt4DiKSFBXj3Gi jKldEa3NFP2kxjWvgqrjc84caQfWKWA3eW6muHOwhwlL5mZJO7MN1Mw72VJjoQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=afc5ab870d8661a7dacdbd65554c2f3533aecb8d commit afc5ab870d8661a7dacdbd65554c2f3533aecb8d Author: Warner Losh AuthorDate: 2021-11-23 20:37:14 +0000 Commit: Warner Losh CommitDate: 2021-11-23 20:37:14 +0000 Basic signal tests: Can we deliver a signal? Basic signal tests that tests can we deliver a signal via raise() and can we deliver one via SIGALARM asynchronously. In addition, tests whether or not on ARM T32 (Thumb) code can interrupt A32 (normal) and vice versa. While this test is aimed at ensuring basic qemu signals are working, it's good to have in the base. Sponsored by: Netflix Discussed with: kevans, cognet Differential Revision: https://reviews.freebsd.org/D33078 --- tests/sys/kern/Makefile | 1 + tests/sys/kern/basic_signal.c | 159 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 160 insertions(+) diff --git a/tests/sys/kern/Makefile b/tests/sys/kern/Makefile index b0f83b97db41..b8fee0944c06 100644 --- a/tests/sys/kern/Makefile +++ b/tests/sys/kern/Makefile @@ -9,6 +9,7 @@ TESTSRC= ${SRCTOP}/contrib/netbsd-tests/kernel TESTSDIR= ${TESTSBASE}/sys/kern +ATF_TESTS_C+= basic_signal #ATF_TESTS_C+= kcov ATF_TESTS_C+= kern_copyin ATF_TESTS_C+= kern_descrip_test diff --git a/tests/sys/kern/basic_signal.c b/tests/sys/kern/basic_signal.c new file mode 100644 index 000000000000..0b3200e2b8ab --- /dev/null +++ b/tests/sys/kern/basic_signal.c @@ -0,0 +1,159 @@ +/*- + * Copyright (c) 2021 Warner Losh + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include +#include +#include + +static volatile sig_atomic_t signal_fired = 0; + +static void +sig_handler(int signo, siginfo_t *info __unused, void *ucp __unused) +{ + signal_fired++; +} + +ATF_TC(signal_test); + +ATF_TC_HEAD(signal_test, tc) +{ + + atf_tc_set_md_var(tc, "descr", "Testing delivery of a signal"); +} + +ATF_TC_BODY(signal_test, tc) +{ + /* + * Setup the signal handlers + */ + struct sigaction sa = { + .sa_sigaction = sig_handler, + .sa_flags = SA_SIGINFO, + }; + ATF_REQUIRE(sigemptyset(&sa.sa_mask) == 0); + ATF_REQUIRE(sigaction(SIGUSR1, &sa, NULL) == 0); + ATF_REQUIRE(sigaction(SIGUSR2, &sa, NULL) == 0); + ATF_REQUIRE(sigaction(SIGALRM, &sa, NULL) == 0); + + /* + * Fire SIGUSR1 + */ + ATF_CHECK(signal_fired == 0); + ATF_REQUIRE(raise(SIGUSR1) == 0); + ATF_CHECK(signal_fired == 1); + + /* + * Fire SIGUSR2 + */ + ATF_REQUIRE(raise(SIGUSR2) == 0); + ATF_CHECK(signal_fired == 2); + + /* + * Fire SIGALRM after a timeout + */ + ATF_REQUIRE(alarm(1) == 0); + ATF_REQUIRE(pause() == -1); + ATF_REQUIRE(errno == EINTR); + ATF_CHECK(signal_fired == 3); +} + +/* + * Special tests for 32-bit arm. We can call thumb code (really just t32) from + * normal (a32) mode and vice versa. Likewise, signals can interrupt a T32 + * context with A32 code and vice versa. Make sure these all work with a simple + * test that raises the signal and ensures that it executed. No other platform + * has these requirements. Also note: we only support thumb2, so there's no T16 + * vs T32 issues we have to test for. + */ +#ifdef __arm__ + +#define a32_isa __attribute__((target("arm"))) +#define t32_isa __attribute__((target("thumb"))) + +static volatile sig_atomic_t t32_fired = 0; +static volatile sig_atomic_t a32_fired = 0; + +a32_isa static void +sig_a32(int signo, siginfo_t *info __unused, void *ucp __unused) +{ + a32_fired++; +} + +t32_isa static void +sig_t32(int signo, siginfo_t *info __unused, void *ucp __unused) +{ + t32_fired++; +} + + +ATF_TC(signal_test_T32_to_A32); + +ATF_TC_HEAD(signal_test_T32_to_A32, tc) +{ + + atf_tc_set_md_var(tc, "descr", "Testing delivery of a signal from T32 to A32"); +} + +t32_isa ATF_TC_BODY(signal_test_T32_to_A32, tc) +{ + /* + * Setup the signal handlers + */ + struct sigaction sa = { + .sa_sigaction = sig_a32, + .sa_flags = SA_SIGINFO, + }; + ATF_REQUIRE(sigemptyset(&sa.sa_mask) == 0); + ATF_REQUIRE(sigaction(SIGUSR1, &sa, NULL) == 0); + + ATF_REQUIRE((((uintptr_t)sig_a32) & 1) == 0); /* Make sure compiled as not thumb */ + + ATF_CHECK(a32_fired == 0); + ATF_REQUIRE(raise(SIGUSR1) == 0); + ATF_CHECK(a32_fired == 1); +} + +ATF_TC(signal_test_A32_to_T32); + +ATF_TC_HEAD(signal_test_A32_to_T32, tc) +{ + + atf_tc_set_md_var(tc, "descr", "Testing delivery of a signal from A32 to T32"); +} + +a32_isa ATF_TC_BODY(signal_test_A32_to_T32, tc) +{ + /* + * Setup the signal handlers + */ + struct sigaction sa = { + .sa_sigaction = sig_t32, + .sa_flags = SA_SIGINFO, + }; + ATF_REQUIRE(sigemptyset(&sa.sa_mask) == 0); + ATF_REQUIRE(sigaction(SIGUSR1, &sa, NULL) == 0); + + ATF_REQUIRE((((uintptr_t)sig_t32) & 1) == 1); /* Make sure compiled as thumb */ + + ATF_CHECK(t32_fired == 0); + ATF_REQUIRE(raise(SIGUSR1) == 0); + ATF_CHECK(t32_fired == 1); +} +#endif + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, signal_test); +#ifdef __arm__ + ATF_TP_ADD_TC(tp, signal_test_T32_to_A32); + ATF_TP_ADD_TC(tp, signal_test_A32_to_T32); +#endif + + return (atf_no_error()); +}