Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F168909099
D58349.id182254.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
5 KB
Referenced Files
None
Subscribers
None
D58349.id182254.diff
View Options
diff --git a/etc/mtree/BSD.tests.in b/etc/mtree/BSD.tests.in
--- a/etc/mtree/BSD.tests.in
+++ b/etc/mtree/BSD.tests.in
@@ -1301,6 +1301,8 @@
..
praudit
..
+ pkg
+ ..
pw
..
quot
diff --git a/tools/build/mk/OptionalObsoleteFiles.inc b/tools/build/mk/OptionalObsoleteFiles.inc
--- a/tools/build/mk/OptionalObsoleteFiles.inc
+++ b/tools/build/mk/OptionalObsoleteFiles.inc
@@ -6968,6 +6968,9 @@
.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
--- a/usr.sbin/pkg/Makefile
+++ b/usr.sbin/pkg/Makefile
@@ -1,3 +1,5 @@
+.include <src.opts.mk>
+
PACKAGE= pkg-bootstrap
.MAKEFLAGS: -W
@@ -32,4 +34,7 @@
CFLAGS+=-I${SRCTOP}/contrib/libder/libder
CFLAGS+=-I${SRCTOP}/crypto/libecc/include
+HAS_TESTS=
+SUBDIR.${MK_TESTS}= tests
+
.include <bsd.prog.mk>
diff --git a/usr.sbin/pkg/tests/Makefile b/usr.sbin/pkg/tests/Makefile
new file mode 100644
--- /dev/null
+++ b/usr.sbin/pkg/tests/Makefile
@@ -0,0 +1,3 @@
+ATF_TESTS_SH= pkg_test
+
+.include <bsd.test.mk>
diff --git a/usr.sbin/pkg/tests/pkg_test.sh b/usr.sbin/pkg/tests/pkg_test.sh
new file mode 100644
--- /dev/null
+++ b/usr.sbin/pkg/tests/pkg_test.sh
@@ -0,0 +1,182 @@
+#
+# 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"
+}
+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 <<EOF
+${jname} { mount.devfs; path="${PWD}"; persist; }
+EOF
+ atf_check jail -f jail.conf -qc "${jname}"
+ atf_check -s exit:1 -e match:"pkg is not installed" \
+ "${pkg7}" -j "${jname}" -N
+
+ # Add a fake pkg to our jail
+ 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}" -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"
+}
+add_jail_body()
+{
+ local jname="j$$"
+ pkg_prepare
+ atf_check -o match:"Creating package for pkg" "${pkg8}" create -o . pkg
+ atf_check mkdir -p dev usr/bin
+ atf_check install -m 0755 /usr/bin/uname usr/bin
+ cat >jail.conf <<EOF
+${jname} { mount.devfs; path="${PWD}"; persist; }
+EOF
+ atf_check jail -f jail.conf -qc "${jname}"
+ atf_check -s exit:1 -e match:"pkg is not installed" \
+ "${pkg7}" -j "${jname}" -N
+ atf_check -e ignore -o match:"Installing pkg" \
+ "${pkg7}" -j "${jname}" add pkg-*pkg
+ atf_check ln -f "${PWD}${LOCALBASE}/sbin/pkg-static" \
+ "${PWD}${LOCALBASE}/sbin/pkg"
+ atf_check -e inline:"pkg: 1 packages installed\n" \
+ "${pkg7}" -j "${jname}" -N
+}
+add_jail_cleanup()
+{
+ if [ -f jail.conf ]; then
+ jail -f jail.conf -qr '*' || true
+ fi
+}
+
+atf_test_case add_root
+add_root_head()
+{
+ atf_set descr "Install pkg in a root"
+}
+add_root_body()
+{
+ pkg_prepare
+ atf_check -o match:"Creating package for pkg" "${pkg8}" create -o . pkg
+ atf_check -s exit:1 -e match:"pkg is not installed" \
+ "${pkg7}" -r "${PWD}" -N
+ atf_check -e ignore -o match:"Installing pkg" \
+ "${pkg7}" -r "${PWD}" add pkg-*pkg
+ atf_check -e inline:"pkg: 1 packages installed\n" \
+ "${pkg7}" -r "${PWD}" -N
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case activation
+ atf_add_test_case activation_jail
+ atf_add_test_case activation_root
+ atf_add_test_case add_jail
+ atf_add_test_case add_root
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Aug 31, 5:18 PM (11 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
37707092
Default Alt Text
D58349.id182254.diff (5 KB)
Attached To
Mode
D58349: pkg: Add tests
Attached
Detach File
Event Timeline
Log In to Comment