diff --git a/tests/test/check/data/main.fmf b/tests/test/check/data/main.fmf index 713558aa17..fd7513c0bf 100644 --- a/tests/test/check/data/main.fmf +++ b/tests/test/check/data/main.fmf @@ -13,6 +13,15 @@ failure-pattern: - 'Hypervisor detected' + /multiple-reports: + check: + - how: dmesg + result: respect + - how: dmesg + result: respect + - how: dmesg + result: respect + /avc: check: - how: avc diff --git a/tests/test/check/test-dmesg.sh b/tests/test/check/test-dmesg.sh index ff454bb6f3..1d70229807 100755 --- a/tests/test/check/test-dmesg.sh +++ b/tests/test/check/test-dmesg.sh @@ -20,6 +20,7 @@ rlJournalStart rlRun "harmless=$run/plan/execute/data/guest/default-0/dmesg/harmless-1" rlRun "segfault=$run/plan/execute/data/guest/default-0/dmesg/segfault-1" rlRun "custom_patterns=$run/plan/execute/data/guest/default-0/dmesg/custom-patterns-1" + rlRun "multiple_reports=$run/plan/execute/data/guest/default-0/dmesg/multiple-reports-1" rlRun "pushd data" rlRun "set -o pipefail" @@ -97,6 +98,22 @@ rlJournalStart rlAssertExists "$dump_after" rlLogInfo "$(cat $dump_after)" rlPhaseEnd + + rlPhaseStartTest "Test multiple dmesg reports with $PROVISION_HOW" + rlRun "dump_before=$multiple_reports/checks/dmesg-before-test.txt" + rlRun "dump_after=$multiple_reports/checks/dmesg-after-test.txt" + + rlRun "tmt run --id $run --scratch -a -vv provision -h $PROVISION_HOW test -n /dmesg/multiple-reports" + rlRun "cat $results" + + rlLogInfo "$(cat $dump_before)" + rlAssertEquals "There should be 3 reports before the test" \ + "$(grep 'Acquired at' $dump_before | wc -l)" "3" + + rlLogInfo "$(cat $dump_after)" + rlAssertEquals "There should be 3 reports after the test" \ + "$(grep 'Acquired at' $dump_after | wc -l)" "3" + rlPhaseEnd fi rlPhaseStartCleanup diff --git a/tmt/checks/dmesg.py b/tmt/checks/dmesg.py index c0bf460a26..a4a369767c 100644 --- a/tmt/checks/dmesg.py +++ b/tmt/checks/dmesg.py @@ -11,7 +11,12 @@ from tmt.checks import Check, CheckEvent, CheckPlugin, _RawCheck, provides_check from tmt.result import CheckResult, ResultOutcome from tmt.steps.provision import GuestCapability -from tmt.utils import Path, field, format_timestamp, render_run_exception_streams +from tmt.utils import ( + Path, + field, + format_timestamp, + render_command_report, + ) if TYPE_CHECKING: import tmt.base @@ -102,21 +107,22 @@ def _save_dmesg( path = invocation.check_files_path / TEST_POST_DMESG_FILENAME.format(event=event.value) try: - dmesg_output = self._fetch_dmesg(invocation.guest, logger) + output = self._fetch_dmesg(invocation.guest, logger) except tmt.utils.RunError as exc: outcome = ResultOutcome.ERROR - output = "\n".join(render_run_exception_streams(exc.output, verbose=1)) + output = exc.output else: outcome = ResultOutcome.PASS - output = dmesg_output.stdout or '' - if any(pattern.search(output) for pattern in self.failure_pattern): + + if any(pattern.search(output.stdout or '') for pattern in self.failure_pattern): outcome = ResultOutcome.FAIL invocation.phase.write( path, - f'# Acquired at {timestamp}\n{output}') + '\n'.join(render_command_report(label=f'Acquired at {timestamp}', output=output)), + mode='a') return outcome, path.relative_to(invocation.phase.step.workdir)