Skip to content

xen: Add test-ring0 tests #304

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

xen: Add test-ring0 tests #304

wants to merge 1 commit into from

Conversation

dinhngtu
Copy link
Member

@dinhngtu dinhngtu commented May 7, 2025

Run the test-ring0 tests that are straightforward to run.
The ones that are not (e.g. legacy tests, tests that crash the host or leak resources infinitely) are skipped, but included for completeness.

test_xst_memory_leak requires a custom kernel with CONFIG_DEBUG_KMEMLEAK set.

host.ssh(f"echo 1 > /sys/kernel/debug/xst/{testname}/run")
host.ssh(f"grep -q 'status: pass' /sys/kernel/debug/xst/{testname}/results")
finally:
host.ssh(f"modprobe -r xst_{modname}", check=False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we want to ignore modprobe's exit status here (and on similar cases)?

Copy link
Member Author

@dinhngtu dinhngtu May 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly since failure to remove test modules has no bearing on the test results, and the host is cleaned up afterwards by rebooting anyway.

def test_xst_livepatch(self, host: Host):
try:
host.ssh("lsmod | grep -wq livepatch_tester")
pytest.skip("livepatch_tester already loaded, needs reboot")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't that rather be an error?

Comment on lines 84 to 85
except SSHCommandFailed:
pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel it would be easier to read as something like

if host.ssh(...):
    pytest.error(...)

finally:
host.ssh("modprobe -r xst_ioemu_msi", check=False)

def test_xst_livepatch(self, host: Host):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without prior context, it is hard to understand what we're testing here. A detailed description and/or more comments seem to be needed

Comment on lines 1 to 8
import logging
import secrets
import time
from typing import Optional
import pytest

from lib.commands import SSHCommandFailed
from lib.host import Host
from lib.vm import VM
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be reordered. Straight imports first, alphabetically. Then a blank line. Then "from xxx" imports, alphabetically.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As Yann indicated above, I forgot about the split between external and internal libs, too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from typing here does not bother me much, and pep8 indeed does not seem to mandate any sorting within each of the 3 import blocks. IMO we should check what various checkers report.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stack Overflow most voted answer pushes for sorting, and that's also the convention we tend to use.

https://stackoverflow.com/questions/20762662/whats-the-correct-way-to-sort-python-import-x-and-from-x-import-y-statement

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought you were originally refering to pytest not being sorted 😉

Comment on lines 82 to 83
host.ssh("lsmod | grep -wq livepatch_tester")
pytest.skip("livepatch_tester already loaded, needs reboot")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We avoid skipping tests for such reasons. One might falsely think that the test was executed, in CI, as no one checks all skips one by one. What we do instead is check for prerequisites in a fixture and fail the test if the prerequisite is not met.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not use fail, that's rather what error is for

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that's appropriate, then we have a few fixtures to fix.

Copy link
Member Author

@dinhngtu dinhngtu May 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find pytest.error anywhere. I'll use pytest.fail.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By moving the prerequisite test to a fixture as I suggested (and that's one of the things fixtures are here for in pytest), it would be obvious that the failure is in the prerequisites and not in the test itself.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, my bad, there does not seem to be another mechanism than fixtures to generate error rather than failure (https://docs.pytest.org/en/stable/explanation/fixtures.html#fixture-errors seems to be where they talk about it, but it does not spell out precisely that errors are solely coming from fixtures)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Next question would be, do we want to do this in a host_without_livepatch_tester fixture to be able to get an error rather than a failure?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's precisely what I'm talking about from the beginning :D (though in other fixtures we do use pytest.fail too at the moment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it is, the test will be executed as part of the xen job. This job is currently very short and runs at the beginning of our test pipeline, on real hardware. However, with a reboot, we'll go from 1 minute to close to 10 minutes.

Are the tests themselves long to execute?

Our options:

  • keep as is
  • move to a separate job that we'll run later in the pipeline
  • split between fast tests that would not require a reboot (if any) and the rest.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests themselves are quite short. I can split it to a separate job if desired.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can keep them in the same job for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the xen job description in jobs.py to indicate that it will reboot the master host.

@dinhngtu dinhngtu force-pushed the dnt-test-ring0 branch 3 times, most recently from 8fcffa8 to b4ce123 Compare May 7, 2025 11:13
@dinhngtu dinhngtu requested a review from ydirson May 7, 2025 11:16
@dinhngtu dinhngtu requested a review from stormi May 7, 2025 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants