github.com/jaypipes/ghw@v0.21.1/pkg/cpu/cpu_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 cpu_test 8 9 import ( 10 "os" 11 "testing" 12 13 "github.com/jaypipes/ghw/pkg/cpu" 14 ) 15 16 // nolint: gocyclo 17 func TestCPU(t *testing.T) { 18 if _, ok := os.LookupEnv("GHW_TESTING_SKIP_CPU"); ok { 19 t.Skip("Skipping CPU tests.") 20 } 21 22 info, err := cpu.New() 23 24 if err != nil { 25 t.Fatalf("Expected nil err, but got %v", err) 26 } 27 if info == nil { 28 t.Fatalf("Expected non-nil CPUInfo, but got nil") 29 } 30 31 if len(info.Processors) == 0 { 32 t.Fatalf("Expected >0 processors but got 0.") 33 } 34 35 for _, p := range info.Processors { 36 if p.TotalCores == 0 { 37 t.Fatalf("Expected >0 cores but got 0.") 38 } 39 if p.TotalHardwareThreads == 0 { 40 t.Fatalf("Expected >0 threads but got 0.") 41 } 42 if len(p.Capabilities) == 0 { 43 t.Fatalf("Expected >0 capabilities but got 0.") 44 } 45 if !p.HasCapability(p.Capabilities[0]) { 46 t.Fatalf("Expected p to have capability %s, but did not.", 47 p.Capabilities[0]) 48 } 49 if len(p.Cores) == 0 { 50 t.Fatalf("Expected >0 cores in processor, but got 0.") 51 } 52 for _, c := range p.Cores { 53 if c.TotalHardwareThreads == 0 { 54 t.Fatalf("Expected >0 threads but got 0.") 55 } 56 if len(c.LogicalProcessors) == 0 { 57 t.Fatalf("Expected >0 logical processors but got 0.") 58 } 59 } 60 } 61 }