-
Notifications
You must be signed in to change notification settings - Fork 182
/
host_test.go
89 lines (72 loc) · 1.87 KB
/
host_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
//
// Use and distribution licensed under the Apache license version 2.
//
// See the COPYING file in the root project directory for full text.
//
package ghw
import (
"os"
"testing"
)
// nolint: gocyclo
func TestHost(t *testing.T) {
if _, ok := os.LookupEnv("GHW_TESTING_SKIP_HOST"); ok {
t.Skip("Skipping host tests.")
}
host, err := Host()
if err != nil {
t.Fatalf("Expected nil error but got %v", err)
}
if host == nil {
t.Fatalf("Expected non-nil host but got nil.")
}
mem := host.Memory
if mem == nil {
t.Fatalf("Expected non-nil Memory but got nil.")
}
tpb := mem.TotalPhysicalBytes
if tpb < 1 {
t.Fatalf("Expected >0 total physical memory, but got %d", tpb)
}
tub := mem.TotalUsableBytes
if tub < 1 {
t.Fatalf("Expected >0 total usable memory, but got %d", tub)
}
cpu := host.CPU
if cpu == nil {
t.Fatalf("Expected non-nil CPU, but got nil")
}
cores := cpu.TotalCores
if cores < 1 {
t.Fatalf("Expected >0 total cores, but got %d", cores)
}
threads := cpu.TotalThreads
if threads < 1 {
t.Fatalf("Expected >0 total threads, but got %d", threads)
}
block := host.Block
if block == nil {
t.Fatalf("Expected non-nil Block but got nil.")
}
blockTpb := block.TotalPhysicalBytes
if blockTpb < 1 {
t.Fatalf("Expected >0 total physical block bytes, but got %d", blockTpb)
}
topology := host.Topology
if topology == nil {
t.Fatalf("Expected non-nil Topology but got nil.")
}
if len(topology.Nodes) < 1 {
t.Fatalf("Expected >0 nodes , but got %d", len(topology.Nodes))
}
gpu := host.GPU
if gpu == nil {
t.Fatalf("Expected non-nil GPU but got nil.")
}
// Processing accelerator cards are not common nowadays.
// You may not have one in your machine, so this check displays a message but does not interrupt the test.
accel := host.Accelerator
if accel == nil {
t.Logf("WARNING: Processing accelerator cards not detected.")
}
}