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