* [LTP] [PATCH v5 1/2] Makefile: Add kernel modules related make targets
2025-08-15 8:19 [LTP] [PATCH v5 0/2] make: Add kernel modules targets, FORCE_MODULES=1 Petr Vorel
@ 2025-08-15 8:19 ` Petr Vorel
2025-08-15 8:19 ` [LTP] [PATCH v5 2/2] modules.mk: Add FORCE_MODULES=1 to fail on error Petr Vorel
1 sibling, 0 replies; 6+ messages in thread
From: Petr Vorel @ 2025-08-15 8:19 UTC (permalink / raw)
To: ltp; +Cc: Ricardo B . Marlière
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.
Add 'modules', 'modules-clean' and 'modules-install' make targets to
make it easier to build them.
Reviewed-by: Li Wang <liwang@redhat.com>
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
INSTALL | 10 ++++++++++
Makefile | 21 +++++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/INSTALL b/INSTALL
index cbe27f32ea..10c19d4105 100644
--- a/INSTALL
+++ b/INSTALL
@@ -165,6 +165,16 @@ PKG_CONFIG_LIBDIR=/usr/lib/i386-linux-gnu/pkgconfig CFLAGS=-m32 LDFLAGS=-m32 ./c
* Arch Linux
PKG_CONFIG_LIBDIR=/usr/lib32/pkgconfig CFLAGS=-m32 LDFLAGS=-m32 ./configure
+Kernel modules
+--------------
+
+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.
+
+'modules', 'modules-clean' and 'modules-install' make targets are shortcuts
+to build just these modules and tests.
+
Android Users
-------------
diff --git a/Makefile b/Makefile
index eab40da8a6..b2cc77463c 100644
--- a/Makefile
+++ b/Makefile
@@ -212,6 +212,27 @@ endif
test-metadata: metadata-all
$(MAKE) -C $(abs_srcdir)/metadata test
+MODULE_DIRS := $(shell \
+ dirname $$(grep -l 'include.*module\.mk' $$(find testcases/ -type f -name 'Makefile')))
+
+
+.PHONY: modules modules-clean modules-install
+modules:
+ @$(foreach dir,$(MODULE_DIRS),\
+ echo "Build $(dir)";\
+ $(MAKE) -C $(abs_srcdir)/$(dir) || exit $$?; \
+)
+modules-clean:
+ @$(foreach dir,$(MODULE_DIRS),\
+ echo "Build $(dir)";\
+ $(MAKE) -C $(abs_srcdir)/$(dir) clean || exit $$?; \
+)
+modules-install: modules
+ @$(foreach dir,$(MODULE_DIRS),\
+ echo "Build $(dir)";\
+ $(MAKE) -C $(abs_srcdir)/$(dir) install || exit $$?; \
+)
+
## Help
.PHONY: help
help:
--
2.50.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [LTP] [PATCH v5 2/2] modules.mk: Add FORCE_MODULES=1 to fail on error
2025-08-15 8:19 [LTP] [PATCH v5 0/2] make: Add kernel modules targets, FORCE_MODULES=1 Petr Vorel
2025-08-15 8:19 ` [LTP] [PATCH v5 1/2] Makefile: Add kernel modules related make targets Petr Vorel
@ 2025-08-15 8:19 ` Petr Vorel
2025-08-15 9:24 ` Li Wang via ltp
2025-08-15 14:12 ` Cyril Hrubis
1 sibling, 2 replies; 6+ messages in thread
From: Petr Vorel @ 2025-08-15 8:19 UTC (permalink / raw)
To: ltp; +Cc: Ricardo B . Marlière
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
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 6+ messages in thread