| 1 |
set test "library" |
| 2 |
|
| 3 |
proc cleanup_handler { verbose } { |
| 4 |
if { $verbose == 0 } { |
| 5 |
catch {exec rm -f libsdt.so sdt_misc.x } |
| 6 |
} |
| 7 |
catch {exec rm -f sdt_misc_.c sdt_misc_.h sdt_misc_.o } |
| 8 |
} |
| 9 |
|
| 10 |
proc error_handler { res message } { |
| 11 |
global test |
| 12 |
if { $res == 0 } { |
| 13 |
verbose $message 2 |
| 14 |
fail "$test $message" |
| 15 |
return 1 |
| 16 |
} else { |
| 17 |
pass "$test $message" |
| 18 |
return 0 |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
if {![installtest_p]} {untested $test; return} |
| 23 |
if {![utrace_p]} { |
| 24 |
untested "$test" |
| 25 |
return |
| 26 |
} |
| 27 |
set stap_path $env(SYSTEMTAP_PATH)/stap |
| 28 |
set dpath "[pwd]/sdt_misc_.d" |
| 29 |
set hpath "[pwd]/sdt_misc_.h" |
| 30 |
set opath "[pwd]/sdt_misc_.o" |
| 31 |
|
| 32 |
set exepath "[pwd]/sdt_misc.x" |
| 33 |
set sopath "libsdt.so" |
| 34 |
|
| 35 |
# Run dtrace |
| 36 |
|
| 37 |
if {[installtest_p]} { |
| 38 |
set dtrace $env(SYSTEMTAP_PATH)/dtrace |
| 39 |
} else { |
| 40 |
set dtrace ../dtrace |
| 41 |
} |
| 42 |
|
| 43 |
verbose -log "$dtrace -DSTAP_SDT_V3 --types -h -s $srcdir/$subdir/sdt_misc_.d" |
| 44 |
if {[catch {exec $dtrace --types -h -s $srcdir/$subdir/sdt_misc_.d} res]} { |
| 45 |
verbose -log "unable to run $dtrace: $res" |
| 46 |
} |
| 47 |
verbose -log "$dtrace -DSTAP_SDT_V3 --types -G -s $srcdir/$subdir/sdt_misc_.d" |
| 48 |
if {[catch {exec $dtrace -DSTAP_SDT_V3 --types -G \ |
| 49 |
-s $srcdir/$subdir/sdt_misc_.d} res]} { |
| 50 |
verbose -log "unable to run $dtrace: $res" |
| 51 |
} |
| 52 |
if { [error_handler [expr {[file exists $hpath] |
| 53 |
&& [file exists $opath]}] "dtrace"] } { |
| 54 |
cleanup_handler $verbose |
| 55 |
return |
| 56 |
} |
| 57 |
|
| 58 |
set F additional_flags |
| 59 |
set flags "$F=[sdt_includes] $F=$opath $F=-I. $F=-shared $F=-fPIC $F=-DNO_MAIN $F=-g" |
| 60 |
set res [target_compile $srcdir/$subdir/sdt_misc.c $sopath executable $flags ] |
| 61 |
if { [error_handler [expr {$res == ""}] "target_compile libsdt.so"] } { |
| 62 |
cleanup_handler $verbose |
| 63 |
return |
| 64 |
} |
| 65 |
|
| 66 |
set flags "$F=-Wl,-rpath,[pwd] $F=-L[pwd] $F=-lsdt $F=-DONLY_MAIN $F=-g" |
| 67 |
set res [target_compile $srcdir/$subdir/sdt_misc.c $exepath executable $flags ] |
| 68 |
if { [error_handler [expr {$res == ""}] "target_compile sdt_misc.x"] } { |
| 69 |
cleanup_handler $verbose |
| 70 |
return |
| 71 |
} |
| 72 |
|
| 73 |
# Test globbing |
| 74 |
|
| 75 |
proc globbing_test { mssg script builddir } { |
| 76 |
global sopath exepath srcdir subdir stap_path |
| 77 |
eval set globs "{{*} {*libsdt*} $sopath {PATH/*libsdt*} PATH/$sopath}" |
| 78 |
foreach glob $globs { |
| 79 |
eval set test_glob [string map {PATH "$builddir"} "$glob"] |
| 80 |
foreach runtime [get_runtime_list] { |
| 81 |
set test_name "sdt_misc" |
| 82 |
if {$runtime != ""} { |
| 83 |
lappend test_name "($runtime)" |
| 84 |
spawn $stap_path --runtime=$runtime -c $exepath \ |
| 85 |
$script $exepath "$test_glob" |
| 86 |
} elseif {[uretprobes_p]} { |
| 87 |
spawn $stap_path -c $exepath $script $exepath "$test_glob" |
| 88 |
} else { |
| 89 |
untested "library $test_name $glob $mssg" |
| 90 |
continue |
| 91 |
} |
| 92 |
set ok 0 |
| 93 |
expect { |
| 94 |
-timeout 180 |
| 95 |
-re {^bar begin\r\n} { incr ok; exp_continue } |
| 96 |
-re {^bar 2\r\n} { incr ok; exp_continue } |
| 97 |
-re {^In test_probe_2 probe 0x2\r\n} { incr ok; exp_continue } |
| 98 |
-re {^bar end\r\n} { incr ok; exp_continue } |
| 99 |
-re {^baz begin\r\n} { incr ok; exp_continue } |
| 100 |
-re {^baz 3 abc\r\n} { incr ok; exp_continue } |
| 101 |
-re {^In test_probe_0 probe 0x3\r\n} { incr ok; exp_continue } |
| 102 |
-re {^In test_probe_3 probe 0x3 0x[0-9a-f][0-9a-f]*\r\n} { |
| 103 |
incr ok; exp_continue } |
| 104 |
-re {^baz end\r\n} { incr ok; exp_continue } |
| 105 |
-re {^buz begin\r\n} { incr ok; exp_continue } |
| 106 |
-re {^buz 4\r\n} { incr ok; exp_continue } |
| 107 |
-re {^In test_probe_4 dtrace probe 0x[0-9a-f][0-9a-f]*\r\n} { |
| 108 |
incr ok; exp_continue } |
| 109 |
-re {^In test_probe_1 probe 0x0\r\n} { incr ok; exp_continue } |
| 110 |
-re {^buz end\r\n} { incr ok; exp_continue } |
| 111 |
-re {^WARNING:.*No DWARF information found.*\r\n} { |
| 112 |
exp_continue } |
| 113 |
-re {^Missing separate debuginfos.*\r\n} { exp_continue } |
| 114 |
timeout { fail "$test_name (timeout)" } |
| 115 |
eof { } |
| 116 |
} |
| 117 |
|
| 118 |
catch {close}; catch {wait} |
| 119 |
error_handler [expr {$ok == 15}] \ |
| 120 |
"$test_name $glob $mssg ($ok != 15)" |
| 121 |
} ; # foreach runtime |
| 122 |
} ; # foreach glob |
| 123 |
} ; # proc globbing_test |
| 124 |
|
| 125 |
set script_path [fullpath $srcdir/$subdir/library.stp] |
| 126 |
globbing_test "" $script_path "." |
| 127 |
set savedir [pwd] |
| 128 |
cd /tmp |
| 129 |
globbing_test "rpath" $script_path $savedir |
| 130 |
cd $savedir |
| 131 |
|
| 132 |
# Test --ldd |
| 133 |
|
| 134 |
foreach runtime [get_runtime_list] { |
| 135 |
set test_name "printf --ldd" |
| 136 |
if {$runtime != ""} { |
| 137 |
lappend test_name "($runtime)" |
| 138 |
spawn $stap_path --ldd -v -v -v -c $exepath -e "probe process(\"$exepath\").library(\"*\").statement(\"baz@sdt_misc.c\") \{printf(\"%s \", pn())\}" |
| 139 |
} elseif {[uprobes_p]} { |
| 140 |
spawn $stap_path --ldd -v -v -v -c $exepath -e "probe process(\"$exepath\").library(\"*\").statement(\"baz@sdt_misc.c\") \{printf(\"%s \", pn())\}" |
| 141 |
} else { |
| 142 |
untested "library $test_name" |
| 143 |
continue |
| 144 |
} |
| 145 |
set ok 0 |
| 146 |
expect { |
| 147 |
-timeout 180 |
| 148 |
-re {Added -d '.*libsdt.so' due to 'libsdt.so'} { |
| 149 |
incr ok; exp_continue } |
| 150 |
-re {Added -d '/lib.*/libm.so.[0-9]' due to 'libm.so.[0-9]'} { |
| 151 |
incr ok; exp_continue } |
| 152 |
-re {Added -d '/lib.*/libc.so.[0-9]' due to 'libc.so.[0-9]'} { |
| 153 |
incr ok; exp_continue } |
| 154 |
-re {Added -d '/lib.*/.*ld.*so'} { incr ok; exp_continue } |
| 155 |
timeout { fail "$test_name (timeout)" } |
| 156 |
eof { } |
| 157 |
} |
| 158 |
catch {close}; catch {wait} |
| 159 |
error_handler [expr {$ok >= 4}] "$test_name ($ok) ($ok != 4)" |
| 160 |
} |
| 161 |
|
| 162 |
# Test .exported. Notice we're only testing exported functions in our |
| 163 |
# compiled 'libsdt' shared library. We could test exported functions |
| 164 |
# in glibc, but to find them we'd need glibc debuginfo installed, |
| 165 |
# which might or might not be present. |
| 166 |
|
| 167 |
foreach runtime [get_runtime_list] { |
| 168 |
set test_name ".exported" |
| 169 |
if {$runtime != ""} { |
| 170 |
lappend test_name "($runtime)" |
| 171 |
spawn $stap_path --runtime=$runtime -c $exepath -e "probe process(\"$exepath\").library(\"$sopath\").function(\"*\").exported \{printf(\"%s \", pp())\}" |
| 172 |
} elseif {[uprobes_p]} { |
| 173 |
spawn $stap_path -c $exepath -e "probe process(\"$exepath\").library(\"$sopath\").function(\"*\").exported \{printf(\"%s \", pp())\}" |
| 174 |
} else { |
| 175 |
untested "library $test_name" |
| 176 |
continue |
| 177 |
} |
| 178 |
set ok 0 |
| 179 |
expect { |
| 180 |
-timeout 180 |
| 181 |
-re {libsdt.so.*bar} { incr ok; exp_continue } |
| 182 |
-re {libsdt.so.*baz} { incr ok; exp_continue } |
| 183 |
-re {libsdt.so.*buz} { incr ok; exp_continue } |
| 184 |
timeout { fail "$test_name (timeout)" } |
| 185 |
eof { } |
| 186 |
} |
| 187 |
catch {close}; catch {wait} |
| 188 |
error_handler [expr {$ok >= 3}] "$test_name ($ok) ($ok >= 3)" |
| 189 |
} |
| 190 |
cleanup_handler $verbose |