| 1 |
set test "tracepoints" |
| 2 |
|
| 3 |
set tracepoints {} |
| 4 |
spawn stap -l {kernel.trace("*")} |
| 5 |
expect { |
| 6 |
-timeout 60 |
| 7 |
-re {^kernel.trace[^\r\n]*\r\n} { |
| 8 |
append tracepoints $expect_out(0,string) |
| 9 |
exp_continue |
| 10 |
} |
| 11 |
timeout {} |
| 12 |
eof {} |
| 13 |
} |
| 14 |
catch {close}; catch { wait } |
| 15 |
pass "$test list [llength $tracepoints]" |
| 16 |
|
| 17 |
# Use this to test each tracepoint individually. |
| 18 |
#foreach tp $tracepoints { |
| 19 |
# set test "tracepoint $tp -p4" |
| 20 |
# if {[catch {exec stap -w -p4 -e "probe $tp { println($\$name, $\$vars) }"} res]} { |
| 21 |
# fail "$test $res" |
| 22 |
# } else { |
| 23 |
# pass "$test" |
| 24 |
# } |
| 25 |
#} |
| 26 |
|
| 27 |
# This tests all tracepoints all at once (much faster than the |
| 28 |
# above). We need to save the script to a file, since on systems with |
| 29 |
# lots of tracepoints the script length can be greater than the |
| 30 |
# command line allows. |
| 31 |
set script "probe begin {}\n" |
| 32 |
foreach tp $tracepoints { |
| 33 |
set script "$script probe $tp { println($\$system, $\$name, $\$vars) }\n" |
| 34 |
} |
| 35 |
set test_stppath "[pwd]/$test.stp" |
| 36 |
set test_fp [open $test_stppath "w"] |
| 37 |
puts $test_fp "$script" |
| 38 |
close $test_fp |
| 39 |
|
| 40 |
send_log "Trying stap -w -p4 $test_stppath\n" |
| 41 |
if {[catch {exec stap -w -p4 $test_stppath} res]} { |
| 42 |
fail "$test - can't compile" |
| 43 |
verbose -log "stap error: $res" |
| 44 |
} else { |
| 45 |
pass "$test - compiled" |
| 46 |
} |
| 47 |
if { $verbose == 0 } { catch { exec rm -f $test_stppath } } |
| 48 |
|
| 49 |
proc test_tp {tp {filter ""} {num -1}} { |
| 50 |
global test |
| 51 |
|
| 52 |
# Use the tp itself as the filter if no filter given |
| 53 |
if {![string length $filter]} { |
| 54 |
set filter $tp |
| 55 |
} |
| 56 |
|
| 57 |
set tp "kernel.trace(\"$tp\")" |
| 58 |
set err [catch {exec stap -l $tp} out options] |
| 59 |
if {$err} { |
| 60 |
set exit_reason [dict get $options -errorcode] |
| 61 |
# Check if stap died with nonzero error and we were expecting it (i.e. num == 0) |
| 62 |
if {[lindex $exit_reason 0] eq "CHILDSTATUS" && $num == 0} { |
| 63 |
pass "$test - $tp" |
| 64 |
} else { # stap wasn't supposed to die |
| 65 |
fail "$test - $tp" |
| 66 |
verbose -log "error: $out" |
| 67 |
} |
| 68 |
return |
| 69 |
} |
| 70 |
|
| 71 |
# Make into a list |
| 72 |
set lines [split $out "\n"] |
| 73 |
|
| 74 |
# Check that number expected matches if we care |
| 75 |
if {$num != -1 && $num != [llength $lines]} { |
| 76 |
fail "$test - $tp" |
| 77 |
verbose -log "expected $num results, but got [llength $lines]" |
| 78 |
return |
| 79 |
} |
| 80 |
|
| 81 |
# Check if every listed line matches the filter |
| 82 |
set filter "kernel.trace(\"$filter\")" |
| 83 |
foreach line $lines { |
| 84 |
if {![string match $filter $line]} { |
| 85 |
fail "$test - $tp" |
| 86 |
verbose -log "requested: $tp with filter $filter" |
| 87 |
verbose -log "received: $line" |
| 88 |
return |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
pass "$test - $tp" |
| 93 |
} |
| 94 |
|
| 95 |
# Do some syntax checking if we actually found tracepoints |
| 96 |
if {[string length $tracepoints]} { |
| 97 |
|
| 98 |
# Check if this listing displays system:tracepoint syntax |
| 99 |
if {![string match *:* [lindex $tracepoints 0]]} { |
| 100 |
|
| 101 |
# Consider this an error if kernel_v >= 2.6.32, which has |
| 102 |
# TRACE_SYSTEM support |
| 103 |
fail "$test - TRACE_SYSTEM not printed" |
| 104 |
|
| 105 |
} else { |
| 106 |
|
| 107 |
# The following tests assume there is a sched system with multiple |
| 108 |
# tracepoints, including sched_switch. |
| 109 |
|
| 110 |
# Wildcarded tp |
| 111 |
test_tp "sched:*" |
| 112 |
|
| 113 |
# Wildcarded system (this assumes only the sched system has a tp |
| 114 |
# called sched_switch) |
| 115 |
test_tp "*:sched_switch" "sched:sched_switch" 1 |
| 116 |
|
| 117 |
# Check that specifying just the tracepoint gives only that |
| 118 |
# tracepoint, and is listed with its system |
| 119 |
test_tp "sched_switch" "sched:sched_switch" 1 |
| 120 |
|
| 121 |
# Check that specifying the tracepoint and system uniquely still |
| 122 |
# works |
| 123 |
test_tp "sched:sched_switch" "sched:sched_switch" 1 |
| 124 |
|
| 125 |
# Test ? |
| 126 |
test_tp "sche?:sched_switc?" "sched:sched_switch" 1 |
| 127 |
|
| 128 |
# Boundary colons |
| 129 |
test_tp ":sched_switch" "sched:sched_switch" 1 |
| 130 |
|
| 131 |
# Corner error cases (0 indicates we expect stap to fail) |
| 132 |
test_tp "" "" 0 |
| 133 |
test_tp ":" "" 0 |
| 134 |
test_tp "bla:" "" 0 |
| 135 |
test_tp "sched:" "" 0 |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
if {![installtest_p]} { untested $test; return } |
| 140 |
|
| 141 |
set ::result_string {tracepoints OK} |
| 142 |
stap_run2 $srcdir/$subdir/$test.stp -w |
| 143 |
|
| 144 |
# Now test tracepoints2.stp |
| 145 |
append test 2 |
| 146 |
|
| 147 |
set ::result_string {sched:sched_switch} |
| 148 |
stap_run2 $srcdir/$subdir/$test.stp |