From 7fa995f188f1af449f86bcba6d3c3704212d5599 Mon Sep 17 00:00:00 2001 From: teo1747 Date: Mon, 9 Nov 2026 15:04:48 +0100 Subject: [PATCH] tests: a hand-run test targets x86_64-elf, as the suite does Since #198 embcc compiles for the host when nothing names a target. tests/run.sh pins x86_64-elf for the suite, but a test run by hand did not get it: on a Mac it built Mach-O objects, and embld-doctor failed for the contributor of #201 although CI passed. tests/lib.sh, which 447 of the 479 golden tests source, now exports it too. target-select builds a TARGETS=arm compiler, which lacks x86_64-elf and refused even --version under the suite's default; it unsets it, as default-target.sh does, and passes both ways. That failure had been reported as a SKIP since #198: run.sh counts a failing test as skipped when its output says "this embcc was built without the X backend", and target-select provokes that message on purpose. A test is now skipped only when X is a family the suite's own compiler lacks ("Not built:" in its --version); on a full build none is. In CI's last run target-select was the only test skipped that way. --- tests/golden/target-select.sh | 4 ++++ tests/lib.sh | 7 +++++++ tests/run.sh | 16 +++++++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/tests/golden/target-select.sh b/tests/golden/target-select.sh index 2264fb951..723346a9d 100644 --- a/tests/golden/target-select.sh +++ b/tests/golden/target-select.sh @@ -27,6 +27,10 @@ set -u echo "TEST-MARKER target-select" . "$(dirname "$0")/../lib.sh" +# The compilers built here choose their own default; the suite's +# x86_64-elf (tests/run.sh, tests/lib.sh) is one a TARGETS=arm compiler +# lacks, and it refused even --version. As default-target.sh does. +unset EMBCC_DEFAULT_TARGET EMBCC=${EMBCC:-$EMBCC_ROOT/embcc} out=$EMBCC_ROOT/tests/golden/out/target-select diff --git a/tests/lib.sh b/tests/lib.sh index 45ee58148..aa775f290 100644 --- a/tests/lib.sh +++ b/tests/lib.sh @@ -21,6 +21,13 @@ fi . "$EMBCC_ROOT/tools/hostpaths.sh" NEWLIB_INC=$X86_NEWLIB/include +# The target nothing names, as tests/run.sh sets it: the tests were written +# against x86_64-elf and name every other target. Since embcc compiles for +# the host by default (#198), a test run by hand on a Mac built Mach-O +# objects without this, and embld-doctor failed for a contributor although +# the suite passed (#201). default-target.sh unsets it to test the default. +export EMBCC_DEFAULT_TARGET=x86_64-elf + # READELF / OBJDUMP / OBJCOPY come from tools/hostpaths.sh too. # An x86-64 program is run natively only where the host IS x86-64 Linux; any diff --git a/tests/run.sh b/tests/run.sh index 7eae42c7b..b422a8585 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -128,6 +128,20 @@ if ! why=$("$EMBCC" --target="$TARGET" --print-target 2>&1 >/dev/null) && exit 0 fi +# The families this compiler lacks ("Not built:" in --version; none for a +# full build). A test that stops on one of them is a skip. A test that +# names a family this compiler HAS was refused by a compiler the test +# built itself -- target-select's TARGETS=arm one says exactly these words +# on purpose -- and its failure is a failure: counted as a skip, it hid +# target-select failing in CI from #198 on. +NOT_BUILT=$("$EMBCC" --version 2>/dev/null | sed -n 's/^Not built://p') +unbuilt_skip() { # unbuilt_skip OUTPUT: stopped on a family it lacks? + for fam in $(printf '%s\n' "$1" | grep -o "$UNBUILT" | awk '{print $7}'); do + case " $NOT_BUILT " in *" $fam "*) return 0 ;; esac + done + return 1 +} + pass=0 fail=0 skip=0 @@ -243,7 +257,7 @@ while [ $i -lt $n_sh ]; do ok "$t" elif [ "$status" -eq 0 ]; then bad "$t" "exit 0 but marker 'TEST-MARKER $name' missing — did it run?" "$out" - elif printf '%s\n' "$out" | grep -q "$UNBUILT"; then + elif unbuilt_skip "$out"; then # stopped on a target this compiler was built without (make # TARGETS=): not run, so neither a pass nor a failure echo "SKIP $t ($(printf '%s\n' "$out" | grep -m1 "$UNBUILT" |