1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
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