2 # the next line restarts using expect \
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"
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
]
25 proc _errorlog
{message
} {
31 puts
$errorfileID "------------------------------------------------------------------"
32 puts
$errorfileID " FAILED TEST CASE: $TCtitle"
33 puts
$errorfileID " ERROR MESSAGE : $message"
34 puts
$errorfileID "------------------------------------------------------------------"
39 proc _compiler_err
{} {
41 send
-i $sh_id "compiler Temp.ttcn\n"
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
}
55 proc _compiler
{message
} {
57 send
-i $sh_id "compiler Temp.ttcn \n"
59 puts
">>>DEBUG:$sh_id"
62 puts
"\n---------------------------------------"
63 puts
"ERROR! NOT MATCHING MESSAGE, EXPECTED: "
65 puts
"---------------------------------------"
66 _errorlog
"NOT MATCHING MESSAGE \n\n$message"
68 -i $sh_id -exact $message {
69 puts
"\n---------------------------------------"
70 puts
"MATCHING MESSAGE, EXPECTED: "
72 puts
"---------------------------------------"
75 puts
"ended at: [exec date +"%H
:%M
:%S
"]"
81 proc _executor
{message coverage_args rt_2
} {
84 if {![file exists Makefile
]} {
85 puts
"Can not find Makefile, you need one so that you can execute test case!!"
88 if {![file exists Temp.cfg
]} {
89 puts
"Can not find Temp.cfg, you need one so that you can execute test case!!"
96 -i $spawn_id -re "^.*\r\n" {exp_continue
}
104 -i $spawn_id -re ".*\r\n" {exp_continue
}
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"
119 -i $sh_id -re "\r\n.*>>>> "
122 send
-i $sh_id "./Temp Temp.cfg\n"
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: "
131 puts
"---------------------------------------"
134 -i $sh_id -re ".*\r\n" {exp_continue
}
135 -i $sh_id -exact ">>>> " {}
138 -i $sh_id -re ".*\r\n" {exp_continue
}
139 -i $sh_id -exact ">>>> " {
140 puts
"\n---------------------------------------"
141 puts
"NOT MATCHING MESSAGE, EXPECTED: "
143 puts
"---------------------------------------"
144 _errorlog
"NOT MATCHING MESSAGE, MESSAGE EXPECTED: \n\n$message"}
146 puts
"\n---------------------------------------"
147 puts
"ERROR! TIMEOUT OCCURED, MESSAGE EXPECTED: "
149 puts
"---------------------------------------"
150 _errorlog
"TIMEOUT OCCURED, NOT MATCHING MESSAGE \n\n$message"
153 puts
"ended at: [exec date +"%H
:%M
:%S
"]"
159 send
-i $sh_id "PS1='>>>> '\n"
163 set errpostfix
"_error"
166 set start_date
[exec date +"%H:%M:%S"]
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!"}
172 set errorfilename
$argv$errpostfix
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}
180 while {-1 != [gets
$TIfileID Line
]} {
181 if {[string first
<TC
$Line 0] == 0} {incr tc_counter
}
185 puts
"\n-------------------------------------------------"
186 puts
"$tc_counter test case(s) were found in file $argv"
187 puts
"-------------------------------------------------"
190 set errorfileID
[open
$errorfilename w
]
191 set TIfileID
[open
$argv r
]
193 while {$i <= $tc_counter} {
197 set tempfileID
[open Temp.ttcn w
]
199 while {(-1 != [gets
$TIfileID Line
])&&(0 != [string first
<TC
$Line 0])} {}
203 while {(-1 != [gets
$TIfileID Line
])&&(0 != [string first
<STATIC
$Line 0])} {}
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}
211 puts
$tempfileID "module Temp {"
213 while {(-1 != [gets
$TIfileID Line
])&&(0 != [string first
<RESULT
> $Line 0])} {
215 if {0 == [string first
<TTCN_TC
:PURE_EXEC
$Line 0]} {
216 set tc_state
"pure_execute"
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"
223 if {0 == [string first
<TTCN_TC
:EXEC
$Line 0]} {set tc_state
"execute"}
226 if {(0 != [string first
# $Line 0])&&(0 != [string first <TT $Line 0])} {puts $tempfileID $Line}
230 if {($tc_state == "present")||
($tc_state == "execute")} {puts
$tempfileID "\} \n\ncontrol \{ \nexecute (TC()) \n\}";}
237 puts
"\n-------------------------------------------------"
238 puts
"Compiling test case $TCtitle ($i/$tc_counter)"
239 puts
"started at: [exec date +"%H
:%M
:%S
"]"
240 puts
"-------------------------------------------------"
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"
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
262 if {$err_counter == 0} {file delete
$errorfilename}
266 send
-i $sh_id "rm -f *%\n"
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"
274 # starting end ending time
275 puts
"started at: $start_date"
276 puts
"finished at: [exec date +"%H
:%M
:%S
"]"
280 send
-i $sh_id "exit \n"