package platform import ( "errors" "os" "testing" ) func TestStorageSATCommands(t *testing.T) { t.Parallel() nvme := storageSATCommands("/dev/nvme0n1") if len(nvme) != 3 || nvme[2].cmd[0] != "nvme" { t.Fatalf("unexpected nvme commands: %#v", nvme) } sata := storageSATCommands("/dev/sda") if len(sata) != 2 || sata[0].cmd[0] != "smartctl" { t.Fatalf("unexpected sata commands: %#v", sata) } } func TestRunNvidiaAcceptancePackIncludesGPUStress(t *testing.T) { t.Parallel() jobs := nvidiaSATJobs() if len(jobs) != 5 { t.Fatalf("jobs=%d want 5", len(jobs)) } if got := jobs[4].cmd[0]; got != "bee-gpu-stress" { t.Fatalf("gpu stress command=%q want bee-gpu-stress", got) } if got := jobs[3].cmd[1]; got != "--output-file" { t.Fatalf("bug report flag=%q want --output-file", got) } } func TestNvidiaSATJobsUseEnvOverrides(t *testing.T) { t.Setenv("BEE_GPU_STRESS_SECONDS", "9") t.Setenv("BEE_GPU_STRESS_SIZE_MB", "96") jobs := nvidiaSATJobs() got := jobs[4].cmd want := []string{"bee-gpu-stress", "--seconds", "9", "--size-mb", "96"} if len(got) != len(want) { t.Fatalf("cmd len=%d want %d", len(got), len(want)) } for i := range want { if got[i] != want[i] { t.Fatalf("cmd[%d]=%q want %q", i, got[i], want[i]) } } } func TestEnvIntFallback(t *testing.T) { os.Unsetenv("BEE_MEMTESTER_SIZE_MB") if got := envInt("BEE_MEMTESTER_SIZE_MB", 123); got != 123 { t.Fatalf("got %d want 123", got) } t.Setenv("BEE_MEMTESTER_SIZE_MB", "bad") if got := envInt("BEE_MEMTESTER_SIZE_MB", 123); got != 123 { t.Fatalf("got %d want 123", got) } t.Setenv("BEE_MEMTESTER_SIZE_MB", "256") if got := envInt("BEE_MEMTESTER_SIZE_MB", 123); got != 256 { t.Fatalf("got %d want 256", got) } } func TestClassifySATResult(t *testing.T) { tests := []struct { name string job string out string err error status string }{ {name: "ok", job: "memtester", out: "done", err: nil, status: "OK"}, {name: "unsupported", job: "smartctl-self-test-short", out: "Self-test not supported", err: errors.New("rc 1"), status: "UNSUPPORTED"}, {name: "failed", job: "bee-gpu-stress", out: "cuda error", err: errors.New("rc 1"), status: "FAILED"}, {name: "cuda not ready", job: "bee-gpu-stress", out: "cuInit failed: CUDA_ERROR_SYSTEM_NOT_READY", err: errors.New("rc 1"), status: "UNSUPPORTED"}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got, _ := classifySATResult(tt.job, []byte(tt.out), tt.err) if got != tt.status { t.Fatalf("status=%q want %q", got, tt.status) } }) } }