From dbc9d0fb6863026b16f4805709acc7e4977d7e66 Mon Sep 17 00:00:00 2001 From: Denys Fedoryshchenko Date: Sun, 30 Aug 2026 03:10:39 +0300 Subject: cmake: fix kernel module installation Install each module from its real build directory, propagate staged install roots, and fail when kbuild modules_install fails. Add a rootless CTest and CI regression for successful and failed installs. Best practices followed: Use the standard CMake DESTDIR and kbuild INSTALL_MOD_PATH staging interfaces: https://cmake.org/cmake/help/latest/envvar/DESTDIR.html https://docs.kernel.org/kbuild/modules.html#install-mod-path Check child command status with execute_process RESULT_VARIABLE: https://cmake.org/cmake/help/latest/command/execute_process.html Register repeatable tests with CTest add_test: https://cmake.org/cmake/help/latest/command/add_test.html --- tests/kernel-module-install/Makefile | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 tests/kernel-module-install/Makefile (limited to 'tests/kernel-module-install/Makefile') diff --git a/tests/kernel-module-install/Makefile b/tests/kernel-module-install/Makefile new file mode 100644 index 00000000..9b8bf2bc --- /dev/null +++ b/tests/kernel-module-install/Makefile @@ -0,0 +1,18 @@ +.PHONY: kernelrelease modules modules_install + +kernelrelease: + @printf '%s\n' test-kernel + +modules: + @module=$$(basename "$$(dirname "$(M)")"); \ + printf 'test module %s\n' "$$module" > "$(M)/$$module.ko" + +modules_install: + @test "$(M)" != "" + @test -d "$(M)" + @if test "$${FAIL_MODULES_INSTALL:-0}" = 1; then exit 42; fi + @module=$$(basename "$$(dirname "$(M)")"); \ + test -f "$(M)/$$module.ko"; \ + destination="$(INSTALL_MOD_PATH)/lib/modules/test-kernel/extra"; \ + mkdir -p "$$destination"; \ + cp "$(M)/$$module.ko" "$$destination/$$module.ko" -- cgit v1.2.3