From nobody Mon Dec 06 15:56:32 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 7386618C5C26; Mon, 6 Dec 2021 15:56:38 +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 4J77Mk2lRlz4bbc; Mon, 6 Dec 2021 15:56:34 +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 9F59C6A68; Mon, 6 Dec 2021 15:56:32 +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 1B6FuWDZ033661; Mon, 6 Dec 2021 15:56:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1B6FuWok033660; Mon, 6 Dec 2021 15:56:32 GMT (envelope-from git) Date: Mon, 6 Dec 2021 15:56:32 GMT Message-Id: <202112061556.1B6FuWok033660@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: 359f5cf29ff1 - stable/13 - 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/13 X-Git-Reftype: branch X-Git-Commit: 359f5cf29ff125a9f32d1ec70b73ecbdc49c956c Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1638806195; 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=mwmlvKnye5yUDocbJqchwsJ6EOx/xXQ/+itKz5P4FiU=; b=EyX4nlYLUD07zjc5XHMZQLvev2SFmzdAzxmCzGwonU91xIIlup5h1gMcpwlQfl41ugGgEv smHXUspeDB7ZfGGoGHpBtw5kK31QdV3n9Mf+vJB11SMfdg4olkrmKHK9BYqxf8Qj3sNvvA CL+Va/HPNGQ0GeL1ioDUnx4D2OktCosSyyVQ5so8cQNO+7NflyKpgCrOXTn7CmvnTSLLuF QxA3AuU28/Mg5ppIolMUcdYNwJiq+U95+6hotqH3HCpJE2i0A/WL+Q3bMEKeAdKCMEwXae RsNzCT6SBiPcKnRdpIVUIMpST9uy5XzFRv9z8BjdZxpPhIWAMLyflgpErVxHtQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1638806195; a=rsa-sha256; cv=none; b=RMmFARTTrC8HScqrIryQDjDvRiLQP14MoR0Da4oIzt0Ywvb88RDi11Ckdq3BbmmtSqFjof Mq0J5ZN1xn7Hyl7GLOJAz8B9S5NbTSbc2hRD+sHvChOsufSdSPAqY+gnBnK6unyZtu8Qhp 4JEQtPpGySuYWvkYodW+muzUZNF3CWRdNfXDeESPxiStv605TaKX16fHauTEvPfQOknxwt Y1naJHhRs7CP7gOi5EKfHd/t62KuL2+fnWyJ+/M1EhYPpqxLKV62R5m+LQT1b7XfALWckm td5orraJE8GAWsuIlhiVzTZZ+P64IsQToHdKZ1VzobuhlM0QLtOEnOm89MFPPQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=359f5cf29ff125a9f32d1ec70b73ecbdc49c956c commit 359f5cf29ff125a9f32d1ec70b73ecbdc49c956c Author: Warner Losh AuthorDate: 2021-11-23 20:37:14 +0000 Commit: Warner Losh CommitDate: 2021-12-06 15:55:57 +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 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()); +}