Files
makronix/tools/test-tools.sh
T
lotherk b74473cb8e ext-resync: a file the work directory already has is no reason to clean
userland-2026-11-17f.log:11 'pkgsrc changed ./include/Dt/WsmP.h, cleaning':
the .pristine was older than the extract (the run before was started with
the userland.sh that kept no snapshot after a failure), so a header changed
since then looked like pkgsrc's, and MCDE was compiled from nothing for a
file the work directory already held as the new archive has it.  Such a
file is now skipped -- not cleaned and not copied, so its time stamp stays
and make does not recompile what includes it.

tools/test-ext-resync.sh (asked for by t0231, never written): six cases in
a scratch tree with a stand-in bmake; the committed ext-resync.sh fails
"stale pristine: no clean", this one passes 14 of 14.  test-tools.sh runs
it (34 ok, 0 bad).
2026-11-17 16:48:20 +00:00

348 lines
13 KiB
Bash
Executable File

#!/bin/sh
# License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
#
# test-tools.sh -- tests for the build tools (t0232)
#
# usage: test-tools.sh
#
# Tests pkglist.sh, tools/makronix-set.sh, tools/keep-images.sh and mxupgrade
# with artificial inputs in a scratch directory. No network, no build.
# Exit 0 when all cases pass. Output: result: N ok, M bad
set -eu
R=$(cd "$(dirname "$0")/.." && pwd)
TMP=$(mktemp -d "${TMPDIR:-/tmp}/test-tools.XXXXXX")
trap 'rm -rf "$TMP"' EXIT
ok=0
fail=0
pass() { printf 'ok %s\n' "$1"; ok=$((ok + 1)); }
bad() { printf 'BAD %s: %s\n' "$1" "$2" >&2; fail=$((fail + 1)); }
# --- pkglist.sh -----------------------------------------------------------
# Uses a test packages.list via PACKAGES_LIST. Covers set/repo/fetch/bin/
# sysroot/games/built/all, -n, @ARCH, unknown kind (error).
cat > "$TMP/packages.list" <<'EOF'
# comment
wm/mcde
devel/git-base bin
editors/vim bin
shells/ksh93 bin
multimedia/xine-ui fetch
games/freeciv games
misc/something repo
archivers/p7zip fetch @aarch64
EOF
plist_set=$(PACKAGES_LIST="$TMP/packages.list" sh "$R/tools/pkglist.sh" set)
plist_repo=$(PACKAGES_LIST="$TMP/packages.list" sh "$R/tools/pkglist.sh" repo)
plist_fetch=$(PACKAGES_LIST="$TMP/packages.list" sh "$R/tools/pkglist.sh" fetch)
plist_bin=$(PACKAGES_LIST="$TMP/packages.list" sh "$R/tools/pkglist.sh" bin)
plist_sysroot=$(PACKAGES_LIST="$TMP/packages.list" sh "$R/tools/pkglist.sh" sysroot)
plist_games=$(PACKAGES_LIST="$TMP/packages.list" sh "$R/tools/pkglist.sh" games)
plist_built=$(PACKAGES_LIST="$TMP/packages.list" sh "$R/tools/pkglist.sh" built)
plist_all=$(PACKAGES_LIST="$TMP/packages.list" sh "$R/tools/pkglist.sh" all)
plist_set_n=$(PACKAGES_LIST="$TMP/packages.list" sh "$R/tools/pkglist.sh" set -n)
expect_eq() {
name=$1; got=$2; want=$3
if [ "$got" = "$want" ]; then pass "$name"; else bad "$name" "got [$got] want [$want]"; fi
}
expect_has() {
name=$1; got=$2; needle=$3
case "$got" in *"$needle"*) pass "$name" ;; *) bad "$name" "[$got] missing [$needle]" ;; esac
}
expect_not() {
name=$1; got=$2; needle=$3
case "$got" in *"$needle"*) bad "$name" "[$got] unexpectedly has [$needle]" ;; *) pass "$name" ;; esac
}
expect_eq "pkglist set" "$plist_set" "wm/mcde"
expect_eq "pkglist set -n" "$plist_set_n" "mcde"
expect_eq "pkglist repo" "$plist_repo" "misc/something"
expect_eq "pkglist games" "$plist_games" "games/freeciv"
expect_has "pkglist fetch has xine-ui" "$plist_fetch" "multimedia/xine-ui"
expect_has "pkglist fetch has bin" "$plist_fetch" "devel/git-base"
expect_not "pkglist fetch no games" "$plist_fetch" "games/freeciv"
expect_has "pkglist bin has vim" "$plist_bin" "editors/vim"
expect_not "pkglist bin no fetch-only" "$plist_bin" "multimedia/xine-ui"
expect_eq "pkglist sysroot==bin" "$plist_sysroot" "$plist_bin"
expect_has "pkglist built has set" "$plist_built" "wm/mcde"
expect_has "pkglist built has repo" "$plist_built" "misc/something"
expect_not "pkglist built no fetch" "$plist_built" "multimedia/xine-ui"
expect_not "pkglist built no games" "$plist_built" "games/freeciv"
expect_has "pkglist all has repo" "$plist_all" "misc/something"
expect_has "pkglist all has games" "$plist_all" "games/freeciv"
expect_not "pkglist all no aarch64-only on amd64" "$plist_all" "archivers/p7zip"
plist_aarch=$(PACKAGES_LIST="$TMP/packages.list" ARCH=aarch64 sh "$R/tools/pkglist.sh" all)
expect_has "pkglist @aarch64 selected" "$plist_aarch" "archivers/p7zip"
# unknown kind must fail
set +e
printf 'misc/bad\tbogus\n' > "$TMP/bad.list"
PACKAGES_LIST="$TMP/bad.list" sh "$R/tools/pkglist.sh" all >/dev/null 2>&1
rc=$?
set -e
if [ "$rc" -ne 0 ]; then pass "pkglist unknown kind fails"; else bad "pkglist unknown kind fails" "rc=$rc"; fi
# --- keep-images.sh -------------------------------------------------------
# Fake release images dir and SHA512. keep-images copies and verifies.
KD="$TMP/keepenv"
mkdir -p "$KD/build/obj/releasedir/images" "$KD/tools"
cp "$R/tools/keep-images.sh" "$KD/tools/keep-images.sh"
printf 'disk' > "$KD/build/obj/releasedir/images/Makronix-0.99.10-amd64.iso"
printf 'img' > "$KD/build/obj/releasedir/images/Makronix-0.99.10-amd64.img"
(
cd "$KD/build/obj/releasedir/images"
for f in *.iso *.img; do
printf 'SHA512 (%s) = %s\n' "$f" "$(sha512sum "$f" | awk '{print $1}')"
done > SHA512
)
# keep-images computes TOP from dirname/.. of itself -> KD
if sh "$KD/tools/keep-images.sh" test1 >"$TMP/keep1.out" 2>&1; then
if [ -f "$KD/build/keep-test1/Makronix-0.99.10-amd64.iso" ] && \
grep -q 'ok' "$TMP/keep1.out"; then
pass "keep-images copies and verifies"
else
bad "keep-images copies and verifies" "missing copy or ok"
fi
else
bad "keep-images copies and verifies" "exit $?"
fi
# wrong SHA512 must fail
KD2="$TMP/keepenv2"
mkdir -p "$KD2/build/obj/releasedir/images" "$KD2/tools"
cp "$R/tools/keep-images.sh" "$KD2/tools/keep-images.sh"
printf 'disk' > "$KD2/build/obj/releasedir/images/x.iso"
printf 'SHA512 (x.iso) = 0000\n' > "$KD2/build/obj/releasedir/images/SHA512"
set +e
sh "$KD2/tools/keep-images.sh" bad >"$TMP/keep2.out" 2>&1
rc=$?
set -e
if [ "$rc" -ne 0 ]; then pass "keep-images bad checksum fails"; else bad "keep-images bad checksum fails" "rc=$rc"; fi
# --- mxupgrade -n ---------------------------------------------------------
# Artificial release directory with empty sets and a kernel carrying a version
# string. With -n it must report and change nothing (no sysupgrade, no root).
MR="$TMP/release/amd64"
mkdir -p "$MR/binary/sets" "$MR/binary/kernel" "$MR/installation/miniroot"
: > "$MR/binary/sets/base.tgz"
: > "$MR/binary/sets/etc.tgz"
# create a tiny gz whose uncompressed content contains the version string
printf 'Makronix 0.99.11 kernel\n' | gzip -c > "$MR/binary/kernel/netbsd-GENERIC.gz"
# file:// URL and plain path; -n exits 0 and prints info
set +e
MXUPGRADE_CONF=/nonexistent sh "$R/src/usr.sbin/mxupgrade/mxupgrade.sh" -n "$MR" >"$TMP/mx1.out" 2>&1
rc1=$?
MXUPGRADE_CONF=/nonexistent sh "$R/src/usr.sbin/mxupgrade/mxupgrade.sh" -n "file://$MR" >"$TMP/mx2.out" 2>&1
rc2=$?
MXUPGRADE_CONF=/nonexistent sh "$R/src/usr.sbin/mxupgrade/mxupgrade.sh" -n /no/such/release >"$TMP/mx3.out" 2>&1
rc3=$?
set -e
if [ "$rc1" -eq 0 ] && grep -q '0.99.11' "$TMP/mx1.out" && grep -q 'nothing was changed' "$TMP/mx1.out"; then
pass "mxupgrade -n reports release dir"
else
bad "mxupgrade -n reports release dir" "rc=$rc1"
fi
if [ "$rc2" -eq 0 ] && grep -q 'nothing was changed' "$TMP/mx2.out"; then
pass "mxupgrade -n accepts file://"
else
bad "mxupgrade -n accepts file://" "rc=$rc2"
fi
if [ "$rc3" -ne 0 ]; then
pass "mxupgrade rejects missing release dir"
else
bad "mxupgrade rejects missing release dir" "rc=$rc3"
fi
# --- makronix-set.sh ------------------------------------------------------
# Build a minimal fake TOP so makronix-set.sh (which derives TOP from its own
# location) can run against artificial pkgdb/DESTDIR/METALOG without touching
# the real tree. Covers: relative @cwd (build/obj/destdir.../usr/pkg),
# @ignore followed by +COMMENT, @pkgdir, a file name with a space (skipped with
# a warning, not fatal), and a directory that must appear in METALOG.
MS="$TMP/mset"
mkdir -p "$MS/tools" "$MS/src/distrib/sets/lists/makronix" "$MS/build/pkg/sbin" "$MS/build/logs"
cp "$R/tools/makronix-set.sh" "$MS/tools/makronix-set.sh"
cp "$R/tools/pkglist.sh" "$MS/tools/pkglist.sh"
DD="$MS/build/obj/destdir.test"
mkdir -p "$DD/usr/pkg/bin" "$DD/usr/pkg/lib" "$DD/usr/pkg/share/doc/pkgA" "$DD/usr/pkg/etc/dt/cde/fontaliases"
printf '#!/bin/sh\nexit 0\n' > "$DD/usr/pkg/bin/progA"
chmod 755 "$DD/usr/pkg/bin/progA"
printf 'lib\n' > "$DD/usr/pkg/lib/libA.so.1"
printf 'hi\n' > "$DD/usr/pkg/share/doc/pkgA/readme.txt"
# file name with a space (setuptools template case): must be warned and skipped
printf 'x\n' > "$DD/usr/pkg/share/doc/pkgA/lorem ipsum.txt"
touch "$DD/METALOG"
# pkgdb: pkgA is the "set" package, pkgB a runtime dep
mkdir -p "$DD/usr/pkg/pkgdb/pkgA-1.0" "$DD/usr/pkg/pkgdb/pkgB-2.0"
cat > "$DD/usr/pkg/pkgdb/pkgA-1.0/+BUILD_INFO" <<'EOF'
PKGNAME=pkgA-1.0
PKGPATH=cat/pkgA
EOF
cat > "$DD/usr/pkg/pkgdb/pkgA-1.0/+CONTENTS" <<'EOF'
@name pkgA-1.0
@cwd build/obj/destdir.test/usr/pkg
@pkgdir etc/dt/cde/fontaliases
@ignore
+COMMENT
bin/progA
@comment MD5:000
@pkgdep pkgB>=1
lib/libA.so.1
share/doc/pkgA/readme.txt
share/doc/pkgA/lorem ipsum.txt
EOF
cat > "$DD/usr/pkg/pkgdb/pkgB-2.0/+BUILD_INFO" <<'EOF'
PKGNAME=pkgB-2.0
PKGPATH=cat/pkgB
EOF
cat > "$DD/usr/pkg/pkgdb/pkgB-2.0/+CONTENTS" <<'EOF'
@name pkgB-2.0
@cwd /usr/pkg
EOF
# packages.list with the set seed
cat > "$MS/packages.list" <<'EOF'
cat/pkgA
EOF
# fake pkg_info: -E <pattern> -> echo matching installed package name
cat > "$MS/build/pkg/sbin/pkg_info" <<'SH'
#!/bin/sh
DB=
while [ $# -gt 0 ]; do
case $1 in
-K) DB=$2; shift 2 ;;
-E) pat=$2; shift 2 ;;
*) shift ;;
esac
done
for d in "$DB"/*/; do
[ -d "$d" ] || continue
n=${d%/}; n=${n##*/}
base=$(printf '%s\n' "$n" | sed 's/-[^-]*$//')
case "$n" in "$pat"|"${pat}-"*|"$pat".*)
printf '%s\n' "$n"; exit 0 ;;
esac
case "$base" in "$pat") printf '%s\n' "$n"; exit 0 ;; esac
done
exit 1
SH
chmod 755 "$MS/build/pkg/sbin/pkg_info"
# fake pkg_delete (not expected to be needed here, but present)
cat > "$MS/build/pkg/sbin/pkg_delete" <<'SH'
#!/bin/sh
exit 0
SH
chmod 755 "$MS/build/pkg/sbin/pkg_delete"
set +e
sh "$MS/tools/makronix-set.sh" "$DD" >"$TMP/mset.out" 2>&1
mrc=$?
set -e
MLIST="$MS/src/distrib/sets/lists/makronix/mi"
if [ "$mrc" -eq 0 ] && [ -f "$MLIST" ]; then
pass "makronix-set runs on crafted pkgdb"
else
bad "makronix-set runs on crafted pkgdb" "rc=$mrc"
fi
# relative @cwd resolved: file recorded as usr/pkg/bin/progA
if grep -q '^\./usr/pkg/bin/progA' "$MLIST" 2>/dev/null; then
pass "makronix-set relative @cwd"
else
bad "makronix-set relative @cwd" "progA missing from list"
fi
# @ignore consumed +COMMENT (no +COMMENT as a file)
if grep -q '+COMMENT' "$MLIST" 2>/dev/null; then
bad "makronix-set @ignore skips +COMMENT" "+COMMENT present"
else
pass "makronix-set @ignore skips +COMMENT"
fi
# @pkgdir recorded
if grep -q 'fontaliases' "$MLIST" 2>/dev/null; then
pass "makronix-set @pkgdir recorded"
else
bad "makronix-set @pkgdir recorded" "fontaliases missing"
fi
# space in name warned+skipped, not fatal (already rc==0 above)
if grep -q 'lorem ipsum' "$MLIST" 2>/dev/null; then
bad "makronix-set skips space-in-name" "name with space present"
elif grep -q 'space' "$TMP/mset.out" 2>/dev/null; then
pass "makronix-set skips space-in-name"
else
bad "makronix-set skips space-in-name" "no warning found"
fi
# directories present in METALOG (nbmtree missing directory in specification case)
if grep -q '^\./usr/pkg/bin type=dir' "$DD/METALOG" 2>/dev/null; then
pass "makronix-set METALOG has directories"
else
bad "makronix-set METALOG has directories" "usr/pkg/bin dir record missing"
fi
# intentionally broken case: relative @cwd handling removed -> progA missing/fail
BROKEN="$TMP/mset-broken"
cp -R "$MS" "$BROKEN"
# remove the relative @cwd normalization line
sed '/\*\/usr\/pkg) cwd=\/usr\/pkg ;; esac/d' "$MS/tools/makronix-set.sh" > "$BROKEN/tools/makronix-set.sh"
rm -f "$BROKEN/src/distrib/sets/lists/makronix/mi"
: > "$BROKEN/build/obj/destdir.test/METALOG"
set +e
sh "$BROKEN/tools/makronix-set.sh" "$BROKEN/build/obj/destdir.test" >"$TMP/mset.broken.out" 2>&1
brc=$?
set -e
if [ "$brc" -ne 0 ] || ! grep -q '^\./usr/pkg/bin/progA' "$BROKEN/src/distrib/sets/lists/makronix/mi" 2>/dev/null; then
pass "makronix-set broken relative-@cwd falls red"
else
bad "makronix-set broken relative-@cwd falls red" "rc=$brc but progA still listed"
fi
# --- docs/guide -----------------------------------------------------------
# The guide's installed forms: green on the tree as it is, red when one of
# them is missing. check.sh reads only the installed copies; it does not
# need pandoc or Chrome.
G="$TMP/guideroot"
mkdir -p "$G/src/share/doc/makronix" "$G/src/share/man/man7" "$G/src/etc" "$G/www"
cp -R "$R/src/share/doc/makronix/." "$G/src/share/doc/makronix/"
cp "$R/src/share/man/man7"/makronix-guide*.7 "$G/src/share/man/man7/"
cp "$R/src/etc/makronix-xsession" "$R/src/etc/Makefile" "$G/src/etc/"
cp "$R/www/guide.html" "$R/www/style.css" "$G/www/"
cp -R "$R/www/img" "$G/www/"
if sh "$R/docs/guide/check.sh" "$G" >"$TMP/guide.ok" 2>&1; then
pass "guide check green"
else
bad "guide check green" "$(cat "$TMP/guide.ok")"
fi
rm -f "$G/src/share/man/man7/makronix-guide-mcde.7"
if sh "$R/docs/guide/check.sh" "$G" >"$TMP/guide.bad" 2>&1; then
bad "guide check broken man page falls red" "check still passed"
else
pass "guide check broken man page falls red"
fi
# --- ext-resync.sh: its own cases (tools/test-ext-resync.sh) -----------------
if sh "$R/tools/test-ext-resync.sh" > "${TMPDIR:-/tmp}/test-ext-resync.out.$$" 2>&1; then
pass "ext-resync cases"
else
cat "${TMPDIR:-/tmp}/test-ext-resync.out.$$" >&2
bad "ext-resync cases" "see the BAD lines above"
fi
rm -f "${TMPDIR:-/tmp}/test-ext-resync.out.$$"
printf 'result: %s ok, %s bad\n' "$ok" "$fail"
[ "$fail" -eq 0 ]