Codebase list golang-procfs / 95d2514
Split process map tests into 32/64 bit variants Signed-off-by: Daniel Swarbrick <daniel.swarbrick@gmail.com> Daniel Swarbrick 3 years ago
3 changed file(s) with 227 addition(s) and 185 deletion(s). Raw diff Collapse all Expand all
0 // Copyright 2019 The Prometheus Authors
1 // Licensed under the Apache License, Version 2.0 (the "License");
2 // you may not use this file except in compliance with the License.
3 // You may obtain a copy of the License at
4 //
5 // http://www.apache.org/licenses/LICENSE-2.0
6 //
7 // Unless required by applicable law or agreed to in writing, software
8 // distributed under the License is distributed on an "AS IS" BASIS,
9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 // See the License for the specific language governing permissions and
11 // limitations under the License.
12
13 // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
14 // +build 386 arm mips mipsle
15
16 package procfs
17
18 import (
19 "testing"
20
21 "github.com/google/go-cmp/cmp"
22 "golang.org/x/sys/unix"
23 )
24
25 func TestProcMaps(t *testing.T) {
26 tsts32 := []*ProcMap{
27 {
28 StartAddr: 0x08048000,
29 EndAddr: 0x08089000,
30 Perms: &ProcMapPermissions{true, false, true, false, true},
31 Offset: 0,
32 Dev: unix.Mkdev(0x03, 0x01),
33 Inode: 104219,
34 Pathname: "/bin/tcsh",
35 },
36 {
37 StartAddr: 0x08089000,
38 EndAddr: 0x0808c000,
39 Perms: &ProcMapPermissions{true, true, false, false, true},
40 Offset: 266240,
41 Dev: unix.Mkdev(0x03, 0x01),
42 Inode: 104219,
43 Pathname: "/bin/tcsh",
44 },
45 {
46 StartAddr: 0x0808c000,
47 EndAddr: 0x08146000,
48 Perms: &ProcMapPermissions{true, true, true, false, true},
49 Offset: 0,
50 Dev: unix.Mkdev(0x00, 0x00),
51 Inode: 0,
52 Pathname: "",
53 },
54 {
55 StartAddr: 0x40000000,
56 EndAddr: 0x40015000,
57 Perms: &ProcMapPermissions{true, false, true, false, true},
58 Offset: 0,
59 Dev: unix.Mkdev(0x03, 0x01),
60 Inode: 61874,
61 Pathname: "/lib/ld-2.3.2.so",
62 },
63 }
64
65 // 32-bit test pid and fixtures
66 tpid := 26234
67 tsts := tsts32
68
69 p, err := getProcFixtures(t).Proc(tpid)
70 if err != nil {
71 t.Fatal(err)
72 }
73
74 maps, err := p.ProcMaps()
75 if err != nil {
76 t.Fatal(err)
77 }
78
79 if want, have := len(maps), len(tsts); want > have {
80 t.Errorf("want at least %d parsed proc/map entries, have %d", want, have)
81 }
82
83 for idx, tst := range tsts {
84 want, got := tst, maps[idx]
85 if diff := cmp.Diff(want, got); diff != "" {
86 t.Fatalf("unexpected proc/map entry (-want +got):\n%s", diff)
87 }
88 }
89
90 }
0 // Copyright 2019 The Prometheus Authors
1 // Licensed under the Apache License, Version 2.0 (the "License");
2 // you may not use this file except in compliance with the License.
3 // You may obtain a copy of the License at
4 //
5 // http://www.apache.org/licenses/LICENSE-2.0
6 //
7 // Unless required by applicable law or agreed to in writing, software
8 // distributed under the License is distributed on an "AS IS" BASIS,
9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 // See the License for the specific language governing permissions and
11 // limitations under the License.
12
13 // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
14 // +build !386,!arm,!mips,!mipsle
15
16 package procfs
17
18 import (
19 "testing"
20
21 "github.com/google/go-cmp/cmp"
22 "golang.org/x/sys/unix"
23 )
24
25 func TestProcMaps(t *testing.T) {
26 tsts64 := []*ProcMap{
27 {
28 StartAddr: 0x55680ae1e000,
29 EndAddr: 0x55680ae20000,
30 Perms: &ProcMapPermissions{true, false, false, false, true},
31 Offset: 0,
32 Dev: unix.Mkdev(0xfd, 0x01),
33 Inode: 47316994,
34 Pathname: "/bin/cat",
35 },
36 {
37 StartAddr: 0x55680ae29000,
38 EndAddr: 0x55680ae2a000,
39 Perms: &ProcMapPermissions{true, true, true, true, false},
40 Offset: 40960,
41 Dev: unix.Mkdev(0xfd, 0x01),
42 Inode: 47316994,
43 Pathname: "/bin/cat",
44 },
45 {
46 StartAddr: 0x55680bed6000,
47 EndAddr: 0x55680bef7000,
48 Perms: &ProcMapPermissions{true, true, false, false, true},
49 Offset: 0,
50 Dev: unix.Mkdev(0, 0),
51 Inode: 0,
52 Pathname: "[heap]",
53 },
54 {
55 StartAddr: 0x7fdf964fc000,
56 EndAddr: 0x7fdf973f2000,
57 Perms: &ProcMapPermissions{true, false, false, false, true},
58 Offset: 0,
59 Dev: unix.Mkdev(0xfd, 0x01),
60 Inode: 17432624,
61 Pathname: "/usr/lib/locale/locale-archive",
62 },
63 {
64 StartAddr: 0x7fdf973f2000,
65 EndAddr: 0x7fdf97417000,
66 Perms: &ProcMapPermissions{true, false, false, false, true},
67 Offset: 0,
68 Dev: unix.Mkdev(0xfd, 0x01),
69 Inode: 60571062,
70 Pathname: "/lib/x86_64-linux-gnu/libc-2.29.so",
71 },
72 {
73 StartAddr: 0x7ffe9215c000,
74 EndAddr: 0x7ffe9217f000,
75 Perms: &ProcMapPermissions{true, true, false, false, true},
76 Offset: 0,
77 Dev: 0,
78 Inode: 0,
79 Pathname: "[stack]",
80 },
81 {
82 StartAddr: 0x7ffe921da000,
83 EndAddr: 0x7ffe921dd000,
84 Perms: &ProcMapPermissions{true, false, false, false, true},
85 Offset: 0,
86 Dev: 0,
87 Inode: 0,
88 Pathname: "[vvar]",
89 },
90 {
91 StartAddr: 0x7ffe921dd000,
92 EndAddr: 0x7ffe921de000,
93 Perms: &ProcMapPermissions{true, false, true, false, true},
94 Offset: 0,
95 Dev: 0,
96 Inode: 0,
97 Pathname: "[vdso]",
98 },
99 {
100 StartAddr: 0xffffffffff600000,
101 EndAddr: 0xffffffffff601000,
102 Perms: &ProcMapPermissions{false, false, true, false, true},
103 Offset: 0,
104 Dev: 0,
105 Inode: 0,
106 Pathname: "[vsyscall]",
107 },
108 }
109
110 // 64-bit test pid and fixtures
111 tpid := 26232
112 tsts := tsts64
113
114 p, err := getProcFixtures(t).Proc(tpid)
115 if err != nil {
116 t.Fatal(err)
117 }
118
119 maps, err := p.ProcMaps()
120 if err != nil {
121 t.Fatal(err)
122 }
123
124 if want, have := len(maps), len(tsts); want > have {
125 t.Errorf("want at least %d parsed proc/map entries, have %d", want, have)
126 }
127
128 for idx, tst := range tsts {
129 want, got := tst, maps[idx]
130 if diff := cmp.Diff(want, got); diff != "" {
131 t.Fatalf("unexpected proc/map entry (-want +got):\n%s", diff)
132 }
133 }
134
135 }
+0
-185
proc_maps_test.go less more
0 // Copyright 2019 The Prometheus Authors
1 // Licensed under the Apache License, Version 2.0 (the "License");
2 // you may not use this file except in compliance with the License.
3 // You may obtain a copy of the License at
4 //
5 // http://www.apache.org/licenses/LICENSE-2.0
6 //
7 // Unless required by applicable law or agreed to in writing, software
8 // distributed under the License is distributed on an "AS IS" BASIS,
9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 // See the License for the specific language governing permissions and
11 // limitations under the License.
12
13 // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
14
15 package procfs
16
17 import (
18 "testing"
19
20 "github.com/google/go-cmp/cmp"
21 "golang.org/x/sys/unix"
22 )
23
24 func TestProcMaps(t *testing.T) {
25 tsts32 := []*ProcMap{
26 {
27 StartAddr: 0x08048000,
28 EndAddr: 0x08089000,
29 Perms: &ProcMapPermissions{true, false, true, false, true},
30 Offset: 0,
31 Dev: unix.Mkdev(0x03, 0x01),
32 Inode: 104219,
33 Pathname: "/bin/tcsh",
34 },
35 {
36 StartAddr: 0x08089000,
37 EndAddr: 0x0808c000,
38 Perms: &ProcMapPermissions{true, true, false, false, true},
39 Offset: 266240,
40 Dev: unix.Mkdev(0x03, 0x01),
41 Inode: 104219,
42 Pathname: "/bin/tcsh",
43 },
44 {
45 StartAddr: 0x0808c000,
46 EndAddr: 0x08146000,
47 Perms: &ProcMapPermissions{true, true, true, false, true},
48 Offset: 0,
49 Dev: unix.Mkdev(0x00, 0x00),
50 Inode: 0,
51 Pathname: "",
52 },
53 {
54 StartAddr: 0x40000000,
55 EndAddr: 0x40015000,
56 Perms: &ProcMapPermissions{true, false, true, false, true},
57 Offset: 0,
58 Dev: unix.Mkdev(0x03, 0x01),
59 Inode: 61874,
60 Pathname: "/lib/ld-2.3.2.so",
61 },
62 }
63
64 tsts64 := []*ProcMap{
65 {
66 StartAddr: 0x55680ae1e000,
67 EndAddr: 0x55680ae20000,
68 Perms: &ProcMapPermissions{true, false, false, false, true},
69 Offset: 0,
70 Dev: unix.Mkdev(0xfd, 0x01),
71 Inode: 47316994,
72 Pathname: "/bin/cat",
73 },
74 {
75 StartAddr: 0x55680ae29000,
76 EndAddr: 0x55680ae2a000,
77 Perms: &ProcMapPermissions{true, true, true, true, false},
78 Offset: 40960,
79 Dev: unix.Mkdev(0xfd, 0x01),
80 Inode: 47316994,
81 Pathname: "/bin/cat",
82 },
83 {
84 StartAddr: 0x55680bed6000,
85 EndAddr: 0x55680bef7000,
86 Perms: &ProcMapPermissions{true, true, false, false, true},
87 Offset: 0,
88 Dev: unix.Mkdev(0, 0),
89 Inode: 0,
90 Pathname: "[heap]",
91 },
92 {
93 StartAddr: 0x7fdf964fc000,
94 EndAddr: 0x7fdf973f2000,
95 Perms: &ProcMapPermissions{true, false, false, false, true},
96 Offset: 0,
97 Dev: unix.Mkdev(0xfd, 0x01),
98 Inode: 17432624,
99 Pathname: "/usr/lib/locale/locale-archive",
100 },
101 {
102 StartAddr: 0x7fdf973f2000,
103 EndAddr: 0x7fdf97417000,
104 Perms: &ProcMapPermissions{true, false, false, false, true},
105 Offset: 0,
106 Dev: unix.Mkdev(0xfd, 0x01),
107 Inode: 60571062,
108 Pathname: "/lib/x86_64-linux-gnu/libc-2.29.so",
109 },
110 {
111 StartAddr: 0x7ffe9215c000,
112 EndAddr: 0x7ffe9217f000,
113 Perms: &ProcMapPermissions{true, true, false, false, true},
114 Offset: 0,
115 Dev: 0,
116 Inode: 0,
117 Pathname: "[stack]",
118 },
119 {
120 StartAddr: 0x7ffe921da000,
121 EndAddr: 0x7ffe921dd000,
122 Perms: &ProcMapPermissions{true, false, false, false, true},
123 Offset: 0,
124 Dev: 0,
125 Inode: 0,
126 Pathname: "[vvar]",
127 },
128 {
129 StartAddr: 0x7ffe921dd000,
130 EndAddr: 0x7ffe921de000,
131 Perms: &ProcMapPermissions{true, false, true, false, true},
132 Offset: 0,
133 Dev: 0,
134 Inode: 0,
135 Pathname: "[vdso]",
136 },
137 {
138 StartAddr: 0xffffffffff600000,
139 EndAddr: 0xffffffffff601000,
140 Perms: &ProcMapPermissions{false, false, true, false, true},
141 Offset: 0,
142 Dev: 0,
143 Inode: 0,
144 Pathname: "[vsyscall]",
145 },
146 }
147
148 var (
149 tsts []*ProcMap
150 tpid int
151 )
152
153 if (32 << uintptr(^uintptr(0)>>63)) == 64 {
154 // 64b test pid
155 tpid = 26232
156 tsts = tsts64
157 } else {
158 // 32b test pid
159 tpid = 26234
160 tsts = tsts32
161 }
162
163 p, err := getProcFixtures(t).Proc(tpid)
164 if err != nil {
165 t.Fatal(err)
166 }
167
168 maps, err := p.ProcMaps()
169 if err != nil {
170 t.Fatal(err)
171 }
172
173 if want, have := len(maps), len(tsts); want > have {
174 t.Errorf("want at least %d parsed proc/map entries, have %d", want, have)
175 }
176
177 for idx, tst := range tsts {
178 want, got := tst, maps[idx]
179 if diff := cmp.Diff(want, got); diff != "" {
180 t.Fatalf("unexpected proc/map entry (-want +got):\n%s", diff)
181 }
182 }
183
184 }