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