microsoft/openvmm

Public

mirrored from https://github.com/microsoft/openvmmAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
bf06c4c91e2907d0f898c19c69e54cbac1e23ae4

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

Guide/src/dev_guide/tests/vmm.md

125lines · modecode

1# VMM Tests
2
3```admonish tip
4Note: We recommend using [cargo-nextest](https://nexte.st/) to run unit / VMM
5tests. It is a significant improvement over the built-in `cargo test` runner,
6and is the test runner we use in all our CI pipelines.
7
8You can install it locally by running: `cargo install cargo-nextest --locked`
9
10See the [cargo-nextest](https://nexte.st/) documentation for more info.
11```
12
13The OpenVMM repo contains a set of "heavyweight" VMM tests that fully boot a
14virtual machine and run validation against it. Unlike Unit tests, these are all
15centralized in a single top-level `vmm_tests` directory.
16
17The OpenVMM CI pipeline will run the full test suite; you'd typically run only
18the tests relevant to the changes you're working on.
19
20### Running VMM Tests
21
22```admonish warning
23`cargo nextest run` won't rebuild any of your changes. Make sure you `cargo build`
24or `cargo xflowey igvm [RECIPE]` first!
25```
26
27VMM tests are run using standard Rust test infrastructure, and are invoked via
28`cargo test` / `cargo nextest`.
29
30```bash
31cargo nextest run -p vmm_tests [TEST_FILTERS]
32```
33
34For example, to run a simple VMM test that simply boots using UEFI:
35
36```bash
37cargo nextest run -p vmm_tests x86_64::uefi_x64_frontpage
38```
39
40And, for further example, to rebuild everything and run all the tests
41(see below for details on these steps):
42
43```bash
44# Install (most) of the dependencies; cargo nextest run may tell you
45# about other deps.
46rustup target add x86_64-unknown-uefi
47rustup target add x86_64-pc-windows-msvc
48sudo apt install clang-tools-14 lld-14
49
50cargo xtask guest-test download-image
51cargo xtask guest-test uefi --bootx64
52
53# Rebuild all, and run all tests
54cargo build --target x86_64-pc-windows-msvc -p pipette
55cargo build --target x86_64-unknown-linux-musl -p pipette
56
57cargo build --target x86_64-pc-windows-msvc -p openvmm
58
59cargo xflowey build-igvm x64-test-linux-direct
60cargo xflowey build-igvm x64-cvm
61cargo xflowey build-igvm x64
62
63cargo nextest run --target x86_64-pc-windows-msvc -p vmm_tests
64```
65
66#### \[Linux] Cross-compiling `pipette.exe`
67
68These commands might use the test agent (`pipette`) that is put inside the VM,
69and if the host machine OS and the guest machine OS are different, a setup
70is required for cross-building. The recommended approach is to use WSL2 and
71cross-compile using the freely available Microsoft Visual Studio Build Tools
72or Microsoft Visual Studio Community Edition as described in
73[\[WSL2\] Cross Compiling from WSL2 to Windows](../getting_started/suggested_dev_env.md#wsl2-cross-compiling-from-wsl2-to-windows)
74
75If that is not possible, here is another option that relies on [MinGW-w64](https://www.mingw-w64.org/)
76and doesn't require installing Windows:
77
78```bash
79# Do 1 once, do 2 as needed.
80#
81# 1. Setup the toolchain
82rustup target add x86_64-pc-windows-gnu
83sudo apt-get install mingw-w64-x86-64-dev
84mingw-genlib -a x86_64 ./support/pal/api-ms-win-security-base-private-l1-1-1.def
85sudo mv libapi-ms-win-security-base-private-l1-1-1.a /usr/x86_64-w64-mingw32/lib
86
87# 2. Build Pipette (builds target/x86_64-pc-windows-gnu/debug/pipette.exe first)
88cargo build --target x86_64-pc-windows-gnu -p pipette
89```
90
91```bash
92# Run a test
93cargo nextest run -p vmm_tests x86_64::uefi_x64_windows_datacenter_core_2022_x64_boot
94```
95
96#### Acquiring external dependencies
97
98Unlike Unit Tests, VMM tests may rely on additional external artifacts in order
99to run. e.g: Virtual Disk Images, pre-built OpenHCL binaries, UEFI / PCAT
100firmware blobs, etc...
101
102As such, the first step in running a VMM test is to ensure you have acquired all
103external test artifacts it may depend upon.
104
105At this time, the VMM test infrastructure does not automatically fetch / rebuild
106necessary artifacts. That said - test infrastructure is designed to report clear
107and actionable error messages whenever a required test artifact cannot be found,
108which provide detailed instructions on how to build / acquire the missing
109artifact.
110
111
112#### Printing logs for VMM Tests
113
114In order to see the OpenVMM logs while running a VMM test, do the following:
1151. Add the `--no-capture` flag to your `cargo nextest` command.
1162. Set `OPENVMM_LOG=trace`, replacing `trace` with the log level you want to view.
117
118### Writing VMM Tests
119
120To streamline the process of booting and interacting VMs during VMM tests, the
121OpenVMM project uses a in-house test framework/library called `petri`.
122
123The library does not yet have a stable API, so at this time, the best way to
124learn how to write new VMM tests is by reading through the existing corpus of
125tests, as well as reading through `petri`'s rustdoc-generated API docs.