forked from jaypipes/ghw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpu_test.go
47 lines (42 loc) · 1019 Bytes
/
cpu_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
package ghw
import (
"testing"
)
func TestCPU(t *testing.T) {
info, err := CPU()
if err != nil {
t.Fatalf("Expected nil err, but got %v", err)
}
if info == nil {
t.Fatalf("Expected non-nil CPUInfo, but got nil")
}
if len(info.Processors) == 0 {
t.Fatalf("Expected >0 processors but got 0.")
}
for _, p := range info.Processors {
if p.NumCores == 0 {
t.Fatalf("Expected >0 cores but got 0.")
}
if p.NumThreads == 0 {
t.Fatalf("Expected >0 threads but got 0.")
}
if len(p.Capabilities) == 0 {
t.Fatalf("Expected >0 capabilities but got 0.")
}
if !p.HasCapability(p.Capabilities[0]) {
t.Fatalf("Expected p to have capability %s, but did not.",
p.Capabilities[0])
}
if len(p.Cores) == 0 {
t.Fatalf("Expected >0 cores in processor, but got 0.")
}
for _, c := range p.Cores {
if c.NumThreads == 0 {
t.Fatalf("Expected >0 threads but got 0.")
}
if len(c.LogicalProcessors) == 0 {
t.Fatalf("Expected >0 logical processors but got 0.")
}
}
}
}