From nobody Sun Jun 15 16:02:28 2025 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 4bKyZX51scz5pf04; Sun, 15 Jun 2025 16:02:28 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bKyZX32pwz3Xpv; Sun, 15 Jun 2025 16:02:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1750003348; 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=RM6Epq55nzOapdyzdr/wNvIAGTK6tjVWkoP7mqRPfFo=; b=vriVWsciP58GAAARY07xfT0oH08U1/kEpVM/veI5Ecp44AEUNmWc2hI9/PREpnHoR0twWQ Fm5L2v7HxDcmEMM6ZZDOQNzWfS2F/D8PHFfsDyuTA0m36wWCnoTuwEBO7AaZWliCmJFoL8 z2RvT+hzhj2UVUEYLv4+jT1Rpx+U2zbVOEE5QkoTU69zyhtl61SLvt/uY//YMMSUi2ro1+ u3J2PLpaOpwJDdYhyr/rigDARFMCIUt4waiKLQLAoOdRCqlABP62x4Ik5/AZYNitv0uO+0 gDvEOaEmJ0aUlo6Uu47yWgJBDb+Q38W3pKpKj5evTn0QocnQf5GKHtJvFBPLkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1750003348; 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=RM6Epq55nzOapdyzdr/wNvIAGTK6tjVWkoP7mqRPfFo=; b=byljqPpjlaztOLdZN7NrMTiiV6Ka1ZJXJX7RN8ZXzIy9ORAfY9v8TmSjHnSPyIokXqxbKe YmdSRH44rF2DI3f/QCFqNVsN0UkJZHAKCo2A3MYcAyQvSGAoRpryGQmU1/8zWIB2xAPVwc vkc4OPMeZ0RkM3KUF9fq0XK/1b/Zy5ZsVaXP8AlPt/N8b+gtc7czhBix4XeD8/ZZTUom1h 5gx2WbGcQf7doHeRYMbsMlk5lpZglRREQFylQY/dOj6DdMWXexKOZW1ApcNh2o5cZjDAbk zAsvH0A2t3m+EuQ1U5fMwBS3dTMHQIS/i2cicvaPGK4BbkORoTJelmT5gWwnbA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1750003348; a=rsa-sha256; cv=none; b=Pfd3rtmGb2+mC0U2g36NsDqpdaySBPLXZFCVeTILhzOq7pzpJ6me8xA/mnYa1SryEIiTwx FzFb9A+293rX+L76eIzDDD+JDSoAcfblrpeV5CVn4KNtZ90btqVXhVsK/KBA5Sg6Z99zIG Ye1PPbhNX5uqV6pwWPcdlar1Bo7rdXXjod9fL6kaiO4r4KQ2th2KvNc/wthXz1gwb8qUG9 0J9i/WUHwZIjuRfkE1TKvZ2E8b+mb2+fJSluw2ke4J4BrOMM8YvybpU9GCUnjW5TtK4goF Cw9qKq8Zs+TO+y4DxKO5MG2/kYvNlj07StsNJYPgWjErXAUN7GXVpkRJoQUmjA== 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 4bKyZX2dyjz4HR; Sun, 15 Jun 2025 16:02:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 55FG2S36047775; Sun, 15 Jun 2025 16:02:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 55FG2SHe047772; Sun, 15 Jun 2025 16:02:28 GMT (envelope-from git) Date: Sun, 15 Jun 2025 16:02:28 GMT Message-Id: <202506151602.55FG2SHe047772@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Alan Somers Subject: git: 5c1ba994a8bc - main - Add a regression test for a libtpool bug 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: asomers X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 5c1ba994a8bcb6676ea3d1bb21b072b90e2d3ae9 Auto-Submitted: auto-generated The branch main has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=5c1ba994a8bcb6676ea3d1bb21b072b90e2d3ae9 commit 5c1ba994a8bcb6676ea3d1bb21b072b90e2d3ae9 Author: Alan Somers AuthorDate: 2024-05-07 17:48:33 +0000 Commit: Alan Somers CommitDate: 2025-06-15 16:01:37 +0000 Add a regression test for a libtpool bug Test that tpool_dispatch returns an error if it cannot start even one worker. Previously, it would hang. The test must reside here rather than in the OpenZFS repo because the latter has no infrastructure for writing libtpool tests. https://github.com/openzfs/zfs/issues/16172 MFC after: 2 weeks Sponsored by: Axcient Differential Revision: https://reviews.freebsd.org/D45587 --- cddl/lib/libtpool/Makefile | 5 +++ cddl/lib/libtpool/tests/Makefile | 12 +++++ cddl/lib/libtpool/tests/libtpool_test.c | 78 +++++++++++++++++++++++++++++++++ etc/mtree/BSD.tests.dist | 2 + 4 files changed, 97 insertions(+) diff --git a/cddl/lib/libtpool/Makefile b/cddl/lib/libtpool/Makefile index 2afaf0c417e9..3ab625dd306b 100644 --- a/cddl/lib/libtpool/Makefile +++ b/cddl/lib/libtpool/Makefile @@ -22,4 +22,9 @@ CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccomp CFLAGS+= -DHAVE_ISSETUGID CFLAGS+= -include ${SRCTOP}/sys/modules/zfs/zfs_config.h +.include + +HAS_TESTS= +SUBDIR.${MK_TESTS}+= tests + .include diff --git a/cddl/lib/libtpool/tests/Makefile b/cddl/lib/libtpool/tests/Makefile new file mode 100644 index 000000000000..d87f5fc86789 --- /dev/null +++ b/cddl/lib/libtpool/tests/Makefile @@ -0,0 +1,12 @@ +ZFSTOP= ${SRCTOP}/sys/contrib/openzfs + +ATF_TESTS_C+= libtpool_test + +TEST_METADATA+= timeout="10" + +CFLAGS+= -I${ZFSTOP}/include \ + -I${ZFSTOP}/lib/libspl/include + +LIBADD+= pthread tpool + +.include diff --git a/cddl/lib/libtpool/tests/libtpool_test.c b/cddl/lib/libtpool/tests/libtpool_test.c new file mode 100644 index 000000000000..42726a13420c --- /dev/null +++ b/cddl/lib/libtpool/tests/libtpool_test.c @@ -0,0 +1,78 @@ +#include +#include +#include +#include + +#include + +#include + +static void +tp_delay(void *arg) +{ + pthread_barrier_t *barrier = arg; + + /* Block this task until all thread pool workers have been created. */ + pthread_barrier_wait(barrier); +} + +/* + * NB: we could reduce the test's resource cost by using rctl(4). But that + * isn't enabled by default. And even with a thread limit of 1500, it takes < + * 0.1s to run on my machine. So I don't think it's worth optimizing for the + * case where rctl is available. + */ +ATF_TC(complete_exhaustion); +ATF_TC_HEAD(complete_exhaustion, tc) +{ + atf_tc_set_md_var(tc, "descr", + "A thread pool should fail to schedule tasks if it is completely impossible to spawn any threads."); +} + +ATF_TC_BODY(complete_exhaustion, tc) +{ + pthread_barrier_t barrier; + tpool_t *tp0, *tp1; + size_t len; + int max_threads_per_proc = 0; + int nworkers; + int r, i; + + + len = sizeof(max_threads_per_proc); + r = sysctlbyname("kern.threads.max_threads_per_proc", + &max_threads_per_proc, &len, NULL, 0); + ATF_REQUIRE_EQ_MSG(r, 0, "sysctlbyname: %s", strerror(errno)); + nworkers = max_threads_per_proc - 1; + pthread_barrier_init(&barrier, NULL, max_threads_per_proc); + + /* + * Create the first thread pool and spawn the maximum allowed number of + * processes. + */ + tp0 = tpool_create(nworkers, nworkers, 1, NULL); + ATF_REQUIRE(tp0 != NULL); + for (i = 0; i < nworkers; i++) { + ATF_REQUIRE_EQ(tpool_dispatch(tp0, tp_delay, &barrier), 0); + } + + /* + * Now create a second thread pool. Unable to create new threads, the + * dispatch function should return an error. + */ + tp1 = tpool_create(nworkers, 2 * nworkers, 1, NULL); + ATF_REQUIRE(tp1 != NULL); + ATF_REQUIRE_EQ(tpool_dispatch(tp1, tp_delay, NULL), -1); + + /* Cleanup */ + ATF_REQUIRE_EQ(pthread_barrier_wait(&barrier), 0); + tpool_wait(tp1); + tpool_wait(tp0); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, complete_exhaustion); + + return (atf_no_error()); +} diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist index bfd21607ed4d..7d21dcbd2cbf 100644 --- a/etc/mtree/BSD.tests.dist +++ b/etc/mtree/BSD.tests.dist @@ -80,6 +80,8 @@ .. cddl lib + libtpool + .. .. sbin ..