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

Li Wang liwang@redhat.com
Thu Aug 7 05:37:53 CEST 2025


On Thu, Aug 7, 2025 at 5:14 AM Petr Vorel <pvorel@suse.cz> wrote:

> 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>
> ---
> New in v3
>
>  INSTALL              |  6 ++++++
>  include/mk/module.mk | 21 ++++++++++++++++++++-
>  2 files changed, 26 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..65054ae502 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
> @@ -24,6 +32,15 @@ endif
>
>  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)),)
> @@ -41,7 +58,9 @@ MODULE_SOURCES := $(patsubst %.ko,%.c,$(filter %.ko,
> $(MAKE_TARGETS)))
>  # kernel internal API changes. The user-space test will return TCONF, if
> it
>  # doesn't find the module (i.e. it wasn't built either due to kernel-devel
>  # missing or module build failure).
> +ifneq ($(FORCE_MODULES),1)
>  %.ko: %.c .dep_modules ;
> +endif
>

Unfortunately, this wouldn't work as expected, the module's build process
only skipped silently with `make modules FORCE_MODULES=1`.


>  .dep_modules: $(MODULE_SOURCES)
>         @echo "Building modules: $(MODULE_SOURCES)"
> --
> 2.50.1
>
>

-- 
Regards,
Li Wang


More information about the ltp mailing list