| 1 |
# Script for testing $$vars, $$parms, $$locals |
| 2 |
# |
| 3 |
# This works by grep'ing for the format strings produced in pass-3, then |
| 4 |
# comparing that $$vars is the same as $$parms + $$locals. |
| 5 |
# |
| 6 |
# NB: With PR3217 compiled-printf code, we can't tell as easily what was |
| 7 |
# generated. However, there's still the ifdef'ed STP_LEGACY_PRINT code which |
| 8 |
# has the format string we care about here. If that ever goes away, we'll |
| 9 |
# probably have to fall back to comparing pass-2 output instead. |
| 10 |
# |
| 11 |
# NB2: We FAIL if any of the functions tested have no locals or no |
| 12 |
# params to ensure we're not testing a null hypothesis. |
| 13 |
|
| 14 |
set test "vars" |
| 15 |
|
| 16 |
proc get_listings { probe_point } { |
| 17 |
if {![catch {exec stap -l ${probe_point} 2>@1} output]} { |
| 18 |
return [split $output "\n"] |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
proc parse_lineno { function line } { |
| 23 |
if {[regexp "\[^:\]+:(\[0-9\]+)\"" $line dummy submatch]} { |
| 24 |
verbose -log "parsed lineno $submatch in line $line" |
| 25 |
return $submatch |
| 26 |
} else { |
| 27 |
verbose -log "can't parse lineno in $line" |
| 28 |
return 0 |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
proc func_exists { function } { |
| 33 |
set probe_point "kernel.function\(\"$function\"\)" |
| 34 |
set line [get_listings $probe_point] |
| 35 |
if {$line == ""} { |
| 36 |
return 0 |
| 37 |
} else { |
| 38 |
return 1 |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
proc get_first_valid_lineno { function } { |
| 43 |
set linenos "" |
| 44 |
set probe_point "kernel.statement\(\"$function:*\"\)" |
| 45 |
set line [lindex [get_listings $probe_point] 0] |
| 46 |
return [parse_lineno $function $line] |
| 47 |
} |
| 48 |
|
| 49 |
proc grab_C_statements { probe_point type } { |
| 50 |
|
| 51 |
set cmd [concat stap -p3 -e { "probe kernel.statement(\"$probe_point\") {print (\$\$$type)}" } \ |
| 52 |
| grep {"_stp_snprintf.*="} \ |
| 53 |
| head -n 1 \ |
| 54 |
| sed -e {"s/^.*MAXSTRINGLEN, \"//"} -e "s/\".*$//"] |
| 55 |
catch {eval exec $cmd} out |
| 56 |
|
| 57 |
if {$out == ""} { |
| 58 |
error "no output for $type" |
| 59 |
} else { |
| 60 |
verbose -log "output for $type: $out" |
| 61 |
} |
| 62 |
|
| 63 |
return $out |
| 64 |
} |
| 65 |
|
| 66 |
proc get_vars { probe_point } { |
| 67 |
set vars [grab_C_statements $probe_point vars] |
| 68 |
|
| 69 |
# syntax check of $$vars c statement |
| 70 |
set syntax_ok [regexp "(\[a-z_\]+=%#llx *)+" $vars] |
| 71 |
if {!$syntax_ok} { |
| 72 |
error "bad vars syntax" |
| 73 |
verbose -log "vars is $vars" |
| 74 |
} |
| 75 |
|
| 76 |
return $vars |
| 77 |
} |
| 78 |
|
| 79 |
proc get_parms { probe_point } { |
| 80 |
return [grab_C_statements $probe_point parms] |
| 81 |
} |
| 82 |
|
| 83 |
proc get_locals { probe_point } { |
| 84 |
return [grab_C_statements $probe_point locals] |
| 85 |
} |
| 86 |
|
| 87 |
proc test_function { function } { |
| 88 |
global test |
| 89 |
set subtest "$test - $function" |
| 90 |
|
| 91 |
if {! [func_exists $function]} { |
| 92 |
untested "$subtest - doesn't exist" |
| 93 |
return |
| 94 |
} |
| 95 |
|
| 96 |
set lineno [get_first_valid_lineno $function] |
| 97 |
if {$lineno == 0} { |
| 98 |
fail "$subtest (no first lineno)" |
| 99 |
return |
| 100 |
} else { |
| 101 |
pass "$subtest (first lineno is $lineno)" |
| 102 |
} |
| 103 |
|
| 104 |
if {[catch { |
| 105 |
set probe_point "$function:$lineno" |
| 106 |
set vars [get_vars $probe_point] |
| 107 |
set parms [get_parms $probe_point] |
| 108 |
set locals [get_locals $probe_point] |
| 109 |
} err]} { |
| 110 |
fail "$subtest ($err)" |
| 111 |
return |
| 112 |
} else { |
| 113 |
pass "$subtest" |
| 114 |
} |
| 115 |
|
| 116 |
# $$vars should be equivalent to $$parms + $$locals |
| 117 |
if {![string equal $vars "$parms $locals"]} { |
| 118 |
fail "$subtest (parms/locals)" |
| 119 |
verbose -log "vars=$vars=" |
| 120 |
verbose -log "rest=$parms $locals=" |
| 121 |
} else { |
| 122 |
pass "$subtest (parms/locals)" |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
# Test a few different functions |
| 127 |
test_function {bio_copy_user@*/bio.c} |
| 128 |
test_function {bio_copy_user_iov@*/bio.c} |
| 129 |
test_function {vfs_read@fs/read_write.c} |