diff --git a/tools/objtool/tests/fixtures/basic.c b/tools/objtool/tests/generic/fixtures/basic.c similarity index 100% rename from tools/objtool/tests/fixtures/basic.c rename to tools/objtool/tests/generic/fixtures/basic.c diff --git a/tools/objtool/tests/test-basic.sh b/tools/objtool/tests/generic/test-basic.sh similarity index 91% rename from tools/objtool/tests/test-basic.sh rename to tools/objtool/tests/generic/test-basic.sh index 6b769962399a..562edfbc8646 100755 --- a/tools/objtool/tests/test-basic.sh +++ b/tools/objtool/tests/generic/test-basic.sh @@ -3,7 +3,7 @@ # # Only functions whose code changed get cloned into the patch. -. "$(dirname "$0")/lib.sh" +. "$(dirname "$0")/../lib.sh" setup build_pair basic.c diff --git a/tools/objtool/tests/lib.sh b/tools/objtool/tests/lib.sh index 46bdb985765e..fdea9b790c4d 100644 --- a/tools/objtool/tests/lib.sh +++ b/tools/objtool/tests/lib.sh @@ -9,7 +9,10 @@ # of regressions. TESTS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -FIXTURES_DIR="$TESTS_DIR/fixtures" + +# Tests live in generic/ or in an architecture directory beside it, and each +# carries its own fixtures. +FIXTURES_DIR="$(cd "$(dirname "$0")/fixtures" 2>/dev/null && pwd)" # The kernel's convention: CROSS_COMPILE is the one knob, with per-tool # overrides for what it does not cover. objtool itself is always a host binary @@ -36,7 +39,7 @@ OBJTOOL="${OBJTOOL:-$TESTS_DIR/../objtool}" # klp_preflight() { - local tmp tool cc_version host cc_arch + local tmp tool cc_version arch host cc_arch bail() { echo "Bail out! $*" >&2; exit 1; } @@ -96,8 +99,26 @@ klp_preflight() esac rm -rf "$tmp" + # Normalize to the kernel's SRCARCH. + case "${ARCH:-$(uname -m)}" in + x86_64|i?86) arch=x86 ;; + aarch64*) arch=arm64 ;; + *) arch="${ARCH:-$(uname -m)}" ;; + esac + + case "$(uname -m)" in + x86_64|i?86) host=x86 ;; + aarch64*) host=arm64 ;; + *) host="$(uname -m)" ;; + esac + + [ -z "$cc_arch" ] || [ "$cc_arch" = "$arch" ] || + bail "ARCH says $arch but '$CC' builds $cc_arch objects;" \ + "the $arch tests would run against the wrong architecture" + + KLP_TEST_ARCH="$arch" KLP_TEST_PREFLIGHT=done - export OBJTOOL CC KLP_TEST_PREFLIGHT + export OBJTOOL CC KLP_TEST_ARCH KLP_TEST_PREFLIGHT cc_version="$($CC --version 2>/dev/null | head -1)" cat </dev/null | wc -l) + [ "$n" -gt 0 ] || continue + echo "# not run: $n test$( [ "$n" = 1 ] || echo s ) in $d/" \ + "(this run is $KLP_TEST_ARCH)" +done + echo "1..${#tests[@]}" rc=0