From 2f3e2d0ff0db8ee6a6824654263d44427d545e8f Mon Sep 17 00:00:00 2001 From: koennecke Date: Wed, 13 Sep 2006 07:16:59 +0000 Subject: [PATCH] - Added regression tests for a counter and the new MultiCounter - Enhanced regression tests for motors --- test/countertest.tcl | 271 +++++++++++++++++++++++++++++++++++++++++++ test/mottest.tcl | 47 +++++++- test/sicsstat.tcl | 12 ++ test/testini.tcl | 23 ++++ test/testsics | 11 +- test/testutil.tcl | 54 ++++++++- 6 files changed, 414 insertions(+), 4 deletions(-) create mode 100644 test/countertest.tcl diff --git a/test/countertest.tcl b/test/countertest.tcl new file mode 100644 index 00000000..291e0433 --- /dev/null +++ b/test/countertest.tcl @@ -0,0 +1,271 @@ +#------------------------------------------------------------- +# Testing of the counter module +# +# The regression counter has various errortypes which can be simulated: +# 0 = none +# 1 = failed start +# 2 = status failure +# 3 = pause fail +# 4 = continue fail +# 5 = failed read +# +# Another parameter is recover which causes the problem to go away +# when 1 +# +# TODO: What shall happen when pausing fails? Currently it continues +# counting. This may be exactly what we need, but???? +# +# This code needs the counter name two times: onxe as countername and +# as errorname. The purpose is that this module may be used for testing +# both the real and the multi counter. +# +# Mark Koennecke, September 2006 +#------------------------------------------------------------- +#set countername aba +#set errorname aba + +puts stdout "Testing counter: $countername" + +#--------------------------------------------------------------- +config rights Mugger Mugger +$errorname setpar errortype 1 0 + +test counter-1.0 {Test Mode Setting} -body { + config rights Spy Spy + set res [eval $countername setmode monitor] + if {[string first ERROR $res] < 0} { + error "Managed to set parameter even if not allowed" + } + config rights User User + set res [eval $countername setmode monitor] + if {[string first ERROR $res] >= 0} { + error "Setting parameter failed with $res" + } + set readback [SICSValue "$countername getmode"] + compareValue [string tolower $readback] monitor + config rights Spy Spy + set res [eval $countername setmode timer] + if {[string first ERROR $res] < 0} { + error "Managed to set parameter even if not allowed" + } + config rights User User + set res [eval $countername setmode timer] + if {[string first ERROR $res] >= 0} { + error "Setting parameter failed with $res" + } + set readback [SICSValue "$countername getmode"] + compareValue [string tolower $readback] timer + return "OK" +} -result OK +#------------------------------------------------------------------- +test counter-1.1 {Test Preset Setting} -body { + config rights Spy Spy + set val 12 + set res [eval $countername setpreset $val] + if {[string first ERROR $res] < 0} { + error "Managed to set parameter even if not allowed" + } + config rights User User + set res [eval $countername setpreset $val] + if {[string first ERROR $res] >= 0} { + error "Setting parameter failed with $res" + } + set readback [SICSValue "$countername getpreset"] + compareValue $readback $val + return "OK" +} -result OK +#--------------------------------------------------------------------- +test counter-1.3 {Test Normal Counting} -body { + config rights Spy Spy + set status [catch {testNBCounting "$countername countnb 10" 11} msg] + if {$status == 0} { + error "Counted in spite of lacking privilege" + } + config rights User User + testNBCounting "$countername countnb 10" 11 +} -result OK +#--------------------------------------------------------------------- +test counter-1.4 {Test Blocking Counting} -body { + config rights Spy Spy + set status [catch {testBlockCounting "$countername countnb 10" 11} msg] + if {$status == 0} { + error "Counted in spite of lacking privilege" + } + config rights User User + testBlockCounting "$countername countnb 10" 11 +} -result OK +#-------------------------------------------------------------------- +test counter-1.5 {Interrupted Counting} -body { + testInterruptedCount "$countername countnb 100" +} -result OK +#-------------------------------------------------------------------- +config rights User User + +test counter-1.51 {Pause Counting Test} -body { + global socke + $countername countnb 300 + exec sleep 1 + set ans [status] + if {[string first Counting $ans] < 0} { + error "Failed to start counting: $ans" + } + pause + exec sleep 1 + set ans [status] + if {[string first Paus $ans] < 0} { + error "Failed to pause counting: $ans" + } + puts $socke continue + flush $socke + exec sleep 1 + set ans [status] + if {[string first Count $ans] < 0} { + error "Failed to continue counting: $ans" + } + puts $socke "INT1712 3" + flush $socke + set ans [status] + return OK +} -result OK +#--------------------------------------------------------- +test counter-1.52 {Pause Interrupt Test} -body { + global socke + $countername countnb 300 + exec sleep 2 + set ans [status] + if {[string first Counting $ans] < 0} { + error "Failed to start counting: $ans" + } + pause + exec sleep 1 + set ans [status] + if {[string first Paus $ans] < 0} { + error "Failed to pause counting: $ans" + } + puts $socke "INT1712 3" + flush $socke + set ans [status] + if {[string first Eager $ans] < 0} { + error "Failed to interrupt paused counting: $ans" + } + return OK +} -result OK +#------------------------------------------------------------------- +test counter-1.53 {Counter Value Read Test} -body { + config rights User User + $countername count 10 + set ans [SICSValue "$countername gettime"] + compareValue $ans 10 + set ans [SICSValue "$countername getcounts"] + compareValue $ans 5 + set ans [SICSValue "$countername getmonitor 1"] + compareValue $ans 10 + set ans [SICSValue "$countername getmonitor 2"] + compareValue $ans 25 + set ans [SICSValue "$countername getmonitor 3"] + compareValue $ans 35 + set ans [SICSValue "$countername getmonitor 4"] + compareValue $ans 45 + set ans [SICSValue "$countername getmonitor 5"] + compareValue $ans 55 + set ans [SICSValue "$countername getmonitor 6"] + compareValue $ans 65 + return OK +} -result OK +#-------------------------------------------------------------------- +config rights Mugger Mugger +$errorname setpar errortype 1 1 +$errorname setpar recover 1 0 + +test counter-1.6 {Counting Start Failure} -body { + set ans [$countername countnb 100] + if { [string first "Counting aborted" $ans] < 0} { + error "Failed to trigger count start failure: $ans" + } + return OK +} -result OK +#--------------------------------------------------------------- +$errorname setpar errortype 1 1 +$errorname setpar recover 1 1 + +test counter-1.7 {Counting Start Failure with Recovery} -body { + set ans [$countername countnb 10] + if { [string first "WARNING" $ans] < 0} { + error "Failed to trigger count start failure: $ans" + } + set ans [SICSValue status] + if {[string first Counting $ans] < 0} { + error "Did not recover from start failure" + } + exec sleep 12 + set ans [SICSValue status] + if {[string first Eager $ans] < 0} { + error "Did not stop counting after start failure" + } + return OK +} -result OK +#---------------------------------------------------------------------- +$errorname setpar errortype 1 2 +$errorname setpar recover 1 0 + +test counter-1.8 {Counting Status Failure} -body { + set ans [$countername countnb 100] + set ans [status] + if { [string first "Full Stop called" $ans] < 0} { + error "Failed to trigger count start failure: $ans" + } + return OK +} -result OK +#--------------------------------------------------------------- +$errorname setpar errortype 1 2 +$errorname setpar recover 1 1 + +test counter-1.9 {Counting Status Failure with Recovery} -body { + set ans [$countername countnb 10] + set ans [status] + if { [string first "WARNING" $ans] < 0} { + error "Failed to trigger count start failure: $ans" + } + if {[string first Counting $ans] < 0} { + error "Did not recover from status failure" + } + exec sleep 12 + set ans [SICSValue status] + if {[string first Eager $ans] < 0} { + error "Did not stop counting after status failure" + } + return OK +} -result OK +#------------------------------------------------------------------- +$errorname setpar errortype 1 5 +$errorname setpar recover 1 0 + +test counter-1.10 {Counter Read Failure} -body { + set ans [$countername count 2] + if { [string first "Full Stop" $ans] < 0} { + error "Failed to trigger count read failure: $ans" + } + set ans [SICSValue status] + if {[string first Eager $ans] < 0} { + error "Did not stop counting after read failure" + } + return OK +} -result OK + +#---------------------------------------------------------------- +$errorname setpar errortype 1 5 +$errorname setpar recover 1 1 + +test counter-1.10 {Counter Read Recover} -body { + set ans [$countername count 2] + if { [string first "WARN" $ans] < 0} { + error "Failed to trigger count read failure: $ans" + } + set ans [SICSValue status] + if {[string first Eager $ans] < 0} { + error "Did not stop counting after read failure" + } + return OK +} -result OK + + diff --git a/test/mottest.tcl b/test/mottest.tcl index 111f1652..9c6f7b23 100644 --- a/test/mottest.tcl +++ b/test/mottest.tcl @@ -18,6 +18,7 @@ # copyright: see file COPYRIGHT # # Mark Koennecke, July 2006 +# #------------------------------------------------------------------------------ puts stdout "Testing motor code" @@ -169,7 +170,7 @@ test motor-1.8 {Test Hardware Failure Recover} -body { brumm errortype 4 -test motor-1.9 {Test Consistent mispositioning} -body { +test motor-1.9 {Test Consistent Mispositioning} -body { set ans [drive brumm -20.3] if { [string first "off position" $ans] < 0} { error "Failed to trigger motor off position" @@ -257,4 +258,46 @@ test motor-1.12 {Motor Alarm} -body { return OK } -result OK - \ No newline at end of file +brumm errortype 0 +config rights Mugger Mugger + +test motor-1.13 {Motor Sign} -body { + brumm sign 1 + drive brumm 27. + set old [SICSValue brumm] + brumm sign -1 + set newVal [SICSValue brumm] + set br [brumm sign] + brumm sign 1 + return [compareValue [expr $old * -1] $newVal] +} -result OK + +brumm sign 1. + +test motor-1.14 {Motor Recover} -body { + brumm sign -1. + brumm softzero 5 + set data [brumm list] + backup hugo.bck + recover hugo.bck + set newData [brumm list] + if {[string compare $data $newData] != 0} { + backup hugo2.bck + error "Recovery failed: look at diff between hugo.bck and hugo2.bck" + } + brumm sign 1 + brumm softzero 0 + set data [brumm list] + backup hugo.bck + recover hugo.bck + set newData [brumm list] + if {[string compare $data $newData] != 0} { + backup hugo2.bck + error "Recovery failed: look at diff between hugo.bck and hugo2.bck" + } + return OK +} -result OK + +config rights Spy Spy +test motorpar-1.15 {Test sign setting} -body { + testPar "brumm sign" -1 Mugger } -result OK diff --git a/test/sicsstat.tcl b/test/sicsstat.tcl index 6e638151..41306db0 100644 --- a/test/sicsstat.tcl +++ b/test/sicsstat.tcl @@ -11,3 +11,15 @@ brumm precision 0.100000 brumm ignorefault 0.000000 brumm AccessCode 2.000000 brumm movecount 10.000000 +# Counter aba +aba SetPreset 10.000000 +aba SetMode Timer +# Counter hugo +hugo SetPreset 10.000000 +hugo SetMode Timer +# Counter lieselotte +lieselotte SetPreset 10.000000 +lieselotte SetMode Timer +# Counter multi +multi SetPreset 10.000000 +multi SetMode Timer diff --git a/test/testini.tcl b/test/testini.tcl index ab1630a4..76b42b81 100644 --- a/test/testini.tcl +++ b/test/testini.tcl @@ -41,5 +41,28 @@ SicsUser User User 2 SicsUser Spy Spy 3 #SicsUser Spy 007 1 +#----------------- Motors --------------------------------------------------- Motor brumm regress MakeDrive + +#----------------- Counters ------------------------------------------------- +MakeCounter aba regress +MakeCounter hugo SIM -1. +MakeCounter lieselotte SIM -1. +#------------------------------ +proc SICSValue {command} { + set txt [eval $command] + set l [split $txt =] + return [string trim [lindex $l 1]] +} +#----------------------------- +proc multitransfer {} { + append res [SICSValue "aba gettime"] " " + for {set i 0} {$i < 7} {incr i} { + append res [SICSValue "aba getmonitor $i"] " " + } + return $res +} +#----------------------------------- +MakeMultiCounter multi aba hugo lieselotte +multi transferscript multitransfer diff --git a/test/testsics b/test/testsics index b2b7c006..c54151aa 100755 --- a/test/testsics +++ b/test/testsics @@ -18,7 +18,16 @@ source testutil.tcl source sicstcldebug.tcl #-------------- Test for motors -source mottest.tcl +#source mottest.tcl + +#-------------- Test Counter +set countername aba +set errorname aba +#source countertest.tcl + +#-------------- Test Multi Counter +set countername multi +source countertest.tcl #------------ print test summary cleanupTests diff --git a/test/testutil.tcl b/test/testutil.tcl index ef0cb52b..a5c6c5f9 100644 --- a/test/testutil.tcl +++ b/test/testutil.tcl @@ -17,7 +17,7 @@ proc compareValue {is should} { error "Bad compare is: $is, should $should" } } else { - if {[string compare $is $rhould] != 0} { + if {[string compare $is $should] != 0} { error "Bad compare is: $is, should $should" } } @@ -87,3 +87,55 @@ proc testDriveInterrupt {name value} { } return OK } +#--------------------------------------------------------------------- +proc testNBCounting {startCommand waitTime} { + set res [$startCommand] + if {[string first ERROR $res] >= 0} { + error "Starting count failed with $res" + } + exec sleep 1 + set res [SICSValue status] + if {[string first "Count" $res] < 0} { + error "Status does not say counting" + } + exec sleep $waitTime + set res [SICSValue status] + if {[string first "Eager" $res] < 0} { + error "Counting did not stop" + } + return "OK" +} +#---------------------------------------------------------------- +proc testBlockCounting {startCommand waitTime} { + set res [$startCommand] + if {[string first ERROR $res] >= 0} { + error "Starting count failed with $res" + } + exec sleep $waitTime + set res [SICSValue status] + if {[string first "Eager" $res] < 0} { + error "Counting did not stop" + } + return "OK" +} +#--------------------------------------------------------------- +proc testInterruptedCount {startCommand} { + global socke + set res [$startCommand] + if {[string first ERROR $res] >= 0} { + error "Starting count failed with $res" + } + puts $socke "INT1712 3" + flush $socke + exec sleep 10 + set ans [eval status] + config rights Spy Spy + if {[string first Interrupt $ans] < 0} { + puts stdout $ans + error "Failed to abort counting" + } + if { [string first Eager $ans] < 0} { + error "Failed to finish counting" + } + return OK +} \ No newline at end of file