...

Source file src/github.com/prometheus/procfs/zoneinfo_test.go

Documentation: github.com/prometheus/procfs

     1  // Copyright 2019 The Prometheus Authors
     2  // Licensed under the Apache License, Version 2.0 (the "License");
     3  // you may not use this file except in compliance with the License.
     4  // You may obtain a copy of the License at
     5  //
     6  // http://www.apache.org/licenses/LICENSE-2.0
     7  //
     8  // Unless required by applicable law or agreed to in writing, software
     9  // distributed under the License is distributed on an "AS IS" BASIS,
    10  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  //go:build !windows
    15  // +build !windows
    16  
    17  package procfs
    18  
    19  import (
    20  	"testing"
    21  
    22  	"github.com/google/go-cmp/cmp"
    23  )
    24  
    25  func TestZoneinfo(t *testing.T) {
    26  	fs := getProcFixtures(t)
    27  
    28  	protectionDMA := []*int64{newPInt64(0), newPInt64(2877), newPInt64(7826), newPInt64(7826), newPInt64(7826)}
    29  	protectionDMA32 := []*int64{newPInt64(0), newPInt64(0), newPInt64(4949), newPInt64(4949), newPInt64(4949)}
    30  	protectionNormal := []*int64{newPInt64(0), newPInt64(0), newPInt64(0), newPInt64(0), newPInt64(0)}
    31  	protectionMovable := []*int64{newPInt64(0), newPInt64(0), newPInt64(0), newPInt64(0), newPInt64(0)}
    32  	protectionDevice := []*int64{newPInt64(0), newPInt64(0), newPInt64(0), newPInt64(0), newPInt64(0)}
    33  
    34  	refs := []Zoneinfo{
    35  		{Node: "0", Zone: "DMA", NrFreePages: newPInt64(3952), Min: newPInt64(33), Low: newPInt64(41), High: newPInt64(49), Spanned: newPInt64(4095), Present: newPInt64(3975), Managed: newPInt64(3956), NrActiveAnon: newPInt64(547580), NrInactiveAnon: newPInt64(230981), NrIsolatedAnon: newPInt64(0), NrAnonPages: newPInt64(795576), NrAnonTransparentHugepages: newPInt64(0), NrActiveFile: newPInt64(346282), NrInactiveFile: newPInt64(316904), NrIsolatedFile: newPInt64(0), NrFilePages: newPInt64(761874), NrSlabReclaimable: newPInt64(131220), NrSlabUnreclaimable: newPInt64(47320), NrKernelStack: newPInt64(0), NrMapped: newPInt64(215483), NrDirty: newPInt64(908), NrWriteback: newPInt64(0), NrUnevictable: newPInt64(115467), NrShmem: newPInt64(224925), NrDirtied: newPInt64(8007423), NrWritten: newPInt64(7752121), NumaHit: newPInt64(1), NumaMiss: newPInt64(0), NumaForeign: newPInt64(0), NumaInterleave: newPInt64(0), NumaLocal: newPInt64(1), NumaOther: newPInt64(0), Protection: protectionDMA},
    36  		{Node: "0", Zone: "DMA32", NrFreePages: newPInt64(204252), Min: newPInt64(19510), Low: newPInt64(21059), High: newPInt64(22608), Spanned: newPInt64(1044480), Present: newPInt64(759231), Managed: newPInt64(742806), NrKernelStack: newPInt64(2208), NumaHit: newPInt64(113952967), NumaMiss: newPInt64(0), NumaForeign: newPInt64(0), NumaInterleave: newPInt64(0), NumaLocal: newPInt64(113952967), NumaOther: newPInt64(0), Protection: protectionDMA32},
    37  		{Node: "0", Zone: "Normal", NrFreePages: newPInt64(18553), Min: newPInt64(11176), Low: newPInt64(13842), High: newPInt64(16508), Spanned: newPInt64(1308160), Present: newPInt64(1308160), Managed: newPInt64(1268711), NrKernelStack: newPInt64(15136), NumaHit: newPInt64(162718019), NumaMiss: newPInt64(0), NumaForeign: newPInt64(0), NumaInterleave: newPInt64(26812), NumaLocal: newPInt64(162718019), NumaOther: newPInt64(0), Protection: protectionNormal},
    38  		{Node: "0", Zone: "Movable", Min: newPInt64(0), Low: newPInt64(0), High: newPInt64(0), Spanned: newPInt64(0), Present: newPInt64(0), Managed: newPInt64(0), Protection: protectionMovable},
    39  		{Node: "0", Zone: "Device", Min: newPInt64(0), Low: newPInt64(0), High: newPInt64(0), Spanned: newPInt64(0), Present: newPInt64(0), Managed: newPInt64(0), Protection: protectionDevice},
    40  	}
    41  
    42  	data, err := fs.Zoneinfo()
    43  	if err != nil {
    44  		t.Fatalf("failed to parse zoneinfo: %v", err)
    45  	}
    46  	if len(data) != 5 {
    47  		t.Fatal("failed to get all all node info")
    48  	}
    49  
    50  	for index, ref := range refs {
    51  		want, got := ref, data[index]
    52  		if diff := cmp.Diff(want, got); diff != "" {
    53  			t.Fatalf("unexpected crypto entry (-want +got):\n%s", diff)
    54  		}
    55  
    56  	}
    57  }
    58  

View as plain text