From nobody Thu Apr 25 18:36:26 2024 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 4VQPhB6NMnz5JJDW; Thu, 25 Apr 2024 18:36:26 +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 4VQPhB4nTVz4YRH; Thu, 25 Apr 2024 18:36:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1714070186; 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=W9vJ/Ra0qJsBgjjaD+snGmOXN7Y0L5B7Usowu67fC/E=; b=hx3qaDLi5sgub4rlgtj9YfQiuiWIY+38E4yc6lOKbBPNM1MBQRc6eNT0/uqeFE6WeoAZWA EnF/yie4IlI5629WOeCpO87XPI+7zOAOLkaoxcJXJt7WpGK5EQT23D3g6ViZEU0/FamYqM U52n10+JcpTdEzyxlZyF38c1H6LhVgfnKzsISuuYbGMVy8uoO+PmS8xSvTqoAvxgebm9ly jH7hRx2HSiH8MM4uJfMVyAFEszGYsbS9z+ZdekEZccdLDtTFDZnUbqM+jrkNeYx01Q++TY rFGlzDivXq+Wy3AuCxp15aVJJuiTSAxCZ546hOvi68vvy4C2NvrMXqGk4KdKMg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1714070186; a=rsa-sha256; cv=none; b=us+Cr9bSQuJp8DYweuTgXxRW07NnfjRY9Fq0zziRvhXYBbJl8U3TvjiWdelZ8GhCFw/94t 719OHIWHuX0eUnGbIsE2SfbSeh4eKO768MBa4iBhmm4pGuOWH7LrMijWuNIXAd0xqvJPLi 7j0G8Yae1H7G7gF+GjBmmAa1SPfwoy1lbF7qeJWhWlLFiCANY+9RPePBvMjCttHx3RMjJc X95YSgME8sbOrdv2U4bWMtrAoxBbhCVO07Pp2Z9ORIK/OJSbcu6f1XjV8ADnQbUTbdaSA/ bKhnPvhxN6gUt4vUhQTxRX/V531+BmGqZgZHFD0ExYxKhMibTCC8cRaMNBmKlA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1714070186; 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=W9vJ/Ra0qJsBgjjaD+snGmOXN7Y0L5B7Usowu67fC/E=; b=LE3DN1h6D00gLIA2yCk2WRFNyMEAH3RvKqkUHyHcf8vWcLE3xYW9Wk8lEEbti+PAnN17r4 CNkHqsZRurH5Y+Z/d3SQ77OP3k5uniYktZY61NSFH10Tn8GcRIJaCqYyr3AJShpWnBLA1f cMwXrlWjmnuJNO/7XP3tdgE2fgsR79SDRqvTAUfFgO8nRPPNVRlcIhHp6kTjVyp0cqwrjc W0pvnCcJvVVzVYS/pVD5vZXAap8tl3WVG60eKyQkK6fOD4yu0mmvV8Cla5zVj/rBhqsiyd tt+NCC0KA+Z0M399IgKnRIQCdyW1CX6X0hLbaszQhJMaLnAXnLUFBOnqBrYznA== 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 4VQPhB3YrLz19BS; Thu, 25 Apr 2024 18:36:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 43PIaQVP032875; Thu, 25 Apr 2024 18:36:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 43PIaQYn032872; Thu, 25 Apr 2024 18:36:26 GMT (envelope-from git) Date: Thu, 25 Apr 2024 18:36:26 GMT Message-Id: <202404251836.43PIaQYn032872@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: 83a6e984ac01 - main - tftpd: Check the server status after each test. 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 83a6e984ac01657819418746f722163367ec30db Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=83a6e984ac01657819418746f722163367ec30db commit 83a6e984ac01657819418746f722163367ec30db Author: Dag-Erling Smørgrav AuthorDate: 2024-04-25 18:35:24 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2024-04-25 18:36:13 +0000 tftpd: Check the server status after each test. * In the setup phase, wait for the server to start (or fail to start) before proceeding with the test. This makes it possible to write test cases that don't expect a response from the server without ending up in a race over the server PID file. * After running each test, wait up to 30 seconds for the server to exit and check that the exit status matches what the test case says to expect (usually 0). * We still kill and collect the server in the cleanup phase, in case the test ended early. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D44956 --- libexec/tftpd/tests/functional.c | 44 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/libexec/tftpd/tests/functional.c b/libexec/tftpd/tests/functional.c index bbe4f3782192..3b70962854ba 100644 --- a/libexec/tftpd/tests/functional.c +++ b/libexec/tftpd/tests/functional.c @@ -208,11 +208,14 @@ ATF_TC_HEAD(name ## _v4, tc) \ } \ ATF_TC_BODY(name ## _v4, tc) \ { \ + int exitcode = 0; \ __VA_ARGS__; \ protocol = AF_INET; \ s = setup(&addr, __COUNTER__); \ name ## _body(); \ close(s); \ + if (exitcode >= 0) \ + check_server(exitcode); \ } \ ATF_TC_CLEANUP(name ## _v4, tc) \ { \ @@ -225,11 +228,14 @@ ATF_TC_HEAD(name ## _v6, tc) \ } \ ATF_TC_BODY(name ## _v6, tc) \ { \ + int exitcode = 0; \ __VA_ARGS__; \ protocol = AF_INET6; \ s = setup(&addr, __COUNTER__); \ name ## _body(); \ close(s); \ + if (exitcode >= 0) \ + check_server(exitcode); \ } \ ATF_TC_CLEANUP(name ## _v6, tc) \ { \ @@ -244,6 +250,33 @@ name ## _body(void) ATF_TP_ADD_TC(tp, name ## _v6); \ } while (0) +static void +sigalrm(int signo __unused) +{ +} + +/* Check that server exits with specific exit code */ +static void +check_server(int exitcode) +{ + struct sigaction sa = { .sa_handler = sigalrm }; + struct itimerval it = { .it_value = { .tv_sec = 30 } }; + FILE *f; + pid_t pid; + int wstatus; + + f = fopen(pidfile, "r"); + ATF_REQUIRE(f != NULL); + ATF_REQUIRE_INTEQ(1, fscanf(f, "%d", &pid)); + ATF_CHECK_INTEQ(0, fclose(f)); + ATF_REQUIRE_INTEQ(0, sigaction(SIGALRM, &sa, NULL)); + ATF_REQUIRE_EQ(0, setitimer(ITIMER_REAL, &it, NULL)); + ATF_REQUIRE_EQ(pid, waitpid(pid, &wstatus, 0)); + ATF_CHECK(WIFEXITED(wstatus)); + ATF_CHECK_INTEQ(exitcode, WEXITSTATUS(wstatus)); + unlink(pidfile); +} + /* Standard cleanup used by all testcases */ static void cleanup(void) @@ -254,12 +287,12 @@ cleanup(void) f = fopen(pidfile, "r"); if (f == NULL) return; + unlink(pidfile); if (fscanf(f, "%d", &pid) == 1) { kill(pid, SIGTERM); waitpid(pid, NULL, 0); } fclose(f); - unlink(pidfile); } /* Assert that two binary buffers are identical */ @@ -299,6 +332,9 @@ setup(struct sockaddr_storage *to, uint16_t idx) struct pidfh *pfh; uint16_t port = BASEPORT + idx; socklen_t len; + int pd[2]; + + ATF_REQUIRE_EQ(0, pipe2(pd, O_CLOEXEC)); if (protocol == PF_INET) { len = sizeof(addr4); @@ -358,6 +394,10 @@ setup(struct sockaddr_storage *to, uint16_t idx) break; default: /* In parent */ + ATF_REQUIRE_INTEQ(0, close(pd[1])); + /* block until other end is closed on exec() or exit() */ + ATF_REQUIRE_INTEQ(0, read(pd[0], &pd[1], sizeof(pd[1]))); + ATF_REQUIRE_INTEQ(0, close(pd[0])); bzero(to, sizeof(*to)); if (protocol == PF_INET) { struct sockaddr_in *to4 = (struct sockaddr_in *)to; @@ -374,7 +414,7 @@ setup(struct sockaddr_storage *to, uint16_t idx) to6->sin6_addr = loopback; } - close(server_s); + ATF_REQUIRE_INTEQ(0, close(server_s)); ATF_REQUIRE((client_s = socket(protocol, SOCK_DGRAM, 0)) > 0); break; }