package platform import ( "strings" "testing" ) func TestClassifyGPUFromVendorClass(t *testing.T) { cases := []struct { name string vendor string class string wantIsGPU bool wantVendor string }{ {"nvidia GPU", "0x10de", "0x030200", true, "nvidia"}, {"amd GPU", "0x1002", "0x030000", true, "amd"}, {"nvidia NIC (same vendor, not display class)", "0x10de", "0x020000", false, ""}, {"intel NIC", "0x8086", "0x020000", false, ""}, {"unrelated display-class vendor", "0x1234", "0x030000", false, ""}, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { gotIsGPU, gotVendor := classifyGPUFromVendorClass(tc.vendor, tc.class) if gotIsGPU != tc.wantIsGPU || gotVendor != tc.wantVendor { t.Fatalf("classifyGPUFromVendorClass(%q,%q) = (%v,%q), want (%v,%q)", tc.vendor, tc.class, gotIsGPU, gotVendor, tc.wantIsGPU, tc.wantVendor) } }) } } func TestRenderPCIeLinkCheckSummaryDegradedGPU(t *testing.T) { findings := []pcieLinkFinding{ {BDF: "0000:0d:00.0", Description: "NVIDIA GPU", IsGPU: true, GPUVendor: "nvidia", BeforeSpeed: "Gen1", AfterSpeed: "Gen1", MaxSpeed: "Gen5", Degraded: true}, {BDF: "0000:37:00.0", Description: "NVIDIA GPU", IsGPU: true, GPUVendor: "nvidia", BeforeSpeed: "Gen1", AfterSpeed: "Gen5", MaxSpeed: "Gen5", Degraded: false}, {BDF: "0000:01:00.0", Description: "Mellanox NIC", IsGPU: false, BeforeSpeed: "Gen3", AfterSpeed: "Gen4", MaxSpeed: "Gen4", Degraded: false}, } summary := renderPCIeLinkCheckSummary(findings) if !strings.Contains(summary, "gpu_nvidia_status=FAILED") { t.Fatalf("expected gpu_nvidia_status=FAILED (one degraded GPU should fail the vendor group), got:\n%s", summary) } if !strings.Contains(summary, "other_status=OK") { t.Fatalf("expected other_status=OK, got:\n%s", summary) } if !strings.Contains(summary, "overall_status=FAILED") { t.Fatalf("expected overall_status=FAILED, got:\n%s", summary) } } func TestRenderPCIeLinkCheckSummaryAllClean(t *testing.T) { findings := []pcieLinkFinding{ {BDF: "0000:0d:00.0", IsGPU: true, GPUVendor: "nvidia", BeforeSpeed: "Gen1", AfterSpeed: "Gen5", MaxSpeed: "Gen5"}, {BDF: "0000:2c:00.0", Skipped: "device disabled (no data traffic; link state has no operational impact)"}, } summary := renderPCIeLinkCheckSummary(findings) if !strings.Contains(summary, "overall_status=OK") { t.Fatalf("expected overall_status=OK, got:\n%s", summary) } if strings.Contains(summary, "other_status=") { t.Fatalf("disabled/skipped-only device should not produce an other_status line, got:\n%s", summary) } }