2 # Test: This module contains the testing scaffolding necessary to implement
3 # testing in a consistant and easy manner.
5 # Functions & Variables
30 # Variables useful for testing
32 variable salira_prompt "\# "
33 variable success $salira_prompt
34 variable succeeded "succeeded"
36 variable failure "Error"
37 variable total_tests_run
38 variable total_tests_passed
39 variable total_tests_failed
43 # Internal state variables
46 variable test_base "/dview/defaria_default/Tools/testing"
50 variable machine "172.16.35.211"
55 # Reporting procedures
59 send_user "ERROR: [join $args]\n"
65 send_user "WARNING: [join $args]\n"
71 if {[info exist verbose]} {
72 send_user "[join $args]\n"
79 if {[info exist debug]} {
80 send_user "DEBUG: [join $args]\n"
85 send_user "[join $args]\n"
93 puts $logfile [join $args]
98 variable total_tests_passed
101 if {[info exist total_tests_passed]} {
102 incr total_tests_passed
104 set total_tests_passed 1
107 Log "Test PASSED: $test_name [join $args]"
111 variable total_tests_failed
114 if {[info exist total_tests_failed]} {
115 incr total_tests_failed
117 set total_tests_failed 1
120 Log "Test FAILED: $test_name [join $args]"
124 proc Login {machine {username root} {password root}} {
135 # Check to see if we are already connected
136 if {[info exist connection]} {
141 # Establish connection
142 spawn "telnet" $machine
143 set connection $spawn_id
145 Debug "Logging into $machine..."
147 # Look for Login prompt
152 Error "$machine is not responding"
162 Error "Password prompt not issued"
168 Debug "Logged into $machine"
171 Error "$machine appears to be dead"
175 if {![info exist depth]} {
188 if {[info exist leaveopen] && $leaveopen == 1} {
192 for {set i 0} {$i < $depth} {incr i} {
197 proc LoginVxWorks {{username root} {password root}} {
198 Debug "Logging into VxWorks console..."
207 Error "Fatal error: Unable to switch to VxWorks console"
212 # Due to a bug we need to hit return one more time
220 Error "Fatal error: Unable to switch to VxWorks console"
225 # OK now we are read to login
233 Error "Fatal error: VxWorks did not issue a password prompt!"
245 Error "Fatal error: Unable to switch to VxWorks console"
250 if {![info exist depth]} {
256 Debug "Logged into VxWorks console"
267 set date_n_time [clock format [clock seconds] -format "%m-%d-%Y-%H-%M"]
268 set logfilename "$test_base/results/testrun-$date_n_time.log"
269 set logfile [open $logfilename w]
271 Log ">>>\tStart test run [clock format [clock seconds]]"
274 proc Start {{name} {to_machine $Test::machine}} {
281 variable total_tests_run
286 set machine $to_machine
290 # For individual test attempt to Login. Note if StartSuite was
291 # called then we will already be connected so Login will simply
295 # $logfile will be already opened if StartSuite was called. If not
296 # then we are running a single test so open a logfile per test case
297 if {[info exists logfile] == 0} {
298 set scriptname [string range [info script] 0 \
299 [expr [string last "." [info script]] - 1]]
300 set logfilename "$scriptname.log"
301 set logfile [open $logfilename w]
304 Log ">\tStart test $test_name [clock format [clock seconds]]"
306 if {[info exists total_tests_run]} {
309 set total_tests_run 1
326 Log ">\tEnd test $test_name [clock format [clock seconds]]"
332 variable total_tests_run
333 variable total_tests_passed
334 variable total_tests_failed
336 # Set to zero any undefined variables
337 if {![info exist total_tests_run]} {
338 set total_tests_run 0
340 if {![info exist total_tests_passed]} {
341 set total_tests_passed 0
343 if {![info exist total_tests_failed]} {
344 set total_tests_failed 0
347 Log ">>>\tEnd test run [clock format [clock seconds]]"
348 Log "========================="
349 Log "Tests run:\t$total_tests_run"
350 Log "Tests passed:\t$total_tests_passed"
351 Log "Tests failed:\t$total_tests_failed"
352 Log "========================="
358 proc CLI {cmd {success ""}} {
359 if {$success == ""} {
360 set success $Test::salira_prompt
368 } "Error: Bad command" {
370 Log "Bad command $cmd encountered"
374 Log "Unable to execute $cmd - expecting $success"