Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Add tmt check for kmemleak #3245

Open
sbertramrh opened this issue Sep 26, 2024 · 2 comments
Open

Enhancement: Add tmt check for kmemleak #3245

sbertramrh opened this issue Sep 26, 2024 · 2 comments
Labels
area | check Test check implementation

Comments

@sbertramrh
Copy link

sbertramrh commented Sep 26, 2024

We are attempting to automate testing on a debug kernel and want to incorporate triggering a kmemleak scan at the end of each test. If there is memleak detected then save the trace cat /sys/kernel/debug/kmemlek > $TMT_PLAN_DATA/some_file.log or any location tmt decides is best.

After reading about tmt.check functions I thought this would be a great next step.

So for each test, as with dmesg, we clear at the start:
echo clear > /sys/kernel/debug/kmemleak

Scan at the end:
echo scan > /sys/kernel/debug/kmemleak (should happen before capturing dmesg)

Capture contents of kmemleak as mentioned above. This file maybe empty.

See https://www.kernel.org/doc/html/latest/dev-tools/kmemleak.html

It is essential we get this process automated and this tmt module seems like the right fit for it.

cc: @thrix

@happz happz added the area | check Test check implementation label Sep 26, 2024
@dennisbrendel
Copy link

Thanks @sbertramrh . I think this makes a lot of sense. I would like to add that before the first test execution of the selected plan there should be a scan followed by a clearing the kmleak report (or possibly store it in a special file), so that we do not include leaks from before actually running the first test.

@psss
Copy link
Collaborator

psss commented Oct 4, 2024

The check implementation handles two events: CheckEvent.BEFORE_TEST and CheckEvent.AFTER_TEST:

tmt/tmt/checks/dmesg.py

Lines 175 to 206 in 14d60dc

@classmethod
def before_test(
cls,
*,
check: 'DmesgCheck',
invocation: 'TestInvocation',
environment: Optional[tmt.utils.Environment] = None,
logger: tmt.log.Logger) -> list[CheckResult]:
if not invocation.guest.facts.has_capability(GuestCapability.SYSLOG_ACTION_READ_ALL):
return [CheckResult(name='dmesg', result=ResultOutcome.SKIP)]
outcome, path = check._save_dmesg(invocation, CheckEvent.BEFORE_TEST, logger)
return [CheckResult(name='dmesg', result=outcome, log=[path])]
@classmethod
def after_test(
cls,
*,
check: 'DmesgCheck',
invocation: 'TestInvocation',
environment: Optional[tmt.utils.Environment] = None,
logger: tmt.log.Logger) -> list[CheckResult]:
if not invocation.guest.facts.has_capability(GuestCapability.SYSLOG_ACTION_READ_ALL):
return [CheckResult(name='dmesg', result=ResultOutcome.SKIP)]
if not invocation.is_guest_healthy:
return [CheckResult(name='dmesg', result=ResultOutcome.SKIP)]
outcome, path = check._save_dmesg(invocation, CheckEvent.AFTER_TEST, logger)
return [CheckResult(name='dmesg', result=outcome, log=[path])]

I belive the before_test part could be used to clear the kmleak report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area | check Test check implementation
Projects
None yet
Development

No branches or pull requests

4 participants