1
2
3
4
5
6
7
8
9
10
11
12
13
14 package procfs
15
16 import (
17 "testing"
18
19 "github.com/google/go-cmp/cmp"
20 )
21
22 func TestNetSoftnet(t *testing.T) {
23 fs, err := NewFS(procTestFixtures)
24 if err != nil {
25 t.Fatal(err)
26 }
27
28 want := []SoftnetStat{
29 {
30 Processed: 0x00358fe3,
31 Dropped: 0x00006283,
32 TimeSqueezed: 0x00000000,
33 CPUCollision: 0x00000000,
34 ReceivedRps: 0x000855fc,
35 FlowLimitCount: 0x00000076,
36 SoftnetBacklogLen: 0x00000000,
37 Index: 0x00000000,
38 Width: 13,
39 },
40 {
41 Processed: 0x00953d1a,
42 Dropped: 0x00000446,
43 TimeSqueezed: 0x000000b1,
44 CPUCollision: 0x00000000,
45 ReceivedRps: 0x008eeb9a,
46 FlowLimitCount: 0x0000002b,
47 SoftnetBacklogLen: 0x000000dc,
48 Index: 0x00000001,
49 Width: 13,
50 },
51 {
52 Processed: 0x00015c73,
53 Dropped: 0x00020e76,
54 TimeSqueezed: 0xf0000769,
55 CPUCollision: 0x00000004,
56 ReceivedRps: 0x00000003,
57 FlowLimitCount: 0x00000002,
58 Index: 0x00000002,
59 Width: 11,
60 },
61 {
62 Processed: 0x01663fb2,
63 Dropped: 0x00000000,
64 TimeSqueezed: 0x0109a4,
65 CPUCollision: 0x00020e76,
66 Index: 0x00000003,
67 Width: 9,
68 },
69 {
70 Processed: 0x00008e78,
71 Dropped: 0x00000001,
72 TimeSqueezed: 0x00000011,
73 CPUCollision: 0x00000020,
74 ReceivedRps: 0x00000010,
75 Index: 0x00000004,
76 Width: 10,
77 },
78 }
79
80 got, err := fs.NetSoftnetStat()
81 if err != nil {
82 t.Fatal(err)
83 }
84
85 if diff := cmp.Diff(want, got); diff != "" {
86 t.Fatalf("unexpected softnet stats(-want +got):\n%s", diff)
87 }
88 }
89
90 func TestBadSoftnet(t *testing.T) {
91 softNetProcFile = "net/softnet_stat.broken"
92 fs, err := NewFS(procTestFixtures)
93 if err != nil {
94 t.Fatal(err)
95 }
96
97 _, err = fs.NetSoftnetStat()
98 if err == nil {
99 t.Fatal("expected error, got nil")
100 }
101 }
102
View as plain text