Debian Codegraph @

testsuite/systemtap.server/server_args.exp

raw
1 set test "Server Argument Test"
2 if {! [nss_p]} { unsupported $test; return }
3
4 # Each test will take 3 seconds or more due to the use of avahi to browse for
5 # servers, so limit iterations to some small but reasonable number.
6 set iterations 10
7
8 # Allow seeding the random number generator using an environment variable in
9 # order to facilitate reproducing a given series of tests. Otherwise seed it
10 # using the current time.
11 if [info exists env(STAP_RANDOM_SEED)] {
12 set random_seed $env(STAP_RANDOM_SEED)
13 } else {
14 set random_seed [clock seconds]
15 }
16 verbose -log "Random seed is $random_seed"
17 expr srand($random_seed)
18
19 proc stap_direct_and_with_client {stap options} {
20 global installed_stap use_server
21
22 # tcl's 'eval' creates a string containing the arguments and
23 # recursively passes it to the tcl interpreter. Special
24 # characters need to be quoted.
25 regsub -all "\[\"\\\\;\]" $options {\\\0} options
26 regsub -all "\[\n\]" $options {\\n} options
27
28 # If the options contain -I/ or the equivalent, then the client will balk.
29 # So test that the client balks.
30 if {[regexp -- "\-I */$" $options] || [regexp -- "\-I */ " $options]} {
31 set passed 0
32 set fallthrough 0
33 set cmd [concat stap $options $use_server]
34 send_log "executing: $cmd\n"
35 eval spawn $cmd
36 expect {
37 -timeout 150
38 -re {^Unable to send / to the server\r\n} {
39 set passed 1
40 }
41 # Some other options can cause errors which occur before the one for -I/.
42 # If one of these errors occurs, then fall through to the normal test.
43 -re {^ERROR: Safety pattern mismatch for -. parameter .*\r\n} {
44 set fallthrough 1
45 }
46 -re {^.*\r\n} { exp_continue }
47 timeout {
48 kill -INT -[exp_pid] 2
49 }
50 }
51 catch {close}; catch {wait}
52 if { $fallthrough == 0 } {
53 return $passed
54 }
55 }
56
57 # Otherwise, check the that output from compiling directly and using
58 # the client/server are reasonable similar.
59 verbose -log "eval exec $stap $options"
60 catch {eval exec $stap $options} res_stap
61 verbose -log $res_stap
62
63 # Now run it using the client
64 verbose -log "eval exec $stap $use_server $options"
65 catch {eval exec $stap $use_server $options} res_stap_client
66 verbose -log $res_stap_client
67
68 # Now check the output
69 set skip_hostname_mode 0
70 set n 0
71 set expected [split $res_stap "\n"]
72 set received [split $res_stap_client "\n"]
73 foreach line $received {
74 # Instructed to skip hostnames?
75 if {$skip_hostname_mode} {
76 if {[regexp {^ \S+$} $line]} {
77 verbose -log "skipping: $line"
78 continue
79 } else {
80 set skip_hostname_mode 0
81 }
82 }
83 # Ignore warnings about the domain name on the certificate not matching
84 if {[regexp {^WARNING: The domain name, [^,]*, does not match the DNS name\(s\) on the server certificate:} $line]} {
85 set skip_hostname_mode 1
86 verbose -log "skipping: $line"
87 continue
88 }
89 set expected_line [lindex $expected $n]
90 # Some messages contain the names of files or directories
91 # and will be prefixed for the client.
92 if {[regexp "^ (.*)" $expected_line match data]} {
93 verbose -log "MATCH: $match"
94 verbose -log "DATA: $data"
95 # Special characters in the regexp need to be quoted.
96 regsub -all "\[\"\\\\;\*\(\)\]" $data {\\\0} data
97 if {[regexp "^ tapset.*/$data" $line]} {
98 incr n
99 continue
100 }
101 if {[regexp "^ runtime.*/$data" $line]} {
102 incr n
103 continue
104 }
105 # Some messages contain the name of the module based on the
106 # process id.
107 if {[regexp "^ stap_\[0-9\]*" $expected_line] &&
108 [regexp "^ stap_\[0-9\]*" $line]} {
109 incr n
110 continue
111 }
112 } elseif {[regexp "^Input file '(.*)' is empty or missing." $expected_line match data]} {
113 # Special characters in the regexp need to be quoted.
114 regsub -all "\[\"\\\\;\*\]" $data {\\\0} data
115 if {[regexp "^Input file 'script.*/$data' is empty or missing." $line]} {
116 incr n
117 continue
118 }
119 } elseif {[regexp "^Input file '(.*)' is missing." $expected_line match data]} {
120 # Special characters in the regexp need to be quoted.
121 regsub -all "\[\"\\\\;\*\]" $data {\\\0} data
122 if {[regexp "^Input file 'script.*/$data' is missing." $line]} {
123 incr n
124 continue
125 }
126 } elseif {[regexp "^(.*/stap): (.*)" $line match data1 data2]} {
127 # Special characters in the regexp need to be quoted.
128 regsub -all "\[\"\\\\;\*\]" $data2 {\\\0} data2
129 if {[regexp "^$stap: $data2" $expected_line]} {
130 incr n
131 continue
132 }
133 }
134
135 # Otherwise the output must be identical.
136 if {! [string equal $line $expected_line]} {
137 break
138 }
139 incr n
140 }
141 if {$n == [llength $expected] && [llength $expected] <= [llength $received]} {
142 # Test passes
143 return 1
144 }
145 # Test fails
146 send_log "line [expr $n + 1]:\n"
147 send_log "Expected: \"[lindex $expected $n]\"\n"
148 send_log "Got : \"$line\"\n"
149 return 0
150 }
151
152 # ************ Start of mainline *************
153
154 # Don't attempt these tests if the client/server are not available
155 if {! [setup_server]} then {
156 untested "$test"
157 return
158 }
159
160 # Make sure we call the correct instance of stap
161 # There is a copy of stap on the PATH which always uses --use-server NOT ANY MORE!!!
162 #if {[installtest_p]} then {
163 # # For 'make installcheck', use the installed stap
164 # set stap $installed_stap
165 #} else {
166 # # For 'make check' use stap from the build tree
167 # set stap [exec pwd]/../stap
168 #}
169 set stap stap
170
171 # Test some argument strings which have failed in the past. This is useful
172 # for debugging a currently failing case and helps to ensure that previously
173 # fixed cases do not regress.
174
175 # TODO: Debug this one: "-p1 -I -e\\;/ -Dhn6 -cejijqmi0 -S3-k -"
176 set previously_fixed [list \
177 "-p1 -I=\\w94\nbh -e -Dhfuo0iu7 -c" \
178 "-p1 -I8o\\2ie -e'1\\ -D\n\" -c" \
179 "-p1 -Ira\\3;c g -e0fle'qq -Dr/316k\\o8 -cjyoc\n3" \
180 "-p1 -I6p3 -elc -Dqgsgv' -c" \
181 "-p1 -I\"vyv;z -ej\"/3 -D/ 01qck\n -c3u55zut" \
182 "-p1 -I1 -eo9e\nx047q -D9xyefk0a -cvl98/x1'i" \
183 "-p1 -c; test.stp" \
184 "-p1 -I4hgy96 -e5oo39p -Ddx8v -c4;" \
185 "-p1 -I -esq3wors -Dz -c*eibz8h2e" \
186 "-p1 -I a -em339db5 -Du2;c0ps -ch9o\\" \
187 "-p1 -Ipfjps4 -ebug4dc -Du8vd fvkl -c" \
188 "-p1 -I0\"nspzjyf -e5r3up8h -Dmi;ojp9m -cx;a2fat" \
189 "-p1 -Iu -ek7;r -Dcu\"; -c\"hc" \
190 "-p1 -Icd4fidq m40mv -edn -D;8ha\\cjr -c1*vnq" \
191 "-p1 -I;3 -er8e -D -cb6k29z" \
192 "-p1 -Ircj -e -D -c\\vmww" \
193 "-p1 -Illc5 -e65wof9 qr*=x7x5 -D -cgx;" \
194 "-p1 -Iyaj420=3 -e\" -D -cd'5mi" \
195 "-p1 -Ir -e -D29\\ -cj2szt;4" \
196 "-p1 -Ibno3=b4sk -e' -Dg2-j;e -c2ijx'" \
197 "-p1 -I285v7pl -eo5\\0 -D86s -c-c*v" \
198 "-l syscall.open* -- -p5" \
199 "-l syscall.open* -- -rfoo" \
200 "-p1 -I/ 1\\nbzg3 -ebf -Do -ckrll=\\;oh -\S4" \
201 "-p1 -I / 1\\nbzg3 -ebf -Do -ckrll=\\;oh -\S4" \
202 "-p1 1\\nbzg3 -ebf -Do -ckrll=\\;oh -\S4 -I/" \
203 "-p1 1\\nbzg3 -ebf -Do -ckrll=\\;oh -\S4 -I /" \
204 "-p1 -I -e\\;/ -Dhn6 -cejijqmi0 -S3-k -" \
205 "-p1 -I/ -e/ -D -c\\n1v\\;nd8 -S--" \
206 "-p1 -I/ -e0xzu -Dxrk -c*sum8fe -St546jn" \
207 ]
208
209 set i 0
210 foreach options $previously_fixed {
211 if {[stap_direct_and_with_client $stap $options]} {
212 pass "$test $i"
213 } else {
214 fail "$test $i"
215 }
216 incr i
217 }
218
219 # Generate semi-random arguments containing with potential problem characters.
220 # Check that running systemtap with the client/server generates output
221 # comparable to running stap directly.
222 set dangerous_options [list "-I" "-e" "-D" "-c" "-S"]
223 # NB: Other options could be candidates here, like -r and -B, but
224 # there stap-server imposes more restrictions than local stap, so
225 # this simple error-matching test cannot use them.
226 set argchars "0123456789/;*'=-\\\"\n abcdefghijklmnopqrstuvwxyz"
227
228 for {set i 0} {$i < $iterations} {incr i} {
229 verbose -log "Iteration $i"
230
231 # First generate an argument string
232 set options "-p1"
233 foreach option $dangerous_options {
234 set options "$options $option"
235 set limit [expr int(rand() * 10)]
236 for {set c 0} {$c < $limit} {incr c} {
237 set options "$options[string index $argchars [expr int(rand() * [string length $argchars])]]"
238 }
239 }
240
241 # Now test it against stap and stap client
242 if {[stap_direct_and_with_client $stap $options]} {
243 pass "Fuzzing $test $i"
244 } else {
245 fail "Fuzzing $test $i"
246 }
247 }
248
249 # Shudown the server.
250 shutdown_server