Skip to content

Commit ea13ad6

Browse files
roxellbhcopeland
authored andcommitted
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 <anders.roxell@linaro.org>
1 parent 324db3d commit ea13ad6

6 files changed

Lines changed: 37 additions & 4 deletions

File tree

test/test_build.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,19 @@ def test_kselftest_merge_runs_right_after_config_and_before_default(self, linux)
10461046
names = [t.name for t in build.targets]
10471047
assert names == ["config", "kselftest-merge", "default", "kernel"]
10481048

1049+
def test_nonfatal_continues_on_failure(self, linux, mocker):
1050+
b = Build(tree=linux, targets=["config"])
1051+
target = mocker.MagicMock()
1052+
target.name = "kselftest"
1053+
target.nonfatal = True
1054+
target.dependencies = []
1055+
target.preconditions = []
1056+
target.commands = [Command(["false"]), Command(["true"])]
1057+
mocker.patch.object(b, "run_cmd", side_effect=[False, True])
1058+
mocker.patch.object(b, "check_artifacts", return_value=True)
1059+
result = b.build(target)
1060+
assert result.passed
1061+
10491062

10501063
class TestHeaders:
10511064
def test_basics(self, linux):

test/test_target.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,18 @@ def test_no_exclude_for_gcc(self, build):
213213
kselftest = Kselftest("kselftest", build)
214214
assert not getattr(kselftest, "exclude_build_makevars", set())
215215

216+
def test_kselftest_is_nonfatal(self, build):
217+
kselftest = Kselftest("kselftest", build)
218+
assert kselftest.nonfatal
219+
220+
def test_kselftest_bpf_is_nonfatal(self, build):
221+
kselftest_bpf = Kselftest("kselftest-bpf", build)
222+
assert kselftest_bpf.nonfatal
223+
224+
def test_config_is_not_nonfatal(self, build):
225+
config = Target("config", build)
226+
assert not config.nonfatal
227+
216228
def test_kdir_set_to_build_dir(self, build):
217229
build.toolchain.name = "gcc-14"
218230
kselftest = Kselftest("kselftest", build)

tuxmake/build.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,8 +599,11 @@ def build(self, target):
599599
interactive=cmd.interactive,
600600
exclude_build_makevars=exclude_keys,
601601
):
602-
fail = True
603-
break
602+
if target.nonfatal:
603+
self.log("W: command failed, continuing (nonfatal target)")
604+
else:
605+
fail = True
606+
break
604607

605608
if not fail and not self.check_artifacts(target):
606609
fail = True

tuxmake/target.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def __init_config__(self):
8080
self.runs_after = self.config["target"].get("runs_after", "").split()
8181
self.preconditions = self.__split_cmds__("target", "preconditions")
8282
self.commands = self.__split_cmds__("target", "commands")
83+
self.nonfatal = self.config["target"].get("nonfatal", "").lower() == "true"
8384
self.kconfig_add = self.__split_kconfigs__()
8485
try:
8586
artifacts = dict(self.config["artifacts"])

tuxmake/target/kselftest-bpf.ini

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ description = "Kernel BPF selftest (kselftest)"
55
# config options are needed to run all BPF tests but not currently included
66
# by the kselftest-merge target.
77
dependencies = kernel headers
8-
commands = {make} -C tools/testing/selftests/ install
8+
nonfatal = true
9+
commands = {make} -C tools/testing/selftests/ all
10+
&& {make} -o all -C tools/testing/selftests/ install
911
&& {tar_caf} {build_dir}/kselftest-bpf.tar{z_ext} -C {build_dir}/kselftest_bpf_install .
1012

1113
[makevars]

tuxmake/target/kselftest.ini

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
description = "Kernel selftest (kselftest)"
33
dependencies = config
44
runs_after = kselftest-merge
5-
commands = {make} -C tools/testing/selftests install
5+
nonfatal = true
6+
commands = {make} -C tools/testing/selftests all
7+
&& {make} -o all -C tools/testing/selftests install
68
&& {tar_caf} {build_dir}/kselftest.tar{z_ext} -C {build_dir}/kselftest_install .
79

810
[makevars]

0 commit comments

Comments
 (0)