- Started regression test suite for SICS.

- The framework is there and testing motors works now
This commit is contained in:
koennecke
2006-08-16 14:17:42 +00:00
parent a7b4b4069d
commit c1dce3f145
8 changed files with 3837 additions and 0 deletions

260
test/mottest.tcl Normal file
View File

@ -0,0 +1,260 @@
#------------------------------------------------------------------------------
# Regression tests fo a motor. It is assumed that the motors name is
# brumm and that it has been initialized with the regress motor
# driver. Moreover, this has to be loaded after tcltest.tcl, testutil.tcl
# and sicstcldebug.tcl
#
# The regression motor has various errortypes which can be simulated:
# 0 = none
# 1 = failed start
# 2 = position fault
# 3 = hardware failure
# 4 = off position, without explicit position fault
# 5 = failed read
# 6 = keep running (for testing interupting)
# Moreover there is a recover flag which causes the motor to recover when it is
# 1
#
# copyright: see file COPYRIGHT
#
# Mark Koennecke, July 2006
#------------------------------------------------------------------------------
puts stdout "Testing motor code"
test motorpar-1.0 {Test sll} -body {
testPar "brumm softlowerlim" -175 User } -result OK
test motorpar-1.1 {Test slu} -body {
testPar "brumm softupperlim" 175 User } -result OK
test motorpar-1.2 {Test ss} -body {
testPar "brumm softzero" 5 User } -result OK
test motorpar-1.3 {Test interrupt} -body {
testPar "brumm interruptmode" 2 Mugger } -result OK
test motorpar-1.4 {Test accesscode} -body {
testPar "brumm accesscode" 3 Mugger } -result OK
test motorpar-1.5 {Test precision} -body {
testPar "brumm precision" .5 Mugger } -result OK
test motorpar-1.6 {Test fail} -body {
testPar "brumm failafter" 5 Mugger } -result OK
test motorpar-1.7 {Test retry} -body {
testPar "brumm maxretry" 5 Mugger } -result OK
test motorpar-1.8 {Test ignorefault} -body {
testPar "brumm ignorefault" 1 Mugger } -result OK
test motorpar-1.9 {Test movecount} -body {
testPar "brumm movecount" 12 Mugger } -result OK
test motorpar-1.10 {Test hardupper} -body {
testROPar "brumm hardupperlim" 180 } -result OK
test motorpar-1.11 {Test hardlower} -body {
testROPar "brumm hardlowerlim" -180 } -result OK
brumm recover 0
brumm errortype 0
test motor-1.0 {Test Normal Driving} -body {
testDrive brumm 10 User } -result OK
brumm errortype 6
test motor-1.1 {Test Interrupting} -body {
testDriveInterrupt brumm 0 } -result OK
brumm errortype 1
config rights User User
test motor-1.2 {Test Start Failure} -body {
set ans [drive brumm 20.3]
if { [string first "Failed to start motor" $ans] < 0} {
error "Failed to trigger motor start failure: $ans"
}
set ans [status]
if { [string first "Eager" $ans] < 0} {
error "Motor did not return from start failure"
}
return OK
} -result OK
brumm recover 1
test motor-1.3 {Test Recover from start problem} -body {
set ans [drive brumm 20.3]
if { [string first "Failed to start motor" $ans] < 0} {
error "Failed to trigger motor start failure"
}
set ans [status]
if { [string first "Eager" $ans] < 0} {
error "Motor did not return from start failure"
}
compareValue [SICSValue brumm] 20.3
} -result OK
brumm recover 0
brumm errortype 2
test motor-1.4 {Test Position Failure} -body {
set ans [drive brumm -20.3]
if { [string first "Position not reached" $ans] < 0} {
error "Failed to trigger motor position fault: $ans"
}
set ans [status]
if { [string first "Eager" $ans] < 0} {
error "Motor did not return from position failure"
}
set ans [SICSValue brumm]
if {abs($ans - -20.3) < .01} {
error "Motor positioned OK inspite of position fault"
}
return OK
} -result OK
brumm recover 1
test motor-1.6 {Test Position Failure Recover} -body {
set ans [drive brumm 20.3]
if { [string first "Position not reached" $ans] < 0} {
error "Failed to trigger motor position fault: $ans"
}
if { [string first "restarting" $ans] < 0} {
error "Restarting message not received"
}
set ans [status]
if { [string first "Eager" $ans] < 0} {
error "Motor did not return from position failure"
}
compareValue [SICSValue brumm] 20.3
return OK
} -result OK
brumm errortype 3
brumm recover 0
test motor-1.7 {Test Hardware Failure} -body {
set ans [drive brumm 20.3]
if { [string first "Hardware is mad" $ans] < 0} {
error "Failed to trigger motor hardware fault: $ans"
}
set ans [status]
if { [string first "Eager" $ans] < 0} {
error "Motor did not return from position failure"
}
set ans [SICSValue brumm]
if {abs($ans - 20.3) < .01} {
error "Motor positioned OK inspite of hardware fault"
}
return OK
} -result OK
brumm recover 1
test motor-1.8 {Test Hardware Failure Recover} -body {
set ans [drive brumm 20.3]
if { [string first "Hardware is mad" $ans] < 0} {
error "Failed to trigger motor hardware fault: $ans"
}
if { [string first "restarting" $ans] < 0} {
error "Restarting message not received"
}
set ans [status]
if { [string first "Eager" $ans] < 0} {
error "Motor did not return from hardware failure"
}
compareValue [SICSValue brumm] 20.3
return OK
} -result OK
brumm errortype 4
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"
}
if { [string first "restarting" $ans] < 0} {
error "Restarting message not received"
}
if { [string first "aborting" $ans] < 0} {
error "Aborting message not received"
}
set ans [status]
if { [string first "Eager" $ans] < 0} {
error "Motor did not return after consistent position problem"
}
set ans [SICSValue brumm]
if {abs($ans - -20.3) < .01} {
error "Motor positioned OK inspite of mispositioning"
}
return OK
} -result OK
brumm errortype 0
drive brumm 27.
brumm errortype 5
brumm recover 0
test motor-1.10 {Failed read} -body {
set ans [brumm]
if { [string first "Failed to read" $ans] < 0} {
error "Failed to trigger motor failed read"
}
if { [string first "Error obtaining position" $ans] < 0} {
error "Failed to abort reading"
}
if { [string first "cannot fix" $ans] < 0} {
error "Missing cannot fix message"
}
set ans [status]
if { [string first "Eager" $ans] < 0} {
error "Motor did not return after failed read"
}
return OK
} -result OK
brumm recover 1
test motor-1.11 {Failed read recover} -body {
set ans [brumm]
if { [string first "Failed to read" $ans] < 0} {
error "Failed to trigger motor failed read"
}
if { [string first "brumm =" $ans] < 0} {
error "Motor did not return value after fixing failed read"
}
set ans [status]
if { [string first "Eager" $ans] < 0} {
error "Motor did not return after failed read"
}
return OK
} -result OK
brumm errortype 0
drive brumm 27.
brumm recover 0
brumm errortype 3
test motor-1.12 {Motor Alarm} -body {
drive brumm -27
drive brumm -27
drive brumm -27
drive brumm -27
set ans [drive brumm -27]
if { [string first "MOTOR ALARM" $ans] < 0} {
error "Motor did not stop with Alarm"
}
set ans [status]
if { [string first "Eager" $ans] < 0} {
error "Motor did not return after Alarm"
}
brumm errortype 0
set ans [drive brumm -27]
if { [string first "sucessfully" $ans] < 0} {
error "Motor did not recover after Alarm"
}
return OK
} -result OK

13
test/sicsstat.tcl Normal file
View File

@ -0,0 +1,13 @@
exe batchpath ./
exe syspath ./
# Motor brumm
brumm sign 1.000000
brumm SoftZero 0.000000
brumm SoftLowerLim -180.000000
brumm SoftUpperLim 180.000000
brumm Fixed -1.000000
brumm InterruptMode 0.000000
brumm precision 0.100000
brumm ignorefault 0.000000
brumm AccessCode 2.000000
brumm movecount 10.000000

40
test/sicstcldebug.tcl Normal file
View File

@ -0,0 +1,40 @@
#------------------------------------------------------------------
# This is a helper file in order to debug SICS Tcl scripts. The idea
# is that a connection to a SICS interpreter at localhost:2911 is opened.
# Then unknown is reimplemented to send unknown commands (which must be
# SICS commands) to the SICS interpreter for evaluation. This is done
# with transact in order to figure out when SICS finished processing.
# Thus is should be possible to debug SICS Tcl scripts in a normal
# standalone interpreter without the overhead of restarting SICS
# all the time. It may even be possible to use one of the normal
# Tcl debuggers then....
#
# Mark Koennecke, February 2006
#------------------------------------------------------------------
set socke [socket localhost 2911]
gets $socke
puts $socke "Spy Spy"
flush $socke
gets $socke
#------------------------------------------------------------------
proc unknown args {
global socke
append com "transact " [join $args]
puts $socke $com
flush $socke
set reply ""
while {1} {
set line [gets $socke]
if {[string first TRANSACTIONFINISHED $line] >= 0} {
return $reply
} else {
append reply $line "\n"
}
}
}
#------------------------------------------------------------------
proc clientput args {
puts stdout [join $args]
}
#------------------------------------------------------------------

3354
test/tcltest.tcl Normal file

File diff suppressed because it is too large Load Diff

10
test/testinc.tcl Normal file
View File

@ -0,0 +1,10 @@
#------------------------------------------------------------------------------
# This is a prelude to source into tcl for testing regression tests.
# copyright: see file COPYRIGHT
#
# Mark Koennecke, July 2006
#------------------------------------------------------------------------------
source tcltest.tcl
namespace import tcltest::*
source testutil.tcl
source sicstcldebug.tcl

45
test/testini.tcl Normal file
View File

@ -0,0 +1,45 @@
# --------------------------------------------------------------------------
# Initialization script for testing SICS
#
# Started: Dr. Mark Koennecke, July 2006
#---------------------------------------------------------------------------
# O P T I O N S
# --------------- Initialize Tcl internals --------------------------------
# first all the server options are set
ServerOption ReadTimeOut 10
# timeout when checking for commands. In the main loop SICS checks for
# pending commands on each connection with the above timeout, has
# PERFORMANCE impact!
ServerOption AcceptTimeOut 10
# timeout when checking for connection req.
# Similar to above, but for connections
ServerOption ReadUserPasswdTimeout 500000
# time to wiat for a user/passwd to be sent from a client. Increase this
# if there is a problem connecting to a server due to network overload\
ServerOption ServerPort 2911
# the port number the server is going to listen at. The client MUST know
# this number in order to connect. It is in client.ini
ServerOption InterruptPort 2913
# The UDP port where the server will wait for Interrupts from clients.
# Obviously, clients wishing to interrupt need to know this number.
#---------------------------------------------------------------------------
# U S E R S
# than the SICS users are specified
# Syntax: SicsUser name password userRightsCode
SicsUser Mugger Mugger 1
SicsUser User User 2
SicsUser Spy Spy 3
#SicsUser Spy 007 1
Motor brumm regress
MakeDrive

26
test/testsics Executable file
View File

@ -0,0 +1,26 @@
#!/usr/bin/tclsh
#------------------------------------------------------------------------------
# This is a regression test for SICS. Before this can be used a SICServer must
# have been started with: SICServer testini.tcl. This file uses the
# tcltest package which comes with SICS for tests.
#
# copyright: see file COPYRIGHT
#
# Started: Mark Koennecke, July 2006
#------------------------------------------------------------------------------
# as of now we have tcl8.3 which has an outdated version of tcltest. We use
# a better version in a local file. Once tcl8.4 has made it into the distro
# I use, use the line below. We need tcltest 2.+
# package require tcltest
source tcltest.tcl
namespace import tcltest::*
source testutil.tcl
source sicstcldebug.tcl
#-------------- Test for motors
source mottest.tcl
#------------ print test summary
cleanupTests
exit 1

89
test/testutil.tcl Normal file
View File

@ -0,0 +1,89 @@
#------------------------------------------------------------------------------
# utility routines for testing SICS
#
# copyright: see file COPYRIGHT
#
# Mark Koennecke, July 2006
#------------------------------------------------------------------------------
proc SICSValue {command} {
set txt [eval $command]
set l [split $txt =]
return [string trim [lindex $l 1]]
}
#-----------------------------------------------------------------------------
proc compareValue {is should} {
if {[string is double $is] == 1} {
if {abs($should - $is) > .01} {
error "Bad compare is: $is, should $should"
}
} else {
if {[string compare $is $rhould] != 0} {
error "Bad compare is: $is, should $should"
}
}
return OK
}
#------------------------------------------------------------------------------
proc testPar {name testval priv } {
config rights Spy Spy
set value [SICSValue $name]
set res [eval $name $testval]
if {[string first ERROR $res] < 0} {
error "Managed to set parameter even if not allowed"
}
config rights $priv $priv
set res [eval $name $testval]
if {[string first ERROR $res] >= 0} {
error "Setting parameter failed with $res"
}
set readback [SICSValue $name]
compareValue $readback $testval
eval $name $value
return "OK"
}
#-------------------------------------------------------------------------------
proc testROPar {name val} {
config rights Mugger Mugger
set value [SICSValue $name]
compareValue $value $val
catch {$name [expr $val + 1]} msg
set value [SICSValue $name]
compareValue $value $val
config rights Spy Spy
return OK
}
#------------------------------------------------------------------------------
proc testDrive {name value priv} {
config rights Spy Spy
set ans [eval drive $name $value]
if {[string first ERROR $ans] < 0} {
error "Protection on drivable does not work"
}
config rights $priv $priv
set ans [eval drive $name $value]
if { [string first sucessfully $ans] < 0} {
error "Driving $name failed: $ans"
}
set readback [SICSValue $name]
compareValue $readback $value
config rights Spy Spy
return OK
}
#------------------------------------------------------------------------------
proc testDriveInterrupt {name value} {
global socke
config rights Mugger Mugger
run $name $value
puts $socke "INT1712 3"
flush $socke
set ans [eval status]
config rights Spy Spy
if {[string first Interrupt $ans] < 0} {
puts stdout $ans
error "Failed to abort driving"
}
if { [string first Eager $ans] < 0} {
error "Failed to finish driving"
}
return OK
}