Add a script that checks if header files under /tools match their
original version in the kernel. Perform the check at the end of the
make, so warnings are shown after all tests are built. Note that
the build is _not_ aborted if any diff check fails.
The list of header files to check was obtained from the union of the
output of these (at tools/testing/selftests/kvm):
CFLAGS="-H" make ARCH=x86_64 2>&1 | grep '.h$' | grep 'tools'
CFLAGS="-H" make ARCH=arm64 CC=aarch64-linux-gnu-gcc-10 2>&1 | grep '.h$' | grep 'tools'
and then by manually removing the header files that were updated on the
tools/ side but not on the kernel side. There is no point in checking
for these as their changes will not be synced back to the kernel. Here
are the removed headers and the first commit that made them drift apart
from their original copies:
tools/include/linux/kernel.h
d0761e37fe3 perf tools: Uninline scnprintf() and vscnprint()
tools/include/linux/list.h
5602ea09c19 tools include: Add compiler.h to list.h
tools/include/linux/poison.h
6ae8eefc6c8 tools include: Do not use poison with C++
tools/include/linux/types.h
70ba6b8f975 tools include: add __aligned_u64 to types.h
tools/include/asm-generic/bitsperlong.h
2a00f026a15 tools: Fix up BITS_PER_LONG setting
Based on tools/perf/check-headers.sh.
Signed-off-by: Ricardo Koller <[email protected]>
---
tools/testing/selftests/kvm/Makefile | 2 +
tools/testing/selftests/kvm/check-headers.sh | 55 ++++++++++++++++++++
2 files changed, 57 insertions(+)
create mode 100755 tools/testing/selftests/kvm/check-headers.sh
diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile
index ea5c42841307..69dc4f5e9ee3 100644
--- a/tools/testing/selftests/kvm/Makefile
+++ b/tools/testing/selftests/kvm/Makefile
@@ -147,6 +147,8 @@ $(OUTPUT)/libkvm.a: $(LIBKVM_OBJS)
x := $(shell mkdir -p $(sort $(dir $(TEST_GEN_PROGS))))
all: $(STATIC_LIBS)
+ @./check-headers.sh
+
$(TEST_GEN_PROGS): $(STATIC_LIBS)
cscope: include_paths = $(LINUX_TOOL_INCLUDE) $(LINUX_HDR_PATH) include lib ..
diff --git a/tools/testing/selftests/kvm/check-headers.sh b/tools/testing/selftests/kvm/check-headers.sh
new file mode 100755
index 000000000000..c21a69b52bcd
--- /dev/null
+++ b/tools/testing/selftests/kvm/check-headers.sh
@@ -0,0 +1,55 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+#
+# Adapted from tools/perf/check-headers.sh
+
+FILES='
+arch/x86/include/asm/msr-index.h
+include/linux/bits.h
+include/linux/const.h
+include/uapi/asm-generic/bitsperlong.h
+include/uapi/linux/const.h
+include/vdso/bits.h
+include/vdso/const.h
+'
+
+check_2 () {
+ file1=$1
+ file2=$2
+
+ shift
+ shift
+
+ cmd="diff $* $file1 $file2 > /dev/null"
+
+ test -f $file2 && {
+ eval $cmd || {
+ echo "Warning: Kernel header at '$file1' differs from latest version at '$file2'" >&2
+ echo diff -u $file1 $file2
+ }
+ }
+}
+
+check () {
+ file=$1
+
+ shift
+
+ check_2 tools/$file $file $*
+}
+
+# Check if we are at the right place (we have the kernel headers)
+# (tools/testing/selftests/kvm/../../../../include)
+test -d ../../../../include || exit 0
+
+cd ../../../..
+
+# simple diff check
+for i in $FILES; do
+ check $i -B
+done
+
+# diff with extra ignore lines
+check include/linux/build_bug.h '-I "^#\(ifndef\|endif\)\( \/\/\)* static_assert$"'
+
+cd tools/testing/selftests/kvm
--
2.31.1.498.g6c1eba8ee3d-goog