From 47fee84c37c7349c353a7e9586e8968426d2c09b Mon Sep 17 00:00:00 2001 From: Anders Roxell Date: Fri, 17 Apr 2026 12:33:03 +0200 Subject: [PATCH] kselftest: allow partial build failures Many selftests do not cross-compile. The kernel kselftest Makefile now fails if any sub-target fails to build. The install target depends on all. When all fails, make skips install and nothing gets packaged. Split into two make steps. Run all first, then install with -o all to skip the dependency. Add a nonfatal flag so command failures do not stop the build. Mark kselftest and kselftest-bpf as nonfatal. Signed-off-by: Anders Roxell --- test/test_build.py | 13 +++++++++++++ test/test_target.py | 12 ++++++++++++ tuxmake/build.py | 7 +++++-- tuxmake/target.py | 1 + tuxmake/target/kselftest-bpf.ini | 4 +++- tuxmake/target/kselftest.ini | 4 +++- 6 files changed, 37 insertions(+), 4 deletions(-) diff --git a/test/test_build.py b/test/test_build.py index 162117ce..ffc9ff43 100644 --- a/test/test_build.py +++ b/test/test_build.py @@ -1046,6 +1046,19 @@ def test_kselftest_merge_runs_right_after_config_and_before_default(self, linux) names = [t.name for t in build.targets] assert names == ["config", "kselftest-merge", "default", "kernel"] + def test_nonfatal_continues_on_failure(self, linux, mocker): + b = Build(tree=linux, targets=["config"]) + target = mocker.MagicMock() + target.name = "kselftest" + target.nonfatal = True + target.dependencies = [] + target.preconditions = [] + target.commands = [Command(["false"]), Command(["true"])] + mocker.patch.object(b, "run_cmd", side_effect=[False, True]) + mocker.patch.object(b, "check_artifacts", return_value=True) + result = b.build(target) + assert result.passed + class TestHeaders: def test_basics(self, linux): diff --git a/test/test_target.py b/test/test_target.py index e5c538f4..7c729798 100644 --- a/test/test_target.py +++ b/test/test_target.py @@ -213,6 +213,18 @@ def test_no_exclude_for_gcc(self, build): kselftest = Kselftest("kselftest", build) assert not getattr(kselftest, "exclude_build_makevars", set()) + def test_kselftest_is_nonfatal(self, build): + kselftest = Kselftest("kselftest", build) + assert kselftest.nonfatal + + def test_kselftest_bpf_is_nonfatal(self, build): + kselftest_bpf = Kselftest("kselftest-bpf", build) + assert kselftest_bpf.nonfatal + + def test_config_is_not_nonfatal(self, build): + config = Target("config", build) + assert not config.nonfatal + def test_kdir_set_to_build_dir(self, build): build.toolchain.name = "gcc-14" kselftest = Kselftest("kselftest", build) diff --git a/tuxmake/build.py b/tuxmake/build.py index 052f6363..2efde729 100644 --- a/tuxmake/build.py +++ b/tuxmake/build.py @@ -599,8 +599,11 @@ def build(self, target): interactive=cmd.interactive, exclude_build_makevars=exclude_keys, ): - fail = True - break + if target.nonfatal: + self.log("W: command failed, continuing (nonfatal target)") + else: + fail = True + break if not fail and not self.check_artifacts(target): fail = True diff --git a/tuxmake/target.py b/tuxmake/target.py index 3f592399..f36a9bd6 100644 --- a/tuxmake/target.py +++ b/tuxmake/target.py @@ -80,6 +80,7 @@ def __init_config__(self): self.runs_after = self.config["target"].get("runs_after", "").split() self.preconditions = self.__split_cmds__("target", "preconditions") self.commands = self.__split_cmds__("target", "commands") + self.nonfatal = self.config["target"].get("nonfatal", "").lower() == "true" self.kconfig_add = self.__split_kconfigs__() try: artifacts = dict(self.config["artifacts"]) diff --git a/tuxmake/target/kselftest-bpf.ini b/tuxmake/target/kselftest-bpf.ini index 18f999a4..cc8dd856 100644 --- a/tuxmake/target/kselftest-bpf.ini +++ b/tuxmake/target/kselftest-bpf.ini @@ -5,7 +5,9 @@ description = "Kernel BPF selftest (kselftest)" # config options are needed to run all BPF tests but not currently included # by the kselftest-merge target. dependencies = kernel headers -commands = {make} -C tools/testing/selftests/ install +nonfatal = true +commands = {make} -C tools/testing/selftests/ all + && {make} -o all -C tools/testing/selftests/ install && {tar_caf} {build_dir}/kselftest-bpf.tar{z_ext} -C {build_dir}/kselftest_bpf_install . [makevars] diff --git a/tuxmake/target/kselftest.ini b/tuxmake/target/kselftest.ini index 34cff015..7db259fe 100644 --- a/tuxmake/target/kselftest.ini +++ b/tuxmake/target/kselftest.ini @@ -2,7 +2,9 @@ description = "Kernel selftest (kselftest)" dependencies = config runs_after = kselftest-merge -commands = {make} -C tools/testing/selftests install +nonfatal = true +commands = {make} -C tools/testing/selftests all + && {make} -o all -C tools/testing/selftests install && {tar_caf} {build_dir}/kselftest.tar{z_ext} -C {build_dir}/kselftest_install . [makevars]