From nobody Tue Nov 10 01:33:00 2026 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 4jNq0Y38ySz70r81 for ; Tue, 10 Nov 2026 01:33:01 +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) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jNq0Y0PYjz4RsJ for ; Tue, 10 Nov 2026 01:33:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794274381; 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=+8UFa0QaDeQd1MhV+OLU3Qcxy2+v5+r1k63YrIqcPlM=; b=eftmKDWVOGPob5IcNvQuH6dEDhf6najTfLX8J3tobWZ02rBaQF8CI9v5QKceD5ZNRWf7g+ 6XLvux4B4McEx4EGiKXEiulRMvWWd94Df206CP8CK9hLnDBUQcYh2kBrMxPvN6uyr1QT0I uiYLJsEa80OmgQ+7dMgH5hWChNiYksyete7GGnjMtY54Dfu/qLxigk9ocI0YNnrF3qhi1q Y3TVbaQfpo1gXS5fhceBRR8yOx/ReLHTSYmtvEVgvwi6GaZYKU2AkhcmgQEnwxPaYLzCa9 pyPHUKqsTS3Bb3htQfD3turpDP04XKtPdHoxjL4+8lBiWFrltOMDqlYs/EQQ0A== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794274381; b=W/tERPQLVOmp9EggTSlmK80mjVBYrOeYxMrJFBE+Q1c2zepkE7DD3dwIlsT+IGBE9Lhhhj VqKvnxsSkceO3WI4FKMr/Nj23iyglF9MB55jI9q4lxbIP3NusY3H4RVRZvdgUoji21cd9a MrtowthJ+0re9fcdoLFf/XNMZJDj8ghjlLoaF9jdHynSet1y3qq+HQgdzV569BF4l3mw3Q 0X6RO2l6MypHZiMnQstZDD9VAdqMFDvrOwPYXIXT/Cc70/94JxICGR4L093bR/RQpOR+bx nFB7PT5YRucTVBjqnZb0H5bw2g3AVkXdyets9QhwjqXkK2EgbwX/A89sDT7PNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794274381; 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=+8UFa0QaDeQd1MhV+OLU3Qcxy2+v5+r1k63YrIqcPlM=; b=dcAChRTgKLtJO0IWTisLzdPlLT1mFx3jNXZOCrmO/4hsaPlXgVVN41aIErd99Y+8Qrsdy8 bE4yMrOGVjs+5DfjWkFPgcAA+pYG18XY5MOMvtQMgzJIPeFH0FgLlPzSEsDU+PuKD3PD/P etp2MjRudHoW8SZpBY04kEMdqyWynRIEBhAIOFful3OMdNFjK9wsE+Hfmhz3Xf3j9b0OVt J1XetbSltuZmLS0IILwL2Iyy+ka8q5bnFxtoDn7KXByvhPDuQ0PwJ/S2ilO5HHuexraaVw neScbu3iU8+utsRusGwVHtRBbkNRIpZH7/dnBUEaUFuRCu3u6HNMLb9ZZ5vQ6A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jNq0Y011Tz15n0 for ; Tue, 10 Nov 2026 01:33:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 165a2 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 10 Nov 2026 01:33:00 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Enji Cooper Subject: git: dda15b669d02 - main - tests/sys/capsicum: restore test coverage with root user List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: ngie X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: dda15b669d021346682009f38acc6db2639fb99f Auto-Submitted: auto-generated Date: Tue, 10 Nov 2026 01:33:00 +0000 Message-Id: <6af2744c.165a2.57229187@gitrepo.freebsd.org> The branch main has been updated by ngie: URL: https://cgit.FreeBSD.org/src/commit/?id=dda15b669d021346682009f38acc6db2639fb99f commit dda15b669d021346682009f38acc6db2639fb99f Author: Enji Cooper AuthorDate: 2026-11-10 01:32:45 +0000 Commit: Enji Cooper CommitDate: 2026-11-10 01:32:45 +0000 tests/sys/capsicum: restore test coverage with root user This change builds capsicum_test and installs/runs it as an unprivileged user ("tests" in vanilla FreeBSD) and root. This required adjusting logic in the Makefile in order to build two binaries with the same sources and running them as separate binaries. Moreover, in order to restore coverage and ensure that some tests which require `other_uid` (typically specified via `-u` on the CLI with the test program) don't fail, become the "tests" user when run as root. This technically doesn't honor unprivileged_user property in kyua.conf: the property needs to be passed via a command-line parameter to the test program. MFC after: 1 week Reported by: markj Fixes: 3fb03fb35b20 ("[tests] switch GoogleTest tests ...") Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D61066 --- tests/sys/capsicum/Makefile | 27 ++++++++++++++++++--------- tests/sys/capsicum/capsicum-test-main.cc | 24 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/tests/sys/capsicum/Makefile b/tests/sys/capsicum/Makefile index 9a88c9cf0ec1..daf508ba7f30 100644 --- a/tests/sys/capsicum/Makefile +++ b/tests/sys/capsicum/Makefile @@ -9,14 +9,11 @@ CFLAGS+= -I${SRCTOP}/tests .if ${MK_GOOGLETEST} != no -GTESTS+= capsicum-test -# This test script runs the same test suite twice, once as root and once as an -# unprivileged user. Serialize them since some tests access global namespaces, -# e.g., mqueuefs, and can trample on each other. -TEST_METADATA.functional+= is_exclusive="true" -TEST_METADATA.functional+= required_kmods="mqueuefs" +GTESTS+= capsicum-test_privileged +GTESTS+= capsicum-test_unprivileged -SRCS.capsicum-test+= \ +# SRCS required for `capsicum-test*`. +SRCS.capsicum-test= \ capsicum-test-main.cc \ capsicum-test.cc \ capability-fd.cc \ @@ -36,8 +33,20 @@ SRCS.capsicum-test+= \ overhead.cc \ rename.cc -LIBADD.capsicum-test+= gtest pthread procstat -TEST_METADATA.capsicum-test= required_user="unprivileged" +.for gtest in ${GTESTS} +SRCS.${gtest}= ${SRCS.capsicum-test} + +LIBADD.${gtest}+= gtest pthread procstat + +# This test script runs the same test suite twice, once as root and once as an +# unprivileged user. Serialize them since some tests access global namespaces, +# e.g., mqueuefs, and can trample on each other. +TEST_METADATA.${gtest}+= is_exclusive="true" +TEST_METADATA.${gtest}+= required_kmods="mqueuefs" +.endfor + +TEST_METADATA.capsicum-test_privileged+= required_user="root" +TEST_METADATA.capsicum-test_unprivileged+= required_user="unprivileged" .for p in mini-me mini-me.noexec mini-me.setuid PROGS+= $p diff --git a/tests/sys/capsicum/capsicum-test-main.cc b/tests/sys/capsicum/capsicum-test-main.cc index 2a2c75000039..308c121a0281 100644 --- a/tests/sys/capsicum/capsicum-test-main.cc +++ b/tests/sys/capsicum/capsicum-test-main.cc @@ -136,6 +136,30 @@ int main(int argc, char* argv[]) { } } + // Last ditch effort to get an unprivileged user on the fly from /etc/passwd + // for testcases that need it. + // + // This must be done this way because the typical way of handling this (via + // the `-u` argument) isn't supported yet with kyua: + // https://github.com/freebsd/kyua/issues/354 . + // + // IMPORTANT: + // - this doesn't honor `unprivileged_user` in `kyua.conf`. + // - this doesn't fail because doing that could break all testing on systems + // where the `tests` user isn't available. + if (other_uid == 0) { + const char *test_user = "tests"; + + struct passwd *test_user_entry = getpwnam(test_user); + + if (test_user_entry) { + other_uid = test_user_entry->pw_uid; + } else { + std::cerr << "Failed to get entry for " << test_user << ", errno=" << errno << "; some tests may fail" << std::endl; + } + + } + testing::AddGlobalTestEnvironment(new SetupEnvironment()); return RUN_ALL_TESTS(); }