| 1 |
# Contains common procs used by onthefly testcases. |
| 2 |
|
| 3 |
# Returns true if this subtest targets dyninst |
| 4 |
proc is_dyninst_subtest {subtest} { |
| 5 |
return [string match dyninst_* $subtest] |
| 6 |
} |
| 7 |
|
| 8 |
# Checks if the output matches the expected pattern. The 'patterns' arg is a |
| 9 |
# list of lines which are matched against the output using [string match], so |
| 10 |
# globby chars are allowed. |
| 11 |
proc is_valid_output {output patterns} { |
| 12 |
|
| 13 |
# i represents the index of the last pattern matched in 'patterns' list |
| 14 |
set i -1 |
| 15 |
foreach line [split $output "\n"] { |
| 16 |
|
| 17 |
# Passed all patterns |
| 18 |
if {$i >= [llength $patterns]} { |
| 19 |
verbose -log "no more patterns to match against" |
| 20 |
return 0 |
| 21 |
} |
| 22 |
|
| 23 |
# Matches the next pattern? |
| 24 |
set next_pattern [lindex $patterns [expr $i + 1]] |
| 25 |
if {[string match $next_pattern $line]} { |
| 26 |
incr i |
| 27 |
} else { |
| 28 |
verbose -log "expected: $next_pattern" |
| 29 |
verbose -log "received: $line" |
| 30 |
# continue; $i will be too small, but we can see more errors |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
# Check that we went through all the patterns |
| 35 |
if {$i >= [expr [llength $patterns] - 1]} { |
| 36 |
return 1 |
| 37 |
} else { |
| 38 |
return 0 |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
# Runs the subtest with the given parameters. See make_script for SUBTEST, |
| 43 |
# ENABLED, MAXTOGGLES, and TIMER. The 'args' parameter contains any extra |
| 44 |
# arguments to pass to stap. |
| 45 |
proc run_subtest {SUBTEST ENABLED MAXTOGGLES TIMER args} { |
| 46 |
global test |
| 47 |
|
| 48 |
# Prepare the script |
| 49 |
set script [make_script $SUBTEST $ENABLED $MAXTOGGLES $TIMER] |
| 50 |
|
| 51 |
# Run stap (and throw on error) |
| 52 |
if {[catch {run_stap $SUBTEST $args $script} stapout]} { |
| 53 |
verbose -log "stap error: $stapout" |
| 54 |
error "stap" |
| 55 |
return |
| 56 |
} |
| 57 |
|
| 58 |
return $stapout |
| 59 |
} |
| 60 |
|
| 61 |
proc cannot_test {subtest timer} { |
| 62 |
global test |
| 63 |
|
| 64 |
if {[is_dyninst_subtest $subtest] && ![dyninst_p]} { |
| 65 |
untested "$test - $subtest (no dyninst)" |
| 66 |
return 1 |
| 67 |
} |
| 68 |
|
| 69 |
if {$timer < 1000 && ![hrtimer_p]} { |
| 70 |
untested "$test - $subtest (no hrtimer)" |
| 71 |
return 1 |
| 72 |
} |
| 73 |
|
| 74 |
return 0 |
| 75 |
} |
| 76 |
|
| 77 |
# Same as run_subtest, except that the output is then checked for validity |
| 78 |
proc run_subtest_valid {subtest start_enabled max_toggles timer args} { |
| 79 |
global test |
| 80 |
if {[cannot_test $subtest $timer]} { return } |
| 81 |
|
| 82 |
if {[catch {eval run_subtest $subtest $start_enabled \ |
| 83 |
$max_toggles $timer $args} output]} { |
| 84 |
fail "$test - $subtest ($output)" |
| 85 |
return |
| 86 |
} |
| 87 |
|
| 88 |
# Prepare the pattern |
| 89 |
set pattern [make_pattern $subtest $start_enabled $max_toggles] |
| 90 |
|
| 91 |
# Check that the output is valid |
| 92 |
if {![is_valid_output $output $pattern]} { |
| 93 |
fail "$test - $subtest (invalid output)" |
| 94 |
return |
| 95 |
} |
| 96 |
|
| 97 |
pass "$test - $subtest (valid output)" |
| 98 |
} |
| 99 |
|
| 100 |
# Same as run_subtest, except that errors are caught and cause FAILs. If |
| 101 |
# run_subtest returns without errors, we PASS. |
| 102 |
proc run_subtest_stress {subtest start_enabled max_toggles timer args} { |
| 103 |
global test |
| 104 |
if {[cannot_test $subtest $timer]} { return } |
| 105 |
|
| 106 |
# We don't care about warnings/handler errors |
| 107 |
set args "$args --suppress-handler-errors -w" |
| 108 |
|
| 109 |
if {[catch {eval run_subtest $subtest $start_enabled \ |
| 110 |
$max_toggles $timer $args} output]} { |
| 111 |
fail "$test - $subtest ($output)" |
| 112 |
return |
| 113 |
} |
| 114 |
|
| 115 |
pass "$test - $subtest (survived)" |
| 116 |
} |
| 117 |
|