diff --git a/tools/posix/mkiso.sh b/tools/posix/mkiso.sh index 52fefbd..a1663a6 100644 --- a/tools/posix/mkiso.sh +++ b/tools/posix/mkiso.sh @@ -49,8 +49,25 @@ set -e -BUILD=${BUILD:-build} +# Run from anywhere: resolve the repo root from this script's own location +# rather than trusting the caller's working directory. Everything below is +# relative to it, and running from tools/posix/ used to fail with "missing +# build/kernel/kernel -- run make first" on a tree that was perfectly built. +script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) +repo=$(CDPATH= cd -- "$script_dir/../.." && pwd) +# An output path given on the command line means where the *caller* is, not +# where the repo is, so it is made absolute before the cd below moves the goal +# posts under it. Without an argument the disc lands at the repo root, which is +# where `make iso` has always put it. +invoked_from=$(pwd) OUT=${1:-schos.iso} +case $OUT in + /*) ;; + *) OUT=$invoked_from/$OUT ;; +esac +cd "$repo" + +BUILD=${BUILD:-build} STAGING="$BUILD/iso" SYSROOT=${SYSROOT:-sysroot} diff --git a/tools/posix/mutate.sh b/tools/posix/mutate.sh index 7f890d8..b17a198 100644 --- a/tools/posix/mutate.sh +++ b/tools/posix/mutate.sh @@ -8,7 +8,22 @@ # say -- would otherwise look exactly like a passing mutation test, which is # the same failure this script exists to catch. set -e -cd /mnt/d/DEV/SchOS + +# Run from anywhere. This used to `cd /mnt/d/DEV/SchOS` -- an absolute WSL path +# from the Windows machine this was written on, which meant the script could not +# run on any other checkout at all. +script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) +repo=$(CDPATH= cd -- "$script_dir/../.." && pwd) +cd "$repo" + + +# Where the host tools land. These moved to build/tools/ in the bt/ -> tools/ +# migration and this script kept the old names; make then answered "No rule to +# make target", which the harness reported as "rejected at compile time". Every +# mutation looked handled and not one of them ever reached a test. +MKSCHFS=build/tools/mkschfs +FSCK=build/tools/schfs_fsck +OBJT=build/tools/schfs_objtest OBJ=kernel/fs/schfs/obj.c OBJW=kernel/fs/schfs/objw.c @@ -29,6 +44,16 @@ trap restore EXIT FAILED=0 +# Quote the line that says why, falling back to the last thing the suite said. +# Two mutations used to report a bare "caught:" with nothing after it -- the +# suite had failed, but nothing in it matched the patterns below, so the +# evidence was an exit status and an empty string. +why() { + line=$(grep -aE 'FAIL|Only in|differ|loop|error|assert' "$1" | head -1) + [ -n "$line" ] || line=$(grep -av '^[[:space:]]*$' "$1" | tail -1) + printf '%s' "$line" | sed 's/^ *//' +} + # try [suite] # # suite is "image" (the default: build an image and diff it against the source @@ -50,29 +75,31 @@ try() { fi if [ "$suite" = obj ]; then - if ! make build/schfs_objtest > /tmp/mk.log 2>&1; then + if ! make "$OBJT" > /tmp/mk.log 2>&1; then echo " rejected at compile time" + sed -n '$p' /tmp/mk.log | sed 's/^/ /' return fi - if ./build/schfs_objtest > /tmp/rt.log 2>&1; then + if "./$OBJT" > /tmp/rt.log 2>&1; then echo " NOT CAUGHT -- the suite passed with this bug present" FAILED=1 else - echo " caught: $(grep -aE 'FAIL' /tmp/rt.log | head -1 | sed 's/^ *//')" + echo " caught: $(why /tmp/rt.log)" fi return fi - if ! make build/mkschfs build/schfs_fsck > /tmp/mk.log 2>&1; then + if ! make "$MKSCHFS" "$FSCK" > /tmp/mk.log 2>&1; then echo " rejected at compile time" + sed -n '$p' /tmp/mk.log | sed 's/^/ /' return fi - if sh tools/schfs_roundtrip.sh ./build/mkschfs ./build/schfs_fsck \ + if sh tools/posix/schfs_roundtrip.sh "./$MKSCHFS" "./$FSCK" \ > /tmp/rt.log 2>&1; then echo " NOT CAUGHT -- the suite passed with this bug present" FAILED=1 else - echo " caught: $(grep -aE 'FAIL|Only in|differ|loop' /tmp/rt.log | head -1 | sed 's/^ *//')" + echo " caught: $(why /tmp/rt.log)" fi } diff --git a/tools/posix/schcom_test.sh b/tools/posix/schcom_test.sh index c419b78..551fa48 100644 --- a/tools/posix/schcom_test.sh +++ b/tools/posix/schcom_test.sh @@ -10,6 +10,14 @@ # captures whichever QEMU considers active, which need not be the one /dev/fb0 # maps. set -e +# Run from anywhere: resolve the repo root from this script's own location +# rather than trusting the caller's working directory. Everything below is +# relative to it, and running from tools/posix/ used to fail with "missing +# build/kernel/kernel -- run make first" on a tree that was perfectly built. +script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) +repo=$(CDPATH= cd -- "$script_dir/../.." && pwd) +cd "$repo" + BUILD=${BUILD:-build} mkdir -p "$BUILD"