From nobody Mon Apr 8 20:29:39 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 4VD10g6VFnz5HjHj; Mon, 8 Apr 2024 20:29:39 +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 4VD10g5vHPz45nx; Mon, 8 Apr 2024 20:29:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1712608179; 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=ulbIFc4d2kVe9H6Ol7JMSDngddCOmzzSNXjTClncxL8=; b=Id5HjP76SuDeky/8OzPe+hVqwmg0ysJ+dELOCcq68KyK8msgLeV0pu1jinO4hnUQon2wRx n1W5txfXie3VshV8VJJEmQt3oMswoWiWxd1e35GwvdwAfezsgUTXVEFeK1EZ6ePiHDPjNY Ke4EVoMAauCViUnzcDmDSoydApyy+mau4bNTZeEzLydzLIgne/iXfw4lkDFgRYRlHrLV4K dqTNC11DqA+rrrc7OJpPCdncLzwKp6P78+BsCn4xQuo5RarPWMRpxH94ysMrp14NSxROaF VV8J724G7wFj3oopkLxQ/RKV9aiQ41VpUs9QDXzRHRBdj9IsoyKKYDD8+PFUEA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1712608179; a=rsa-sha256; cv=none; b=J3y4teNr21a9KXjdcw39W9WRmh30PfengZURMhKIT3sp4h+SsKoCPdZ6Tepa44d8bBhA2T QcyZwT9xjEQu/m+Bx/9El1k2AXOM3lMF551KcAM4jWNJHLiLDlAE+4DQR56BaSx4vX8vY7 2NxDe8O5eQFgJdVzL+QDvXlmENXnjG8XFctyDGZTKpBlhQCkTINjQMCpDx6Su2P6mfi6RN KvlQuHvjkBl56Bf+MapnXif0uWhe1DlYdKfHEx5sILGxXfP48uTow9DM+VJ/aGW1UaoiL0 pBZfYUq8c/8P0/Kmfh2H1mVeZzL6n2zHPAwYY3sXnR+ra+0tVATXqehUq7LTmg== 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=1712608179; 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=ulbIFc4d2kVe9H6Ol7JMSDngddCOmzzSNXjTClncxL8=; b=D5BkBT5E/2tcbnv7VGXHjgO4yVatQ5DgKztQX8OBQeof9ngSD1w5vIm26Stii7BEXJkVsO GTjtQg49j+qR22h8mQIZUJt8MsICFhoX+zdpeRZLgM/j7ut0LloalG+7mdCd0RjVn2vNfD ucyBCxTnUWP2xCyNqQzqP+xmgvw2x2WKQyQ2QPWyGpYkdpG66Z4NT3o4nYP8541TbmyBLr S48u+Zoj/QEfXp4xj/gRTeoQU7l4n67OFgkNrNFr8Zfy8GjovdWvyAnNWSKzmh+ZN60Zu8 bep04vfzysol/JSy4Fp45qW+WOaGoKBZHj7+aUovjG5t2h6VYP5CNWEJyadXEQ== 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 4VD10g5VsxzQjY; Mon, 8 Apr 2024 20:29:39 +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 438KTd6J041439; Mon, 8 Apr 2024 20:29:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 438KTdCX041436; Mon, 8 Apr 2024 20:29:39 GMT (envelope-from git) Date: Mon, 8 Apr 2024 20:29:39 GMT Message-Id: <202404082029.438KTdCX041436@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: eb338e2370b4 - main - tests/unix_seqpacket: provide random data pumping test with MSG_EOR 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: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: eb338e2370b4644382e6404d7402bc05eef13e54 Auto-Submitted: auto-generated The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=eb338e2370b4644382e6404d7402bc05eef13e54 commit eb338e2370b4644382e6404d7402bc05eef13e54 Author: Gleb Smirnoff AuthorDate: 2024-04-08 20:16:50 +0000 Commit: Gleb Smirnoff CommitDate: 2024-04-08 20:16:50 +0000 tests/unix_seqpacket: provide random data pumping test with MSG_EOR Allocate a big chunk of randomly initialized memory. Send it to the peer in random sized chunks, throwing MSG_EOR at randomly initialized offsets. Receive into random sized chunks setting MSG_WAITALL randomly. Check that MSG_EORs where they should be, check that MSG_WAITALL is abode, but overriden by MSG_EOR. And finally memcmp() what we receive. Reviewed by: asomers, tuexen Differential Revision: https://reviews.freebsd.org/D43775 --- tests/sys/kern/unix_seqpacket_test.c | 151 +++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) diff --git a/tests/sys/kern/unix_seqpacket_test.c b/tests/sys/kern/unix_seqpacket_test.c index ca3fcdef9e6a..d463ae9b3ce6 100644 --- a/tests/sys/kern/unix_seqpacket_test.c +++ b/tests/sys/kern/unix_seqpacket_test.c @@ -1,5 +1,8 @@ /*- + * + * Copyright (c) 2024 Gleb Smirnoff * Copyright (c) 2014 Spectra Logic Corporation. All rights reserved. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -27,7 +30,9 @@ #include #include #include +#include #include +#include #include #include @@ -1089,6 +1094,151 @@ ATF_TC_BODY(sendrecv_128k_nonblocking, tc) test_sendrecv_symmetric_buffers(128 * 1024, false); } +ATF_TC(random_eor_and_waitall); +ATF_TC_HEAD(random_eor_and_waitall, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test random sized send/recv with " + "randomly placed MSG_EOR and randomly applied MSG_WAITALL on " + "PF_UNIX/SOCK_SEQPACKET"); +} + +struct random_eor_params { + u_long recvspace; + char *sendbuf; + size_t *records; + u_int nrecords; + int sock; + u_short seed[6]; +}; + +#define RANDOM_TESTSIZE ((size_t)100 * 1024 * 1024) +/* Below defines are factor of recvspace. */ +#define RANDOM_MAXRECORD 10 +#define RANDOM_SENDSIZE 2 +#define RANDOM_RECVSIZE 4 + +static void * +sending_thread(void *arg) +{ + struct random_eor_params *params = arg; + size_t off = 0; + int eor = 0; + + while (off < RANDOM_TESTSIZE) { + ssize_t len; + int flags; + + len = nrand48(¶ms->seed[3]) % + (RANDOM_SENDSIZE * params->recvspace); + if (off + len >= params->records[eor]) { + len = params->records[eor] - off; + flags = MSG_EOR; + eor++; + } else + flags = 0; + ATF_REQUIRE(send(params->sock, ¶ms->sendbuf[off], len, + flags) == len); + off += len; +#ifdef DEBUG + printf("send %zd%s\n", off, flags ? " EOR" : ""); +#endif + } + + return (NULL); +} + +ATF_TC_BODY(random_eor_and_waitall, tc) +{ + struct random_eor_params params; + void *recvbuf; + pthread_t t; + size_t off; + int fd[2], eor; + + arc4random_buf(params.seed, sizeof(params.seed)); + printf("Using seed:"); + for (u_int i = 0; i < (u_int)sizeof(params.seed)/sizeof(u_short); i++) + printf(" 0x%.4x,", params.seed[i]); + printf("\n"); + + ATF_REQUIRE((params.sendbuf = malloc(RANDOM_TESTSIZE)) != NULL); + for (u_int i = 0; i < RANDOM_TESTSIZE / (u_int )sizeof(long); i++) + ((long *)params.sendbuf)[i] = nrand48(¶ms.seed[0]); + + ATF_REQUIRE(sysctlbyname("net.local.stream.recvspace", + ¶ms.recvspace, &(size_t){sizeof(u_long)}, NULL, 0) != -1); + ATF_REQUIRE((recvbuf = + malloc(RANDOM_RECVSIZE * params.recvspace)) != NULL); + + params.nrecords = 2 * RANDOM_TESTSIZE / + (RANDOM_MAXRECORD * params.recvspace); + + ATF_REQUIRE((params.records = + malloc(params.nrecords * sizeof(size_t *))) != NULL); + off = 0; + for (u_int i = 0; i < params.nrecords; i++) { + off += 1 + nrand48(¶ms.seed[0]) % + (RANDOM_MAXRECORD * params.recvspace); + if (off > RANDOM_TESTSIZE) { + params.nrecords = i; + break; + } + params.records[i] = off; + } + params.records[params.nrecords - 1] = RANDOM_TESTSIZE; + + ATF_REQUIRE(socketpair(PF_LOCAL, SOCK_SEQPACKET, 0, fd) == 0); + params.sock = fd[0]; + ATF_REQUIRE(pthread_create(&t, NULL, sending_thread, ¶ms) == 0); + + off = 0; + eor = 0; + while (off < RANDOM_TESTSIZE) { + struct iovec iov = { + .iov_base = recvbuf, + .iov_len = nrand48(¶ms.seed[0]) % + (RANDOM_RECVSIZE * params.recvspace) + }; + struct msghdr hdr = { + .msg_iov = &iov, + .msg_iovlen = 1, + }; + size_t len; + int waitall = iov.iov_len & 0x1 ? MSG_WAITALL : 0; + + len = recvmsg(fd[1], &hdr, waitall); + if (waitall && !(hdr.msg_flags & MSG_EOR)) + ATF_CHECK_EQ_MSG(len, iov.iov_len, + "recvmsg(MSG_WAITALL): %zd, expected %zd", + len, iov.iov_len); + if (off + len == params.records[eor]) { + ATF_REQUIRE_MSG(hdr.msg_flags & MSG_EOR, + "recvmsg(): expected EOR @ %zd", off + len); + eor++; + } else { + ATF_REQUIRE_MSG(off + len < params.records[eor], + "recvmsg() past EOR: %zd, expected %zd", + off + len, params.records[eor]); + ATF_REQUIRE_MSG(!(hdr.msg_flags & MSG_EOR), + "recvmsg() spurious EOR at %zd, expected %zd", + off + len, params.records[eor]); + } + ATF_REQUIRE_MSG(0 == memcmp(params.sendbuf + off, recvbuf, len), + "data corruption past %zd", off); + off += len; +#ifdef DEBUG + printf("recv %zd%s %zd/%zd%s\n", off, + (hdr.msg_flags & MSG_EOR) ? " EOR" : "", + len, iov.iov_len, + waitall ? " WAITALL" : ""); +#endif + } + + ATF_REQUIRE(pthread_join(t, NULL) == 0); + free(params.sendbuf); + free(recvbuf); + free(params.records); +} /* * Main. @@ -1142,6 +1292,7 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, pipe_8k_128k); ATF_TP_ADD_TC(tp, pipe_128k_8k); ATF_TP_ADD_TC(tp, pipe_128k_128k); + ATF_TP_ADD_TC(tp, random_eor_and_waitall); return atf_no_error(); }