MCPcopy Create free account
hub / github.com/prometheus/procfs / TestKernelTainted

Function TestKernelTainted

kernel_tainted_test.go:22–67  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

20)
21
22func TestKernelTainted(t *testing.T) {
23 fs, err := NewFS(procfsFixtures)
24 if err != nil {
25 t.Fatalf("failed to access %s: %v", procfsFixtures, err)
26 }
27
28 tainted, err := fs.KernelTainted()
29 if err != nil {
30 t.Fatalf("failed to collect %s/sys/kernel/tainted: %v", procfsFixtures, err)
31 }
32
33 // Fixture value is 12288 = bit 12 (O) + bit 13 (E).
34 if tainted.Value != 12288 {
35 t.Errorf("tainted value: want %d, got %d", 12288, tainted.Value)
36 }
37
38 const wantBits = 20
39 if len(tainted.Bits) != wantBits {
40 t.Fatalf("tainted bits length: want %d, got %d", wantBits, len(tainted.Bits))
41 }
42
43 for _, tc := range []struct {
44 index int
45 flag string
46 set bool
47 }{
48 {0, "P", false},
49 {12, "O", true}, // Externally-built (out-of-tree) module
50 {13, "E", true}, // Unsigned module
51 {14, "L", false}, // Soft lockup — must be clear
52 {17, "T", false},
53 {18, "N", false},
54 {19, "J", false},
55 } {
56 b := tainted.Bits[tc.index]
57 if b.Index != tc.index {
58 t.Errorf("bit[%d].Index: want %d, got %d", tc.index, tc.index, b.Index)
59 }
60 if b.Flag != tc.flag {
61 t.Errorf("bit[%d].Flag: want %q, got %q", tc.index, tc.flag, b.Flag)
62 }
63 if b.Set != tc.set {
64 t.Errorf("bit[%d] (%s): want Set=%v, got Set=%v", tc.index, tc.flag, tc.set, b.Set)
65 }
66 }
67}
68
69func TestParseTainted(t *testing.T) {
70 // Test parsing directly without filesystem access.

Callers

nothing calls this directly

Calls 2

KernelTaintedMethod · 0.95
NewFSFunction · 0.70

Tested by

no test coverage detected