microsoft/openvmm

Public

mirrored fromhttps://github.com/microsoft/openvmmAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1453b0c8194d3a8a48f5f48d4a5bd9e93a993f45

Branches

Tags

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

Clone

HTTPS

Download ZIP

Guide/src/dev_guide/tests/vmm.md

128lines · 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-none
47rustup target add x86_64-unknown-uefi
48rustup target add x86_64-pc-windows-msvc
49sudo apt install clang-tools-14 lld-14
50
51cargo install cargo-nextest --locked
52
53cargo xtask guest-test download-image
54cargo xtask guest-test uefi --bootx64
55
56# Rebuild all, and run all tests
57cargo build --target x86_64-pc-windows-msvc -p pipette
58cargo build --target x86_64-unknown-linux-musl -p pipette
59
60cargo build --target x86_64-pc-windows-msvc -p openvmm
61
62cargo xflowey build-igvm x64-test-linux-direct
63cargo xflowey build-igvm x64-cvm
64cargo xflowey build-igvm x64
65
66cargo nextest run --target x86_64-pc-windows-msvc -p vmm_tests
67```
68
69#### \[Linux] Cross-compiling `pipette.exe`
70
71These commands might use the test agent (`pipette`) that is put inside the VM,
72and if the host machine OS and the guest machine OS are different, a setup
73is required for cross-building. The recommended approach is to use WSL2 and
74cross-compile using the freely available Microsoft Visual Studio Build Tools
75or Microsoft Visual Studio Community Edition as described in
76[\[WSL2\] Cross Compiling from WSL2 to Windows](../getting_started/suggested_dev_env.md#wsl2-cross-compiling-from-wsl2-to-windows)
77
78If that is not possible, here is another option that relies on [MinGW-w64](https://www.mingw-w64.org/)
79and doesn't require installing Windows:
80
81```bash
82# Do 1 once, do 2 as needed.
83#
84# 1. Setup the toolchain
85rustup target add x86_64-pc-windows-gnu
86sudo apt-get install mingw-w64-x86-64-dev
87mingw-genlib -a x86_64 ./support/pal/api-ms-win-security-base-private-l1-1-1.def
88sudo mv libapi-ms-win-security-base-private-l1-1-1.a /usr/x86_64-w64-mingw32/lib
89
90# 2. Build Pipette (builds target/x86_64-pc-windows-gnu/debug/pipette.exe first)
91cargo build --target x86_64-pc-windows-gnu -p pipette
92```
93
94```bash
95# Run a test
96cargo nextest run -p vmm_tests x86_64::uefi_x64_windows_datacenter_core_2022_x64_boot
97```
98
99#### Acquiring external dependencies
100
101Unlike Unit Tests, VMM tests may rely on additional external artifacts in order
102to run. e.g: Virtual Disk Images, pre-built OpenHCL binaries, UEFI / PCAT
103firmware blobs, etc...
104
105As such, the first step in running a VMM test is to ensure you have acquired all
106external test artifacts it may depend upon.
107
108At this time, the VMM test infrastructure does not automatically fetch / rebuild
109necessary artifacts. That said - test infrastructure is designed to report clear
110and actionable error messages whenever a required test artifact cannot be found,
111which provide detailed instructions on how to build / acquire the missing
112artifact.
113
114
115#### Printing logs for VMM Tests
116
117In order to see the OpenVMM logs while running a VMM test, do the following:
1181. Add the `--no-capture` flag to your `cargo nextest` command.
1192. Set `OPENVMM_LOG=trace`, replacing `trace` with the log level you want to view.
120
121### Writing VMM Tests
122
123To streamline the process of booting and interacting VMs during VMM tests, the
124OpenVMM project uses a in-house test framework/library called `petri`.
125
126The library does not yet have a stable API, so at this time, the best way to
127learn how to write new VMM tests is by reading through the existing corpus of
128tests, as well as reading through `petri`'s rustdoc-generated API docs.
129