github.com/jaypipes/ghw@v0.21.1/pkg/topology/topology_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 topology_test 8 9 import ( 10 "os" 11 "testing" 12 13 "github.com/jaypipes/ghw/pkg/topology" 14 ) 15 16 // nolint: gocyclo 17 func TestTopology(t *testing.T) { 18 if _, ok := os.LookupEnv("GHW_TESTING_SKIP_TOPOLOGY"); ok { 19 t.Skip("Skipping topology tests.") 20 } 21 22 info, err := topology.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 TopologyInfo, but got nil") 29 } 30 31 if len(info.Nodes) == 0 { 32 t.Fatalf("Expected >0 nodes but got 0.") 33 } 34 35 if info.Architecture == topology.ArchitectureNUMA && len(info.Nodes) == 1 { 36 t.Fatalf("Got NUMA architecture but only 1 node.") 37 } 38 39 for _, n := range info.Nodes { 40 if len(n.Cores) == 0 { 41 t.Fatalf("Expected >0 cores but got 0.") 42 } 43 for _, c := range n.Cores { 44 if len(c.LogicalProcessors) == 0 { 45 t.Fatalf("Expected >0 logical processors but got 0.") 46 } 47 if uint32(len(c.LogicalProcessors)) != c.TotalHardwareThreads { 48 t.Fatalf( 49 "Expected TotalHardwareThreads == len(logical procs) but %d != %d", 50 c.TotalHardwareThreads, 51 len(c.LogicalProcessors), 52 ) 53 } 54 } 55 if len(n.Caches) == 0 { 56 t.Fatalf("Expected >0 caches but got 0.") 57 } 58 } 59 }