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

Introduce an E2E testing framework #258

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

mtjhrc
Copy link
Collaborator

@mtjhrc mtjhrc commented Jan 27, 2025

This PR adds a testing framework for writing (mostly) end-to-end tests using libkrun.

The tests are E2E in the sense that they use the public API of libkrun to start a VM and run a test program in the guest. Note that currently this is very limited, because there are no other userspace executables or libraries (not even libc) in the guest apart from guest-agent. guest-agent is a statically linked Rust executable, that executes the guest part of each test.

In the future this can be extended to run tests with specific images which would allow the use of system libraries by the test program.

This also introduces 2 tests:

  • test-vm-config - asserts the VM is constructed with the correct number of CPUs and amount of memory. This also serves as an example how tests can be parameterized.
  • vsock-guest-connect - This tests the guest connecting to a vsock port created by the krun_add_vsock_port API.

You can run these tests using make test.

Note: Currently these tests won't be ran on CI, because we need a CI that supports nested virtualization.

@mtjhrc mtjhrc force-pushed the tests branch 6 times, most recently from d97941d to 0a08462 Compare February 4, 2025 13:18
@mtjhrc mtjhrc marked this pull request as ready for review February 4, 2025 13:30
@mtjhrc mtjhrc force-pushed the tests branch 4 times, most recently from 5d4e48e to e20a964 Compare February 6, 2025 12:08
These bindings are useful for the testing framework.
It could also be nice to publish them on crates.io in the future.

Imported from https://github.com/AsahiLinux/muvm/

Signed-off-by: Matej Hrica <[email protected]>
Make sure we can build the krun-sys crate in the CI, by installing the
dependencies. The krun-sys bindings are currently not built on the macOS CI
(missing llvm/clang dependency).

Signed-off-by: Matej Hrica <[email protected]>
Add a tests directory containing an E2E testing framework.
The tests are E2E in the sense that they use the public API of libkrun to
start a VM and run a test program in the guest.
Note that currently this is very limited, because there are no other userspace
executables or libraries (not even libc) in the guest apart from `guest-agent`.

`guest-agent` is a statically linked Rust executable, that executes the guest
part of each test.

In the future this can be extended to run tests with specific images which would
allow the use of system libraries by the test program.

This also introduces 2 tests:
test_vm_config - asserts the VM is constructed with the correct number of CPUs
                 and amount of memory. This also serves as an example how the
		 tests can be parameterized.
test_vsock_guest_connect - This tests the guest connecting to a vsock port
                           created by the `krun_add_vsock_port` API.

Signed-off-by: Matej Hrica <[email protected]>
The build targets only depend on the init binary target, so running `make`
after changing some other part of the source code doesn't trigger a rebuild.

Make the LIBRARY_RELEASE_* and LIBRARY_DEBUG_* targets .PHONY to make sure the
library is always rebuilt when running `make`.

Signed-off-by: Matej Hrica <[email protected]>
The install target needs to depend on the generation of the libkrun.pc file,
this is because the libkrun.pc file might already exists and be generated, but
it could be made using a different PREFIX, which would lead to the installed
libkrun.pc pointing to the wrong prefix.

Signed-off-by: Matej Hrica <[email protected]>
Intruduce a test target in Makefile, that runs the e2e tests agains the built binary.

Signed-off-by: Matej Hrica <[email protected]>
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.

1 participant