github.com/jaypipes/ghw@v0.21.1/pkg/memory/memory_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 memory_test 8 9 import ( 10 "os" 11 "testing" 12 13 "github.com/jaypipes/ghw/pkg/memory" 14 ) 15 16 // nolint: gocyclo 17 func TestMemory(t *testing.T) { 18 if _, ok := os.LookupEnv("GHW_TESTING_SKIP_MEMORY"); ok { 19 t.Skip("Skipping MEMORY tests.") 20 } 21 22 mem, err := memory.New() 23 if err != nil { 24 t.Fatalf("Expected nil error, but got %v", err) 25 } 26 27 tpb := mem.TotalPhysicalBytes 28 tub := mem.TotalUsableBytes 29 if tpb == 0 { 30 t.Fatalf("Total physical bytes reported zero") 31 } 32 if tub == 0 { 33 t.Fatalf("Total usable bytes reported zero") 34 } 35 if tpb < tub { 36 t.Fatalf("Total physical bytes < total usable bytes. %d < %d", 37 tpb, tub) 38 } 39 40 sps := mem.SupportedPageSizes 41 42 if sps == nil { 43 t.Fatalf("Expected non-nil supported page sizes, but got nil") 44 } 45 if len(sps) == 0 { 46 t.Fatalf("Expected >0 supported page sizes, but got 0.") 47 } 48 49 if mem.DefaultHugePageSize == 0 { 50 t.Fatalf("Expected >0 default hugepagesize, but got 0") 51 } 52 53 if len(sps) != len(mem.HugePageAmountsBySize) { 54 t.Fatalf("Expected %d hugepages, but got %d", len(sps), len(mem.HugePageAmountsBySize)) 55 } 56 }