From 770794f1d24a6bfb4eacabcc8f272e4bb44890ab Mon Sep 17 00:00:00 2001 From: hunt Date: Wed, 19 Sep 2007 16:35:02 +0000 Subject: [PATCH] 2007-09-19 Martin Hunt PR 4931 * test-debug.tcl (cleanup): Remove print. * README: Update. * syscall.exp: Source test.tcl and call run_one_test() from there. * test.tcl: Rewrite as a function. Do compilation as well as testing. Compile into and execute in a directory in /tmp. --- testsuite/systemtap.syscall/ChangeLog | 10 ++ testsuite/systemtap.syscall/README | 27 +--- testsuite/systemtap.syscall/syscall.exp | 34 ++-- testsuite/systemtap.syscall/test-debug.tcl | 1 - testsuite/systemtap.syscall/test.tcl | 180 +++++++++++---------- 5 files changed, 121 insertions(+), 131 deletions(-) diff --git a/testsuite/systemtap.syscall/ChangeLog b/testsuite/systemtap.syscall/ChangeLog index 3be84fdf0..c9d8077b0 100644 --- a/testsuite/systemtap.syscall/ChangeLog +++ b/testsuite/systemtap.syscall/ChangeLog @@ -1,3 +1,13 @@ +2007-09-19 Martin Hunt + PR 4931 + * test-debug.tcl (cleanup): Remove print. + * README: Update. + * syscall.exp: Source test.tcl and call run_one_test() + from there. + * test.tcl: Rewrite as a function. Do compilation + as well as testing. Compile into and execute in + a directory in /tmp. + 2007-09-17 Martin Hunt * timer.c (main): Remove the return value checks. diff --git a/testsuite/systemtap.syscall/README b/testsuite/systemtap.syscall/README index 41e6d8957..480bd8cdd 100644 --- a/testsuite/systemtap.syscall/README +++ b/testsuite/systemtap.syscall/README @@ -1,32 +1,11 @@ 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 diff --git a/testsuite/systemtap.syscall/syscall.exp b/testsuite/systemtap.syscall/syscall.exp index e9ea9537b..2313403f5 100644 --- a/testsuite/systemtap.syscall/syscall.exp +++ b/testsuite/systemtap.syscall/syscall.exp @@ -1,3 +1,5 @@ +source $srcdir/$subdir/test.tcl + proc test_procedure {} { global srcdir subdir set wd [pwd] @@ -29,20 +31,18 @@ proc test_procedure {} { 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} } } @@ -61,20 +61,18 @@ proc test_procedure {} { 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} } } } diff --git a/testsuite/systemtap.syscall/test-debug.tcl b/testsuite/systemtap.syscall/test-debug.tcl index 3497e41bc..13e0ad54d 100755 --- a/testsuite/systemtap.syscall/test-debug.tcl +++ b/testsuite/systemtap.syscall/test-debug.tcl @@ -6,7 +6,6 @@ set current_dir "" proc cleanup {} { global dir current_dir - puts "Cleanup" if {$current_dir != ""} { cd $current_dir if {$dir != ""} {exec rm -rf $dir} diff --git a/testsuite/systemtap.syscall/test.tcl b/testsuite/systemtap.syscall/test.tcl index 8c228cba4..24a9642f7 100755 --- a/testsuite/systemtap.syscall/test.tcl +++ b/testsuite/systemtap.syscall/test.tcl @@ -1,113 +1,117 @@ -#!/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 -- 2.43.5