Files
Reims-Go/internal/host/optimizations_test.go
T
Nwflower 74be2f73a9 refactor(macos): own guest tools images and tuning
Build Guest Tools images in the macOS driver after all start hooks pass, through a host callback rather than a new macOS-to-guesttools dependency.

Add driver.OptimizationAdvisor, keep generic hardware evaluation in host, and move WHPX recommendations and tests into macosdriver for both the UI and diagnostics.
2026-11-30 08:45:12 -07:00

89 lines
2.9 KiB
Go

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 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 := EvaluateCoreOptimizations(rep)
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)
}
}