Sync with 5.1.0
[deliverable/titan.core.git] / function_test / Tools / SAtester
1 #!/bin/sh
2 # the next line restarts using expect \
3 exec expect "$0" "$@"
4
5 #wait to delete a file until it finished running
6 proc _delete_files {filelist} {
7 foreach filename $filelist {
8 while { [file exists $filename] } {
9 if [ catch {file delete $filename} ] then {
10 puts "couldn't delete $filename , trying again in 1 sec"
11 exec sleep 1
12 }
13 }
14 }
15 }
16
17 proc _cleanup {} {
18 _delete_files [list Temp.log Temp.exe Temp \
19 Temp.o TempA.o EncRAW.o EncBER.o \
20 Temp.cc Temp.hh TempA.cc TempA.hh compile]
21 }
22
23
24
25 proc _errorlog {message} {
26
27 global err_counter
28 global errorfileID
29 global TCtitle
30
31 puts $errorfileID "------------------------------------------------------------------"
32 puts $errorfileID " FAILED TEST CASE: $TCtitle"
33 puts $errorfileID " ERROR MESSAGE : $message"
34 puts $errorfileID "------------------------------------------------------------------"
35 puts $errorfileID ""
36 incr err_counter
37 }
38
39 proc _compiler_err {} {
40 global sh_id
41 send -i $sh_id "compiler Temp.ttcn\n"
42 set timeout 10
43 expect {
44 timeout {_cleanup}
45 -i $sh_id "FATAL" {_errorlog "FATAL ERROR"; _cleanup}
46 -i $sh_id "egmentation" {_errorlog "SEGMENTATION FAULT"; _cleanup}
47 -i $sh_id "leakage" {_errorlog "MEMORY LEAKAGE"; _cleanup}
48 }
49 send -i $sh_id "\n"
50 expect {"$"}
51 }
52
53
54
55 proc _compiler {message} {
56 global sh_id
57 send -i $sh_id "compiler Temp.ttcn \n"
58 set timeout 10
59 puts ">>>DEBUG:$sh_id"
60 expect {
61 timeout {
62 puts "\n---------------------------------------"
63 puts "ERROR! NOT MATCHING MESSAGE, EXPECTED: "
64 puts $message
65 puts "---------------------------------------"
66 _errorlog "NOT MATCHING MESSAGE \n\n$message"
67 }
68 -i $sh_id -exact $message {
69 puts "\n---------------------------------------"
70 puts "MATCHING MESSAGE, EXPECTED: "
71 puts $message
72 puts "---------------------------------------"
73 }
74 }
75 puts "ended at: [exec date +"%H:%M:%S"]"
76 _cleanup
77
78
79 }
80
81 proc _executor {message coverage_args rt_2} {
82 global sh_id
83
84 if {![file exists Makefile]} {
85 puts "Can not find Makefile, you need one so that you can execute test case!!"
86 return
87 }
88 if {![file exists Temp.cfg]} {
89 puts "Can not find Temp.cfg, you need one so that you can execute test case!!"
90 return
91 }
92
93 spawn make clean
94 set timeout 20
95 expect {
96 -i $spawn_id -re "^.*\r\n" {exp_continue}
97 -i $spawn_id eof
98 wait -i $spawn_id
99 }
100
101 spawn make
102 set timeout 120
103 expect {
104 -i $spawn_id -re ".*\r\n" {exp_continue}
105 -i $spawn_id eof
106 wait -i $spawn_id
107 }
108
109 if {![file exists Temp] && ![file exists Temp.exe]} {
110 puts "\n---------------------------------------"
111 puts "Executable Temp cannot be found !!"
112 puts "---------------------------------------"
113 _errorlog "EXECUTABLE CANNOT BE FOUND"
114 return
115 }
116
117 set timeout 30
118 expect {
119 -i $sh_id -re "\r\n.*>>>> "
120 }
121
122 send -i $sh_id "./Temp Temp.cfg\n"
123 set timeout 120
124 expect {
125 -i $sh_id eof {_errorlog "NOT MATCHING MESSAGE, MESSAGE EXPECTED: \n\n$message"}
126 -i $sh_id "leak at" {_errorlog "MEMORY LEAKAGE"}
127 -i $sh_id -exact $message {
128 puts "\n---------------------------------------"
129 puts "MATCHING MESSAGE, EXPECTED: "
130 puts $message
131 puts "---------------------------------------"
132 expect {
133 -i $sh_id eof
134 -i $sh_id -re ".*\r\n" {exp_continue}
135 -i $sh_id -exact ">>>> " {}
136 }
137 }
138 -i $sh_id -re ".*\r\n" {exp_continue}
139 -i $sh_id -exact ">>>> " {
140 puts "\n---------------------------------------"
141 puts "NOT MATCHING MESSAGE, EXPECTED: "
142 puts $message
143 puts "---------------------------------------"
144 _errorlog "NOT MATCHING MESSAGE, MESSAGE EXPECTED: \n\n$message"}
145 timeout {
146 puts "\n---------------------------------------"
147 puts "ERROR! TIMEOUT OCCURED, MESSAGE EXPECTED: "
148 puts $message
149 puts "---------------------------------------"
150 _errorlog "TIMEOUT OCCURED, NOT MATCHING MESSAGE \n\n$message"
151 }
152 }
153 puts "ended at: [exec date +"%H:%M:%S"]"
154 _cleanup
155 }
156
157 spawn sh
158 set sh_id $spawn_id
159 send -i $sh_id "PS1='>>>> '\n"
160
161 set tc_counter 0
162 set err_counter 0
163 set errpostfix "_error"
164 set coverage_args ""
165 set rt_2 ""
166 set start_date [exec date +"%H:%M:%S"]
167
168 if {[lindex $argv 0] == "-coverage"} {set argv [lrange $argv 1 end]; set coverage_args "COVERAGE=1"; puts "Coverage mode enabled!"}
169 # RT2 comes after coverage
170 if {[lindex $argv 0] == "-rt2"} {set argv [lrange $argv 1 end]; set rt_2 "RT2=2"; puts "Function-test runtime enabled!"}
171
172 set errorfilename $argv$errpostfix
173
174 # The whole argument list is treated as a single file.
175 if {[file exists $argv]} {set TIfileID [open $argv r]} else {puts "File $argv does not exist!"}
176 if {[file exists Temp.ttcn]} {file delete Temp.ttcn}
177 if {[file exists TempA.asn]} {file delete Temp.asn}
178 if {[file exists $errorfilename]} {file delete $errorfilename}
179
180 while {-1 != [gets $TIfileID Line]} {
181 if {[string first <TC $Line 0] == 0} {incr tc_counter}
182 }
183 close $TIfileID
184
185 puts "\n-------------------------------------------------"
186 puts "$tc_counter test case(s) were found in file $argv"
187 puts "-------------------------------------------------"
188
189 set i 1
190 set errorfileID [open $errorfilename w]
191 set TIfileID [open $argv r]
192
193 while {$i <= $tc_counter} {
194
195 set tc_state ""
196
197 set tempfileID [open Temp.ttcn w]
198
199 while {(-1 != [gets $TIfileID Line])&&(0 != [string first <TC $Line 0])} {}
200
201 set TCtitle $Line
202
203 while {(-1 != [gets $TIfileID Line])&&(0 != [string first <STATIC $Line 0])} {}
204
205 if {0 == [string first <STATIC:ASN $Line 0]} {
206 set asnfileID [open TempA.asn w]
207 while {(-1 != [gets $TIfileID Line])&&(0 != [string first <STATIC $Line 0])} {puts $asnfileID $Line}
208 close $asnfileID
209 }
210
211 puts $tempfileID "module Temp {"
212
213 while {(-1 != [gets $TIfileID Line])&&(0 != [string first <RESULT> $Line 0])} {
214
215 if {0 == [string first <TTCN_TC:PURE_EXEC $Line 0]} {
216 set tc_state "pure_execute"
217 } else {
218 if {0 == [string first <TTCN_TC $Line 0]} {
219 puts $tempfileID "\ntype component TempComp {}\ntestcase TC() runs on TempComp \{"
220 set tc_state "present"
221 }
222
223 if {0 == [string first <TTCN_TC:EXEC $Line 0]} {set tc_state "execute"}
224 }
225
226 if {(0 != [string first # $Line 0])&&(0 != [string first <TT $Line 0])} {puts $tempfileID $Line}
227
228 }
229
230 if {($tc_state == "present")||($tc_state == "execute")} {puts $tempfileID "\} \n\ncontrol \{ \nexecute (TC()) \n\}";}
231
232 puts $tempfileID "}"
233
234 close $tempfileID
235
236
237 puts "\n-------------------------------------------------"
238 puts "Compiling test case $TCtitle ($i/$tc_counter)"
239 puts "started at: [exec date +"%H:%M:%S"]"
240 puts "-------------------------------------------------"
241
242 set result_mess ""
243
244 while {(-1 != [gets $TIfileID Line])&&(0 != [string first <END_TC> $Line 0])} {
245 if {([string length $Line] > 3)&&(0 != [string first # $Line 0])} {
246 if {$result_mess != ""} {set result_mess "$result_mess\n\n"}
247 set result_mess "$result_mess$Line"
248 }
249 }
250
251 if {([string length $result_mess] > 3)&&($tc_state != "execute")&&($tc_state != "pure_execute")} {_compiler $result_mess}
252 if {([string length $Line] > 3)&&($tc_state == "execute")} {_executor $result_mess $coverage_args $rt_2}
253 if {([string length $Line] > 3)&&($tc_state == "pure_execute")} {
254 _executor $result_mess $coverage_args $rt_2
255 }
256
257 incr i
258 }
259
260 close $TIfileID
261 close $errorfileID
262 if {$err_counter == 0} {file delete $errorfilename}
263
264 set timeout 1
265 # What's this?
266 send -i $sh_id "rm -f *%\n"
267
268 puts "\nCOMPILED $tc_counter TEST CASES"
269 puts "$err_counter TEST CASE FAILED"
270 if {$err_counter != 0} {
271 puts "SEE DETAILS IN $errorfilename FILE"
272 }
273
274 # starting end ending time
275 puts "started at: $start_date"
276 puts "finished at: [exec date +"%H:%M:%S"]"
277
278 #exit $err_counter
279
280 send -i $sh_id "exit \n"
281 expect {
282 timeout {
283 exit $err_counter
284 }
285 }
286 exit $err_counter
This page took 0.037468 seconds and 5 git commands to generate.