From nobody Wed Sep 27 12:52:27 2023 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 4Rwc2g2jxyz4vQXg; Wed, 27 Sep 2023 12:52:27 +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 4Rwc2g1y6dz4TMl; Wed, 27 Sep 2023 12:52:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1695819147; 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=n1Z1+RgqWWgKRaTo8rICf8dljLQkqpbdY5+61dcoJD4=; b=sUGIbwssH0eY9pXAJ+BhNjrgcDSbQtfDgp6D4ACaN3aS0LjiDjzu3G/W5VSoQ49xkAia/n yOOUFYUGLsKdejY08fOO4C8NdonWo8R4PI3T6u3t+MXhdmPppjPFGeDjNa7bcd4W0bg8FA eU2J8Q7btxVvS0D9sWXFafrEwZDnVwloVbzvjtp7To171RSNI/TOYct8pUtQxII3w5nEVl 3rNm+4i8Za2X0qHSNgP/XIn7jsz1ilKCoL5hvjkhW7tAI/JoaRjbrcCZ+YhiYll1d3ghvq sJZKgy1UybDjThBQo8/tC3SgYvJELCxvE6ObyklEhA/F1yYme5sGbsK00gyj2w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1695819147; a=rsa-sha256; cv=none; b=urR+wjuyxkYB7/xYIKuAV90DzsK6ZUM4MAJ5HIyIc/6RXvQ7mMsilu1iu+flfeHsNN29t6 /eJSkHytA7cTCA2GU9flmYVZjuFoALHJDHgpdaRaZUGpxemIH4IlfK4haDAwDvwYGJlvqU B7X0D5EtzHT+I+hKWDDr/uEpkiVP7Y4CTLoC/3cdZzqq2wRBpMghCronbxHoK/tp9HPtlJ NlQ0KIL9Cn3zV4C41IX2TWPgkBNUTiNEbWv17gJyfe4fKGgZuGVm4gvktTWXHxSV7cqkRj mMk5YlW2nGQmB3Ljk8+2uJ8OBzLxoo3+fQgyA/+ddVJlG7Tqn3x0Js2AA6BRGg== 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=1695819147; 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=n1Z1+RgqWWgKRaTo8rICf8dljLQkqpbdY5+61dcoJD4=; b=WBnnG4RTV1CrHKup68sfP3y96TFMTcuAiXEKkKBbDXL5NiLrZ+Cu+mbkTGC7LpN7drTr2p 5Zs1QY2JuiHJjoaQNKybR/LTx9/q/NKQiuR1IlcPc5vUQrOShWvgS9Nr8fjSO1JQumgHSJ ChQkzEB0LEAxXZbkthqgDZe94C+CEi2JIHtb/ZhK2CRapa7U3OmXCKEJlXXs7TZii6pgzT pL8n6UkKdRFaanm69UDPNUtseM2CKzhztMdPtoXI2IMOVwyIZfwYNVgSFeCipokJXsDtyS BP9cGjiL1vH03L8aocWuEkr0ZcOIBrGBDpzaZWAQDeJUaD31qhFbinaxovp6ZQ== 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 4Rwc2g0zTGzfx9; Wed, 27 Sep 2023 12:52:27 +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 38RCqRGE023147; Wed, 27 Sep 2023 12:52:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 38RCqRkE023144; Wed, 27 Sep 2023 12:52:27 GMT (envelope-from git) Date: Wed, 27 Sep 2023 12:52:27 GMT Message-Id: <202309271252.38RCqRkE023144@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: e4ed8e67e206 - stable/13 - socket tests: Add a regression test for MSG_WAITALL 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: e4ed8e67e206c069955d541de41addcd0da05b82 Auto-Submitted: auto-generated The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=e4ed8e67e206c069955d541de41addcd0da05b82 commit e4ed8e67e206c069955d541de41addcd0da05b82 Author: Mark Johnston AuthorDate: 2023-08-31 17:29:29 +0000 Commit: Mark Johnston CommitDate: 2023-09-27 12:33:50 +0000 socket tests: Add a regression test for MSG_WAITALL PR: 212716 MFC after: 1 week Sponsored by: The FreeBSD Foundation (cherry picked from commit 38426b32e106cf251520259b29779372eda7a5f8) --- tests/sys/kern/Makefile | 2 + tests/sys/kern/socket_msg_waitall.c | 181 ++++++++++++++++++++++++++++++++++++ 2 files changed, 183 insertions(+) diff --git a/tests/sys/kern/Makefile b/tests/sys/kern/Makefile index 8dfb3ba47a90..95d6ef9b7bc0 100644 --- a/tests/sys/kern/Makefile +++ b/tests/sys/kern/Makefile @@ -25,6 +25,7 @@ ATF_TESTS_C+= sched_affinity ATF_TESTS_C+= sigaltstack ATF_TESTS_C+= sigwait ATF_TESTS_C+= socket_msg_trunc +ATF_TESTS_C+= socket_msg_waitall TEST_METADATA.sigwait+= is_exclusive="true" .if ${MACHINE_ARCH} != "i386" && ${MACHINE_ARCH:Mpowerpc*} == "" && \ ${MACHINE_CPUARCH} != "mips" @@ -62,6 +63,7 @@ LIBADD.ptrace_test+= pthread LIBADD.unix_seqpacket_test+= pthread LIBADD.kcov+= pthread LIBADD.ktls_test+= crypto +LIBADD.socket_msg_waitall+= pthread LIBADD.sendfile_helper+= pthread LIBADD.fdgrowtable_test+= util pthread kvm procstat LIBADD.sigwait+= rt diff --git a/tests/sys/kern/socket_msg_waitall.c b/tests/sys/kern/socket_msg_waitall.c new file mode 100644 index 000000000000..e9018b47eec1 --- /dev/null +++ b/tests/sys/kern/socket_msg_waitall.c @@ -0,0 +1,181 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2023 The FreeBSD Foundation + * + * This software was developed by Mark Johnston under sponsorship from + * the FreeBSD Foundation. + */ + +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include + +struct close_test_params { + struct sockaddr_storage sa; + size_t msglen; + int count; + int af, type, proto; +}; + +static void * +close_test_client(void *arg) +{ + struct close_test_params *p = arg; + char *buf; + size_t buflen; + + buflen = p->msglen + 1; + buf = malloc(buflen); + ATF_REQUIRE(buf != NULL); + + while (p->count-- > 0) { + ssize_t n; + int error, s; + + s = socket(p->af, p->type, p->proto); + ATF_REQUIRE_MSG(s >= 0, "socket: %s", strerror(errno)); + + error = connect(s, (struct sockaddr *)&p->sa, p->sa.ss_len); + ATF_REQUIRE_MSG(error == 0, "connect: %s", strerror(errno)); + + n = recv(s, buf, buflen, MSG_WAITALL); + ATF_REQUIRE_MSG(n == (ssize_t)p->msglen, + "recv: %s", strerror(errno)); + + ATF_REQUIRE(close(s) == 0); + } + + return (NULL); +} + +static void +close_test(struct sockaddr *sa, unsigned int count, int af, int type, int proto) +{ + struct close_test_params p; + const char *msg; + pthread_t t; + size_t msglen; + int error, s; + + s = socket(af, type, proto); + ATF_REQUIRE_MSG(s >= 0, "socket %s", strerror(errno)); + + ATF_REQUIRE_MSG(bind(s, sa, sa->sa_len) == 0, + "bind: %s", strerror(errno)); + ATF_REQUIRE_MSG(listen(s, 1) == 0, + "listen: %s", strerror(errno)); + ATF_REQUIRE_MSG(getsockname(s, sa, &(socklen_t){ sa->sa_len }) == 0, + "getsockname: %s", strerror(errno)); + + msg = "hello bonjour"; + msglen = strlen(msg) + 1; + p = (struct close_test_params){ + .count = count, + .msglen = msglen, + .af = af, + .type = type, + .proto = proto, + }; + memcpy(&p.sa, sa, sa->sa_len); + error = pthread_create(&t, NULL, close_test_client, &p); + ATF_REQUIRE_MSG(error == 0, "pthread_create: %s", strerror(error)); + + while (count-- > 0) { + ssize_t n; + int cs; + + cs = accept(s, NULL, NULL); + ATF_REQUIRE_MSG(cs >= 0, "accept: %s", strerror(errno)); + + n = send(cs, msg, msglen, 0); + ATF_REQUIRE_MSG(n == (ssize_t)msglen, + "send: %s", strerror(errno)); + + ATF_REQUIRE(close(cs) == 0); + } + + ATF_REQUIRE(close(s) == 0); + ATF_REQUIRE(pthread_join(t, NULL) == 0); +} + +/* + * Make sure that closing a connection kicks a MSG_WAITALL recv() out of the + * syscall. See bugzilla PR 212716. + */ +ATF_TC(close_tcp); +ATF_TC_HEAD(close_tcp, tc) +{ + atf_tc_set_md_var(tc, "timeout", "10"); +} +ATF_TC_BODY(close_tcp, tc) +{ + struct sockaddr_in sin; + + sin = (struct sockaddr_in){ + .sin_len = sizeof(sin), + .sin_family = AF_INET, + .sin_addr = { htonl(INADDR_LOOPBACK) }, + .sin_port = htons(0), + }; + close_test((struct sockaddr *)&sin, 1000, AF_INET, SOCK_STREAM, + IPPROTO_TCP); +} + +/* A variant of the above test for UNIX domain stream sockets. */ +ATF_TC(close_unix_stream); +ATF_TC_HEAD(close_unix_stream, tc) +{ + atf_tc_set_md_var(tc, "timeout", "10"); +} +ATF_TC_BODY(close_unix_stream, tc) +{ + struct sockaddr_un sun; + + sun = (struct sockaddr_un){ + .sun_len = sizeof(sun), + .sun_family = AF_UNIX, + .sun_path = "socket_msg_waitall_unix", + }; + close_test((struct sockaddr *)&sun, 1000, AF_UNIX, SOCK_STREAM, 0); + ATF_REQUIRE_MSG(unlink(sun.sun_path) == 0, + "unlink: %s", strerror(errno)); +} + +/* A variant of the above test for UNIX domain seqpacket sockets. */ +ATF_TC(close_unix_seqpacket); +ATF_TC_HEAD(close_unix_seqpacket, tc) +{ + atf_tc_set_md_var(tc, "timeout", "10"); +} +ATF_TC_BODY(close_unix_seqpacket, tc) +{ + struct sockaddr_un sun; + + sun = (struct sockaddr_un){ + .sun_len = sizeof(sun), + .sun_family = AF_UNIX, + .sun_path = "socket_msg_waitall_unix", + }; + close_test((struct sockaddr *)&sun, 1000, AF_UNIX, SOCK_SEQPACKET, 0); + ATF_REQUIRE_MSG(unlink(sun.sun_path) == 0, + "unlink: %s", strerror(errno)); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, close_tcp); + ATF_TP_ADD_TC(tp, close_unix_stream); + ATF_TP_ADD_TC(tp, close_unix_seqpacket); + + return (atf_no_error()); +}