github.com/jaypipes/ghw@v0.21.1/host_test.go (about) 1 // 2 // Use and distribution licensed under the Apache license version 2. 3 // 4 // See the COPYING file in the root project directory for full text. 5 // 6 7 package ghw 8 9 import ( 10 "os" 11 "testing" 12 ) 13 14 // nolint: gocyclo 15 func TestHost(t *testing.T) { 16 if _, ok := os.LookupEnv("GHW_TESTING_SKIP_HOST"); ok { 17 t.Skip("Skipping host tests.") 18 } 19 20 host, err := Host() 21 22 if err != nil { 23 t.Fatalf("Expected nil error but got %v", err) 24 } 25 if host == nil { 26 t.Fatalf("Expected non-nil host but got nil.") 27 } 28 29 mem := host.Memory 30 if mem == nil { 31 t.Fatalf("Expected non-nil Memory but got nil.") 32 } 33 34 tpb := mem.TotalPhysicalBytes 35 if tpb < 1 { 36 t.Fatalf("Expected >0 total physical memory, but got %d", tpb) 37 } 38 39 tub := mem.TotalUsableBytes 40 if tub < 1 { 41 t.Fatalf("Expected >0 total usable memory, but got %d", tub) 42 } 43 44 cpu := host.CPU 45 if cpu == nil { 46 t.Fatalf("Expected non-nil CPU, but got nil") 47 } 48 49 cores := cpu.TotalCores 50 if cores < 1 { 51 t.Fatalf("Expected >0 total cores, but got %d", cores) 52 } 53 54 threads := cpu.TotalThreads 55 if threads < 1 { 56 t.Fatalf("Expected >0 total threads, but got %d", threads) 57 } 58 59 block := host.Block 60 if block == nil { 61 t.Fatalf("Expected non-nil Block but got nil.") 62 } 63 64 blockTpb := block.TotalPhysicalBytes 65 if blockTpb < 1 { 66 t.Fatalf("Expected >0 total physical block bytes, but got %d", blockTpb) 67 } 68 69 topology := host.Topology 70 if topology == nil { 71 t.Fatalf("Expected non-nil Topology but got nil.") 72 } 73 74 if len(topology.Nodes) < 1 { 75 t.Fatalf("Expected >0 nodes , but got %d", len(topology.Nodes)) 76 } 77 78 gpu := host.GPU 79 if gpu == nil { 80 t.Fatalf("Expected non-nil GPU but got nil.") 81 } 82 83 // Processing accelerator cards are not common nowadays. 84 // You may not have one in your machine, so this check displays a message but does not interrupt the test. 85 accel := host.Accelerator 86 if accel == nil { 87 t.Logf("WARNING: Processing accelerator cards not detected.") 88 } 89 }