Dev testing hypervisor

From google/capsem · View interactive version

Dev testing hypervisor is an AI agent skill from the GitHub repository google/capsem. Testing the hypervisor layer, Apple VZ and KVM. Use when testing VM configuration, VirtioFS, vsock, serial console, or the backend abstraction.

How to use this skill

Skill file

Hypervisor Testing

Architecture

The hypervisor module (crates/capsem-core/src/hypervisor/) has:

Tests must cover both backends where possible. macOS CI tests Apple VZ, Linux CI (ubuntu-24.04-arm with /dev/kvm) tests KVM.

Unit tests

VirtioFS FUSE operations have 30+ unit tests in kvm/virtio_fs/mod.rs:

Run them:

cargo test -p capsem-core virtio_fs    # VirtioFS tests only
cargo test -p capsem-core hypervisor   # All hypervisor tests

On macOS these run the KVM module's pure-logic tests (FUSE parsing, FDT generation) but skip anything that needs /dev/kvm. On Linux CI, all tests run including KVM integration.

Integration tests

Cross-crate VM lifecycle tests in crates/capsem-core/tests/:

cargo test -p capsem-core --test '*'   # All integration tests

These test the full boot path: config validation, device setup, serial output, vsock handshake. They require VM assets to be built.

CI setup

macOS (ci.yaml, test job)

Linux (ci.yaml, test-linux job)

Apple VZ restore errors on a locked host

VZErrorDomain12 / permission denied does not establish a missing owner

filesystem grant. Inspect the Apple virtualization worker's logs as well as

the Capsem owner's log. On a locked console, the worker has returned

SecKeyCreateDecryptedDataWithParameters / OSStatus-25308

(errSecInteractionNotAllowed) while restoring saved memory. Ask for a normal

Mac unlock and repeat the native proof before changing confinement. Incidental

owner denials during VZ error localization are consequences, not the cause.

A failed restore must preserve the checkpoint and report failure. Verify the

original foreground process with key-driven interaction after resume: a 200

response or a reused guest PID can conceal a cold boot.

KVM warm-checkpoint device state

A warm checkpoint must preserve host device-model state as well as guest RAM,

vCPUs, and virtqueue indices. In particular, the guest retains VirtioFS inode

numbers and file-handle IDs across resume, so restoring a fresh host-side FUSE

processor is invalid even when the VM reaches Ready and answers pings.

When changing KVM checkpoint or VirtioFS state:

activation;

device/share identity;

file/directory handle references it, and preserve next_ino so a recreated

path cannot inherit the stale guest node ID;

directory FD under /root across suspend, then uses both after resume

without sleeps or retries; this proves Capsem's userspace KVM VirtioFS

handle table, not Apple VZ's framework-owned device state;

hypervisor, and run the lifecycle test serially against one exact runtime asset

cohort.

x86_64 KVM boot: known pitfalls

The x86_64 KVM backend boots bzImage kernels in 64-bit long mode. Key invariants:

What to test when changing hypervisor code

| Change | Tests to run |

|--------|-------------|

| VirtioFS FUSE ops | cargo test virtio_fs + just exec "capsem-doctor -k virtiofs" |

| VM config / boot | cargo test -p capsem-core + just exec (verify boot succeeds) |

| Vsock / serial | cargo test -p capsem-core + just exec "echo ok" (verify I/O works) |

| KVM device model | cargo test -p capsem-core (Linux CI validates) |

| KVM x86_64 boot | cargo test -p capsem-core boot_x86_64 (struct tests run on macOS; full boot needs x86_64 Linux CI) |

| Hypervisor traits | cargo test -p capsem-core on both macOS and Linux CI |

Rust async reference

Read references/rust-async-patterns.md for tokio patterns (tasks, channels, streams, error handling). Relevant for vsock, MITM proxy, and VirtioFS async worker code.

Security invariants to test

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.