...

Source file src/github.com/prometheus/procfs/vm_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 newPInt64(i int64) *int64 {
    26  	return &i
    27  }
    28  
    29  func TestVM(t *testing.T) {
    30  	fs, err := NewFS(procTestFixtures)
    31  	if err != nil {
    32  		t.Fatal(err)
    33  	}
    34  	got, err := fs.VM()
    35  	if err != nil {
    36  		t.Fatal(err)
    37  	}
    38  	zeroPointer := newPInt64(0)
    39  	lowmemreserveratio := []*int64{newPInt64(256), newPInt64(256), newPInt64(32), zeroPointer, zeroPointer}
    40  	want := &VM{
    41  		AdminReserveKbytes:        newPInt64(8192),
    42  		BlockDump:                 zeroPointer,
    43  		CompactUnevictableAllowed: newPInt64(1),
    44  		DirtyBackgroundBytes:      zeroPointer,
    45  		DirtyBackgroundRatio:      newPInt64(10),
    46  		DirtyBytes:                zeroPointer,
    47  		DirtyExpireCentisecs:      newPInt64(3000),
    48  		DirtyRatio:                newPInt64(20),
    49  		DirtytimeExpireSeconds:    newPInt64(43200),
    50  		DirtyWritebackCentisecs:   newPInt64(500),
    51  		DropCaches:                zeroPointer,
    52  		ExtfragThreshold:          newPInt64(500),
    53  		HugetlbShmGroup:           zeroPointer,
    54  		LaptopMode:                newPInt64(5),
    55  		LegacyVaLayout:            zeroPointer,
    56  		LowmemReserveRatio:        lowmemreserveratio,
    57  		MaxMapCount:               newPInt64(65530),
    58  		MemoryFailureEarlyKill:    zeroPointer,
    59  		MemoryFailureRecovery:     newPInt64(1),
    60  		MinFreeKbytes:             newPInt64(67584),
    61  		MinSlabRatio:              newPInt64(5),
    62  		MinUnmappedRatio:          newPInt64(1),
    63  		MmapMinAddr:               newPInt64(65536),
    64  		NumaStat:                  newPInt64(1),
    65  		NumaZonelistOrder:         "Node",
    66  		NrHugepages:               zeroPointer,
    67  		NrHugepagesMempolicy:      zeroPointer,
    68  		NrOvercommitHugepages:     zeroPointer,
    69  		OomDumpTasks:              newPInt64(1),
    70  		OomKillAllocatingTask:     zeroPointer,
    71  		OvercommitKbytes:          zeroPointer,
    72  		OvercommitMemory:          zeroPointer,
    73  		OvercommitRatio:           newPInt64(50),
    74  		PageCluster:               newPInt64(3),
    75  		PanicOnOom:                zeroPointer,
    76  		PercpuPagelistFraction:    zeroPointer,
    77  		StatInterval:              newPInt64(1),
    78  		Swappiness:                newPInt64(60),
    79  		UserReserveKbytes:         newPInt64(131072),
    80  		VfsCachePressure:          newPInt64(100),
    81  		WatermarkBoostFactor:      newPInt64(15000),
    82  		WatermarkScaleFactor:      newPInt64(10),
    83  		ZoneReclaimMode:           zeroPointer,
    84  	}
    85  	if diff := cmp.Diff(want, got); diff != "" {
    86  		t.Fatalf("unexpected power supply class (-want +got):\n%s", diff)
    87  	}
    88  }
    89  

View as plain text