Skip to content

Commit 2fb8ac6

Browse files
roxellbhcopeland
authored andcommitted
kselftest: report WARNING status on nonfatal failures
When a nonfatal target has command failures, report WARNING instead of PASS. This makes partial build failures visible to CI without failing the build. Suggested-by: Ben Copeland <ben.copeland@linaro.org> Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
1 parent d54c423 commit 2fb8ac6

2 files changed

Lines changed: 53 additions & 2 deletions

File tree

test/test_build.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,37 @@ def test_nonfatal_continues_on_failure(self, linux, mocker):
11031103
mocker.patch.object(b, "check_artifacts", return_value=True)
11041104
result = b.build(target)
11051105
assert result.passed
1106+
assert result.warning
1107+
assert not result.failed
1108+
1109+
def test_warning_does_not_block_dependent_targets(self, linux, mocker):
1110+
b = Build(tree=linux, targets=["config"])
1111+
b.status["kselftest"] = BuildInfo("WARNING")
1112+
target = mocker.MagicMock()
1113+
target.name = "next"
1114+
target.nonfatal = False
1115+
target.dependencies = ["kselftest"]
1116+
target.preconditions = []
1117+
target.commands = [Command(["true"])]
1118+
mocker.patch.object(b, "run_cmd", return_value=True)
1119+
mocker.patch.object(b, "check_artifacts", return_value=True)
1120+
result = b.build(target)
1121+
assert result.passed
1122+
assert not result.skipped
1123+
1124+
def test_warning_target_build_not_failed(self, linux):
1125+
b = Build(tree=linux, targets=["config"])
1126+
b.status["config"] = BuildInfo("PASS")
1127+
b.status["kselftest"] = BuildInfo("WARNING")
1128+
assert not b.failed
1129+
assert b.passed
1130+
1131+
def test_fail_overrides_warning(self, linux):
1132+
b = Build(tree=linux, targets=["config"])
1133+
b.status["config"] = BuildInfo("FAIL")
1134+
b.status["kselftest"] = BuildInfo("WARNING")
1135+
assert b.failed
1136+
assert not b.passed
11061137

11071138

11081139
class TestHeaders:

tuxmake/build.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def passed(self):
7979
"""
8080
`True` if this target passed.
8181
"""
82-
return self.status == "PASS"
82+
return self.status in ("PASS", "WARNING")
8383

8484
@property
8585
def skipped(self):
@@ -88,6 +88,13 @@ def skipped(self):
8888
"""
8989
return self.status == "SKIP"
9090

91+
@property
92+
def warning(self):
93+
"""
94+
`True` if this target passed with warnings.
95+
"""
96+
return self.status == "WARNING"
97+
9198

9299
class Build:
93100
"""
@@ -591,6 +598,7 @@ def build(self, target):
591598
target.prepare()
592599

593600
fail = False
601+
had_nonfatal_failure = False
594602
exclude_keys = getattr(target, "exclude_build_makevars", set())
595603
for cmd in target.commands:
596604
if not self.run_cmd(
@@ -601,6 +609,7 @@ def build(self, target):
601609
):
602610
if target.nonfatal:
603611
self.log("W: command failed, continuing (nonfatal target)")
612+
had_nonfatal_failure = True
604613
else:
605614
fail = True
606615
break
@@ -611,6 +620,9 @@ def build(self, target):
611620
if fail:
612621
return BuildInfo("FAIL")
613622

623+
if had_nonfatal_failure:
624+
return BuildInfo("WARNING")
625+
614626
return BuildInfo("PASS")
615627

616628
def check_artifacts(self, target):
@@ -667,7 +679,15 @@ def collect_metadata(self):
667679
}
668680
errors, warnings = self.parse_log()
669681
self.metadata["results"] = {
670-
"status": "PASS" if self.passed else "FAIL",
682+
"status": (
683+
"FAIL"
684+
if self.failed
685+
else (
686+
"WARNING"
687+
if any(info.warning for info in self.status.values())
688+
else "PASS"
689+
)
690+
),
671691
"targets": {
672692
name: {"status": s.status, "duration": s.duration}
673693
for name, s in self.status.items()

0 commit comments

Comments
 (0)