Commit Graph

213 Commits

Author SHA1 Message Date
Wei Liu
d56253196b vmm: Enforce threads_per_core to be at most two
Microsoft Hypervisor's hyperclear technology supports at most two
threads per core.

Practically all x64 CPUs nowadays only support two threads per core.
Enforce this in the common code.

Assisted-by: OpenAI:ChatGPT-5.4
[Test cases written by an LLM ]
Signed-off-by: Wei Liu <liuwe@microsoft.com>
2026-04-22 01:01:06 +00:00
Rob Bradford
ae646f9220 tests: Use wait_until() in test_pci_device_id
The SSH connection may fail initially when under load so use
`wait_until()` to allow retries.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-20 12:35:12 +00:00
Rob Bradford
a77b6231b4 tests: Ensure that virtiofsd has exited before hotplugging
Fix test flakiness where the virtiofsd daemon was still running and
hotplugging was trying to reach the old version. Cleanup the socket so
that waiting for it actually waits for the new instance.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-20 12:35:12 +00:00
Keith Adler
926dd1e141 vmm, devices: Add fw_cfg string item support
QEMU supports passing inline string values to the guest via fw_cfg
(-fw_cfg name=...,string=...). Cloud Hypervisor previously only
supported file-backed fw_cfg items. This adds the 'string' option
so users can pass values like OVMF's X-PciMmio64Mb without creating
a temporary file on the host.

Each fw_cfg item now accepts exactly one of 'file' or 'string'.
The FwCfgInvalidItem invariant is validated in PayloadConfig::validate()
(via FwCfgConfig::validate()), covering both CLI and JSON API paths.
The populate_fw_cfg match arm uses unreachable!() since validation
guarantees the invariant holds at that point.

CLI syntax:
  --fw-cfg-config items=[name=opt/ovmf/X-PciMmio64Mb,string=262144]

Signed-off-by: Keith Adler <kadler@cloudflare.com>
2026-04-20 09:39:56 +00:00
Anirudh Rayabharam
a10d9a3099 tests: Ignore live migration tests on mshv arm64
Live migration is not yet supported on mshv arm64. Annotate the
applicable integration tests with cfg_attr to ignore them for that
configuration.

Signed-off-by: Anirudh Rayabharam <anrayabh@microsoft.com>
2026-04-17 18:05:01 +00:00
Anatol Belski
e38f00644d tests: Replace manual losetup with create_loop_device() call
Use the ioctl based create_loop_device() helper instead of
shelling out to losetup in the file backed 4K alignment test.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-17 08:16:47 +00:00
Anatol Belski
11a86fee3e tests: Add QCOW2 direct I/O UEFI boot integration test
Boot a UEFI guest from a QCOW2 image with direct=on to exercise
the aligned I/O write path during early firmware operations.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-17 08:16:47 +00:00
Rob Bradford
67cf328a9e tests: Speed up test_pci_device_id()
This test was taking > 300s due to SSH backoffs.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-17 07:45:22 +00:00
Pascal Scholz
18873d88d7 tests: Add an integration test for PCI device ID allocation errors
Adds a test that checks the correct error is returned on allocation of
an invalid device ID (one that is not in the range 0-31) and when trying
to allocate a reserved ID (such as that of the root bridge).

Signed-off-by: Pascal Scholz <pascal.scholz@cyberus-technology.de>
On-behalf-of: SAP pascal.scholz@sap.com
Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-17 07:45:22 +00:00
Pascal Scholz
f81faad0a1 tests: Add an integration test to check duplicate PCI device IDs
This integration test verifies that the same device ID cannot be
allocated twice. Moreover, we check that the returned error matches our
expectations.

Signed-off-by: Pascal Scholz <pascal.scholz@cyberus-technology.de>
On-behalf-of: SAP pascal.scholz@sap.com
Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-17 07:45:22 +00:00
Pascal Scholz
f82eebc0b0 tests: Add an integration test to verify PCI device allocations
This commit adds an integration test to verify that the guest sees the
correct BDF. Moreover, we check that we can allocate a random free BDF
and that freeing BDFs works.

Signed-off-by: Pascal Scholz <pascal.scholz@cyberus-technology.de>
On-behalf-of: SAP pascal.scholz@sap.com
Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-17 07:45:22 +00:00
Pascal Scholz
8259f92909 tests: Return stderr when executing commands
If we want to test for error cases, it can be useful to inspect the
`stderr` of a `Command` to analyze the errors. For example, this allows
us to ensure that a `Command` returns an `IoError` by parsing the
error trace, if an `IoError` is expected.

This commit prepares the implementation of negative integration tests
for the configurable BDFs.

Signed-off-by: Pascal Scholz <pascal.scholz@cyberus-technology.de>
On-behalf-of: SAP pascal.scholz@sap.com
2026-04-17 07:45:22 +00:00
Rob Bradford
43b5a474f9 tests: Remove explicit sleep from test_api_dbus_and_http_interleaved
Instead wait for the guest to stop responding on the SSH port.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-16 22:50:47 +00:00
Rob Bradford
1269475c2a tests: Remove explicit sleeps from pvpanic test
Instead wait for the event to be delivered that it has panicked.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-16 22:50:47 +00:00
Rob Bradford
0107675eb1 tests: Remove explicit sleeps from net tests
Use `wait_until()` with the SSH command for detecting if the net device
is present/absent as part of hotplugging/unplugging.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-16 22:50:47 +00:00
Rob Bradford
9ca6d4ca41 tests: Remove explicit sleeps from block tests
Use `wait_until()` with the SSH command for detecting if the block
device is present/absent as part of hotplugging/unplugging.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-16 22:50:47 +00:00
Rob Bradford
78224baac6 tests: Remove explicit sleeps from virtio-fs tests
Instead use `wait_until()` for mounting of the filesystem.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-16 22:50:47 +00:00
Rob Bradford
01decd964f tests: Remove explicit sleep from tests_simple_launch tests
On the shutdown path remove the explicit sleep and instead wait for
the event to be delivered.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-16 22:50:47 +00:00
Rob Bradford
f55a90c170 tests: Remove explicit sleeps from "liveness" checks
The vhost-user tests uses SSH and checking the RAM to test for the
liveness of the VM - replace the explicit sleep before them with
`wait_until()` allowing them to potentially finish earlier.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-16 22:50:47 +00:00
Rob Bradford
a1cfbd6f5c tests: Use wait_until() to check for vhost-user socket
Rather than use a fixed time to wait for the socket to be opened instead
test for its existence using `wait_until()`.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-16 22:50:47 +00:00
Rob Bradford
52c24136b5 tests: Remove explicit sleeps before killing vhost-user daemons
If we're about to kill the daemons we don't need to spin waiting for
them.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-16 22:50:47 +00:00
Rob Bradford
2eafee69be tests: Remove explicit sleeps from balloon tests
Use the new `wait_until()` to test the balloon size.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-16 22:50:47 +00:00
Rob Bradford
030e63476e tests: Reduce explicit sleep time in _test_api_* tests
Use new `wait_until()` and existing boot response mechanisms to remove
explicit sleeps from these tests.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-16 22:50:47 +00:00
Leander Kohler
005ce38ffd main: add --no-shutdown
Add a CLI-only --no-shutdown flag that keeps the VMM process alive
after a guest-triggered shutdown.

Management software may still need the Cloud Hypervisor process
after the guest has powered off. Exposing this separately lets
management software, for example libvirt, keep the VMM around in a
way that is closer to QEMU.

The flag only affects the GuestExit path. Fatal exits and other
existing VMM shutdown paths remain unchanged.

On-behalf-of: SAP leander.kohler@sap.com
Signed-off-by: Leander Kohler <leander.kohler@cyberus-technology.de>
2026-04-15 17:58:56 +00:00
Anatol Belski
11cf332114 tests: Add Windows QCOW2 guest boot with direct I/O test
Boot a Windows guest from a qcow2 overlay with direct=on. After
boot, write 5 randomly filled files from 4MB to 20MB, copy each
file, and compare SHA256 hashes to verify data integrity through
the aligned bounce buffer path.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-15 17:28:58 +00:00
Philipp Schuster
edfd597993 tests: fix weird "console=ttyS0rw" string
On-behalf-of: SAP philipp.schuster@sap.com
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-04-15 11:57:23 +00:00
Philipp Schuster
98aa9d9c12 tests: make VFIO memory hotplug more robust
After memory hotplug, it may happen that it takes a few seconds until a
VFIO device is available again (IOMMU/DMA mappings need update).

On-behalf-of: SAP philipp.schuster@sap.com
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-04-14 15:11:42 +00:00
Philipp Schuster
e6c8b5e816 tests: run more tests in parallel
They can safely run in parallel. This further speeds up the CI by ~5.

On-behalf-of: SAP philipp.schuster@sap.com
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-04-14 15:11:42 +00:00
Nguyen Dinh Phi
1268539b26 main: remove api socket path when start_vmm fails
Previously the UNIX socket file was only removed on the success path
(start_vmm returned Ok(Some(path))). If start_vmm failed after the
HTTP API had bound a path-based socket, the file could be left on disk.
Parse --api-socket in parse_api_socket(), call start_vmm with the
result, then unlink the path in main after start_vmm returns for both
success and failure (fd= mode unchanged: no path to remove).

Signed-off-by: Nguyen Dinh Phi <phind.uet@gmail.com>
2026-04-14 14:18:16 +00:00
Philipp Schuster
d54a7d27a1 tests: Reduce memory usage in integration tests
This reduces pressure on CI and enables to run more tests locally on
developer machines (with 16GB of RAM or less).

No functional changes.

On-behalf-of: SAP philipp.schuster@sap.com
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-04-14 09:18:47 +00:00
Philipp Schuster
cd92f65f7b tests: Replace Windows integration sleeps with polling
Replace fixed sleeps in Windows integration tests with polling
helpers that wait for boot, snapshot readiness, and device
enumeration.

This keeps the same test intent while avoiding long fixed delays on
the fast path.

On-behalf-of: SAP philipp.schuster@sap.com
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-04-14 09:18:47 +00:00
Philipp Schuster
44ac7c0ba0 tests: Poll snapshot restore readiness in Linux tests
Replace fixed sleeps in Linux snapshot and restore integration tests
with event monitor and API readiness checks.

This updates ivshmem and common_sequential snapshot paths to wait for
concrete restore and snapshot completion signals instead of sleeping
for an assumed amount of time.

On-behalf-of: SAP philipp.schuster@sap.com
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-04-14 09:18:47 +00:00
Philipp Schuster
47024e73ce tests: Replace common integration sleeps with polling
Use polling helpers in common integration tests instead of fixed
sleeps where the tests already know the expected ready state.

This updates CPU and memory hotplug checks as well as a few
device- and restore-related waits in common_parallel to stop
oversleeping on the fast path while keeping the same assertions.

On-behalf-of: SAP philipp.schuster@sap.com
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-04-14 09:18:47 +00:00
Philipp Schuster
2c395d4ae8 tests: Plumping to retry when event monitor output is not ready
Treat missing or still-short event monitor files as a retryable state
in integration test helpers.

This keeps polling-based restore and snapshot checks from failing early
with file-not-found or short-file assertions while the monitor output
is still being written.

In the following, we can gracefully wait for the corresponding
conditions to become true.

On-behalf-of: SAP philipp.schuster@sap.com
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-04-14 09:18:47 +00:00
Philipp Schuster
a3b4687caa test_infra: split SSH command helpers by retry behavior
Split the SSH helpers into a one-shot execution path and a retrying
wrapper with linear backoff.

This makes it possible to use a single bounded SSH attempt when tests
need a direct readiness probe while preserving the existing retrying
behavior for callers that expect it.

On-behalf-of: SAP philipp.schuster@sap.com

Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-04-14 09:18:47 +00:00
Max Makarov
c99ed77d1a tests: pci: verify per-segment ACPI _UID in DSDT
Extend test_pci_multiple_segments_numa_node to assert that every
PNP0A08 host bridge in the guest DSDT exposes a unique _UID
matching its PCI segment id. Linux surfaces the evaluated _UID
value through /sys/bus/acpi/devices/PNP0A08:*/uid, so the check
is a single additional ssh command on top of the existing test
plumbing.

This test is used (rather than test_pci_multiple_segments) so
that the assertion runs on both x86_64 and aarch64: the numa_node
variant boots through edk2 firmware on aarch64, making ACPI (and
PNP0A08 host bridges) available, whereas the non-firmware variant
uses FDT on aarch64 and exposes no PNP0A08 nodes.

Without a per-segment _UID, two PNP0A08 nodes share _UID=0 which
violates ACPI 6.5 section 6.1.12 and triggers BSOD 0xA5 on
Windows guests. This assertion would catch any future regression
of that kind.

Signed-off-by: Max Makarov <maxpain@linux.com>
2026-04-13 09:39:55 +00:00
Bo Chen
6adc4f2c90 tests: vfio: Add more checks on the Nvidia GPU from the guest
Signed-off-by: Bo Chen <bchen@crusoe.ai>
2026-04-13 07:40:02 +00:00
Bo Chen
9d47769bc2 tests: Add iommufd integration tests
Add an `iommufd` flag to existing VFIO integration tests. When false,
tests use the legacy vfio container/group backend (existing behavior).
When true, tests use vfio cdev with iommufd and vfio_p2p_dma=off.

vfio_p2p_dma=off is required because the VFIO test runner uses a stock
Ubuntu 24.04 kernel (v6.8) which does not support mapping device MMIO
pages (VM_PFNMAP) through iommufd, causing IOMMU_IOAS_MAP to fail with
-EFAULT on MMIO BAR regions.

Signed-off-by: Bo Chen <bchen@crusoe.ai>
2026-04-10 22:55:38 +00:00
Bo Chen
7f377eadd9 vmm: Fix --platform syntax with optional feature flags
The `--platform` help string was hardcoded and did not reflect which
optional features (tdx, sev_snp) were actually enabled in. Build the
syntax string dynamically as `PlatformConfig::syntax()`, conditionally
appending feature-gated options so the CLI help stays accurate.

Signed-off-by: Bo Chen <bchen@crusoe.ai>
2026-04-10 22:55:38 +00:00
Sebastian Eydam
17919a7a8c tests: add integration test for migration with multiple TCP connections
On-behalf-of: SAP sebastian.eydam@sap.com
Signed-off-by: Sebastian Eydam <sebastian.eydam@cyberus-technology.de>
2026-04-02 23:43:42 +00:00
Sebastian Eydam
a9a832f392 vmm: validate VmSendMigrationData
Validates that there are no conflicting options set, and that the
destination URL is valid.

On-behalf-of: SAP sebastian.eydam@sap.com
Signed-off-by: Sebastian Eydam <sebastian.eydam@cyberus-technology.de>
2026-04-02 23:43:42 +00:00
Muminul Islam
c8bfac66f4 test_infra: Move remote_command to test_infra
Move remote_command() and remote_command_w_output() from
tests/common/utils.rs into test_infra/src/lib.rs to allow
reuse across crates.

The cloud-hypervisor integration tests already use
'use test_infra::*', so the functions are available
without any caller changes.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-04-02 14:39:21 +00:00
Anatol Belski
9db5f0439e tests: Stabilize block rate limiter workloads
Add a ramp time before measuring the block rate limiter tests so
both the single device and group workloads are measured after
warm up to make the measurements less sensitive to startup
transients.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-01 13:36:58 +00:00
Anatol Belski
36d6dacee2 tests: Increase group block rate limiter refill window
Increase the group block refill time from 100 ms to 1000 ms and
scale the shared bucket sizes to preserve the target rate.

Set the one time burst to 0 to avoid transient overshoot and use
the shared block runtime constant directly in the group path.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-01 13:36:58 +00:00
Anatol Belski
f116038111 tests: Increase rate limiter refill time
The rate limiter token bucket has a fixed 100 ms cool down time
that pauses I/O whenever the bucket empties. With a 100 ms refill
time, the actual throughput drops to roughly half of the target
rate and causes the tests to miss their target.

Increase the net and single block refill time from 100 ms to
1000 ms and scale the bucket sizes by 10x to preserve the target
rate. Set the one time burst to 0 to avoid overshooting the upper
bound, and raise the runtime constants from 10 s to 20 s for
steadier measurements.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-01 13:36:58 +00:00
Anatol Belski
6de3d5279f tests: Constify rate limiter runtimes
Introduce named constants for the net and single block rate limiter
test runtimes and use them directly at the call sites.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-01 13:36:58 +00:00
Rob Bradford
a99c40dbbb tests: Add live migration test for virtio-fs
Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-04-01 11:35:38 +00:00
CMGS
e4e2a37afa block: Restrict DISCARD to explicit sparse=true
PR #7852 fixed the missing VirtioBlockConfig fields but did not
change the feature advertisement logic. The condition
`sparse || disk_image.supports_zero_flag()` causes qcow2 to
advertise DISCARD even with sparse=false, because qcow2 can
mark clusters as zero (supports_zero_flag() returns true).

Windows viostor BSODs (DRIVER_IRQL_NOT_LESS_OR_EQUAL) when
DISCARD is advertised on qcow2 backends, making sparse=off
ineffective as a workaround for qcow2 images.

Restrict DISCARD to explicit sparse=true only. WRITE_ZEROES
remains available for all sparse-capable backends.

Fixes #7849

Signed-off-by: CMGS <ilskdw@gmail.com>
2026-03-31 18:57:52 +00:00
Philipp Schuster
c06f6c3293 tests: fix CI flakiness
This test has failed at least once in upstream CI. With the applied
stress workload, reducing the downtime to 1 ms makes it virtually
impossible for CI runners with various speeds to complete VM migration.

In other words: we will always be able to cancel.

On-behalf-of: SAP philipp.schuster@sap.com
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-03-27 16:29:28 +00:00
Rob Bradford
0bc3ca1103 tests: Add snapshot/restore integration test for virtio-fs
Add test_snapshot_restore_virtio_fs which validates that virtio-fs
continues to work correctly across a snapshot/restore cycle.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-03-27 14:18:27 +00:00