forked from prometheus/procfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpuinfo_test.go
202 lines (176 loc) · 6.19 KB
/
cpuinfo_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
// Copyright 2019 The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// +build linux
package procfs
import "testing"
const (
cpuinfoArm7 = `
Processor : ARMv7 Processor rev 5 (v7l)
processor : 0
BogoMIPS : 2400.00
processor : 1
BogoMIPS : 2400.00
Features : swp half thumb fastmult vfp edsp thumbee neon vfpv3 tls vfpv4 idiva idivt
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xc07
CPU revision : 5
Hardware : sun8i
Revision : 0000
Serial : 5400503583203c3c040e`
cpuinfoS390x = `
vendor_id : IBM/S390
# processors : 4
bogomips per cpu: 3033.00
max thread id : 0
features : esan3 zarch stfle msa ldisp eimm dfp edat etf3eh highgprs te vx sie
facilities : 0 1 2 3 4 6 7 8 9 10 12 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 30 31 32 33 34 35 36 37 40 41 42 43 44 45 46 47 48 49 50 51 52 53 55 57 73 74 75 76 77 80 81 82 128 129 131
cache0 : level=1 type=Data scope=Private size=128K line_size=256 associativity=8
cache1 : level=1 type=Instruction scope=Private size=96K line_size=256 associativity=6
cache2 : level=2 type=Data scope=Private size=2048K line_size=256 associativity=8
cache3 : level=2 type=Instruction scope=Private size=2048K line_size=256 associativity=8
cache4 : level=3 type=Unified scope=Shared size=65536K line_size=256 associativity=16
cache5 : level=4 type=Unified scope=Shared size=491520K line_size=256 associativity=30
processor 0: version = FF, identification = 2733E8, machine = 2964
processor 1: version = FF, identification = 2733E8, machine = 2964
processor 2: version = FF, identification = 2733E8, machine = 2964
processor 3: version = FF, identification = 2733E8, machine = 2964
cpu number : 0
cpu MHz dynamic : 5000
cpu MHz static : 5000
cpu number : 1
cpu MHz dynamic : 5000
cpu MHz static : 5000
cpu number : 2
cpu MHz dynamic : 5000
cpu MHz static : 5000
cpu number : 3
cpu MHz dynamic : 5000
cpu MHz static : 5000
`
cpuinfoPpc64 = `
processor : 0
cpu : POWER7 (architected), altivec supported
clock : 3000.000000MHz
revision : 2.1 (pvr 003f 0201)
processor : 1
cpu : POWER7 (architected), altivec supported
clock : 3000.000000MHz
revision : 2.1 (pvr 003f 0201)
processor : 2
cpu : POWER7 (architected), altivec supported
clock : 3000.000000MHz
revision : 2.1 (pvr 003f 0201)
processor : 3
cpu : POWER7 (architected), altivec supported
clock : 3000.000000MHz
revision : 2.1 (pvr 003f 0201)
processor : 4
cpu : POWER7 (architected), altivec supported
clock : 3000.000000MHz
revision : 2.1 (pvr 003f 0201)
processor : 5
cpu : POWER7 (architected), altivec supported
clock : 3000.000000MHz
revision : 2.1 (pvr 003f 0201)
timebase : 512000000
platform : pSeries
model : IBM,8233-E8B
machine : CHRP IBM,8233-E8B
`
)
func TestCPUInfoX86(t *testing.T) {
cpuinfo, err := getProcFixtures(t).CPUInfo()
if err != nil {
t.Fatal(err)
}
if cpuinfo == nil {
t.Fatal("cpuinfo is nil")
}
if want, have := 8, len(cpuinfo); want != have {
t.Errorf("want number of processors %v, have %v", want, have)
}
if want, have := uint(7), cpuinfo[7].Processor; want != have {
t.Errorf("want processor %v, have %v", want, have)
}
if want, have := "GenuineIntel", cpuinfo[0].VendorID; want != have {
t.Errorf("want vendor %v, have %v", want, have)
}
if want, have := "6", cpuinfo[1].CPUFamily; want != have {
t.Errorf("want family %v, have %v", want, have)
}
if want, have := "142", cpuinfo[2].Model; want != have {
t.Errorf("want model %v, have %v", want, have)
}
if want, have := "Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz", cpuinfo[3].ModelName; want != have {
t.Errorf("want model %v, have %v", want, have)
}
if want, have := uint(8), cpuinfo[4].Siblings; want != have {
t.Errorf("want siblings %v, have %v", want, have)
}
if want, have := "1", cpuinfo[5].CoreID; want != have {
t.Errorf("want core id %v, have %v", want, have)
}
if want, have := uint(4), cpuinfo[6].CPUCores; want != have {
t.Errorf("want cpu cores %v, have %v", want, have)
}
if want, have := "vme", cpuinfo[7].Flags[1]; want != have {
t.Errorf("want flag %v, have %v", want, have)
}
}
func TestCPUInfoParseARM(t *testing.T) {
cpuinfo, err := parseCPUInfoARM([]byte(cpuinfoArm7))
if err != nil || cpuinfo == nil {
t.Fatalf("unable to parse arm cpu info: %v", err)
}
if want, have := 2, len(cpuinfo); want != have {
t.Errorf("want number of processors %v, have %v", want, have)
}
if want, have := "ARMv7 Processor rev 5 (v7l)", cpuinfo[0].VendorID; want != have {
t.Errorf("want vendor %v, have %v", want, have)
}
if want, have := "thumb", cpuinfo[1].Flags[2]; want != have {
t.Errorf("want flag %v, have %v", want, have)
}
}
func TestCPUInfoParseS390X(t *testing.T) {
cpuinfo, err := parseCPUInfoS390X([]byte(cpuinfoS390x))
if err != nil || cpuinfo == nil {
t.Fatalf("unable to parse s390x cpu info: %v", err)
}
if want, have := 4, len(cpuinfo); want != have {
t.Errorf("want number of processors %v, have %v", want, have)
}
if want, have := "IBM/S390", cpuinfo[0].VendorID; want != have {
t.Errorf("want vendor %v, have %v", want, have)
}
if want, have := "ldisp", cpuinfo[1].Flags[4]; want != have {
t.Errorf("want flag %v, have %v", want, have)
}
if want, have := 5000.0, cpuinfo[2].CPUMHz; want != have {
t.Errorf("want cpu MHz %v, have %v", want, have)
}
}
func TestCPUInfoParsePPC(t *testing.T) {
cpuinfo, err := parseCPUInfoPPC([]byte(cpuinfoPpc64))
if err != nil || cpuinfo == nil {
t.Fatalf("unable to parse ppc cpu info: %v", err)
}
if want, have := 6, len(cpuinfo); want != have {
t.Errorf("want number of processors %v, have %v", want, have)
}
if want, have := 3000.00, cpuinfo[2].CPUMHz; want != have {
t.Errorf("want cpu mhz %v, have %v", want, have)
}
}