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 14package procfs 15 16import ( 17 "reflect" 18 "testing" 19) 20 21func TestMeminfo(t *testing.T) { 22 expected := Meminfo{ 23 MemTotal: newuint64(15666184), 24 MemFree: newuint64(440324), 25 Buffers: newuint64(1020128), 26 Cached: newuint64(12007640), 27 SwapCached: newuint64(0), 28 Active: newuint64(6761276), 29 Inactive: newuint64(6532708), 30 ActiveAnon: newuint64(267256), 31 InactiveAnon: newuint64(268), 32 ActiveFile: newuint64(6494020), 33 InactiveFile: newuint64(6532440), 34 Unevictable: newuint64(0), 35 Mlocked: newuint64(0), 36 SwapTotal: newuint64(0), 37 SwapFree: newuint64(0), 38 Dirty: newuint64(768), 39 Writeback: newuint64(0), 40 AnonPages: newuint64(266216), 41 Mapped: newuint64(44204), 42 Shmem: newuint64(1308), 43 Slab: newuint64(1807264), 44 SReclaimable: newuint64(1738124), 45 SUnreclaim: newuint64(69140), 46 KernelStack: newuint64(1616), 47 PageTables: newuint64(5288), 48 NFSUnstable: newuint64(0), 49 Bounce: newuint64(0), 50 WritebackTmp: newuint64(0), 51 CommitLimit: newuint64(7833092), 52 CommittedAS: newuint64(530844), 53 VmallocTotal: newuint64(34359738367), 54 VmallocUsed: newuint64(36596), 55 VmallocChunk: newuint64(34359637840), 56 HardwareCorrupted: newuint64(0), 57 AnonHugePages: newuint64(12288), 58 HugePagesTotal: newuint64(0), 59 HugePagesFree: newuint64(0), 60 HugePagesRsvd: newuint64(0), 61 HugePagesSurp: newuint64(0), 62 Hugepagesize: newuint64(2048), 63 DirectMap4k: newuint64(91136), 64 DirectMap2M: newuint64(16039936), 65 } 66 67 have, err := getProcFixtures(t).Meminfo() 68 if err != nil { 69 t.Fatal(err) 70 } 71 72 if !reflect.DeepEqual(have, expected) { 73 t.Logf("have: %+v", have) 74 t.Logf("expected: %+v", expected) 75 t.Errorf("structs are not equal") 76 } 77} 78