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 3 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.

Cargo.toml Outdated
@@ -1,5 +1,5 @@
[workspace]
members = ["src/libkrun"]
members = ["krun-sys", "src/libkrun"]
Copy link
Contributor

Choose a reason for hiding this comment

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

krun-sys is published in crates.io and packaged in Fedora. Can we consume it from there?

Copy link
Collaborator Author

@mtjhrc mtjhrc Feb 20, 2025

Choose a reason for hiding this comment

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

Oh, I didn't know that. But where is the repository for that? Is it the one in muvm? I think we should consume it locally and publish the version located here in crates.io.

Wouldn't the crates.io version depend on system wide installation of libkrun? (something we want to avoid here).

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I didn't know that. But where is the repository for that? Is it the one in muvm? I think we should consume it locally and publish the version located here in crates.io

Yes, it's that one. Perhaps it should be moved here, perhaps it should have its own repo in github.com/containers, perhaps it can stay in muvm but we should definitely consume it from crates.io.

Wouldn't the crates.io version depend on system wide installation of libkrun? (something we want to avoid here).

In its current state, yes. I'm going to create a PR to use pkg-config to find out the location of libkrun. That should allow us to use the local installation from test-prefix.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What would be the advantage of using it from crates.io if it was in this repository here? In that case I think it makes more sense for the tests to use the potentially unpublished and potentially broken newest version of krun-sys (though admittedly since everything is auto-generated it is not that important).

@slp
Copy link
Contributor

slp commented Feb 20, 2025

This is looking good, nice work here. There a couple of very small things to fix, and consume krun-sys from crates.io (this requires a new version of krun-sys.

@slp
Copy link
Contributor

slp commented Feb 27, 2025

I've just published a new version of krun-sys, 1.10.1, which combined with #270 should help us avoid vendoring the crate.

@mtjhrc mtjhrc force-pushed the tests branch 2 times, most recently from 04befe9 to cceb4eb Compare March 3, 2025 10:05
@mtjhrc
Copy link
Collaborator Author

mtjhrc commented Mar 3, 2025

I've changed it to use the new version of krun-sys, all the env variables should now use realpath.
Even though the pkg-config has the path to the library now, we still need LD_LIBRARY_PATH for runtime though (otherwise it doesn't find the libkrun.so.1). We could also specify -rpath in the pkg-config too, but I don't know if this is a good idea.

mtjhrc added 3 commits March 7, 2025 13:54
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 <mhrica@redhat.com>
The install target should depend on generation of the libkrun.pc file,
because it installs it.
The libkrun.pc target should be .PHONY because 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 <mhrica@redhat.com>
Intruduce a test target in Makefile, that runs the e2e tests agains the built binary.

Signed-off-by: Matej Hrica <mhrica@redhat.com>
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.

2 participants