Debian Codegraph @

function_test/Tools/SAtester

raw symbols SCIP
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} {
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 start_date [exec date +"%H:%M:%S"]
166
167 if {[lindex $argv 0] == "-coverage"} {set argv [lrange $argv 1 end]; set coverage_args "COVERAGE=1"; puts "Coverage mode enabled!"}
168 # RT2 comes after coverage
169 if {[lindex $argv 0] == "-rt2"} {set argv [lrange $argv 1 end]; set env(RT2) yes; puts "Function-test runtime enabled!"}
170
171 set errorfilename $argv$errpostfix
172
173 # The whole argument list is treated as a single file.
174 if {[file exists $argv]} {set TIfileID [open $argv r]} else {puts "File $argv does not exist!"}
175 if {[file exists Temp.ttcn]} {file delete Temp.ttcn}
176 if {[file exists TempA.asn]} {file delete Temp.asn}
177 if {[file exists $errorfilename]} {file delete $errorfilename}
178
179 while {-1 != [gets $TIfileID Line]} {
180 if {[string first <TC $Line 0] == 0} {incr tc_counter}
181 }
182 close $TIfileID
183
184 puts "\n-------------------------------------------------"
185 puts "$tc_counter test case(s) were found in file $argv"
186 puts "-------------------------------------------------"
187
188 set i 1
189 set errorfileID [open $errorfilename w]
190 set TIfileID [open $argv r]
191
192 while {$i <= $tc_counter} {
193
194 set tc_state ""
195
196 set tempfileID [open Temp.ttcn w]
197
198 while {(-1 != [gets $TIfileID Line])&&(0 != [string first <TC $Line 0])} {}
199
200 set TCtitle $Line
201
202 while {(-1 != [gets $TIfileID Line])&&(0 != [string first <STATIC $Line 0])} {}
203
204 if {0 == [string first <STATIC:ASN $Line 0]} {
205 set asnfileID [open TempA.asn w]
206 while {(-1 != [gets $TIfileID Line])&&(0 != [string first <STATIC $Line 0])} {puts $asnfileID $Line}
207 close $asnfileID
208 }
209
210 puts $tempfileID "module Temp {"
211
212 while {(-1 != [gets $TIfileID Line])&&(0 != [string first <RESULT> $Line 0])} {
213
214 if {0 == [string first <TTCN_TC:PURE_EXEC $Line 0]} {
215 set tc_state "pure_execute"
216 } else {
217 if {0 == [string first <TTCN_TC $Line 0]} {
218 puts $tempfileID "\ntype component TempComp {}\ntestcase TC() runs on TempComp \{"
219 set tc_state "present"
220 }
221
222 if {0 == [string first <TTCN_TC:EXEC $Line 0]} {set tc_state "execute"}
223 }
224
225 if {(0 != [string first # $Line 0])&&(0 != [string first <TT $Line 0])} {puts $tempfileID $Line}
226
227 }
228
229 if {($tc_state == "present")||($tc_state == "execute")} {puts $tempfileID "\} \n\ncontrol \{ \nexecute (TC()) \n\}";}
230
231 puts $tempfileID "}"
232
233 close $tempfileID
234
235
236 puts "\n-------------------------------------------------"
237 puts "Compiling test case $TCtitle ($i/$tc_counter)"
238 puts "started at: [exec date +"%H:%M:%S"]"
239 puts "-------------------------------------------------"
240
241 set result_mess ""
242
243 while {(-1 != [gets $TIfileID Line])&&(0 != [string first <END_TC> $Line 0])} {
244 if {([string length $Line] > 3)&&(0 != [string first # $Line 0])} {
245 if {$result_mess != ""} {set result_mess "$result_mess\n\n"}
246 set result_mess "$result_mess$Line"
247 }
248 }
249
250 if {([string length $result_mess] > 3)&&($tc_state != "execute")&&($tc_state != "pure_execute")} {_compiler $result_mess}
251 if {([string length $Line] > 3)&&($tc_state == "execute")} {_executor $result_mess $coverage_args}
252 if {([string length $Line] > 3)&&($tc_state == "pure_execute")} {
253 _executor $result_mess $coverage_args
254 }
255
256 incr i
257 }
258
259 close $TIfileID
260 close $errorfileID
261 if {$err_counter == 0} {file delete $errorfilename}
262
263 set timeout 1
264 # What's this?
265 send -i $sh_id "rm -f *%\n"
266
267 puts "\nCOMPILED $tc_counter TEST CASES"
268 puts "$err_counter TEST CASE FAILED"
269 if {$err_counter != 0} {
270 puts "SEE DETAILS IN $errorfilename FILE"
271 }
272
273 # starting end ending time
274 puts "started at: $start_date"
275 puts "finished at: [exec date +"%H:%M:%S"]"
276
277 #exit $err_counter
278
279 send -i $sh_id "exit \n"
280 expect {
281 timeout {
282 exit $err_counter
283 }
284 }
285 exit $err_counter