Skip to content

Commit 4661306

Browse files
authored
virt_support_apic: add local APIC behavior unit tests (#5246)
`virt_support_apic` emulates the local APIC for OpenHCL on SNP/TDX and for OpenVMM's WHP software APIC, but most of its guest-facing behavior had no unit tests. This PR adds 20 tests in `lib.rs` that drive the APIC the way a guest and VMM do: register access over MMIO and MSRs, MSIs, LINT pulses, and the delivery, offload, save, and restore APIs. The test client now records wakes, IO-APIC EOIs, and APIC base updates, and has a settable clock for timer tests. **Coverage areas** - Interrupt priority, EOI, and level-triggered EOI forwarding to the IO-APIC. - Software disable, LVT masking, and reserved vectors. - xAPIC and x2APIC IPI routing: physical, flat and cluster logical, broadcast, shorthands, lowest priority. - INIT, SIPI, NMI, EXTINT, and LINT delivery. - APIC base MSR transitions and MMIO/x2APIC MSR access rules. - Timer one-shot, periodic, divide, and masking. - Save/restore round trip. - Hyper-V APIC MSRs. - APIC offload, lazy EOI, the local fast path, and `scan()`. Two tests are marked `%23[ignore]` for bugs found while writing them: - `dfr_write_with_unknown_model_does_not_panic`: a reserved DFR model panics. Fixed separately in "virt_support_apic: ignore DFR writes with a reserved model"; this test can be dropped once that merges. - `tpr_write_ignores_reserved_bits`: TPR writes pass bits above 7 to CR8. Adds `pal_async` as a dev-dependency for the async `scan()` test. Coverage of production lines goes from 40% to 98%. Tests only; no production code changes.
1 parent 8fc4346 commit 4661306

3 files changed

Lines changed: 1369 additions & 5 deletions

File tree

‎Cargo.lock‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10331,6 +10331,7 @@ dependencies = [
1033110331
"hvdef",
1033210332
"inspect",
1033310333
"inspect_counters",
10334+
"pal_async",
1033410335
"parking_lot",
1033510336
"test_with_tracing",
1033610337
"thiserror 2.0.16",

‎vmm_core/virt_support_apic/Cargo.toml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@ parking_lot.workspace = true
2323
thiserror.workspace = true
2424
tracing.workspace = true
2525

26+
[dev-dependencies]
27+
pal_async.workspace = true
28+
2629
[lints]
2730
workspace = true

0 commit comments

Comments
 (0)