From nobody Mon Dec 06 15:55:16 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 A209518C3F50; Mon, 6 Dec 2021 15:55:20 +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 4J77LF6JZCz4Zr9; Mon, 6 Dec 2021 15:55:17 +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 105BC66B5; Mon, 6 Dec 2021 15:55:17 +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 1B6FtGnu032739; Mon, 6 Dec 2021 15:55:16 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1B6FtGYT032738; Mon, 6 Dec 2021 15:55:16 GMT (envelope-from git) Date: Mon, 6 Dec 2021 15:55:16 GMT Message-Id: <202112061555.1B6FtGYT032738@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Warner Losh Subject: git: ab44780f2c79 - stable/12 - 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/stable/12 X-Git-Reftype: branch X-Git-Commit: ab44780f2c79f81f496507af66f174d47997a493 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1638806118; 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=JQ2qZsYfkLW+aUK2EDqWT+CSCG4E8D6iiuL9ERYuS+A=; b=xBLK25+sq4wthnzPGrhU3tyQnTOtF3JWc1gbZRAIWIuJH5Z1pldmaS9aWripZCwcMB70EE vnK72FTShGm+e+GSihZp/S/g2gY2l6VHGPT6oAhW7mqiJQPBtBo5oWUCabd/i/KqQZg4/C xOzH7tujUdQ0LB6SBuqpmhjbqSW0z57ddUOMsyLiKvMjJul7fcWgt5zFCFsPQqcnM40Uxq SfgUt8RfPDEWAA7uZJx3pw27ileIiOu80YTh4rZhDc9C0aEVtwJDOSG6+RuyEpO35d1j3C +tieWNRuxmMa0f8zG57VbHdwrM/QU48pxx9ywzGoRqfNu6gjS9mE8DvYr+Y7YA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1638806118; a=rsa-sha256; cv=none; b=e90kw1osvRCszmh1GJACFbRtBkfE0NIsmMpurXt98cpmE0vD7OoXy69xS1i51JGBH2QX2u n1w6MRT2N0TkfnjOx1oDKxtEY6p0F3hbz1QxCyQ9mq5JVMMoewUTnALacM0JpDPrGBmKF2 hdGqcCBxnu4IdGebfHyF0GHeJXj6aZvMWX0cMpjG6xQnO9IkJjcORSWehoJaNf+8oQDP89 FtMoWbQheOTXe6vRUHB/0AS79FEenk9uInUZG8D1HHyT+aUPVRHeT4AXjTtdPRfdGPYbyR rAwXCTY6PRpjIA9iL4gBhdmk0EAnxEpmeIMOTbbojhFybHtmEV9uuyUE/ZdWEw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=ab44780f2c79f81f496507af66f174d47997a493 commit ab44780f2c79f81f496507af66f174d47997a493 Author: Warner Losh AuthorDate: 2021-11-23 20:37:14 +0000 Commit: Warner Losh CommitDate: 2021-12-06 15:54:10 +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 (cherry picked from commit afc5ab870d8661a7dacdbd65554c2f3533aecb8d) --- 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 0ab4a70a41b8..3286e7d8b80d 100644 --- a/tests/sys/kern/Makefile +++ b/tests/sys/kern/Makefile @@ -5,6 +5,7 @@ TESTSRC= ${SRCTOP}/contrib/netbsd-tests/kernel TESTSDIR= ${TESTSBASE}/sys/kern +ATF_TESTS_C+= basic_signal ATF_TESTS_C+= kern_copyin ATF_TESTS_C+= kern_descrip_test ATF_TESTS_C+= ptrace_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()); +}