[tip: objtool/core] objtool/klp: Group the klp tests by architecture

tip-bot2 for Song Liu posted 1 patch 6 days, 13 hours ago
There is a newer version of this series
tools/objtool/tests/fixtures/basic.c         | 20 +-----------
tools/objtool/tests/generic/fixtures/basic.c | 20 +++++++++++-
tools/objtool/tests/generic/test-basic.sh    | 17 +++++++++-
tools/objtool/tests/lib.sh                   | 27 ++++++++++++--
tools/objtool/tests/run-tests.sh             | 36 ++++++++++++++++---
tools/objtool/tests/test-basic.sh            | 17 +---------
6 files changed, 92 insertions(+), 45 deletions(-)
delete mode 100644 tools/objtool/tests/fixtures/basic.c
create mode 100644 tools/objtool/tests/generic/fixtures/basic.c
create mode 100755 tools/objtool/tests/generic/test-basic.sh
delete mode 100755 tools/objtool/tests/test-basic.sh
[tip: objtool/core] objtool/klp: Group the klp tests by architecture
Posted by tip-bot2 for Song Liu 6 days, 13 hours ago
The following commit has been merged into the objtool/core branch of tip:

Commit-ID:     141ed8d0c414a5298a2da4e06bacbec46f14614e
Gitweb:        https://git.kernel.org/tip/141ed8d0c414a5298a2da4e06bacbec46f14614e
Author:        Song Liu <song@kernel.org>
AuthorDate:    Wed, 16 Sep 2026 11:42:56 -07:00
Committer:     Josh Poimboeuf <jpoimboe@kernel.org>
CommitterDate: Wed, 16 Sep 2026 17:13:26 -07:00

objtool/klp: Group the klp tests by architecture

Which architecture a test is for is expressed by where it lives: tests are
in generic/ or in a directory named for their architecture, each carrying
its own fixtures, and the runner executes generic/ plus the one that
matches.  A test which cannot apply here is then not run at all, rather
than running in order to announce that it did not.

Layout does this better than a declaration would.  There is no x86_only(),
and no lookup letting a fixtures/<arch>/ file shadow a generic one of the
same name -- an arch-specific test simply carries its own fixtures.

Compilers cannot work the same way: CI varies CC over the same tree, so a
compiler requirement stays a declaration in the test.

What a run leaves out is reported once:

  # not run: 5 tests in x86/ (this run is arm64)

Silence would have been cheaper and wrong.  A run covering less than the
tree holds must not look like a run that covered all of it.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Song Liu <song@kernel.org>
Link: https://patch.msgid.link/20260916184351.2720310-4-song@kernel.org
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
---
 tools/objtool/tests/fixtures/basic.c         | 20 +-----------
 tools/objtool/tests/generic/fixtures/basic.c | 20 +++++++++++-
 tools/objtool/tests/generic/test-basic.sh    | 17 +++++++++-
 tools/objtool/tests/lib.sh                   | 27 ++++++++++++--
 tools/objtool/tests/run-tests.sh             | 36 ++++++++++++++++---
 tools/objtool/tests/test-basic.sh            | 17 +---------
 6 files changed, 92 insertions(+), 45 deletions(-)
 delete mode 100644 tools/objtool/tests/fixtures/basic.c
 create mode 100644 tools/objtool/tests/generic/fixtures/basic.c
 create mode 100755 tools/objtool/tests/generic/test-basic.sh
 delete mode 100755 tools/objtool/tests/test-basic.sh

diff --git a/tools/objtool/tests/fixtures/basic.c b/tools/objtool/tests/fixtures/basic.c
deleted file mode 100644
index 811529e..0000000
--- a/tools/objtool/tests/fixtures/basic.c
+++ /dev/null
@@ -1,20 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/* One changed function and one unchanged function. */
-
-/* klp diff takes the object's module name from .modinfo */
-static const char __modinfo[]
-	__attribute__((section(".modinfo"), used, aligned(1))) = "\0name=vmlinux";
-
-int untouched(int x)
-{
-	return x * 3;
-}
-
-int changed(int x)
-{
-#ifdef PATCHED
-	return x + 2;
-#else
-	return x + 1;
-#endif
-}
diff --git a/tools/objtool/tests/generic/fixtures/basic.c b/tools/objtool/tests/generic/fixtures/basic.c
new file mode 100644
index 0000000..811529e
--- /dev/null
+++ b/tools/objtool/tests/generic/fixtures/basic.c
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0
+/* One changed function and one unchanged function. */
+
+/* klp diff takes the object's module name from .modinfo */
+static const char __modinfo[]
+	__attribute__((section(".modinfo"), used, aligned(1))) = "\0name=vmlinux";
+
+int untouched(int x)
+{
+	return x * 3;
+}
+
+int changed(int x)
+{
+#ifdef PATCHED
+	return x + 2;
+#else
+	return x + 1;
+#endif
+}
diff --git a/tools/objtool/tests/generic/test-basic.sh b/tools/objtool/tests/generic/test-basic.sh
new file mode 100755
index 0000000..562edfb
--- /dev/null
+++ b/tools/objtool/tests/generic/test-basic.sh
@@ -0,0 +1,17 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+#
+# Only functions whose code changed get cloned into the patch.
+
+. "$(dirname "$0")/../lib.sh"
+
+setup
+build_pair basic.c
+run_diff
+
+assert_patched     changed
+assert_not_patched untouched
+assert_section     ".init.klp_funcs"
+assert_section     ".init.klp_objects"
+
+pass "changed function cloned, unchanged function left alone"
diff --git a/tools/objtool/tests/lib.sh b/tools/objtool/tests/lib.sh
index 46bdb98..fdea9b7 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 <<EOF
diff --git a/tools/objtool/tests/run-tests.sh b/tools/objtool/tests/run-tests.sh
index f6a3e1b..48728a9 100755
--- a/tools/objtool/tests/run-tests.sh
+++ b/tools/objtool/tests/run-tests.sh
@@ -3,6 +3,11 @@
 #
 # Run the objtool klp tests.  Each test-*.sh prints one TAP result line.
 #
+# Tests live in generic/ and in a directory per architecture.  A run executes
+# generic/ plus the one matching this architecture, so a test which cannot
+# apply here is not run rather than reporting a skip; what was left out is
+# reported once, as a comment, so differing coverage is still visible.
+#
 # The harness checks the environment once up front and fails the run if the
 # suite cannot execute, rather than letting every test skip and exit 0.
 
@@ -10,13 +15,34 @@ set -u
 
 cd "$(dirname "$0")" || exit 1
 
-tests=( test-*.sh )
-[ "${tests[0]}" = "test-*.sh" ] && { echo "1..0 # SKIP no tests found"; exit 0; }
-
-# Sourcing the harness runs its preflight, and exports what it found so the
-# tests inherit it rather than working it out again.
+# Sourcing the harness runs its preflight, which decides which architecture
+# this run is for -- so the test list cannot be built before it has, and the
+# tests inherit the answers rather than working them out again.
 . ./lib.sh
 
+dirs=( generic )
+[ -d "$KLP_TEST_ARCH" ] && dirs+=( "$KLP_TEST_ARCH" )
+
+tests=()
+for d in "${dirs[@]}"; do
+	for t in "$d"/test-*.sh; do
+		[ -f "$t" ] && tests+=( "$t" )
+	done
+done
+[ "${#tests[@]}" -gt 0 ] || { echo "1..0 # SKIP no tests found"; exit 0; }
+
+# Tests for another architecture are absent from this run entirely.  Say how
+# many, so a run which covers less than the tree holds does not look like one
+# that covers all of it.
+for d in */; do
+	d="${d%/}"
+	case "$d" in generic|"$KLP_TEST_ARCH") continue ;; esac
+	n=$(ls "$d"/test-*.sh 2>/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
diff --git a/tools/objtool/tests/test-basic.sh b/tools/objtool/tests/test-basic.sh
deleted file mode 100755
index 6b76996..0000000
--- a/tools/objtool/tests/test-basic.sh
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/bin/bash
-# SPDX-License-Identifier: GPL-2.0
-#
-# Only functions whose code changed get cloned into the patch.
-
-. "$(dirname "$0")/lib.sh"
-
-setup
-build_pair basic.c
-run_diff
-
-assert_patched     changed
-assert_not_patched untouched
-assert_section     ".init.klp_funcs"
-assert_section     ".init.klp_objects"
-
-pass "changed function cloned, unchanged function left alone"