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

Add a target runner for running tests in VMs #5285

Merged
merged 29 commits into from
Mar 26, 2024
Merged

Conversation

andrewjstone
Copy link
Contributor

@andrewjstone andrewjstone commented Mar 19, 2024

This PR allows us to run tests inside falcon VMs via nextest. Due to the lack of nextest per-test target runners, we enable the target runner via environment variable and run a specific test at a time.

In order to run a test, do the following, where the trailing --nocapture is optional but encouraged at this moment.

cd omicron
CARGO_TARGET_X86_64_UNKNOWN_ILLUMOS_RUNNER=./test-utils/src/bin/falcon_runner.sh cargo nextest run -p <package> <test name> --nocapture

An example:

CARGO_TARGET_X86_64_UNKNOWN_ILLUMOS_RUNNER=./test-utils/src/bin/falcon_runner.sh cargo nextest run -p omicron-test-utils launch --nocapture

A few things remain to be done, although this is safe to merge without adding them in this PR.

  • Right now, only one test can be run per test binary, although we can change this if we want. We should also error out in the case the user doesn't pass a specific test.
  • We don't actually check the error result of the test in the VM. We should do this, and then automatically leave the VM running if the test fails.
  • We need a small binary to allow us to login to a VM on a failed VM test. I hacked up the solo example in falcon for a demo, but we'll want one in Omicron for ease of use.
  • We need a good way to get log files from failing tests out of the VMs. We can actually do this with our hypothetical binary and the falcon exec call like <BIN> exec <VM_NAME> 'cat <FILE>' > <LOCALFILE>. However, a better mechanism would be to make the p9 filesystem read/write instead of read-only, or to inject ssh keys and pull the files that way.

Copy link
Collaborator

@smklein smklein left a comment

Choose a reason for hiding this comment

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

This is extremely rad, great work getting this set up. Took me seconds to check out this PR and get the VMM test up-and-running -- truly incredible!

  • Right now, only one test can be run per test binary, although we can change this if we want.

Given the hoops we're trying to jump through, and the current limitations of nextest, this seems totally reasonable, but probably worthwhile adding some docs in the form of a README ("here is how you add a VMM test, here is how you run it, etc"), even if just to make it "easy to follow along" with the way to use this thing as it develops.

The "requires an environment variable to work" + "single-test-per-binary" constraints are tricky, so we should document them pretty explicitly.

  • We don't actually check the error result of the test in the VM. We should do this, and then automatically leave the VM running if the test fails.

I'd consider this a hard-blocker before encouraging anyone to use this as a test harness. Even if we aren't extracting all the log info we want yet, this seems like it's "dangerous enough to omit" that it should probably be fixed first.

test-utils/src/bin/falcon_runner.rs Outdated Show resolved Hide resolved
test-utils/src/bin/falcon_runner.rs Show resolved Hide resolved
test-utils/src/dev/falcon.rs Outdated Show resolved Hide resolved
//! Mechanisms to launch and control propolis VMs via falcon

#[cfg(test)]
mod test {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Idea, take it or leave it -- it might be kinda nice to have a way to validate "this test is being run from a VMM context, bail out if that isn't true?"

I dunno what we'd want to set in the falcon_runner, but just something to distinguish it from the host, since "getting the config right" is one of the trickiest bits to launch these VM tests right now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a check for the hostname, which is quite unique. We can certainly inject a file though, which might work better once we start using different names for VMs. We'll want to use different names to run tests in parallel.

@andrewjstone andrewjstone marked this pull request as ready for review March 25, 2024 20:45
@andrewjstone
Copy link
Contributor Author

This is probably good enough for a real review now. I added a README to get started and also leave the VM up when a test fails.

@andrewjstone
Copy link
Contributor Author

This is probably good enough for a real review now. I added a README to get started and also leave the VM up when a test fails.

There are few significant limitations listed in the README, but they can be resolved fairly quickly. It would probably be good to get this in to let people play with it, then figure out how we want to perform setup for more sophisticated tests that require injecting data into VMs, and for running in parallel.

Comment on lines 100 to 101
* The name of the test `Runner` and `VM` is currently hardcoded. Therefore,
tests can only be run serially for now. This is an easy limitation to lift, we
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit - the names are hard-coded, but these aren't the names used, right? It's the string including "launchpad_mcduck?"

Comment on lines 63 to 64
let exit_code_index = out.rfind('\n').unwrap();
let exit_code: u8 = (&out[exit_code_index + 1..]).parse().unwrap_or(255);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Couple nitpicks here:

  • If the \n character didn't exist in the output we might want to get better feedback from the test (via an .expect call, perhaps?)
  • The indexing in out seems like it could easily go out-of-bounds -- what if \n was the last character emitted?

@andrewjstone andrewjstone enabled auto-merge (squash) March 26, 2024 00:43
@andrewjstone andrewjstone disabled auto-merge March 26, 2024 00:44
@andrewjstone andrewjstone changed the title [WIP] Add a target runner for running tests in VMs Add a target runner for running tests in VMs Mar 26, 2024
@andrewjstone andrewjstone enabled auto-merge (squash) March 26, 2024 00:44
@andrewjstone andrewjstone merged commit a17750d into main Mar 26, 2024
23 of 24 checks passed
@andrewjstone andrewjstone deleted the falcon-nextest branch March 26, 2024 14:57
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