summaryrefslogtreecommitdiffstats
path: root/testsuite/systemtap.base/sdt_misc.exp
blob: 8a0cdea233fa3f161cfd7a5ee26a6031246a0dd4 (plain)
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
set test "sdt_misc"

# Test miscellaneous features of .mark probes

# Compile a C program to use as the user-space probing target
set sup_srcpath "[pwd]/sdt_misc.c"
set supcplus_exepath "[pwd]/sdt_misc_cplus.x"
set fp [open $sup_srcpath "w"]
puts $fp "
#include <stdlib.h>
#include \"sdt_misc_.h\"

void
bar (int i)
{
  SDT_MISC_TEST_PROBE_2(i);
  if (i == 0)
    i = 1000;
  STAP_PROBE1(static_uprobes,test_probe_2,i);
}

void
baz (int i, char* s)
{
  STAP_PROBE1(static_uprobes,test_probe_0,i);
  if (i == 0)
    i = 1000;
  SDT_MISC_TEST_PROBE_3(i,s);
}

void
buz (int parm)
{
 struct astruct
  {
    int a;
    int b;
  };
  struct astruct bstruct = {parm, parm + 1};
  if (parm == 0)
    parm = 1000;
  DTRACE_PROBE1(sdt_misc,test_probe_4,&bstruct);
}

#ifndef NO_MAIN
int
main ()
{
  bar(2);
  baz(3,(char*)\"abc\");
  buz(4);
}
#endif
"
close $fp

set sup_stppath "[pwd]/sdt_misc.stp"
set fp [open $sup_stppath "w"]
puts $fp "
%( \$# > 1 %?
probe process(@1).library(@2).mark(\"test_probe_0\") 
%:
probe process(@1).mark(\"test_probe_0\") 
%)
{ 
  printf(\"In %s probe %#x\\n\", \$\$name, \$arg1)
}
%( \$# > 1 %?
probe process(@1).library(@2).mark(\"test_probe_2\") 
%:
probe process(@1).mark(\"test_probe_2\") 
%)
{
  printf(\"In %s probe %#x\\n\", \$\$name, \$arg1)
}
%( \$# > 1 %?
probe process(@1).library(@2).mark(\"test_probe_3\") 
%:
probe process(@1).mark(\"test_probe_3\") 
%)
{ 
  printf(\"In %s probe %#x %#x\\n\", \$\$name, \$arg1, \$arg2)
}
%( \$# > 1 %?
probe process(@1).library(@2).mark(\"test_probe_4\")
%:
probe process(@1).mark(\"test_probe_4\")
%)
{ 
  printf(\"In %s dtrace probe %#x %#x\\n\", \$\$name, \$arg1->a, \$arg1->b)
}
"
close $fp

set sup_dpath "[pwd]/sdt_misc_.d" 
set sup_hpath "[pwd]/sdt_misc_.h" 
set sup_opath "[pwd]/sdt_misc_.o" 
set fp [open $sup_dpath "w"]
puts $fp "
provider sdt_misc {
        probe test_probe_0 ();
	probe test_probe_2 (int i);
	probe test_probe_3 (int i, char* x);
	probe test_probe_4 (struct astruct arg);
};
struct astruct {int a; int b;};
"
close $fp

# Test dtrace

if {[installtest_p]} { 
    set dtrace $env(SYSTEMTAP_PATH)/dtrace 
} else {
    set dtrace $srcdir/../dtrace
}
if {[catch {exec $dtrace --types -h -s $sup_dpath} res]} {
    verbose -log "unable to run $dtrace: $res"
}
if {[catch {exec $dtrace --types -G -s $sup_dpath} res]} {
    verbose -log "unable to run $dtrace: $res"
}
if {[file exists $sup_hpath] && [file exists $sup_opath]} then {
    pass "$test dtrace"
} else {
    fail "$test dtrace"
    if { $verbose == 0 } {
    catch {exec rm -f $sup_srcpath $sup_hpath $sup_stppath}
    }
    return
}

if {[installtest_p]} { 
    set sdtdir $env(SYSTEMTAP_INCLUDES)
} else {
    set sdtdir $srcdir/../includes
}

set pbtype_flags {{""} {additional_flags=-O additional_flags=-DEXPERIMENTAL_KPROBE_SDT}}
set pbtype_mssgs {{uprobe} {kprobe}}

# Iterate pbtype_flags
for {set i 0} {$i < [llength $pbtype_flags]} {incr i} {
set pbtype_flag [lindex $pbtype_flags $i]
set pbtype_mssg [lindex $pbtype_mssgs $i]
set sup_exepath "[pwd]/sdt_misc-$pbtype_mssg.x"

set sup_flags "additional_flags=-I$srcdir/../includes/sys"
set sup_flags "$sup_flags additional_flags=-I$sdtdir"
set sup_flags "$sup_flags additional_flags=-g"
set sup_flags "$sup_flags additional_flags=$sup_opath"
set sup_flags "$sup_flags additional_flags=-I. $pbtype_flag"
set res [target_compile $sup_srcpath $sup_exepath executable $sup_flags]
if { $res != "" } {
    verbose "target_compile failed: $res" 2
    fail "$test compiling -g $pbtype_mssg"
    if { $verbose == 0 } {
    catch {exec rm -f $sup_srcpath $sup_hpath $sup_stppath}
    }
    return
} else {
    pass "$test compiling -g $pbtype_mssg"
}

if {![installtest_p]} {untested $test; return}
if {![utrace_p]} {
    untested "$test"
    if { $verbose == 0 } {
    catch {exec rm -f $sup_srcpath}
    }
    return
}

# Run stap on executable built with dtrace generated header file

set ok 0

verbose -log "spawn stap -c $sup_exepath $sup_stppath"
spawn stap -c $sup_exepath $sup_stppath $sup_exepath
expect {
    -timeout 180
    -re {In test_probe_2 probe 0x2} { incr ok; exp_continue }
    -re {In test_probe_0 probe 0x3} { incr ok; exp_continue }
    -re {In test_probe_3 probe 0x3 0x[0-9a-f][0-9a-f]} { incr ok; exp_continue }
    -re {In test_probe_4 dtrace probe 0x4 0x5} { incr ok; exp_continue }
    timeout { fail "$test (timeout)" }
    eof { }
}

wait

if {$ok == 5} { 
    pass "$test $pbtype_mssg"
} else {
    fail "$test ($ok) $pbtype_mssg"
}

# Test passing various C types to .mark probes

set sup_flags "$sup_flags $pbtype_flag additional_flags=-O0 "
set res [target_compile $srcdir/$subdir/sdt_types.c sdt_types.x executable $sup_flags]
if { $res != "" } {
    verbose "target_compile failed: $res" 2
    fail "$test compiling types -g $pbtype_mssg"
    return
} else {
    pass "$test compiling types -g $pbtype_mssg"
}

set ok 0
set fail "types"
verbose -log "spawn stap -c ./sdt_types.x $srcdir/$subdir/sdt_types.stp ./sdt_types.x"
spawn stap -c ./sdt_types.x $srcdir/$subdir/sdt_types.stp ./sdt_types.x

expect {
    -timeout 180
    -re {FAIL: [a-z_]+var} { regexp " .*$" $expect_out(0,string) s; 
	incr ok; set fail "$fail $s"; exp_continue }
    timeout { fail "$test (timeout)" }
    eof { }
}

wait

if { $ok != 0} {
    if { $pbtype_mssg == "uprobe" } {
	fail "$test $fail $pbtype_mssg"
    } else {
	# (needs cast)
	xfail "$test $fail $pbtype_mssg"
    }
} else {
    pass "$test types $pbtype_mssg"
}

# Test probe in shared object

set sup_srcmainpath "[pwd]/sdt_misc_.c"
set fp [open $sup_srcmainpath "w"]
puts $fp "
int
main ()
{
  bar(2);
  baz(3,(char*)\"abc\");
  buz(4);
}
"
close $fp

set sup_flags "$sup_flags additional_flags=-shared"
set sup_flags "$sup_flags additional_flags=-fPIC"
set sup_flags "$sup_flags additional_flags=-DNO_MAIN"
set sup_sopath "[pwd]/libsdt-$pbtype_mssg.so"
set sup_exepath "[pwd]/sdt_misc-$pbtype_mssg-shared.x"
set res0 [target_compile $sup_srcpath $sup_sopath executable $sup_flags ]
set sup0_flags "additional_flags=-g additional_flags=-Wl,-rpath,[pwd]"
set sup0_flags "$sup0_flags additional_flags=-L[pwd] additional_flags=-lsdt-$pbtype_mssg"
set res [target_compile $sup_srcmainpath $sup_exepath executable $sup0_flags ]
if { $res0 != "" || $res != "" } {
    verbose "target_compile failed: $res0 $res" 2
    fail "$test compiling -g -shared $pbtype_mssg"
    if { $verbose == 0 } {
    catch {exec rm -f $sup_srcpath $sup_srcmainpath}
    }
    return
} else {
    pass "$test compiling -g -shared $pbtype_mssg"
}

set ok 0
verbose -log "spawn stap -c $sup_exepath $sup_stppath $sup_exepath $sup_sopath"
if { $pbtype_mssg != "kprobe" } {
    spawn stap -c $sup_exepath $sup_stppath $sup_exepath $sup_sopath
} else {
    spawn stap -c $sup_exepath $sup_stppath $sup_sopath
}
expect {
    -timeout 180
    -re {In test_probe_2 probe 0x2} { incr ok; exp_continue }
    -re {In test_probe_0 probe 0x3} { incr ok; exp_continue }
    -re {In test_probe_3 probe 0x3 0x[0-9a-f][0-9a-f]} { incr ok; exp_continue }
    -re {In test_probe_4 dtrace probe 0x4 0x5} { incr ok; exp_continue }
    timeout { fail "$test (timeout)" }
    eof { }
}

wait

if {$ok == 5} { 
    pass "$test shared $pbtype_mssg"
} else {
    fail "$test ($ok) shared $pbtype_mssg"
}

# Test .mark probe wildcard matching

set ok 0
spawn stap -l "process(\"./sdt_types.x\").mark(\"*\")"
expect {
    -timeout 180
    -re {mark\(\"[a-z_]+\"\)} { incr ok; exp_continue }
    timeout { fail "$test (timeout)" }
    eof { }
}

if { $ok == 45 } {
    pass "$test wildcard $pbtype_mssg"
} else {
    fail "$test wildcard ($ok) $pbtype_mssg"
}

if { $verbose == 0 } {
    catch {exec rm -f libsdt-$pbtype_mssg.so sdt_misc-$pbtype_mssg.x sdt_misc-$pbtype_mssg-shared.x }
}
# for {set i 0}
}

if { $verbose == 0 } {
    catch {exec rm -f sdt_misc_.c sdt_misc.c sdt_misc_.d sdt_misc_.h sdt_misc_.o sdt_misc.stp sdt_types.x}
}