...

Source file src/github.com/prometheus/procfs/proc_maps32_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 (aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris) && (386 || arm || mips || mipsle)
    15  // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
    16  // +build 386 arm mips mipsle
    17  
    18  package procfs
    19  
    20  import (
    21  	"testing"
    22  
    23  	"github.com/google/go-cmp/cmp"
    24  	"golang.org/x/sys/unix"
    25  )
    26  
    27  func TestProcMaps(t *testing.T) {
    28  	tsts32 := []*ProcMap{
    29  		{
    30  			StartAddr: 0x08048000,
    31  			EndAddr:   0x08089000,
    32  			Perms:     &ProcMapPermissions{true, false, true, false, true},
    33  			Offset:    0,
    34  			Dev:       unix.Mkdev(0x03, 0x01),
    35  			Inode:     104219,
    36  			Pathname:  "/bin/tcsh",
    37  		},
    38  		{
    39  			StartAddr: 0x08089000,
    40  			EndAddr:   0x0808c000,
    41  			Perms:     &ProcMapPermissions{true, true, false, false, true},
    42  			Offset:    266240,
    43  			Dev:       unix.Mkdev(0x03, 0x01),
    44  			Inode:     104219,
    45  			Pathname:  "/bin/tcsh",
    46  		},
    47  		{
    48  			StartAddr: 0x0808c000,
    49  			EndAddr:   0x08146000,
    50  			Perms:     &ProcMapPermissions{true, true, true, false, true},
    51  			Offset:    0,
    52  			Dev:       unix.Mkdev(0x00, 0x00),
    53  			Inode:     0,
    54  			Pathname:  "",
    55  		},
    56  		{
    57  			StartAddr: 0x40000000,
    58  			EndAddr:   0x40015000,
    59  			Perms:     &ProcMapPermissions{true, false, true, false, true},
    60  			Offset:    0,
    61  			Dev:       unix.Mkdev(0x03, 0x01),
    62  			Inode:     61874,
    63  			Pathname:  "/lib/ld-2.3.2.so",
    64  		},
    65  	}
    66  
    67  	// 32-bit test pid and fixtures
    68  	tpid := 26234
    69  	tsts := tsts32
    70  
    71  	p, err := getProcFixtures(t).Proc(tpid)
    72  	if err != nil {
    73  		t.Fatal(err)
    74  	}
    75  
    76  	maps, err := p.ProcMaps()
    77  	if err != nil {
    78  		t.Fatal(err)
    79  	}
    80  
    81  	if want, have := len(maps), len(tsts); want > have {
    82  		t.Errorf("want at least %d parsed proc/map entries, have %d", want, have)
    83  	}
    84  
    85  	for idx, tst := range tsts {
    86  		want, got := tst, maps[idx]
    87  		if diff := cmp.Diff(want, got); diff != "" {
    88  			t.Fatalf("unexpected proc/map entry (-want +got):\n%s", diff)
    89  		}
    90  	}
    91  
    92  }
    93  

View as plain text