Backend - Per-VM CPU affinity (vmstart/affinity.go, affinity_flow.go): modes auto / all / P-cores / non-LP-E / custom, saved in the VM folder, applied to the QEMU process on start (GUI and CLI) and live via SetVMAffinity; copied on clone. Start summary logs the resolved mapping. Host report gains CPU topology helpers (mask <-> CPU list). - Offline qcow2 restore points via qemu-img (driver/reims/snapshot.go, snapshot_flow.go): list / create / restore / delete. - SSH helpers (ssh_flow.go): remembered user, open a terminal, write an ~/.ssh/config entry, open VS Code Remote-SSH. - FocusVMWindow brings the QEMU window forward (restoring it if minimized); CopyVMScreenshot copies a full-resolution frame to the clipboard. - DeliverPathsToGuest copies dropped host files into the shared folder; main.go enables Wails file drop on elements marked --wails-drop-target. - VM note (.reims-go-note) and a storage breakdown (extras_flow.go). Frontend - VM page: running state's "Show Window" and the screen preview use FocusVMWindow; camera button and More-menu item copy a screenshot; editable note under the name; SSH row shows the saved user with Terminal / config / VS Code actions; restore-point list; install guide steps can be ticked off; drop files onto the page to send them. - Sidebar right-click menu per VM (start, show window, screenshot, stop, restart, settings, folders, clone, delete); double-click and Ctrl+Enter still run the main action. - AffinityDialog opened from the VM menu and VM settings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
86 lines
3.0 KiB
Go
86 lines
3.0 KiB
Go
package vmstart
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/Nwflower/reims-go/internal/host"
|
|
)
|
|
|
|
func TestVMAffinityRoundTripAndResolve(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
// Default when sidecar does not exist.
|
|
def := ReadVMAffinity(dir)
|
|
if def.Mode != AffinityAuto || !def.ShouldDisableEcoQoS() {
|
|
t.Fatalf("unexpected default: %+v", def)
|
|
}
|
|
|
|
// Custom mode rejects empty selection.
|
|
if _, err := SaveVMAffinity(dir, VMAffinityConfig{Mode: AffinityCustom}, 16); err == nil {
|
|
t.Fatalf("expected error for empty custom CPU list")
|
|
}
|
|
|
|
// Save custom deduplicated/sorted CPUs with EcoQoS disabled=false.
|
|
eco := false
|
|
saved, err := SaveVMAffinity(dir, VMAffinityConfig{
|
|
Mode: AffinityCustom,
|
|
CPUs: []int{5, 2, 2, 0, 99, -1},
|
|
DisableEcoQoS: &eco,
|
|
}, 16)
|
|
if err != nil {
|
|
t.Fatalf("SaveVMAffinity: %v", err)
|
|
}
|
|
wantCPUs := []int{0, 2, 5}
|
|
if !reflect.DeepEqual(saved.CPUs, wantCPUs) || saved.ShouldDisableEcoQoS() {
|
|
t.Fatalf("saved = %+v, want cpus %v eco=false", saved, wantCPUs)
|
|
}
|
|
|
|
loaded := ReadVMAffinity(dir)
|
|
if loaded.Mode != AffinityCustom || !reflect.DeepEqual(loaded.CPUs, wantCPUs) || loaded.ShouldDisableEcoQoS() {
|
|
t.Fatalf("loaded = %+v", loaded)
|
|
}
|
|
|
|
// Resolve on homogeneous 16-thread CPU.
|
|
amd := host.Report{LogicalCPUs: 16}
|
|
res := ResolveVMAffinity(loaded, true, amd, 4)
|
|
if res.EffectiveMode != AffinityCustom || res.Mask != 0x25 || !res.ShouldPin {
|
|
t.Fatalf("custom resolve = %+v, want mask 0x25", res)
|
|
}
|
|
|
|
// Resolve auto on 3-tier Arrow Lake.
|
|
arrowLake := host.Report{
|
|
LogicalCPUs: 16,
|
|
HasHybridCores: true,
|
|
PCoreCount: 6,
|
|
ECoreCount: 8,
|
|
LPECoreCount: 2,
|
|
PCoreMask: 0x3C03,
|
|
PCoreLogicalCPUs: []int{0, 1, 10, 11, 12, 13},
|
|
NonLPEMask: 0x3FFF,
|
|
NonLPELogicalCPUs: []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13},
|
|
}
|
|
r4 := ResolveVMAffinity(DefaultVMAffinityConfig(), true, arrowLake, 4)
|
|
if r4.EffectiveMode != AffinityPCores || r4.Mask != 0x3C03 || !r4.ShouldPin {
|
|
t.Fatalf("auto 4 vCPU = %+v", r4)
|
|
}
|
|
r8 := ResolveVMAffinity(DefaultVMAffinityConfig(), true, arrowLake, 8)
|
|
if r8.EffectiveMode != AffinityNonLPE || r8.Mask != 0x3FFF || !r8.ShouldPin {
|
|
t.Fatalf("auto 8 vCPU = %+v", r8)
|
|
}
|
|
r14 := ResolveVMAffinity(DefaultVMAffinityConfig(), true, arrowLake, 14)
|
|
if r14.EffectiveMode != AffinityAll || !r14.AutoSkipped || r14.ShouldPin {
|
|
t.Fatalf("auto 14 vCPU = %+v", r14)
|
|
}
|
|
// Explicit pcores overrides auto headroom limit when user explicitly asks for it.
|
|
rExplicitP := ResolveVMAffinity(VMAffinityConfig{Mode: AffinityPCores}, false, arrowLake, 8)
|
|
if rExplicitP.EffectiveMode != AffinityPCores || rExplicitP.Mask != 0x3C03 || !rExplicitP.ShouldPin {
|
|
t.Fatalf("explicit pcores = %+v", rExplicitP)
|
|
}
|
|
// Explicit all returns full mask and ShouldPin=false (forceApplyAll handles live reset).
|
|
rAll := ResolveVMAffinity(VMAffinityConfig{Mode: AffinityAll}, true, arrowLake, 4)
|
|
if rAll.EffectiveMode != AffinityAll || rAll.Mask != 0xFFFF || rAll.ShouldPin {
|
|
t.Fatalf("explicit all = %+v", rAll)
|
|
}
|
|
}
|