78 lines
2.4 KiB
Go
78 lines
2.4 KiB
Go
package platform
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestPCIeLinkSummaryAcceptsIdleGen1WhenLinkReachesMaximumUnderLoad(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "summary.txt")
|
|
if err := os.WriteFile(path, []byte("overall_status=OK\n"), 0644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
findings := []nvidiaPCIeBandwidthFinding{{
|
|
Index: 0, BDF: "0000:05:00.0", BeforeSpeed: "Gen1", AfterSpeed: "Gen5",
|
|
MaxSpeed: "Gen5", Width: 16, MaxWidth: 16, Supported: true, Sampled: true,
|
|
}}
|
|
|
|
if err := appendNvidiaPCIeLinkSummary(path, findings); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
raw, err := os.ReadFile(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got := string(raw)
|
|
if !strings.Contains(got, "overall_status=OK\n") || !strings.Contains(got, "pcie_link_under_load_status=OK\n") {
|
|
t.Fatalf("summary did not accept a link that rose from idle Gen1 to maximum under load:\n%s", got)
|
|
}
|
|
}
|
|
|
|
func TestPCIeLinkSummaryFailsLinkStillBelowMaximumAfterLoad(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "summary.txt")
|
|
if err := os.WriteFile(path, []byte("overall_status=UNSUPPORTED\n"), 0644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
findings := []nvidiaPCIeBandwidthFinding{{
|
|
Index: 0, BDF: "0000:05:00.0", BeforeSpeed: "Gen1", AfterSpeed: "Gen1",
|
|
MaxSpeed: "Gen5", Width: 16, MaxWidth: 16, Supported: true, Sampled: true, Degraded: true,
|
|
}}
|
|
|
|
if err := appendNvidiaPCIeLinkSummary(path, findings); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
raw, err := os.ReadFile(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got := string(raw)
|
|
if !strings.Contains(got, "overall_status=FAILED\n") || !strings.Contains(got, "pcie_link_under_load_status=FAILED\n") {
|
|
t.Fatalf("summary did not fail a link that stayed degraded under load:\n%s", got)
|
|
}
|
|
}
|
|
|
|
func TestPCIeLinkSummaryIsUnsupportedWhenLoadNeverRan(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "summary.txt")
|
|
if err := os.WriteFile(path, []byte("overall_status=FAILED\n"), 0644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
findings := []nvidiaPCIeBandwidthFinding{{
|
|
Index: 0, BDF: "0000:05:00.0", BeforeSpeed: "Gen1", MaxSpeed: "Gen5",
|
|
MaxWidth: 16, Supported: true,
|
|
}}
|
|
|
|
if err := appendNvidiaPCIeLinkSummary(path, findings); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
raw, err := os.ReadFile(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got := string(raw)
|
|
if !strings.Contains(got, "pcie_link_under_load_status=UNSUPPORTED\n") {
|
|
t.Fatalf("summary claimed a link verdict although the load callback never ran:\n%s", got)
|
|
}
|
|
}
|