1
2
3
4
5
6
7
8
9
10
11
12
13
14 package procfs
15
16 import (
17 "reflect"
18 "testing"
19 )
20
21 func TestProcInterrupts(t *testing.T) {
22 p, err := getProcFixtures(t).Proc(26231)
23 if err != nil {
24 t.Fatal(err)
25 }
26
27 interrupts, err := p.Interrupts()
28 if err != nil {
29 t.Fatal(err)
30 }
31
32 if want, have := 47, len(interrupts); want != have {
33 t.Errorf("want length %d, have %d", want, have)
34 }
35
36 for _, test := range []struct {
37 name string
38 irq string
39 want Interrupt
40 }{
41 {
42 name: "first line",
43 irq: "0",
44 want: Interrupt{
45 Info: "IO-APIC",
46 Devices: "2-edge timer",
47 Values: []string{"49", "0", "0", "0"},
48 },
49 },
50 {
51 name: "last line",
52 irq: "PIW",
53 want: Interrupt{
54 Info: "Posted-interrupt wakeup event",
55 Devices: "",
56 Values: []string{"0", "0", "0", "0"},
57 },
58 },
59 {
60 name: "empty devices",
61 irq: "LOC",
62 want: Interrupt{
63 Info: "Local timer interrupts",
64 Devices: "",
65 Values: []string{"10196", "7429", "8542", "8229"},
66 },
67 },
68 {
69 name: "single value",
70 irq: "ERR",
71 want: Interrupt{
72 Info: "",
73 Devices: "",
74 Values: []string{"0"},
75 },
76 },
77 } {
78 t.Run(test.name, func(t *testing.T) {
79 if value, ok := interrupts[test.irq]; ok {
80 if value.Info != test.want.Info {
81 t.Errorf("info: want %s, have %s", test.want.Info, value.Info)
82 }
83 if value.Devices != test.want.Devices {
84 t.Errorf("devices: want %s, have %s", test.want.Devices, value.Devices)
85 }
86 if !reflect.DeepEqual(value.Values, test.want.Values) {
87 t.Errorf("values: want %v, have %v", test.want.Values, value.Values)
88 }
89 } else {
90 t.Errorf("IRQ %s not found", test.irq)
91 }
92 })
93 }
94 }
95
View as plain text