File: library.exp

package info (click to toggle)
systemtap 5.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 47,556 kB
  • sloc: cpp: 81,117; ansic: 54,933; xml: 49,795; exp: 43,595; sh: 11,526; python: 5,003; perl: 2,252; tcl: 1,312; makefile: 1,006; javascript: 149; lisp: 105; awk: 101; asm: 91; java: 70; sed: 16
file content (190 lines) | stat: -rw-r--r-- 6,143 bytes parent folder | download | duplicates (3)
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
set test "library"

proc cleanup_handler { verbose } {
    if { $verbose == 0 } {
	catch {exec rm -f libsdt.so sdt_misc.x }
    }
    catch {exec rm -f sdt_misc_.c sdt_misc_.h sdt_misc_.o }
}

proc error_handler { res message } {
    global test
    if { $res == 0 } {
	verbose $message 2
	fail "$test $message"
	return 1
    } else {
	pass "$test $message"
	return 0
    }
}

if {![installtest_p]} {untested $test; return}
if {![utrace_p]} {
    untested "$test"
    return
}
set stap_path $env(SYSTEMTAP_PATH)/stap
set dpath "[pwd]/sdt_misc_.d"
set hpath "[pwd]/sdt_misc_.h"
set opath "[pwd]/sdt_misc_.o"

set exepath "[pwd]/sdt_misc.x"
set sopath "libsdt.so"

# Run dtrace

if {[installtest_p]} {
    set dtrace $env(SYSTEMTAP_PATH)/dtrace
} else {
    set dtrace ../dtrace
}

verbose -log "$dtrace -DSTAP_SDT_V3 --types -h -s $srcdir/$subdir/sdt_misc_.d"
if {[catch {exec $dtrace --types -h -s $srcdir/$subdir/sdt_misc_.d} res]} {
    verbose -log "unable to run $dtrace: $res"
}
verbose -log "$dtrace -DSTAP_SDT_V3 --types -G -s $srcdir/$subdir/sdt_misc_.d"
if {[catch {exec $dtrace -DSTAP_SDT_V3 --types -G \
		-s $srcdir/$subdir/sdt_misc_.d} res]} {
    verbose -log "unable to run $dtrace: $res"
}
if { [error_handler [expr {[file exists $hpath]
			   && [file exists $opath]}] "dtrace"] } { 
    cleanup_handler $verbose
    return
}

set F additional_flags
set flags "$F=[sdt_includes] $F=$opath $F=-I. $F=-shared $F=-fPIC $F=-DNO_MAIN $F=-g"
set res [target_compile $srcdir/$subdir/sdt_misc.c $sopath executable $flags ]
if { [error_handler [expr {$res == ""}] "target_compile libsdt.so"] } {
    cleanup_handler $verbose
    return
}

set flags "$F=-Wl,-rpath,[pwd] $F=-L[pwd] $F=-lsdt $F=-DONLY_MAIN $F=-g"
set res [target_compile $srcdir/$subdir/sdt_misc.c $exepath executable $flags ]
if { [error_handler [expr {$res == ""}] "target_compile sdt_misc.x"] } {
    cleanup_handler $verbose
    return
}

# Test globbing

proc globbing_test { mssg script builddir } {
    global sopath exepath srcdir subdir stap_path
    eval set globs "{{*} {*libsdt*} $sopath {PATH/*libsdt*} PATH/$sopath}"
    foreach glob $globs {
	eval set test_glob [string map {PATH "$builddir"} "$glob"]
	foreach runtime [get_runtime_list] {
	    set test_name "sdt_misc"
	    if {$runtime != ""} {
		lappend test_name "($runtime)"
		spawn $stap_path --runtime=$runtime -c $exepath \
		    $script $exepath "$test_glob"
	    } elseif {[uretprobes_p]} {
		spawn $stap_path -c $exepath $script $exepath "$test_glob"
	    } else {
		untested "library $test_name $glob $mssg"
		continue
	    }
	    set ok 0
	    expect {
		-timeout 180
		-re {^bar begin\r\n} { incr ok; exp_continue }
		-re {^bar 2\r\n} { incr ok; exp_continue }
		-re {^In test_probe_2 probe 0x2\r\n} { incr ok; exp_continue }
		-re {^bar end\r\n} { incr ok; exp_continue }
		-re {^baz begin\r\n} { incr ok; exp_continue }
		-re {^baz 3 abc\r\n} { incr ok; exp_continue }
		-re {^In test_probe_0 probe 0x3\r\n} { incr ok; exp_continue }
		-re {^In test_probe_3 probe 0x3 0x[0-9a-f][0-9a-f]*\r\n} {
		    incr ok; exp_continue }
		-re {^baz end\r\n} { incr ok; exp_continue }
		-re {^buz begin\r\n} { incr ok; exp_continue }
		-re {^buz 4\r\n} { incr ok; exp_continue }
		-re {^In test_probe_4 dtrace probe 0x[0-9a-f][0-9a-f]*\r\n} {
		    incr ok; exp_continue }
		-re {^In test_probe_1 probe 0x0\r\n} { incr ok; exp_continue }
		-re {^buz end\r\n} { incr ok; exp_continue }
		-re {^WARNING:.*No DWARF information found.*\r\n} {
		    exp_continue }
		-re {^Missing separate debuginfos.*\r\n} { exp_continue }
		timeout { fail "$test_name (timeout)" }
		eof { }
	    }

	    catch {close}; catch {wait}
	    error_handler [expr {$ok == 15}] \
		"$test_name $glob $mssg ($ok != 15)"
	} ; # foreach runtime
    } ; # foreach glob
} ; # proc globbing_test

set script_path [fullpath $srcdir/$subdir/library.stp]
globbing_test "" $script_path "."
set savedir [pwd]
cd /tmp
globbing_test "rpath" $script_path $savedir
cd $savedir

# Test --ldd

foreach runtime [get_runtime_list] {
    set test_name "printf --ldd"
    if {$runtime != ""} {
	lappend test_name "($runtime)"
	spawn $stap_path --ldd -v -v -v -c $exepath -e "probe process(\"$exepath\").library(\"*\").statement(\"baz@sdt_misc.c\") \{printf(\"%s \", pn())\}"
    } elseif {[uprobes_p]} {
	spawn $stap_path --ldd -v -v -v -c $exepath -e "probe process(\"$exepath\").library(\"*\").statement(\"baz@sdt_misc.c\") \{printf(\"%s \", pn())\}"
    } else {
	untested "library $test_name"
	continue
    }
    set ok 0
    expect {
	-timeout 180
	-re {Added -d '.*libsdt.so' due to 'libsdt.so'}  {
	    incr ok; exp_continue }
	-re {Added -d '/lib.*/libm.so.[0-9]' due to 'libm.so.[0-9]'} {
	    incr ok; exp_continue }
	-re {Added -d '/lib.*/libc.so.[0-9]' due to 'libc.so.[0-9]'} {
	    incr ok; exp_continue }
	-re {Added -d '/lib.*/.*ld.*so'} { incr ok; exp_continue }
	timeout { fail "$test_name (timeout)" }
	eof { }
    }
    catch {close}; catch {wait}
    error_handler [expr {$ok >= 4}] "$test_name ($ok) ($ok != 4)"
}

# Test .exported. Notice we're only testing exported functions in our
# compiled 'libsdt' shared library. We could test exported functions
# in glibc, but to find them we'd need glibc debuginfo installed,
# which might or might not be present.

foreach runtime [get_runtime_list] {
    set test_name ".exported"
    if {$runtime != ""} {
	lappend test_name "($runtime)"
	spawn $stap_path --runtime=$runtime -c $exepath -e "probe process(\"$exepath\").library(\"$sopath\").function(\"*\").exported \{printf(\"%s \", pp())\}"
    } elseif {[uprobes_p]} {
	spawn $stap_path -c $exepath -e "probe process(\"$exepath\").library(\"$sopath\").function(\"*\").exported \{printf(\"%s \", pp())\}"
    } else {
	untested "library $test_name"
	continue
    }
    set ok 0
    expect {
	-timeout 180
	-re {libsdt.so.*bar} { incr ok; exp_continue }
	-re {libsdt.so.*baz} { incr ok; exp_continue }
	-re {libsdt.so.*buz} { incr ok; exp_continue }
	timeout { fail "$test_name (timeout)" }
	eof { }
    }
    catch {close}; catch {wait}
    error_handler [expr {$ok >= 3}] "$test_name ($ok) ($ok >= 3)"
}
cleanup_handler $verbose