61 lines
1.8 KiB
Go
61 lines
1.8 KiB
Go
package collector
|
|
|
|
import "testing"
|
|
|
|
func TestDmesgSeverity_xidCodes(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
msg string
|
|
want string
|
|
}{
|
|
{
|
|
name: "xid 64 remap write failure escalates to critical",
|
|
msg: "NVRM: Xid (PCI:0000:65:00): 64, pid=1234, name=python",
|
|
want: statusCritical,
|
|
},
|
|
{
|
|
name: "xid 94 contained ecc is downgraded to warning",
|
|
msg: "NVRM: Xid (PCI:0000:65:00): 94, pid=1234, name=python",
|
|
want: statusWarning,
|
|
},
|
|
{
|
|
name: "xid 63 remap committed is downgraded to warning",
|
|
msg: "NVRM: Xid (PCI:0000:65:00): 63, pid=1234, Class 0x90a0",
|
|
want: statusWarning,
|
|
},
|
|
{
|
|
name: "unrecognized xid code falls back to generic critical",
|
|
msg: "NVRM: Xid (PCI:0000:65:00): 79, pid=1234, GPU has fallen off the bus",
|
|
want: statusCritical,
|
|
},
|
|
{
|
|
name: "non-xid generic error keyword",
|
|
msg: "blk_update_request: I/O error, dev sda",
|
|
want: statusCritical,
|
|
},
|
|
{
|
|
name: "disabled by default is not a fault substring match",
|
|
msg: "Yama: disabled by default; enable with sysctl kernel.yama.*",
|
|
want: statusWarning,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := dmesgSeverity(tt.msg)
|
|
if got != tt.want {
|
|
t.Fatalf("dmesgSeverity(%q) = %q, want %q", tt.msg, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseDmesgErrorsSkipsKnownBootNoise(t *testing.T) {
|
|
entries := parseDmesgErrors("[Thu Aug 25 10:00:00 2026] pci 0000:00:02.0: bridge window [mem 0x0000-0x0000] to [bus 01-ff] failed to assign\n" +
|
|
"[Thu Aug 25 10:00:01 2026] NVRM: loading NVIDIA UNIX Open Kernel Module for x86_64\n" +
|
|
"[Thu Aug 25 10:00:02 2026] blk_update_request: I/O error, dev sda\n")
|
|
if len(entries) != 1 || entries[0].Severity == nil || *entries[0].Severity != statusCritical {
|
|
t.Fatalf("entries=%#v, want one critical real error", entries)
|
|
}
|
|
}
|