...

Source file src/github.com/prometheus/procfs/meminfo_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  package procfs
    15  
    16  import (
    17  	"reflect"
    18  	"testing"
    19  )
    20  
    21  func 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  		Percpu:            newuint64(26176),
    57  		HardwareCorrupted: newuint64(0),
    58  		AnonHugePages:     newuint64(12288),
    59  		HugePagesTotal:    newuint64(0),
    60  		HugePagesFree:     newuint64(0),
    61  		HugePagesRsvd:     newuint64(0),
    62  		HugePagesSurp:     newuint64(0),
    63  		Hugepagesize:      newuint64(2048),
    64  		DirectMap4k:       newuint64(91136),
    65  		DirectMap2M:       newuint64(16039936),
    66  
    67  		MemTotalBytes:          newuint64(16042172416),
    68  		MemFreeBytes:           newuint64(450891776),
    69  		BuffersBytes:           newuint64(1044611072),
    70  		CachedBytes:            newuint64(12295823360),
    71  		SwapCachedBytes:        newuint64(0),
    72  		ActiveBytes:            newuint64(6923546624),
    73  		InactiveBytes:          newuint64(6689492992),
    74  		ActiveAnonBytes:        newuint64(273670144),
    75  		InactiveAnonBytes:      newuint64(274432),
    76  		ActiveFileBytes:        newuint64(6649876480),
    77  		InactiveFileBytes:      newuint64(6689218560),
    78  		UnevictableBytes:       newuint64(0),
    79  		MlockedBytes:           newuint64(0),
    80  		SwapTotalBytes:         newuint64(0),
    81  		SwapFreeBytes:          newuint64(0),
    82  		DirtyBytes:             newuint64(786432),
    83  		WritebackBytes:         newuint64(0),
    84  		AnonPagesBytes:         newuint64(272605184),
    85  		MappedBytes:            newuint64(45264896),
    86  		ShmemBytes:             newuint64(1339392),
    87  		SlabBytes:              newuint64(1850638336),
    88  		SReclaimableBytes:      newuint64(1779838976),
    89  		SUnreclaimBytes:        newuint64(70799360),
    90  		KernelStackBytes:       newuint64(1654784),
    91  		PageTablesBytes:        newuint64(5414912),
    92  		NFSUnstableBytes:       newuint64(0),
    93  		BounceBytes:            newuint64(0),
    94  		WritebackTmpBytes:      newuint64(0),
    95  		CommitLimitBytes:       newuint64(8021086208),
    96  		CommittedASBytes:       newuint64(543584256),
    97  		VmallocTotalBytes:      newuint64(35184372087808),
    98  		VmallocUsedBytes:       newuint64(37474304),
    99  		VmallocChunkBytes:      newuint64(35184269148160),
   100  		PercpuBytes:            newuint64(26804224),
   101  		HardwareCorruptedBytes: newuint64(0),
   102  		AnonHugePagesBytes:     newuint64(12582912),
   103  		HugepagesizeBytes:      newuint64(2097152),
   104  		DirectMap4kBytes:       newuint64(93323264),
   105  		DirectMap2MBytes:       newuint64(16424894464),
   106  	}
   107  
   108  	have, err := getProcFixtures(t).Meminfo()
   109  	if err != nil {
   110  		t.Fatal(err)
   111  	}
   112  
   113  	if !reflect.DeepEqual(have, expected) {
   114  		t.Logf("have: %+v", have)
   115  		t.Logf("expected: %+v", expected)
   116  		t.Errorf("structs are not equal")
   117  	}
   118  }
   119  

View as plain text