Initial add of defaria.com
[clearscm.git] / defaria.com / Computers / code / testing / bin / tester
1 #!/usr/bin/expect --
2 ################################################################################
3 #
4 # File:         tester
5 # Description:  This is the test driver program. It is responsible for running
6 #               all tests based on category, etc.
7 # Author:       Andrew@DeFaria.com
8 # Created:      Fri Jun  6 15:37:15 PDT 2003
9 # Language:     Expect
10 #
11 # (c) Copyright 2003, Andrew@DeFaria.com, all rights reserved
12 #
13 ################################################################################
14 # Source in the Testing package
15 set test_base "/dview/defaria_default/Tools/testing"
16 source "$test_base/bin/TestPkg.tcl"
17
18 namespace import Test::*
19
20 # Globals
21 set machine     ""
22 set class       ""
23 set test        ""
24
25 proc usage {} {
26   Display "Usage: tester \[-u\] \[-v\] \[-d\] \[-c <class>\] \[-t <test>\] <IP Address>"
27   Display ""
28   Display "Where:"
29   Display ""
30   Display "\t-u\tUsage (this screen)"
31   Display "\t-v\tTurn on verbose mode"
32   Display "\t-d\tTurn on debug mode"
33   Display "\t-c\tRun only <class> tests"
34   Display "\t-t\tRun only <test>"
35
36   exit 1
37 }
38
39 proc ExecTestCase {test class} {
40   variable debug
41   variable test_base
42
43   cd "$test_base/tests/$class"
44
45   if {[catch {source $test}]} {
46     Warning "Internal problems executing test $test"
47     # If debug is on then re-source the test to see the errors
48 #    if {$Test::debug == 1} {
49 #    Debug "Re-sourcing test..."
50       source $test
51     }
52   }
53 }
54
55 proc ExecTestClass {class} {
56   variable test_base
57
58   cd "$test_base/tests/$class"
59
60   if {[catch {set tests [lsort [glob *.exp]]}]} {
61     Warning "No tests in class $class"
62   } else {
63     set nbr_tests [llength $tests]
64
65     if {$nbr_tests == 1} {
66       Log ">>\tStart $class class of tests ($nbr_tests test)"
67     } else {
68       Log ">>\tStart $class class of tests ($nbr_tests tests)"
69     }
70
71     foreach test $tests {
72       ExecTestCase $test $class
73     }
74
75     Log ">>\tEnd $class class of tests"
76   }
77
78   cd ".."
79 }
80
81 proc ExecAllTests {} {
82   variable test_base
83
84   cd "$test_base/tests"
85
86   foreach class [exec "ls"] {
87     if {[file isdirectory $class]} {
88       ExecTestClass $class
89     }
90   }
91 }
92
93 proc GetParms {argv argc} {
94   # Other machines to try:
95   #     172.16.35.210
96   #     172.16.35.230
97
98   variable machine
99   variable class
100   variable test
101
102   set index 0
103
104   while {$index < $argc} {
105     set arg [lindex $argv $index]
106
107     switch -- $arg {
108       -u {
109         usage
110       }
111
112       -c {
113         incr index
114         set class [lindex $argv $index]
115       }
116
117       -t {
118         incr index
119         set test [lindex $argv $index]
120       }
121
122       -v {
123         set Test::verbose 1
124       }
125
126       -d {
127         set Test::debug 1
128       }
129
130       default {
131         set machine $arg
132       }
133     }
134
135     incr index
136   }
137 }
138
139 # Main
140 GetParms $argv $argc
141
142 if {$machine == ""} {
143 #  Warning "Defaulting to machine $Test::machine"
144   set machine $Test::machine
145 }
146
147 if {$class != ""} {
148   if {[file isdirectory "$test_base/tests/$class"] == 0} {
149     Error "Class $class not found ($test_base/$class)"
150   }
151 }
152
153 if {$test != ""} {
154   if {$class == ""} {
155     Error "You must specify the test class when performing individual test case runs"
156   } else {
157     if {[file exists "$test_base/tests/$class/$test"] == 0} {
158       Error "Test $test not found ($test_base/$class/$test)"
159     }
160   }
161 }
162   
163 # Log into card
164 Login $machine
165
166 # Start test(s)
167 if {$test != ""} {
168   ExecTestCase $test $class
169 } else {
170   StartSuite
171
172   if {$class != ""} {
173     ExecTestClass $class
174   } else {
175     ExecAllTests
176   }
177
178   EndSuite
179 }
180