gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/test/benchmarks/tools/meminfo_test.go (about)

     1  // Copyright 2020 The gVisor Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package tools
    16  
    17  import (
    18  	"testing"
    19  )
    20  
    21  // TestMeminfo checks the Meminfo parser on sample output.
    22  func TestMeminfo(t *testing.T) {
    23  	sampleData := `
    24  MemTotal:       16337408 kB
    25  MemFree:         3742696 kB
    26  MemAvailable:    9319948 kB
    27  Buffers:         1433884 kB
    28  Cached:          4607036 kB
    29  SwapCached:        45284 kB
    30  Active:          8288376 kB
    31  Inactive:        2685928 kB
    32  Active(anon):    4724912 kB
    33  Inactive(anon):  1047940 kB
    34  Active(file):    3563464 kB
    35  Inactive(file):  1637988 kB
    36  Unevictable:      326940 kB
    37  Mlocked:              48 kB
    38  SwapTotal:      33292284 kB
    39  SwapFree:       32865736 kB
    40  Dirty:               708 kB
    41  Writeback:             0 kB
    42  AnonPages:       4304204 kB
    43  Mapped:           975424 kB
    44  Shmem:            910292 kB
    45  KReclaimable:     744532 kB
    46  Slab:            1058448 kB
    47  SReclaimable:     744532 kB
    48  SUnreclaim:       313916 kB
    49  KernelStack:       25188 kB
    50  PageTables:        65300 kB
    51  NFS_Unstable:          0 kB
    52  Bounce:                0 kB
    53  WritebackTmp:          0 kB
    54  CommitLimit:    41460988 kB
    55  Committed_AS:   22859492 kB
    56  VmallocTotal:   34359738367 kB
    57  VmallocUsed:       63088 kB
    58  VmallocChunk:          0 kB
    59  Percpu:             9248 kB
    60  HardwareCorrupted:     0 kB
    61  AnonHugePages:    786432 kB
    62  ShmemHugePages:        0 kB
    63  ShmemPmdMapped:        0 kB
    64  FileHugePages:         0 kB
    65  FilePmdMapped:         0 kB
    66  HugePages_Total:       0
    67  HugePages_Free:        0
    68  HugePages_Rsvd:        0
    69  HugePages_Surp:        0
    70  Hugepagesize:       2048 kB
    71  Hugetlb:               0 kB
    72  DirectMap4k:     5408532 kB
    73  DirectMap2M:    11241472 kB
    74  DirectMap1G:     1048576 kB
    75  `
    76  	want := 9319948.0
    77  	got, err := parseMemAvailable(sampleData)
    78  	if err != nil {
    79  		t.Fatalf("parseMemAvailable failed: %v", err)
    80  	}
    81  	if got != want {
    82  		t.Fatalf("parseMemAvailable got %f, want %f", got, want)
    83  	}
    84  }