1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
# itrace test
# Initialize variables
set exepath "[pwd]/ls_[pid]"
# Why check for 1000 instructions executed? We can't know the actual
# number to look for, so we just look for a reasonable number that
# should work for all platforms.
set itrace_single1_script {
global instrs = 0
probe begin { printf("systemtap starting probe\n") }
probe process("%s").insn
{
instrs += 1
}
probe end {
printf("systemtap ending probe\n")
if (instrs > 1000) {
printf("instrs > 1000 (%%d)\n", instrs)
}
else {
printf("instrs <= 1000 (%%d)\n", instrs)
}
}
}
set itrace_single1_script_output "instrs > 1000 \\(\[0-9\]\[0-9\]*\\)\r\n"
set itrace_single2_script {
global instrs = 0, itrace_on = 0, start_timer = 0
probe begin { start_timer = 1; printf("systemtap starting probe\n") }
probe process("%s").insn if (itrace_on)
{
instrs += 1
if (instrs == 5)
exit()
}
probe timer.ms(1) if (start_timer)
{
itrace_on = 1
}
probe timer.ms(10) if (start_timer)
{
itrace_on = 0
}
probe end { printf("systemtap ending probe\n")
printf("itraced = %%d\n", instrs)
}
}
set itrace_single2_script_output "itraced = 5\r\n"
set itrace_block1_script {
global branches = 0
probe begin
{
printf("systemtap starting probe\n")
}
probe process("%s").insn.block
{
branches += 1
if (branches == 5)
exit()
}
probe end { printf("systemtap ending probe\n")
printf("itraced block mode = %%d\n", branches)
}
}
set itrace_block1_script_output "itraced block mode = 5\r\n"
set itrace_block2_script {
global instrs = 0, itrace_on = 0, start_timer = 0
probe begin { start_timer = 1; printf("systemtap starting probe\n") }
probe process("%s").insn.block if (itrace_on)
{
instrs += 1
if (instrs == 5)
exit()
}
probe timer.ms(1) if (start_timer)
{
itrace_on = 1
}
probe timer.ms(10) if (start_timer)
{
itrace_on = 0
}
probe end { printf("systemtap ending probe\n")
printf("itraced = %%d\n", instrs)
}
}
set itrace_block2_script_output "itraced = 5\r\n"
set itrace_single_step_script {
%{
#include "ptrace_compatibility.h"
%}
function has_single_step() %{
THIS->__retvalue = arch_has_single_step(); /* pure */
%}
probe begin {
printf("has_single_step: %d\n", has_single_step())
exit()
}
}
set itrace_block_step_script {
%{
#include "ptrace_compatibility.h"
%}
function has_block_step() %{
THIS->__retvalue = arch_has_block_step(); /* pure */
%}
probe begin {
printf("has_block_step: %d\n", has_block_step())
exit()
}
}
proc stap_check_feature { test_name script feature } {
set rc -1
verbose -log "stap -g -e \"$script\""
spawn stap -g -e "$script"
expect {
-timeout 60
-re "^$feature: 0" { set rc 0; pass $test_name }
-re "^$feature: 1" { set rc 1; pass $test_name }
eof { fail "$test_name (eof)" }
timeout { fail "$test_name (timeout)" }
}
catch {close}
catch {wait}
return $rc
}
# Set up our own copy of /bin/ls, to make testing for a particular
# executable easy. We can't use 'ln' here, since we might be creating
# a cross-device link. We can't use 'ln -s' here, since the kernel
# resolves the symbolic link and reports that /bin/ls is being
# exec'ed (instead of our local copy).
if {[catch {exec cp /bin/ls $exepath} res]} {
fail "unable to copy /bin/ls: $res"
return
}
# "load" generation function for stap_run. It spawns our own copy of
# /bin/ls, waits 1 second, then kills it.
proc run_ls_1_sec {} {
global exepath
spawn $exepath
set exe_id $spawn_id
after 1000;
exec kill -INT -[exp_pid -i $exe_id]
return 0;
}
# figure out if this system supports single stepping (if we've got
# utrace and we're doing install testing)
set TEST_NAME "itrace single step check"
set single_step_p 0
if {![utrace_p]} {
untested "$TEST_NAME : no kernel utrace support found"
} elseif {![installtest_p]} {
untested $TEST_NAME
} else {
set single_step_p [stap_check_feature $TEST_NAME \
$itrace_single_step_script "has_single_step"]
}
# figure out if this system supports block stepping (if we've got
# utrace and we're doing install testing)
set TEST_NAME "itrace block step check"
set block_step_p 0
if {![utrace_p]} {
untested "$TEST_NAME : no kernel utrace support found"
} elseif {![installtest_p]} {
untested $TEST_NAME
} else {
set block_step_p [stap_check_feature $TEST_NAME \
$itrace_block_step_script "has_block_step"]
}
# Run the single step tests
set TEST_NAME "itrace_single1"
if {![utrace_p]} {
untested "$TEST_NAME : no kernel utrace support found"
} elseif {![installtest_p]} {
untested $TEST_NAME
} elseif {$single_step_p != 1} {
xfail "$TEST_NAME : no kernel single step support"
} else {
set script [format $itrace_single1_script $exepath]
stap_run $TEST_NAME run_ls_1_sec $itrace_single1_script_output -e $script
}
set TEST_NAME "itrace_single2"
if {![utrace_p]} {
untested "$TEST_NAME : no kernel utrace support found"
} elseif {![installtest_p]} {
untested $TEST_NAME
} elseif {$single_step_p != 1} {
xfail "$TEST_NAME : no kernel single step support"
} else {
set script [format $itrace_single2_script $exepath]
stap_run $TEST_NAME run_ls_1_sec $itrace_single2_script_output -e $script
}
# Run the block step tests
set TEST_NAME "itrace_block1"
if {![utrace_p]} {
untested "$TEST_NAME : no kernel utrace support found"
} elseif {![installtest_p]} {
untested $TEST_NAME
} elseif {$block_step_p != 1} {
xfail "$TEST_NAME : no kernel block step support"
} else {
set script [format $itrace_block1_script $exepath]
stap_run $TEST_NAME run_ls_1_sec $itrace_block1_script_output -e $script
}
set TEST_NAME "itrace_block2"
if {![utrace_p]} {
untested "$TEST_NAME : no kernel utrace support found"
} elseif {![installtest_p]} {
untested $TEST_NAME
} elseif {$block_step_p != 1} {
xfail "$TEST_NAME : no kernel block step support"
} else {
set script [format $itrace_block2_script $exepath]
stap_run $TEST_NAME run_ls_1_sec $itrace_block2_script_output -e $script
}
# Cleanup
exec rm -f $exepath
|