How these tests work:
Dejagnu finds all *.c files, compiles them and runs them in a temporary
-directory while running the systemtap script sys.stp. To avoid
-recompiling sys.stp over and over, the test.exp is smart enough to
-compile sys.stp once and save the module.
+directory while running the systemtap script sys.stp.
-
-You can run all the tests here with
-> runtest test.exp
-
-You can run single tests with
+If you need to know why a test is failing you can look in the test log, or
> gcc -o testname testname.c
->./test.tcl testname
-
-OR, if you want to run multiple tests and don't want all the delays
-with recompiling sys.stp each time,
-
-> stap -kp4 sys.stp
-Keeping temporary directory "/tmp/stapPThTaQ"
-> ./test.tcl testname /tmp/stapPThTaQ/*.ko
-> ./test.tcl testname2 /tmp/stapPThTaQ/*.ko
-...
-> rm -rf /tmp/stapPThTaQ
-
-Finally, if you need to know why a test is failing, use
-"test-debug.tcl" exactly as above. After running the test, it will open a
-window with the results and expected results.
-
+> test-debug.tcl testname
HOW TO WRITE TESTS
+source $srcdir/$subdir/test.tcl
+
proc test_procedure {} {
global srcdir subdir
set wd [pwd]
if {$do_64_bit_pass} {
foreach filename [lsort [glob $pattern]] {
- set file [file tail [string range $filename 0 end-2]]
- if {![installtest_p]} { untested $file; continue }
- target_compile $filename $wd/$file executable $flags
- send_log "Testing 64-bit ${file}\n"
- set res [exec $srcdir/$subdir/test.tcl $file $filename]
+ set testname [file tail [string range $filename 0 end-2]]
+ if {![installtest_p]} { untested $testname; continue }
+ send_log "Testing 64-bit ${testname}\n"
+ set res [run_one_test $filename $flags]
if {$res == "PASS"} {
- pass "$file"
+ pass "$testname"
} elseif {$res == "UNSUPP"} {
- unsupported "$file not supported on this arch"
+ unsupported "$testname not supported on this arch"
} else {
- fail "64-bit $file"
+ fail "64-bit $testname"
send_log "$res\n"
}
- catch {exec rm -f $wd/$file}
}
}
if {$do_32_bit_pass} {
foreach filename [lsort [glob $pattern]] {
- set file [file tail [string range $filename 0 end-2]]
- if {![installtest_p]} { untested $file; continue }
- target_compile $filename $wd/$file executable $flags
- send_log "Testing 32-bit ${file}\n"
- set res [exec $srcdir/$subdir/test.tcl $file $filename]
+ set testname [file tail [string range $filename 0 end-2]]
+ if {![installtest_p]} { untested $testname; continue }
+ send_log "Testing 32-bit ${testname}\n"
+ set res [run_one_test $filename $flags]
if {$res == "PASS"} {
- pass "32-bit $file"
+ pass "32-bit $testname"
} elseif {$res == "UNSUPP"} {
- unsupported "$file not supported on this arch"
+ unsupported "$testname not supported on this arch"
} else {
- fail "32-bit $file"
+ fail "32-bit $testname"
send_log "$res\n"
}
- catch {exec rm -f $wd/$file}
}
}
}
-#!/usr/bin/env expect
-
set dir ""
set current_dir ""
proc cleanup {} {
- global dir current_dir
- if {$current_dir != ""} {
- cd $current_dir
- if {$dir != ""} {exec rm -rf $dir}
- set current_dir ""
- }
- exit 0
+ global dir current_dir
+ if {$current_dir != ""} {
+ cd $current_dir
+ set current_dir ""
+ }
+ if {$dir != ""} {
+# puts "rm -rf $dir"
+ exec rm -rf $dir
+ set dir ""
+ }
}
-proc usage {progname} {
- puts "Usage: $progname testname"
+proc cleanup_and_exit {} {
+# puts "cleanup_and_exit"
cleanup
+ exit 0
}
proc bgerror {error} {
puts "ERROR: $error"
cleanup
}
-trap {cleanup} SIGINT
-set testname [lindex $argv 0]
-if {$testname == ""} {
- usage $argv0
- exit
-}
-
-set filename [lindex $argv 1]
-if {$filename == ""} {
- set filename "${testname}.c"
- set sys_prog "../sys.stp"
-} else {
- set sys_prog "[file dirname [file normalize $filename]]/sys.stp"
-}
-set cmd "stap -c ../${testname} ${sys_prog}"
-
-# Extract the expected results
-# Use the preprocessor so we can ifdef tests in and out
+trap {cleanup_and_exit} SIGINT
-set ccmd "gcc -E -C -P $filename"
-catch {eval exec $ccmd} output
+proc run_one_test {filename flags} {
+ global dir current_dir
-set ind 0
-foreach line [split $output "\n"] {
- if {[regsub {//} $line {} line]} {
- set line "$testname: [string trimleft $line]"
+ set testname [file tail [string range $filename 0 end-2]]
+ set result "UNSUPP $testname"
- regsub -all {\(} $line {\\(} line
- regsub -all {\)} $line {\\)} line
- regsub -all {\|} $line {\|} line
-
- regsub -all NNNN $line {[\-0-9]+} line
- regsub -all XXXX $line {[x0-9a-fA-F]+} line
-
- set results($ind) $line
- incr ind
- }
-}
-
-if {$ind == 0} {
- puts "UNSUPP"
- cleanup
- exit
-}
-
-if {[catch {exec mktemp -d staptestXXXXX} dir]} {
- puts stderr "Failed to create temporary directory: $dir"
- cleanup
-}
+ if {[catch {exec mktemp -td staptestXXXXX} dir]} {
+ puts stderr "Failed to create temporary directory: $dir"
+ cleanup
+ }
-set current_dir [pwd]
-cd $dir
-catch {eval exec $cmd} output
+ target_compile $filename $dir/$testname executable $flags
+
+ set sys_prog "[file dirname [file normalize $filename]]/sys.stp"
+ set cmd "stap -c $dir/${testname} ${sys_prog}"
+
+ # Extract the expected results
+ # Use the preprocessor so we can ifdef tests in and out
+
+ set ccmd "gcc -E -C -P $filename"
+ catch {eval exec $ccmd} output
+
+ set ind 0
+ foreach line [split $output "\n"] {
+ if {[regsub {//} $line {} line]} {
+ set line "$testname: [string trimleft $line]"
+
+ regsub -all {\(} $line {\\(} line
+ regsub -all {\)} $line {\\)} line
+ regsub -all {\|} $line {\|} line
+
+ regsub -all NNNN $line {[\-0-9]+} line
+ regsub -all XXXX $line {[x0-9a-fA-F]+} line
+
+ set results($ind) $line
+ incr ind
+ }
+ }
-set i 0
-foreach line [split $output "\n"] {
- if {[regexp $results($i) $line]} {
- incr i
- if {$i >= $ind} {break}
+ if {$ind == 0} {
+ puts "UNSUPP"
+ cleanup
+ return
}
-}
-if {$i >= $ind} {
- puts "PASS"
-} else {
- puts "$testname FAILED. output of \"$cmd\" was:"
- puts "------------------------------------------"
- puts $output
- puts "------------------------------------------"
- puts "RESULTS: (\'*\' = MATCHED EXPECTED)"
+
+ set current_dir [pwd]
+ cd $dir
+
+ catch {eval exec $cmd} output
+
set i 0
foreach line [split $output "\n"] {
- if {[regexp "${testname}: " $line]} {
- if {[regexp $results($i) $line]} {
- puts "*$line"
- incr i
- if {$i >= $ind} {break}
- } else {
- puts "$line"
- }
+ if {[regexp $results($i) $line]} {
+ incr i
+ if {$i >= $ind} {break}
}
}
- if {$i < $ind} {
- puts "--------- EXPECTED and NOT MATCHED ----------"
- }
- for {} {$i < $ind} {incr i} {
- puts "$results($i)"
+ if {$i >= $ind} {
+ set result "PASS"
+ puts "PASS $testname"
+ } else {
+ set result "FAIL $testname"
+ puts "$testname FAILED. output of \"$cmd\" was:"
+ puts "------------------------------------------"
+ puts $output
+ puts "------------------------------------------"
+ puts "RESULTS: (\'*\' = MATCHED EXPECTED)"
+ set i 0
+ foreach line [split $output "\n"] {
+ if {[regexp "${testname}: " $line]} {
+ if {[regexp $results($i) $line]} {
+ puts "*$line"
+ incr i
+ if {$i >= $ind} {break}
+ } else {
+ puts "$line"
+ }
+ }
+ }
+ if {$i < $ind} {
+ puts "--------- EXPECTED and NOT MATCHED ----------"
+ }
+ for {} {$i < $ind} {incr i} {
+ puts "$results($i)"
+ }
}
+ cleanup
+ return $result
}
-cleanup