From nobody Thu Nov 19 13:24: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 4jVfLm6rZ4z7108Y for ; Thu, 19 Nov 2026 13:24: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 4jVfLm3n5xz4Rkf for ; Thu, 19 Nov 2026 13:24:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795094640; 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=B2N1TPRR1ogoak16NWkqNpYutvNKbHwWUkNtWALCH3E=; b=lpjuq5Sp7ppXmhHg9ohSFZQ+wEWfeBUrJR8DVcPpwqNzW37MPzNipJfQUF2WJhaBO9afvr r/UdbV7eMHeefYhKQ+pzM071mk+EeA0ma4rmCHSV01ZIjiBXci8eZErW5oaUzBSSV4TNMy IUqdebjWRrHHNJ4PceS8qsZz3+6Z7ku+FVmuTXS8UljMLI6PfKK4gheo8zInYPU/aYGnBJ 0XxvvusV+gwIcW2hQx1VTxKqbgZaoOFYr1K0s5DmQZPY2likyJYSNREDYiBeANvm6R0uc3 KWiPkkgregqP8qADRWQEoJI/KwudHYF+u9r07ZQY/nohakE35zqV6J0rX9sjSg== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1795094640; b=SdJ7/EZnbfO3Awsvy/So6t8nyk6bCNMWGuJE+8SBQ7zuKGFSyn8EB4rQKAoXE6ZsbvRl66 RTWGgc9FTpD7nCLDBbhrVngwehQ7I1kwNI1XSZqr78NxLF6WpcnXzjz/k2CJccG83OFyjx gfXd1lyxn1G7bvq2vZW2ttYTWZQPooXATI0Wo1T9qLjhO4p6SIP+rbI+FzNEHroBXpfUyo 2pxwpAOtJu9Q6OlZYTbI3O/lLlsgc3YCAxHVzYxj/hT1cArKFCHHgaxqCyR0lxz8BdZP26 J9LtontNWw9hfOHB2ymvAKcBJAFBsoJJ2xdK1Ccm2Yjf7waceuNrthIUvYYeQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795094640; 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=B2N1TPRR1ogoak16NWkqNpYutvNKbHwWUkNtWALCH3E=; b=nY1ysJrNpqvMDSCX9TfCXW8lFfM7qTZbMx10KtGLVaRBf/Irsrck0wBwrPOAb/k45Ihx3X FIloaQCCSiLx5DqGEbkLd+h0OQpg1Kx/TKAwPIbRKwj8vR1KT0fvZaVOu6roncksvyizhM VhV2QIFm8S3xFyfL7yyAptie8MaoqiEIUmqpnxgr2G5Se4EPrGLq/FVnbL4DV37K6kI7Cc hXtveEY1DPWoYvCKSKEAv8WG4HRq+ZcQv9kd8U1uDJneGBmG+G7EfsHbBgsBK8tZYuvBaH cgRJkV2qDHZ9h1FJ0Cnx5v/eyPq9qQ2ayNoXY/2ekDvDbuNPT+VAUzE6qHo36w== 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 4jVfLm2WGxz137T for ; Thu, 19 Nov 2026 13:24:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1d3de by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 19 Nov 2026 13:24:00 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav Subject: git: 4e311732aba5 - main - pkg: Add tests List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: 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: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 4e311732aba557424deb989771d0186a88807f31 Auto-Submitted: auto-generated Date: Thu, 19 Nov 2026 13:24:00 +0000 Message-Id: <6afef870.1d3de.2612b60a@gitrepo.freebsd.org> The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=4e311732aba557424deb989771d0186a88807f31 commit 4e311732aba557424deb989771d0186a88807f31 Author: Dag-Erling Smørgrav AuthorDate: 2026-11-19 13:23:08 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2026-11-19 13:23:46 +0000 pkg: Add tests MFC after: 1 week Reviewed by: ngie Differential Revision: https://reviews.freebsd.org/D58349 --- etc/mtree/BSD.tests.dist | 2 + tools/build/mk/OptionalObsoleteFiles.inc | 3 + usr.sbin/pkg/Makefile | 5 + usr.sbin/pkg/tests/Makefile | 3 + usr.sbin/pkg/tests/pkg_test.sh | 212 +++++++++++++++++++++++++++++++ 5 files changed, 225 insertions(+) diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist index 67ed5dd81199..e828cfd3cc56 100644 --- a/etc/mtree/BSD.tests.dist +++ b/etc/mtree/BSD.tests.dist @@ -1323,6 +1323,8 @@ .. praudit .. + pkg + .. pw .. pwd_mkdb diff --git a/tools/build/mk/OptionalObsoleteFiles.inc b/tools/build/mk/OptionalObsoleteFiles.inc index 4cc2c2525117..a222e29df59b 100644 --- a/tools/build/mk/OptionalObsoleteFiles.inc +++ b/tools/build/mk/OptionalObsoleteFiles.inc @@ -7004,6 +7004,9 @@ OLD_FILES+=usr/share/man/man8/pkg-serve.8.gz .if ${MK_PKGBOOTSTRAP} == no OLD_FILES+=usr/sbin/pkg OLD_FILES+=usr/share/man/man7/pkg.7.gz +OLD_FILES+=usr/tests/usr.sbin/pkg/Kyuafile +OLD_FILES+=usr/tests/usr.sbin/pkg/pkg_test +OLD_DIRS+=usr/tests/usr/sbin/pkg .endif .if ${MK_PMC} == no diff --git a/usr.sbin/pkg/Makefile b/usr.sbin/pkg/Makefile index 3b3249c538dd..101664257831 100644 --- a/usr.sbin/pkg/Makefile +++ b/usr.sbin/pkg/Makefile @@ -1,3 +1,5 @@ +.include + PACKAGE= pkg-bootstrap .MAKEFLAGS: -W @@ -32,4 +34,7 @@ LIBADD= archive der fetch jail pkgecc ucl crypto ssl util md CFLAGS+=-I${SRCTOP}/contrib/libder/libder CFLAGS+=-I${SRCTOP}/crypto/libecc/include +HAS_TESTS= +SUBDIR.${MK_TESTS}= tests + .include diff --git a/usr.sbin/pkg/tests/Makefile b/usr.sbin/pkg/tests/Makefile new file mode 100644 index 000000000000..51327f99690f --- /dev/null +++ b/usr.sbin/pkg/tests/Makefile @@ -0,0 +1,3 @@ +ATF_TESTS_SH= pkg_test + +.include diff --git a/usr.sbin/pkg/tests/pkg_test.sh b/usr.sbin/pkg/tests/pkg_test.sh new file mode 100644 index 000000000000..78adeafae9cc --- /dev/null +++ b/usr.sbin/pkg/tests/pkg_test.sh @@ -0,0 +1,212 @@ +# +# Copyright (c) 2026 Dag-Erling Smørgrav +# +# SPDX-License-Identifier: BSD-2-Clause +# + +pkg_prepare() +{ + : ${LOCALBASE:=$(sysctl -n user.localbase)} + : ${LOCALBASE:=/usr/local} + pkg7=$(command -pv pkg) + pkg8=${LOCALBASE}/sbin/pkg + atf_check test -x "${pkg7}" + atf_check test -x "${pkg8}" + atf_check test ! "${pkg7}" -ef "${pkg8}" +} + +atf_test_case activation +activation_head() +{ + atf_set descr "Activation test without jail or root" +} +activation_body() +{ + pkg_prepare + atf_check -e save:N7 "${pkg7}" -N + atf_check -e save:N8 "${pkg8}" -N + atf_check cmp N7 N8 + atf_check -o match:"packages installed" cat N7 + atf_check -o save:v7 "${pkg7}" --version + atf_check -o save:v8 "${pkg8}" --version + atf_check cmp v7 v8 + atf_check -o match:"^[0-9]+(\.[0-9]+)+$" cat v7 +} + +atf_test_case activation_jail cleanup +activation_jail_head() +{ + atf_set descr "Activation test with jail" + atf_set require.user "root" + atf_set require.files "/rescue/sh" +} +activation_jail_body() +{ + local jname="j$$" + pkg_prepare + + # An empty jail is not bootstrapped + atf_check mkdir dev bin + atf_check install -m 0755 /rescue/sh bin/sh + cat >jail.conf <&2 ;; + r) ;; + '?') OPTIND=$((OPTIND - 1)); break ;; + esac +done +shift $((OPTIND - 1)) +for arg; do + case $arg in + --version) echo 1.2.3 ;; + esac +done +EOF + + # Try again + atf_check -e inline:"pkg: 1 packages installed\n" \ + "${pkg7}" -j "${jname}" -N + atf_check -o inline:"1.2.3\n" "${pkg7}" -j ${jname} --version +} +activation_jail_cleanup() +{ + if [ -f jail.conf ]; then + jail -f jail.conf -qr '*' || true + fi +} + +atf_test_case activation_root +activation_root_head() +{ + atf_set descr "Activation test with root" +} +activation_root_body() +{ + pkg_prepare + + # An empty root is not bootstrapped + atf_check -s exit:1 -e match:"pkg is not installed" \ + "${pkg7}" -r "${PWD}" -N + + # Add a fake pkg to our root + atf_check mkdir -p "${PWD}${LOCALBASE}/sbin" + atf_check install -m 0755 - "${PWD}${LOCALBASE}/sbin/pkg" <<'EOF' +#!/bin/sh +while getopts ":Nr:" opt; do + case $opt in + N) echo "${0##*/}: 1 packages installed" >&2 ;; + r) ;; + '?') OPTIND=$((OPTIND - 1)); break ;; + esac +done +shift $((OPTIND - 1)) +for arg; do + case $arg in + --version) echo 1.2.3 ;; + esac +done +EOF + + # Try again + atf_check -e inline:"pkg: 1 packages installed\n" \ + "${pkg7}" -r "${PWD}" -N + atf_check -o inline:"1.2.3\n" "${pkg7}" -r "${PWD}" --version +} + +atf_test_case add_jail cleanup +add_jail_head() +{ + atf_set descr "Install pkg in a jail" + atf_set require.user "root" +} +add_jail_body() +{ + local jname="j$$" + pkg_prepare + atf_check -o match:"Creating package for pkg" "${pkg8}" create -l3 pkg + atf_check mkdir -p dev usr/bin + atf_check install -m 0755 /usr/bin/uname usr/bin + cat >jail.conf <