Debian Codegraph @

doc/SystemTap_Beginners_Guide/testsuite/systemtap.base/sdt_buildid.exp

raw
1 set test "sdt_buildid"
2
3 set pbtype_flags {{additional_flags=-g} {} {}}
4 set fail_count 0
5
6 # Compile a C program to use as the user-space probing target
7 set stap_path $env(SYSTEMTAP_PATH)/stap
8 set sup_dpath "[pwd]/sdt_buildid_.d"
9 set sup_hpath "[pwd]/sdt_buildid_.h"
10 set sup_opath "[pwd]/sdt_buildid_.o"
11
12 # Run dtrace
13 if {[installtest_p]} {
14 set dtrace $env(SYSTEMTAP_PATH)/dtrace
15 } else {
16 set dtrace ../dtrace
17 }
18
19 verbose -log "$dtrace --types -h -s $srcdir/$subdir/sdt_buildid_.d"
20 if {[catch {exec $dtrace --types -h -s \
21 $srcdir/$subdir/sdt_buildid_.d} res]} {
22 verbose -log "unable to run $dtrace: $res"
23 }
24 verbose -log "$dtrace --types -G -s $srcdir/$subdir/sdt_buildid_.d"
25 if {[catch {exec $dtrace --types -G -s \
26 $srcdir/$subdir/sdt_buildid_.d} res]} {
27 verbose -log "unable to run $dtrace: $res"
28 }
29 if {[file exists $sup_hpath] && [file exists $sup_opath]} then {
30 pass "$test dtrace"
31 } else {
32 incr fail_count
33 fail "$test dtrace"
34 return
35 }
36
37 set sup_flags [sdt_includes]
38 set sup_flags "$sup_flags additional_flags=-Wall"
39 set sup_flags "$sup_flags additional_flags=-Werror"
40 set sup_flags "$sup_flags additional_flags=$sup_opath"
41 set sup_flags "$sup_flags additional_flags=-I."
42 set sup_exepath "[pwd]/sdt_buildid.x"
43
44 set res [target_compile $srcdir/$subdir/sdt_buildid.c $sup_exepath \
45 executable $sup_flags]
46 if { $res != "" } {
47 incr fail_count
48 verbose "target_compile failed: $res" 2
49 fail "$test compiling"
50 return
51 } else {
52 pass "$test compiling"
53 }
54
55
56 set sup41_flags "$sup_flags additional_flags=-shared"
57 set sup41_flags "$sup41_flags additional_flags=-fPIC"
58 set sup41_flags "$sup41_flags additional_flags=-DNO_MAIN"
59 set sup_sopath "[pwd]/libsdt_buildid.so"
60 set sup_exe2path "[pwd]/sdt_buildid_shared.x"
61 set res0 [target_compile $srcdir/$subdir/sdt_buildid.c $sup_sopath \
62 executable $sup41_flags ]
63 set sup42_flags "additional_flags=-Wl,-rpath,[pwd]"
64 set sup42_flags "$sup42_flags additional_flags=-L[pwd] additional_flags=-lsdt_buildid"
65 set sup42_flags "$sup42_flags additional_flags=-DONLY_MAIN"
66 set res [target_compile $srcdir/$subdir/sdt_buildid.c $sup_exe2path \
67 executable $sup42_flags ]
68 if { $res0 != "" || $res != "" } {
69 incr fail_count
70 verbose "target_compile failed: $res0 $res" 2
71 fail "$test compiling -shared"
72 return
73 } else {
74 pass "$test compiling -shared"
75 }
76
77 catch { exec eu-readelf -n $sup_exepath | grep Build.ID | awk "{print \$NF}" } bid1
78 catch { exec eu-readelf -n $sup_sopath | grep Build.ID | awk "{print \$NF}" } bidso
79 catch { exec eu-readelf -n $sup_exe2path | grep Build.ID | awk "{print \$NF}" } bid2
80 verbose -log "buildid: $sup_exepath $bid1"
81 verbose -log "buildid: $sup_sopath $bidso"
82 verbose -log "buildid: $sup_exe2path $bid2"
83 # though we won't use the $bid2
84
85 if {![installtest_p]} {
86 untested $test
87 return
88 }
89
90 # To test via build-id, we need a debuginfod server to scan the testsuite build
91 # directory.
92
93
94 if [catch {exec /usr/bin/which debuginfod} debuginfod] then {
95 untested "$test debuginfod"
96 } else {
97 set port [expr {10000 + int(rand()*10000)}]
98 spawn $debuginfod -p $port -d tmp.sqlite -F .
99 set debuginfod_pid [exp_pid $spawn_id]
100 # give it time to scan the build directory
101 sleep 10
102 # XXX: we could expect some verbose traffic
103 if [info exists env(DEBUGINFOD_URLS)] {
104 set env(DEBUGINFOD_URLS) "http://localhost:$port $env(DEBUGINFOD_URLS)"
105 } else {
106 set env(DEBUGINFOD_URLS) "http://localhost:$port"
107 }
108 verbose -log "started debuginfod on port $port"
109
110 set subtest "$test debuginfod buildid-exe buildid-solib"
111 spawn $stap_path $srcdir/$subdir/sdt_buildid.stp $bid1 $bidso
112 set ok 0
113 expect {
114 -timeout 240
115 -re {^Count [0-9]*[02468][^\r\n]*\r\n} { incr ok; exec $sup_exepath; exp_continue }
116 -re {^Count [0-9]*[13579][^\r\n]*\r\n} { incr ok; exec $sup_exe2path; exp_continue }
117 eof { }
118 timeout { }
119 }
120 catch {close}; catch {wait}
121 if {$ok > 6} then { pass $subtest } else { fail $subtest }
122
123 set subtest "$test debuginfod buildid-exe path-solib"
124 spawn $stap_path $srcdir/$subdir/sdt_buildid.stp $bid1 $sup_sopath
125 set ok 0
126 expect {
127 -timeout 240
128 -re {^Count [0-9]*[02468][^\r\n]*\r\n} { incr ok; exec $sup_exepath; exp_continue }
129 -re {^Count [0-9]*[13579][^\r\n]*\r\n} { incr ok; exec $sup_exe2path; exp_continue }
130 eof { }
131 timeout { }
132 }
133 catch {close}; catch {wait}
134 if {$ok > 6} then { pass $subtest } else { fail $subtest }
135
136 set subtest "$test debuginfod path-exe buildid-solib"
137 spawn $stap_path $srcdir/$subdir/sdt_buildid.stp $sup_exepath $bidso
138 set ok 0
139 expect {
140 -timeout 240
141 -re {^Count [0-9]*[02468][^\r\n]*\r\n} { incr ok; exec $sup_exepath; exp_continue }
142 -re {^Count [0-9]*[13579][^\r\n]*\r\n} { incr ok; exec $sup_exe2path; exp_continue }
143 eof { }
144 timeout { }
145 }
146 catch {close}; catch {wait}
147 if {$ok > 6} then { pass $subtest } else { fail $subtest }
148
149 set subtest "$test debuginfod buildid-solib"
150 spawn $stap_path $srcdir/$subdir/sdt_buildid.stp $bidso
151 set ok 0
152 expect {
153 -timeout 240
154 -re {^Count [0-9]*[02468][^\r\n]*\r\n} { incr ok; exec $sup_exe2path; exp_continue }
155 -re {^Count [0-9]*[13579][^\r\n]*\r\n} { incr ok; exec $sup_exe2path; exp_continue }
156 eof { }
157 timeout { }
158 }
159 catch {close}; catch {wait}
160 if {$ok > 6} then { pass $subtest } else { fail $subtest }
161
162 set subtest "$test debuginfod buildid-exe"
163 spawn $stap_path $srcdir/$subdir/sdt_buildid.stp $bid1
164 set ok 0
165 expect {
166 -timeout 240
167 -re {^Count [0-9]*[02468][^\r\n]*\r\n} { incr ok; exec $sup_exepath; exp_continue }
168 -re {^Count [0-9]*[13579][^\r\n]*\r\n} { incr ok; exec $sup_exepath; exp_continue }
169 eof { }
170 timeout { }
171 }
172 catch {close}; catch {wait}
173 if {$ok > 6} then { pass $subtest } else { fail $subtest }
174
175 kill -INT $debuginfod_pid
176 }
177
178
179 set subtest "$test non-buildid both"
180 spawn $stap_path $srcdir/$subdir/sdt_buildid.stp $sup_exepath $sup_sopath
181 set ok 0
182 expect {
183 -timeout 240
184 -re {^Count [0-9]*[02468][^\r\n]*\r\n} { incr ok; exec $sup_exepath; exp_continue }
185 -re {^Count [0-9]*[13579][^\r\n]*\r\n} { incr ok; exec $sup_exe2path; exp_continue }
186 eof { }
187 timeout { }
188 }
189 catch {close}; catch {wait}
190 if {$ok > 6} then { pass $subtest } else { fail $subtest }
191
192 set subtest "$test non-buildid exe"
193 spawn $stap_path $srcdir/$subdir/sdt_buildid.stp $sup_exepath
194 set ok 0
195 expect {
196 -timeout 240
197 -re {^Count [0-9]*[02468][^\r\n]*\r\n} { incr ok; exec $sup_exepath; exp_continue }
198 -re {^Count [0-9]*[13579][^\r\n]*\r\n} { incr ok; exec $sup_exepath; exp_continue }
199 eof { }
200 timeout { }
201 }
202 catch {close}; catch {wait}
203 if {$ok > 6} then { pass $subtest } else { fail $subtest }
204
205 set subtest "$test non-buildid solib"
206 spawn $stap_path $srcdir/$subdir/sdt_buildid.stp $sup_sopath
207 set ok 0
208 expect {
209 -timeout 240
210 -re {^Count [0-9]*[02468][^\r\n]*\r\n} { incr ok; exec $sup_exe2path; exp_continue }
211 -re {^Count [0-9]*[13579][^\r\n]*\r\n} { incr ok; exec $sup_exe2path; exp_continue }
212 eof { }
213 timeout { }
214 }
215 catch {close}; catch {wait}
216 if {$ok > 6} then { pass $subtest } else { fail $subtest }
217
218 return