| 1 |
set self parse-semok |
| 2 |
set test_suffix "parse-semok" |
| 3 |
|
| 4 |
# This test is somewhat similar to |
| 5 |
# testsuite/parseok/unparser.stp. Here we're going to: |
| 6 |
# |
| 7 |
# 1) See if a systemtap script passes -p2, so we know the script is |
| 8 |
# semantically correct. |
| 9 |
# 2) If so, try running the output of -p1 (parsed output) through |
| 10 |
# -p2. If this passes, we know the parsed output is also semantically |
| 11 |
# correct. |
| 12 |
# |
| 13 |
# If we get any failures here, then we know the parsed output isn't |
| 14 |
# semantically corect. |
| 15 |
|
| 16 |
# Create a temporary directory we can use. |
| 17 |
if {[catch {exec mktemp -d -t staptestXXXXXX} tmpdir]} { |
| 18 |
verbose -log "Failed to create temporary directory: $tmpdir" |
| 19 |
return |
| 20 |
} |
| 21 |
|
| 22 |
# Notice that by default we're just testing the scripts in the |
| 23 |
# 'buildok' (pass 4) directory. If "verbose" is on, we also test the |
| 24 |
# scripts in the 'semok' (pass 2) and 'transok' (pass 3) directories. |
| 25 |
# |
| 26 |
# Notice we never test the scripts in the 'parseok' directory, since |
| 27 |
# those tests are designed to be parsed (-p1), but aren't necessarily |
| 28 |
# semantically correct (i.e. they might not pass -p2). |
| 29 |
if { $verbose } { |
| 30 |
set dirlist [list semok transok buildok] |
| 31 |
} else { |
| 32 |
set dirlist [list buildok] |
| 33 |
} |
| 34 |
foreach dir $dirlist { |
| 35 |
foreach file [lsort [glob -nocomplain $srcdir/$dir/*.stp]] { |
| 36 |
set test "${dir}/[file tail $file]" |
| 37 |
set full_test "${test} ${test_suffix}" |
| 38 |
set extra_args "" |
| 39 |
|
| 40 |
# Most of the "ok" test cases use '#! stap ...'. Try to read |
| 41 |
# this information. |
| 42 |
set f [open $file r] |
| 43 |
set firstbits [gets $f] |
| 44 |
close $f |
| 45 |
if [regexp -line {\#! stap (.*)} $firstbits -> stap_args] { |
| 46 |
# Parse arguments. |
| 47 |
set arg_fail 0 |
| 48 |
foreach arg $stap_args { |
| 49 |
if {[ string index $arg 0 ] != "-" } { break } |
| 50 |
set ch_idx 1 |
| 51 |
while {1} { |
| 52 |
set opt_ch [ string index $arg $ch_idx ] |
| 53 |
if { $opt_ch == "" } { break } |
| 54 |
incr ch_idx |
| 55 |
switch $opt_ch { |
| 56 |
p { |
| 57 |
# Ignore "pass" options. |
| 58 |
incr ch_idx; continue |
| 59 |
} |
| 60 |
g { append extra_args " -g"; continue } |
| 61 |
t { append extra_args " -t"; continue } |
| 62 |
w { append extra_args " -w"; continue } |
| 63 |
v { append extra_args " -v"; continue } |
| 64 |
W { append extra_args " -W"; continue } |
| 65 |
u { append extra_args " -u"; continue } |
| 66 |
- { |
| 67 |
# Handle long arguments ("--FOO") by just |
| 68 |
# adding them. |
| 69 |
append extra_args " $arg"; break |
| 70 |
} |
| 71 |
default { |
| 72 |
verbose -log "unknown argument '${opt_ch}'" |
| 73 |
set arg_fail 1 |
| 74 |
break |
| 75 |
} |
| 76 |
} |
| 77 |
} |
| 78 |
} |
| 79 |
if {$arg_fail == 0} { |
| 80 |
pass "${full_test} - arg parsing" |
| 81 |
} else { |
| 82 |
fail "${full_test} - arg parsing" |
| 83 |
continue |
| 84 |
} |
| 85 |
} else { |
| 86 |
# If "stap" wasn't on the first line of the script, this isn't |
| 87 |
# a systemtap script, but a shell script that will run |
| 88 |
# systemtap. We'll have to skip these. |
| 89 |
untested "$full_test - shell script" |
| 90 |
continue |
| 91 |
} |
| 92 |
|
| 93 |
# 1) See if the script is semantically correct. |
| 94 |
set cmd [concat stap -p2 ${extra_args} ${file}] |
| 95 |
verbose -log "Running $cmd" |
| 96 |
if {[catch {eval exec ${cmd}} res]} { |
| 97 |
verbose -log "$res" |
| 98 |
untested "${full_test} - not semok" |
| 99 |
continue |
| 100 |
} |
| 101 |
pass "${full_test} - semok" |
| 102 |
|
| 103 |
# 2) The test is semantically correct. Now let's see if the parsed |
| 104 |
# output is semantically correct. |
| 105 |
|
| 106 |
# 2a) First, get the parsed output. This should work since it |
| 107 |
# passed -p2 above (so -p1 should work). |
| 108 |
set tmpfile "${tmpdir}/[file rootname [file tail $file]].p1" |
| 109 |
set cmd [concat stap -p1 ${extra_args} ${file} > ${tmpfile}] |
| 110 |
verbose -log "Running $cmd" |
| 111 |
if {[catch {eval exec ${cmd}} res]} { |
| 112 |
verbose -log "$res" |
| 113 |
fail "${full_test} - parsing?" |
| 114 |
continue |
| 115 |
} |
| 116 |
pass "${full_test} - parsing" |
| 117 |
|
| 118 |
# 2b) See if the -p1 output is semantically correct. |
| 119 |
set cmd [concat stap -p2 ${extra_args} ${tmpfile}] |
| 120 |
verbose -log "Running $cmd" |
| 121 |
if {[catch {eval exec ${cmd}} res]} { |
| 122 |
verbose -log "$res" |
| 123 |
fail "${full_test} - parsed output is not semok" |
| 124 |
continue |
| 125 |
} |
| 126 |
pass "${full_test} - parsed output is semok" |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
# Cleanup |
| 131 |
if { $verbose == 0 } { catch {exec /bin/rm -rf $tmpdir} } |