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) } } 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) } }