package host import "testing" func findOpt(t *testing.T, opts []Optimization, id string) Optimization { t.Helper() for _, o := range opts { if o.ID == id { return o } } t.Fatalf("optimization %q not found", id) return Optimization{} } func TestEvaluateOptimizationsWin10AndWin11(t *testing.T) { // Win10 hybrid CPU without startup-ipis patch. win10 := Report{ WHPX: WHPXReady, HasHybridCores: true, PCoreCount: 8, ECoreCount: 4, NeedsColdRebootWorkaround: true, WHPXCaps: WHPXCapabilities{ APICEmulation: true, KernelIrqchipAvailable: true, }, RecommendedGPU: &GPUInfo{Name: "NVIDIA GeForce RTX 4070 Ti", Kind: GPUDiscrete, VulkanICD: "nv-vk64.json"}, } opts := EvaluateOptimizations(win10, []string{"qemu-whpx-win10-compat.patch"}) if o := findOpt(t, opts, "pcore_pin"); o.Status != "recommended" || !o.Supported { t.Fatalf("pcore_pin = %+v", o) } if o := findOpt(t, opts, "kernel_irqchip"); o.Status != "unavailable" || o.Detail != "win10-needs-patch" { t.Fatalf("kernel_irqchip without patch = %+v", o) } if o := findOpt(t, opts, "cold_reboot"); o.Status != "auto" { t.Fatalf("cold_reboot = %+v", o) } // Win10 with startup-ipis patch -> experimental. optsPatched := EvaluateOptimizations(win10, []string{"qemu-whpx-win10-compat.patch", "qemu-whpx-win10-startup-ipis.patch"}) if o := findOpt(t, optsPatched, "kernel_irqchip"); o.Status != "experimental" || !o.Supported { t.Fatalf("kernel_irqchip with patch = %+v", o) } // Win11 where NestedVirtualization probe fails with 0x80370302. win11BrokenNested := Report{ WHPX: WHPXReady, NeedsColdRebootWorkaround: false, WHPXCaps: WHPXCapabilities{ ModernOS: true, APICEmulation: true, KernelIrqchipAvailable: true, NestedVirtProperty: false, NestedVirtProbeError: "0x80370302", }, } opts11 := EvaluateOptimizations(win11BrokenNested, nil) if o := findOpt(t, opts11, "kernel_irqchip"); o.Status != "unavailable" || o.Detail != "0x80370302" { t.Fatalf("win11 broken nested = %+v", o) } if o := findOpt(t, opts11, "cold_reboot"); o.Status != "unavailable" { t.Fatalf("win11 cold_reboot = %+v", o) } // Win11 with nested-virt-nonfatal patch -> kernel_irqchip recommended even when probe returns 0x80370302. opts11Patched := EvaluateOptimizations(win11BrokenNested, []string{"qemu-whpx-nested-virt-nonfatal.patch"}) if o := findOpt(t, opts11Patched, "kernel_irqchip"); o.Status != "recommended" || !o.Supported { t.Fatalf("win11 with nested-virt-nonfatal patch = %+v", o) } // Win11 with full support. win11BrokenNested.WHPXCaps.NestedVirtProperty = true win11BrokenNested.WHPXCaps.NestedVirtProbeError = "" opts11Ok := EvaluateOptimizations(win11BrokenNested, nil) if o := findOpt(t, opts11Ok, "kernel_irqchip"); o.Status != "recommended" || !o.Supported { t.Fatalf("win11 full support = %+v", o) } } func TestCanSafelyPinPCores(t *testing.T) { // Arrow Lake Core Ultra 9 285H: 6 P-cores with NO Hyper-Threading (6 logical CPUs). arrowLake := Report{ HasHybridCores: true, PCoreCount: 6, ECoreCount: 10, PCoreMask: 0x3C03, PCoreLogicalCPUs: []int{0, 1, 10, 11, 12, 13}, } if ok, threads := CanSafelyPinPCores(arrowLake, 8); ok || threads != 6 { t.Fatalf("arrowLake 8 vCPU: got (%v, %d), want (false, 6)", ok, threads) } if ok, threads := CanSafelyPinPCores(arrowLake, 6); ok || threads != 6 { t.Fatalf("arrowLake 6 vCPU: got (%v, %d), want (false, 6)", ok, threads) } if ok, threads := CanSafelyPinPCores(arrowLake, 4); !ok || threads != 6 { t.Fatalf("arrowLake 4 vCPU: got (%v, %d), want (true, 6)", ok, threads) } // Raptor Lake 6P with Hyper-Threading (12 logical CPUs). raptorLake := Report{ HasHybridCores: true, PCoreCount: 6, ECoreCount: 8, PCoreMask: 0xFFF, PCoreLogicalCPUs: []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, } if ok, threads := CanSafelyPinPCores(raptorLake, 8); !ok || threads != 12 { t.Fatalf("raptorLake 8 vCPU: got (%v, %d), want (true, 12)", ok, threads) } if ok, threads := CanSafelyPinPCores(raptorLake, 12); ok || threads != 12 { t.Fatalf("raptorLake 12 vCPU: got (%v, %d), want (false, 12)", ok, threads) } } func TestSelectSafeAffinityThreeTierArrowLake(t *testing.T) { // Intel Core Ultra 9 285H: 6P (no HT) + 8E + 2LP-E = 16 logical CPUs. arrowLake := Report{ HasHybridCores: true, PCoreCount: 6, ECoreCount: 8, LPECoreCount: 2, PCoreMask: 0x3C03, PCoreMaskHex: "0x3C03", PCoreLogicalCPUs: []int{0, 1, 10, 11, 12, 13}, NonLPEMask: 0x3FFF, NonLPEMaskHex: "0x3FFF", NonLPELogicalCPUs: []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, } if p := SelectSafeAffinity(arrowLake, 4); p.Mode != "pcores" || p.Mask != 0x3C03 { t.Fatalf("4 vCPU: got %+v, want pcores 0x3C03", p) } if p := SelectSafeAffinity(arrowLake, 8); p.Mode != "non_lpe" || p.Mask != 0x3FFF || p.ThreadCount != 14 { t.Fatalf("8 vCPU: got %+v, want non_lpe 0x3FFF (14T)", p) } if p := SelectSafeAffinity(arrowLake, 14); p.Mode != "all" || p.Mask != 0 { t.Fatalf("14 vCPU: got %+v, want all", p) } } func TestEvaluateOptimizationsDeepBackingChain(t *testing.T) { rep := Report{ DeepBackingChains: []BackingChainIssue{ {VMName: "dev-clone", Path: `D:\vms\dev-clone\disk.qcow2`, Depth: 2}, }, } opts := EvaluateOptimizations(rep, nil) o := findOpt(t, opts, "cow_backing_chain") if o.Status != "recommended" || !o.Recommended || o.Detail != "dev-clone(depth=2)" { t.Fatalf("cow_backing_chain = %+v", o) } }