From nobody Tue Nov 10 01:56: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 4jNqW43n6gz70sKT for ; Tue, 10 Nov 2026 01:56:00 +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 4jNqW42YvXz4Y72 for ; Tue, 10 Nov 2026 01:56:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794275760; 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=Rxu4w4PmQ01FbyxKFcDKdBTKho2VGBmBqd6E2puP3ZU=; b=bqQqRGDEaO84LTx0bnEUsuFGBI34HbubH/zqfd0BqDTQcV4Eu/4+swWHqFqnh9EP+bRNWt CWDjHr5M3G2tsnKvGyKwTMHI25H5F4ezIbxKNLHoHwQpf01hEStdf4AXZk7h92MpPIwRuF gbhqDKsgS1lDDqHOS2COPuBFYWow2upAQY5rNUBN1pQeEuEfysHEh9BLTMEYf6XRILb63E ZWeYVQ5vw1udLzrSPSirwroPLYXt2WPGGX+9doTeownnokrJ2NyzZNUOf6yo/jXUgijTEu KAEQQ3RWcSCdRQndnmnaXt/sznLkkXPHP1nq3m2gEy34+Khl+Oso6Ih+Nl/D/g== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794275760; b=nCWy1mRfGe7BXmWX7wIejQMoEkeAB2WY6Uf2rLk8iJu6MolQYVIlgttvYFxmVxvpEK+8ZL P6RMn2Ob2SkX9cyv5vSwxyr64Q1err9sxD4jnBXQiNTL4kyI3OdH1A5/0wzckg6ScHHv5V HbTST5BSRE56aGdC5I+DugbZC3DADe1qYSYxII50EMLXXXMl7XBVvwW/juOfmYT/VGhxYx gjR4p9RzvURon9NDK9pUxtyyJOjYptZWTr9h7yRTRqTcS0UTZXwVPUbYwlhAyLFoJaWcja PCfsVQIyPolXjRlt2d9Exf3SZzu9clCAPLJrH9dqs0XAwzpe/OrCLKfp9hschg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794275760; 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=Rxu4w4PmQ01FbyxKFcDKdBTKho2VGBmBqd6E2puP3ZU=; b=oq8Qd8N75WSD5o+Xyh3AGA5OAK0t91iTKd/exs113NzyVfqCytlRxOk79a+8pEKcDTLlxe tV/5zMY9YqDVEqYtV70cn6ODzg0EC9LbX3yrq0t4rIlYnXNmlkFRR18q10n9GndZ10S3/K 86SMYt5Mkr2d4xPIj0W3kljxpD9+kYttviPS/oVczmVg2E1gi6L3bN2aMtltV6TLmLdzaB VyEa3F8qcVvt2Y1HT7+BUtmVCE2Pe2fKD0czYB73ytStm4Eiw6HOUOkucGxgYcHVV+QgFn GZJliwaVJZXYzxKxUo1ERUsF8aXpbsMMdIQZMSNsXf2HFyAtqvyrQJFmtDVC2A== 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 4jNqW424L6z16Wc for ; Tue, 10 Nov 2026 01:56:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 18d2b by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 10 Nov 2026 01:56:00 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Enji Cooper Subject: git: 58e5c5cac1e7 - 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: 58e5c5cac1e7c8c99a6e7f8846b655afed05b74f Auto-Submitted: auto-generated Date: Tue, 10 Nov 2026 01:56:00 +0000 Message-Id: <6af279b0.18d2b.65308590@gitrepo.freebsd.org> The branch main has been updated by ngie: URL: https://cgit.FreeBSD.org/src/commit/?id=58e5c5cac1e7c8c99a6e7f8846b655afed05b74f commit 58e5c5cac1e7c8c99a6e7f8846b655afed05b74f Author: Enji Cooper AuthorDate: 2026-11-10 01:55:45 +0000 Commit: Enji Cooper CommitDate: 2026-11-10 01:55: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 788fa9f9394c..ddd6eadcfc0e 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 2e9839a755d9..a39e192aa385 100644 --- a/tests/sys/capsicum/capsicum-test-main.cc +++ b/tests/sys/capsicum/capsicum-test-main.cc @@ -140,6 +140,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(); }