Files
Reims-Go/internal/host/host_test.go

296 lines
16 KiB
Go

package host
import "testing"
func TestGPUClassificationAndRecommendation(t *testing.T) {
gpus := []GPUInfo{
{Name: "Todesk Virtual Display Adapter", VulkanICD: "", Kind: ClassifyGPU("Todesk Virtual Display Adapter")},
{Name: "Intel(R) UHD Graphics 770", VulkanICD: `C:\igvk64.json`, Kind: ClassifyGPU("Intel(R) UHD Graphics 770")},
{Name: "NVIDIA GeForce RTX 4070 Ti", VulkanICD: `C:\nv-vk64.json`, Kind: ClassifyGPU("NVIDIA GeForce RTX 4070 Ti")},
}
if gpus[0].Kind != GPUVirtual {
t.Fatalf("expected virtual, got %s", gpus[0].Kind)
}
if gpus[1].Kind != GPUIntegrated {
t.Fatalf("expected integrated, got %s", gpus[1].Kind)
}
if gpus[2].Kind != GPUDiscrete {
t.Fatalf("expected discrete, got %s", gpus[2].Kind)
}
rec := PickRecommendedGPU(gpus)
if rec == nil || rec.VulkanICD != `C:\nv-vk64.json` {
t.Fatalf("expected NVIDIA discrete GPU to be recommended, got %#v", rec)
}
// Regression checks for AMD iGPUs and Intel Core Ultra integrated Arc vs discrete Arc.
cases := []struct {
name string
want GPUKind
}{
{"AMD Radeon Graphics", GPUIntegrated},
{"AMD Radeon(TM) Graphics", GPUIntegrated},
{"AMD Radeon(TM) Vega 8 Graphics", GPUIntegrated},
{"AMD Radeon 780M Graphics", GPUIntegrated},
{"AMD Radeon RX 7900 XTX", GPUDiscrete},
{"Intel(R) Arc(TM) Graphics", GPUIntegrated},
{"Intel(R) Arc(TM) 140V GPU", GPUIntegrated},
{"Intel(R) Arc(TM) A770 Graphics", GPUDiscrete},
{"Intel(R) Arc(TM) B580 Graphics", GPUDiscrete},
{"Microsoft Remote Display Adapter", GPUVirtual},
}
for _, tc := range cases {
if got := ClassifyGPU(tc.name); got != tc.want {
t.Errorf("ClassifyGPU(%q) = %s, want %s", tc.name, got, tc.want)
}
}
}
func TestGPUCompatibilityGradingAndRecommendation(t *testing.T) {
allReqExts := map[string]bool{
"VK_KHR_swapchain": true,
"VK_EXT_robustness2": true,
"VK_EXT_calibrated_timestamps": true,
"VK_EXT_line_rasterization": true,
}
v13 := uint32((1 << 22) | (3 << 12) | 289)
v12 := uint32((1 << 22) | (2 << 12) | 195)
if ven, dev := ParsePCIIDs(`PCI\VEN_1002&DEV_164C&SUBSYS_380117AA`); ven != "1002" || dev != "164c" {
t.Fatalf("ParsePCIIDs = (%q, %q), want (1002, 164c)", ven, dev)
}
if got := FormatVulkanVersion(v13); got != "1.3.289" {
t.Fatalf("FormatVulkanVersion = %q, want 1.3.289", got)
}
// 1. AMD Ryzen 5 5500U (Lucienne Vega 7, 1002:164c) -> warn (#181)
vega7 := EvaluateGPUCompat(
GPUInfo{Name: "AMD Radeon Graphics", VulkanICD: `C:\amd-vulkan64.json`, VendorID: "1002", DeviceID: "164c"},
&VulkanDeviceProbe{Name: "AMD Radeon(TM) Graphics", VendorID: 0x1002, DeviceID: 0x164c, DeviceType: 1, APIVersion: v13, Extensions: allReqExts},
)
if vega7.Kind != GPUIntegrated || vega7.Compat != GPUCompatWarn || vega7.CompatCode != "amd_legacy_win_driver" {
t.Fatalf("vega7 = %+v", vega7)
}
// 2. AMD RX 6600 XT (1002:73ff) -> warn (#173)
rx6600 := EvaluateGPUCompat(
GPUInfo{Name: "AMD Radeon RX 6600 XT", VulkanICD: `C:\amd-vulkan64.json`, VendorID: "1002", DeviceID: "73ff"},
&VulkanDeviceProbe{Name: "AMD Radeon RX 6600 XT", VendorID: 0x1002, DeviceID: 0x73ff, DeviceType: 2, APIVersion: v13, Extensions: allReqExts},
)
if rx6600.Compat != GPUCompatWarn || rx6600.CompatCode != "amd_rdna2_device_lost" {
t.Fatalf("rx6600 = %+v", rx6600)
}
// 3. AMD Radeon 780M (RDNA 3, 1002:15bf) -> supported
rdna3 := EvaluateGPUCompat(
GPUInfo{Name: "AMD Radeon 780M Graphics", VulkanICD: `C:\amd-vulkan64.json`, VendorID: "1002", DeviceID: "15bf"},
&VulkanDeviceProbe{Name: "AMD Radeon 780M Graphics", VendorID: 0x1002, DeviceID: 0x15bf, DeviceType: 1, APIVersion: v13, Extensions: allReqExts},
)
if rdna3.Compat != GPUCompatSupported || rdna3.Kind != GPUIntegrated {
t.Fatalf("rdna3 = %+v", rdna3)
}
// 4. Old Vulkan 1.2 GPU -> unsupported
oldVK := EvaluateGPUCompat(
GPUInfo{Name: "Old GPU", VulkanICD: `C:\old.json`, Kind: GPUDiscrete},
&VulkanDeviceProbe{Name: "Old GPU", VendorID: 0x10de, DeviceID: 0x1180, DeviceType: 2, APIVersion: v12, Extensions: allReqExts},
)
if oldVK.Compat != GPUCompatUnsupported || oldVK.CompatCode != "vulkan_too_old" {
t.Fatalf("oldVK = %+v", oldVK)
}
// 5. Missing required extension -> unsupported
noRob2 := EvaluateGPUCompat(
GPUInfo{Name: "Partial GPU", VulkanICD: `C:\p.json`, Kind: GPUIntegrated},
&VulkanDeviceProbe{Name: "Partial GPU", VendorID: 0x8086, DeviceID: 0x5912, DeviceType: 1, APIVersion: v13, Extensions: map[string]bool{"VK_KHR_swapchain": true}},
)
if noRob2.Compat != GPUCompatUnsupported || noRob2.CompatCode != "vulkan_missing_extensions" {
t.Fatalf("noRob2 = %+v", noRob2)
}
// 6. PickRecommendedGPU skips unsupported discrete GPU and picks supported iGPU.
rec := PickRecommendedGPU([]GPUInfo{oldVK, rdna3})
if rec == nil || rec.DeviceID != "15bf" {
t.Fatalf("PickRecommendedGPU(oldVK, rdna3) = %+v, want 15bf", rec)
}
// 7. PickRecommendedGPU skips unsupported completely -> nil.
if recNone := PickRecommendedGPU([]GPUInfo{oldVK, noRob2}); recNone != nil {
t.Fatalf("expected nil when all GPUs unsupported, got %+v", recNone)
}
// 8. PickRecommendedGPU prefers supported discrete over warned Vega iGPU.
rtx := EvaluateGPUCompat(
GPUInfo{Name: "NVIDIA GeForce RTX 3060", VulkanICD: `C:\nv-vk64.json`, VendorID: "10de", DeviceID: "2504"},
&VulkanDeviceProbe{Name: "NVIDIA GeForce RTX 3060", VendorID: 0x10de, DeviceID: 0x2504, DeviceType: 2, APIVersion: v13, Extensions: allReqExts},
)
recDual := PickRecommendedGPU([]GPUInfo{vega7, rtx})
if recDual == nil || recDual.VendorID != "10de" {
t.Fatalf("PickRecommendedGPU(vega7, rtx) = %+v, want 10de", recDual)
}
// 9. MergeRegistryAndVulkanGPUs matches by PCI ID and appends Vulkan-only GPUs.
merged := MergeRegistryAndVulkanGPUs(
[]GPUInfo{{Name: "AMD Radeon Graphics", VulkanICD: `C:\amd-vulkan64.json`, VendorID: "1002", DeviceID: "164c", DriverVersion: "31.0.21924.61"}},
[]VulkanDeviceProbe{
{Name: "AMD Radeon(TM) Graphics", VendorID: 0x1002, DeviceID: 0x164c, DeviceType: 1, APIVersion: v13, Extensions: allReqExts},
{Name: "NVIDIA GeForce RTX 3060", VendorID: 0x10de, DeviceID: 0x2504, DeviceType: 2, APIVersion: v13, Extensions: allReqExts},
},
)
if len(merged) != 2 || merged[0].Compat != GPUCompatWarn || merged[1].Compat != GPUCompatSupported {
t.Fatalf("merged = %+v", merged)
}
// 10. MergeRegistryAndVulkanGPUs never cross-matches distinct PCI IDs by generic name,
// while still matching uppercase PCI IDs and falling back to name when PCI IDs are absent.
noCross := MergeRegistryAndVulkanGPUs(
[]GPUInfo{
{Name: "AMD Radeon(TM) Graphics", VulkanICD: `C:\old-amd.json`, VendorID: "1002", DeviceID: "164e"},
{Name: "NVIDIA GeForce RTX 3060", VulkanICD: `C:\nv-vk64.json`, VendorID: "10DE", DeviceID: "2504"},
{Name: "Intel(R) UHD Graphics 770", VulkanICD: `C:\igvk64.json`},
},
[]VulkanDeviceProbe{
{Name: "AMD Radeon(TM) Graphics", VendorID: 0x1002, DeviceID: 0x13c0, DeviceType: 1, APIVersion: v13, Extensions: allReqExts},
{Name: "NVIDIA GeForce RTX 3060", VendorID: 0x10de, DeviceID: 0x2504, DeviceType: 2, APIVersion: v13, Extensions: allReqExts},
{Name: "Intel(R) UHD Graphics 770", VendorID: 0x8086, DeviceID: 0x4680, DeviceType: 1, APIVersion: v13, Extensions: allReqExts},
},
)
if len(noCross) != 4 {
t.Fatalf("expected 4 GPUs (unmatched 164e + matched 2504 + name-matched 4680 + vulkan-only 13c0), got %+v", noCross)
}
if noCross[0].DeviceID != "164e" || noCross[0].Compat != GPUCompatUnknown || noCross[0].VulkanVersion != "" {
t.Fatalf("164e must not cross-match 13c0 probe: %+v", noCross[0])
}
if noCross[1].DeviceID != "2504" || noCross[1].Compat != GPUCompatSupported {
t.Fatalf("uppercase PCI ID should match 2504 probe: %+v", noCross[1])
}
if noCross[2].DeviceID != "4680" || noCross[2].Compat != GPUCompatSupported {
t.Fatalf("missing PCI ID should fall back to name match: %+v", noCross[2])
}
if noCross[3].DeviceID != "13c0" || noCross[3].Compat != GPUCompatSupported || noCross[3].VulkanICD != "" {
t.Fatalf("13c0 probe should remain separate with no stale ICD: %+v", noCross[3])
}
// 11. Duplicate Vulkan ICD enumerations for the same physical GPU are deduplicated,
// preferring the highest Vulkan version while preserving real multi-GPU setups.
v14 := uint32((1 << 22) | (4 << 12) | 303)
deduped := MergeRegistryAndVulkanGPUs(
[]GPUInfo{
{Name: "NVIDIA GeForce RTX 5070 Laptop GPU", VulkanICD: `C:\nv-vk64.json`, VendorID: "10de", DeviceID: "2d18", DriverVersion: "32.0.15.9174"},
{Name: "Intel(R) Arc(TM) 140T GPU (16GB)", VulkanICD: `C:\igvk64.json`, VendorID: "8086", DeviceID: "7d51", DriverVersion: "32.0.101.6554"},
},
[]VulkanDeviceProbe{
{Name: "NVIDIA GeForce RTX 5070 Laptop GPU", VendorID: 0x10de, DeviceID: 0x2d18, DeviceType: 2, APIVersion: v14, Extensions: allReqExts},
{Name: "Intel(R) Arc(TM) 140T GPU (16GB)", VendorID: 0x8086, DeviceID: 0x7d51, DeviceType: 1, APIVersion: v13, Extensions: allReqExts},
{Name: "Intel(R) Arc(TM) 140T GPU (16GB)", VendorID: 0x8086, DeviceID: 0x7d51, DeviceType: 1, APIVersion: v14, Extensions: allReqExts},
{Name: "Intel(R) Arc(TM) 140T GPU (16GB)", VendorID: 0x8086, DeviceID: 0x7d51, DeviceType: 1, APIVersion: v14, Extensions: allReqExts},
{Name: "Intel(R) Arc(TM) 140T GPU (16GB)", VendorID: 0x8086, DeviceID: 0x7d51, DeviceType: 1, APIVersion: v14, Extensions: allReqExts},
{Name: "Intel(R) Arc(TM) 140T GPU (16GB)", VendorID: 0x8086, DeviceID: 0x7d51, DeviceType: 1, APIVersion: v14, Extensions: allReqExts},
// Duplicate Vulkan-only GPU should also appear only once.
{Name: "AMD Radeon RX 7900 XTX", VendorID: 0x1002, DeviceID: 0x744c, DeviceType: 2, APIVersion: v13, Extensions: allReqExts},
{Name: "AMD Radeon RX 7900 XTX", VendorID: 0x1002, DeviceID: 0x744c, DeviceType: 2, APIVersion: v14, Extensions: allReqExts},
},
)
if len(deduped) != 3 {
t.Fatalf("expected 3 deduplicated GPUs, got %d: %+v", len(deduped), deduped)
}
if deduped[1].DriverVersion != "32.0.101.6554" || deduped[1].VulkanVersion != "1.4.303" {
t.Fatalf("expected Intel GPU to keep driver version and best Vulkan version, got %+v", deduped[1])
}
if deduped[2].DeviceID != "744c" || deduped[2].VulkanVersion != "1.4.303" {
t.Fatalf("expected Vulkan-only duplicate to pick best version, got %+v", deduped[2])
}
// Real dual identical discrete GPUs (two distinct registry adapters) must both remain.
dualIdentical := MergeRegistryAndVulkanGPUs(
[]GPUInfo{
{Name: "NVIDIA GeForce RTX 4090", VulkanICD: `C:\nv-vk64.json`, VendorID: "10de", DeviceID: "2684", DriverVersion: "32.0.15.9174"},
{Name: "NVIDIA GeForce RTX 4090", VulkanICD: `C:\nv-vk64.json`, VendorID: "10de", DeviceID: "2684", DriverVersion: "32.0.15.9174"},
},
[]VulkanDeviceProbe{
{Name: "NVIDIA GeForce RTX 4090", VendorID: 0x10de, DeviceID: 0x2684, DeviceType: 2, APIVersion: v14, Extensions: allReqExts},
{Name: "NVIDIA GeForce RTX 4090", VendorID: 0x10de, DeviceID: 0x2684, DeviceType: 2, APIVersion: v14, Extensions: allReqExts},
},
)
if len(dualIdentical) != 2 {
t.Fatalf("expected both physical identical GPUs to be kept, got %+v", dualIdentical)
}
// Dual identical GPUs with distinct DeviceLUIDs must stay separate even when
// only one (or neither) is in the display-class registry, while duplicate ICDs
// sharing the same DeviceLUID still collapse to one entry.
dualLUID := MergeRegistryAndVulkanGPUs(
[]GPUInfo{
{Name: "NVIDIA GeForce RTX 4090", VulkanICD: `C:\nv-vk64.json`, VendorID: "10de", DeviceID: "2684", DriverVersion: "32.0.15.9174"},
},
[]VulkanDeviceProbe{
{Name: "NVIDIA GeForce RTX 4090", VendorID: 0x10de, DeviceID: 0x2684, DeviceType: 2, APIVersion: v13, Extensions: allReqExts, DeviceLUID: "0000000000000001:1"},
{Name: "NVIDIA GeForce RTX 4090", VendorID: 0x10de, DeviceID: 0x2684, DeviceType: 2, APIVersion: v14, Extensions: allReqExts, DeviceLUID: "0000000000000001:1"},
{Name: "NVIDIA GeForce RTX 4090", VendorID: 0x10de, DeviceID: 0x2684, DeviceType: 2, APIVersion: v13, Extensions: allReqExts, DeviceLUID: "0000000000000002:1"},
{Name: "NVIDIA GeForce RTX 4090", VendorID: 0x10de, DeviceID: 0x2684, DeviceType: 2, APIVersion: v14, Extensions: allReqExts, DeviceLUID: "0000000000000002:1"},
},
)
if len(dualLUID) != 2 {
t.Fatalf("expected 2 distinct physical RTX 4090s with LUIDs, got %d: %+v", len(dualLUID), dualLUID)
}
if dualLUID[0].VulkanVersion != "1.4.303" || dualLUID[1].VulkanVersion != "1.4.303" {
t.Fatalf("expected both LUID-distinct GPUs to pick best Vulkan version, got %+v", dualLUID)
}
// Repeated integrated GPU probes (e.g. Intel Arc 140T enumerated 5x with identical
// DeviceUUID or distinct adapter LUIDs) must collapse to one entry whether or not
// the iGPU was also present in the display-class registry.
const intelUUID = "8680517d030000000002000000000000"
intelDupes := []VulkanDeviceProbe{
{Name: "NVIDIA GeForce RTX 5070 Laptop GPU", VendorID: 0x10de, DeviceID: 0x2d18, DeviceType: 2, APIVersion: v14, Extensions: allReqExts, DeviceUUID: "e666906384a109aef5e564050a6038c8", DeviceLUID: "0000000000000010:1"},
{Name: "Intel(R) Arc(TM) 140T GPU (16GB)", VendorID: 0x8086, DeviceID: 0x7d51, DeviceType: 1, APIVersion: v13, Extensions: allReqExts, DeviceUUID: intelUUID, DeviceLUID: "0000000000000021:1"},
{Name: "Intel(R) Arc(TM) 140T GPU (16GB)", VendorID: 0x8086, DeviceID: 0x7d51, DeviceType: 1, APIVersion: v14, Extensions: allReqExts, DeviceUUID: intelUUID, DeviceLUID: "0000000000000022:1"},
{Name: "Intel(R) Arc(TM) 140T GPU (16GB)", VendorID: 0x8086, DeviceID: 0x7d51, DeviceType: 1, APIVersion: v14, Extensions: allReqExts, DeviceUUID: intelUUID, DeviceLUID: "0000000000000023:1"},
{Name: "Intel(R) Arc(TM) 140T GPU (16GB)", VendorID: 0x8086, DeviceID: 0x7d51, DeviceType: 1, APIVersion: v14, Extensions: allReqExts, DeviceUUID: intelUUID, DeviceLUID: "0000000000000024:1"},
{Name: "Intel(R) Arc(TM) 140T GPU (16GB)", VendorID: 0x8086, DeviceID: 0x7d51, DeviceType: 1, APIVersion: v14, Extensions: allReqExts, DeviceUUID: intelUUID, DeviceLUID: "0000000000000025:1"},
}
withReg := MergeRegistryAndVulkanGPUs(
[]GPUInfo{
{Name: "NVIDIA GeForce RTX 5070 Laptop GPU", VulkanICD: `C:\nv-vk64.json`, VendorID: "10de", DeviceID: "2d18", DriverVersion: "32.0.15.9174"},
{Name: "Intel(R) Arc(TM) 140T GPU (16GB)", VulkanICD: `C:\igvk64.json`, VendorID: "8086", DeviceID: "7d51", DriverVersion: "32.0.101.6554"},
},
intelDupes,
)
if len(withReg) != 2 {
t.Fatalf("expected 2 GPUs when iGPU has identical DeviceUUID / distinct LUIDs (with registry), got %d: %+v", len(withReg), withReg)
}
if withReg[1].VulkanVersion != "1.4.303" {
t.Fatalf("expected Intel iGPU to pick best Vulkan version, got %+v", withReg[1])
}
vkOnly := MergeRegistryAndVulkanGPUs(nil, intelDupes)
if len(vkOnly) != 2 {
t.Fatalf("expected 2 GPUs when iGPU has identical DeviceUUID / distinct LUIDs (Vulkan-only), got %d: %+v", len(vkOnly), vkOnly)
}
// Mixed LUID (one probe reports LUID, duplicate omits it) and discrete GPU sharing
// DeviceUUID across distinct LUIDs must both collapse to one entry.
mixedDupes := MergeRegistryAndVulkanGPUs(
nil,
[]VulkanDeviceProbe{
{Name: "AMD Radeon RX 7900 XTX", VendorID: 0x1002, DeviceID: 0x744c, DeviceType: 2, APIVersion: v13, Extensions: allReqExts, DeviceLUID: "0000000000000031:1"},
{Name: "AMD Radeon RX 7900 XTX", VendorID: 0x1002, DeviceID: 0x744c, DeviceType: 2, APIVersion: v14, Extensions: allReqExts},
{Name: "NVIDIA GeForce RTX 5080", VendorID: 0x10de, DeviceID: 0x2c02, DeviceType: 2, APIVersion: v13, Extensions: allReqExts, DeviceUUID: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", DeviceLUID: "0000000000000041:1"},
{Name: "NVIDIA GeForce RTX 5080", VendorID: 0x10de, DeviceID: 0x2c02, DeviceType: 2, APIVersion: v14, Extensions: allReqExts, DeviceUUID: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", DeviceLUID: "0000000000000042:1"},
},
)
if len(mixedDupes) != 2 {
t.Fatalf("expected 2 deduplicated discrete GPUs, got %d: %+v", len(mixedDupes), mixedDupes)
}
if mixedDupes[0].VulkanVersion != "1.4.303" || mixedDupes[1].VulkanVersion != "1.4.303" {
t.Fatalf("expected deduplicated discrete GPUs to pick best Vulkan version, got %+v", mixedDupes)
}
}
func TestAffinityMaskHelpers(t *testing.T) {
if got := AllCPUsMask(8); got != 0xFF {
t.Fatalf("AllCPUsMask(8) = 0x%X, want 0xFF", got)
}
if got := AllCPUsMask(64); got != ^uint64(0) {
t.Fatalf("AllCPUsMask(64) = 0x%X, want all-ones", got)
}
mask, cpus := CPUsToMask([]int{4, 1, 4, -1, 16}, 16)
if mask != 0x12 || len(cpus) != 2 || cpus[0] != 1 || cpus[1] != 4 {
t.Fatalf("CPUsToMask = (0x%X, %v), want (0x12, [1 4])", mask, cpus)
}
}