| 1 |
set outp [] |
| 2 |
|
| 3 |
# Used to get file length for testing when -w is not specified. |
| 4 |
# The debuginfod file and annotated source file should be of equal length. |
| 5 |
# file is the filename to check the length of |
| 6 |
proc file_len {filename} { |
| 7 |
set fd [open $filename r] |
| 8 |
set i 0 |
| 9 |
while { [gets $fd line] > -1 } { incr i } |
| 10 |
close $fd |
| 11 |
return $i |
| 12 |
} |
| 13 |
|
| 14 |
|
| 15 |
set test "stap-profile-annotate" |
| 16 |
set c_arg "/usr/bin/stress --cpu 4 -t 10" |
| 17 |
|
| 18 |
if {![installtest_p]} { untested $test; return } |
| 19 |
|
| 20 |
if { ! [ file exists "/usr/bin/stress" ] } { |
| 21 |
untested "$test: /usr/bin/stress not present. Skipping..."; |
| 22 |
return |
| 23 |
} |
| 24 |
|
| 25 |
if { ! [info exists env(DEBUGINFOD_URLS)] } { |
| 26 |
untested "$test: DEBUGINFOD_URLS un set" |
| 27 |
return |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
# Command to find a lib to profile on the system |
| 32 |
# There may be multiple, so pick the last one, hoping it's the one |
| 33 |
# /usr/bin/stress is linked against. OTOH since stap-profile-annotate |
| 34 |
# invokes stap with -c stress --ldd, the right one will be found anyway. |
| 35 |
set lib [lindex [glob /lib*/libc.so.*] end] |
| 36 |
|
| 37 |
set test "source-annotate -c, -w=null, debuginfod functionality" |
| 38 |
# Flag to check if -c is found |
| 39 |
set c 0 |
| 40 |
# Lists for checking if debuginfod files exists and |
| 41 |
# annotate files are annotated appropriately |
| 42 |
set annotated_paths [] |
| 43 |
set dbg_paths [] |
| 44 |
set buildids [] |
| 45 |
|
| 46 |
spawn stap-profile-annotate -vvv -d $lib -c $c_arg -T 50 |
| 47 |
expect { |
| 48 |
-timeout 180 |
| 49 |
-re "'-c', '$c_arg'" { incr c ; exp_continue } |
| 50 |
|
| 51 |
# Collect debuginfod file locations |
| 52 |
-re "Stored debuginfod-find source file as ((.*)\#\#(\S+\..))" { append dbg_paths "$expect_out(1,string) "; exp_continue } |
| 53 |
|
| 54 |
# Collect profile-'buildid' locations |
| 55 |
-re {hits in (profile-(.*?)/.*\..+ )over} { append annotated_paths $expect_out(1,string); |
| 56 |
append buildids "$expect_out(2,string) "; exp_continue } |
| 57 |
eof {append outp $expect_out(buffer);} |
| 58 |
timeout { fail "$test: Unexpected timeout" } |
| 59 |
} |
| 60 |
|
| 61 |
# If c is not found |
| 62 |
if { !$c } { |
| 63 |
fail "$test: -c option not found in stap_args"; |
| 64 |
} else { pass $test } |
| 65 |
|
| 66 |
# Remove duplicates from both path lists |
| 67 |
set failme 0 |
| 68 |
foreach b $buildids { |
| 69 |
set cur_dbg [] |
| 70 |
set cur_ann [] |
| 71 |
foreach d $dbg_paths { |
| 72 |
if { [ regexp "$b" $d ] } { append cur_dbg "$d "} |
| 73 |
} |
| 74 |
foreach a $annotated_paths { |
| 75 |
if { [ regexp "$b" $a ] } { append cur_ann "$a " } |
| 76 |
} |
| 77 |
# This for loop assumes that both $annotated_paths and dbg_paths |
| 78 |
# are in an order such that annotated_paths[0] is the annotated |
| 79 |
# version of dbg_paths[0] |
| 80 |
for { set i 0 } { $i < [ llength $cur_dbg ] } { incr i } { |
| 81 |
set dbg [lindex $cur_dbg $i] |
| 82 |
set ann [lindex $cur_ann $i] |
| 83 |
set dbg_len [ file_len $dbg ] |
| 84 |
set ann_len [ file_len $ann ] |
| 85 |
if {$dbg_len != $ann_len} { set failme 1 } |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
if { $failme > 0 } { fail "$test length mismatch" } else { pass $test } |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
# Test to see if -w 0 only prints annotated source lines into files |
| 94 |
set test "source-annotate -w=0" |
| 95 |
set annotated_paths [] |
| 96 |
spawn stap-profile-annotate -w 0 -T 30 -d $lib -vvv |
| 97 |
expect { |
| 98 |
-timeout 180 |
| 99 |
# Collect profile-'buildid' locations |
| 100 |
-re {hits in (profile-(.*?)/.*\..+ )over} { append annotated_paths $expect_out(1,string); exp_continue} |
| 101 |
timeout { fail "$test: Unexpected timeout" } |
| 102 |
} |
| 103 |
|
| 104 |
set failme 0 |
| 105 |
foreach a $annotated_paths { |
| 106 |
set fd [open $a r] |
| 107 |
while { [gets $fd line] > -1 } { |
| 108 |
if { ![regexp {[0-9]{7} } $line] } { |
| 109 |
set failme 1 |
| 110 |
} |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
if { $failme > 0 } then { fail "$test: Line present in $a without hit count" } else { pass $test } |