[LTP] [PATCH v5 2/2] modules.mk: Add FORCE_MODULES=1 to fail on error

Petr Vorel pvorel@suse.cz
Fri Aug 15 10:19:42 CEST 2025


Kernel modules deliberately not fail on error due kABI
(Linux Kernel Driver Interface) not being stable [1].

But that also silently hides modules not being build due change
(LTP module needs to be updated) or distro bug.

Introduce FORCE_MODULES=1 variable for make to force fail on error.
This can happen if
* package for building kernel modules is not installed
* LTP kernel module error mentioned above

$ make modules FORCE_MODULES=1
Build testcases/kernel/syscalls/finit_module
 Check that package for building kernel modules for 6.6.15-amd64 is installed and try again.
 * openSUSE/SLES: kernel-default-devel
 * Fedora/RHEL: kernel-devel/kernel-headers
 * Debian/Ubuntu: linux-kbuild
 You can build anyway by omitting FORCE_MODULES=1.  Stop.
...

NOTE: previously added 'modules' make target keeps trying to build all
modules (don't stop on first error).

[1] https://docs.kernel.org/process/stable-api-nonsense.html

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 INSTALL              |  6 ++++++
 include/mk/module.mk | 24 +++++++++++++++++++++++-
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/INSTALL b/INSTALL
index 10c19d4105..7c25c23347 100644
--- a/INSTALL
+++ b/INSTALL
@@ -172,9 +172,15 @@ LTP contains few kernel modules and tests which are using them.
 These require to be built with the same kernel headers as the running kernel (SUT).
 Sometimes the best way to achieve this is to compile them on the SUT.
 
+Due Linux Kernel Driver Interface unstability [1], error during building kernel
+modules does not break the build. Make errors fatal can be done by FORCE_MODULES=1
+make variable.
+
 'modules', 'modules-clean' and 'modules-install' make targets are shortcuts
 to build just these modules and tests.
 
+[1] https://docs.kernel.org/process/stable-api-nonsense.html)
+
 Android Users
 -------------
 
diff --git a/include/mk/module.mk b/include/mk/module.mk
index c3cbf9c21f..3e97f01289 100644
--- a/include/mk/module.mk
+++ b/include/mk/module.mk
@@ -1,14 +1,22 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
-# Copyright (c) Linux Test Project, 2014-2021
+# Copyright (c) Linux Test Project, 2014-2025
 # Author: Alexey Kodanev <alexey.kodanev@oracle.com>
 #
 # Include it to build kernel modules.
 # REQ_VERSION_MAJOR and REQ_VERSION_PATCH must be defined beforehand.
+#
+# FORCE_MODULES=1: Forcing to fail on error or missing kernel headers (e.g. for CI)).
 
 $(if $(REQ_VERSION_MAJOR),,$(error You must define REQ_VERSION_MAJOR))
 $(if $(REQ_VERSION_PATCH),,$(error You must define REQ_VERSION_PATCH))
 
+define newline
+
+
+endef
+n := $(newline)
+
 ifeq ($(WITH_MODULES),no)
 SKIP := 1
 else
@@ -22,8 +30,18 @@ SKIP ?= $(shell \
 endif
 endif
 
+$(info skip: $(SKIP), FORCE_MODULES: $(FORCE_MODULES))
 ifneq ($(SKIP),0)
 MAKE_TARGETS := $(filter-out %.ko, $(MAKE_TARGETS))
+ifeq ($(FORCE_MODULES),1)
+$(error Kernel modules not built!$(n)\
+Check that package for building kernel modules for $(LINUX_VERSION)\
+is installed and try again.$(n)\
+* openSUSE/SLES: kernel-default-devel$(n)\
+* Fedora/RHEL: kernel-devel/kernel-headers$(n)\
+* Debian/Ubuntu: linux-kbuild$(n)\
+You can build anyway by omitting FORCE_MODULES=1)
+endif
 endif
 
 ifneq ($(filter install clean,$(MAKECMDGOALS)),)
@@ -45,6 +63,10 @@ MODULE_SOURCES := $(patsubst %.ko,%.c,$(filter %.ko, $(MAKE_TARGETS)))
 
 .dep_modules: $(MODULE_SOURCES)
 	@echo "Building modules: $(MODULE_SOURCES)"
+ifneq ($(FORCE_MODULES),1)
 	-$(MAKE) -C $(LINUX_DIR) M=$(abs_srcdir)
+else
+	$(MAKE) -C $(LINUX_DIR) M=$(abs_srcdir)
+endif
 	rm -rf *.mod.c *.o *.ko.unsigned modules.order .tmp* .*.ko .*.cmd Module.symvers
 	@touch .dep_modules
-- 
2.50.1



More information about the ltp mailing list