Skip to content

Commit

Permalink
Store multiple invocations of dmesg check for the same test in one fi…
Browse files Browse the repository at this point in the history
…le (#3393)

This should prevent loosing dmesg reports in the case of tests that
restart or reboot: all reports except the last one are lost.

The filename remains the same, but it's no longer overwritten. `dmesg`
check invocations append to it, with proper headers:

```
\## Acquired at 2024-12-03T13:12:23.536502+00:00
[    0.000000] Linux version 6.11.4-301.fc41.x86_64 (mockbuild@9b6b61418589428cb880a7020233b56f...
[    0.000000] Command line: BOOT_IMAGE=(hd0,gpt3)/vmlinuz-6.11.4-301.fc41.x86_64 no_timer_check...
[    0.000000] BIOS-provided physical RAM map:
[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable
...
\## Acquired at 2024-12-03T13:12:23.596179+00:00
...
\## Acquired at 2024-12-03T13:12:23.622283+00:00
...
```

Fixes #3317
  • Loading branch information
happz authored Dec 6, 2024
1 parent 70048a6 commit 436dcbc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
9 changes: 9 additions & 0 deletions tests/test/check/data/main.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions tests/test/check/test-dmesg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
18 changes: 12 additions & 6 deletions tmt/checks/dmesg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 436dcbc

Please sign in to comment.