3ddc49475038a46f51e9114fe0666d6fff3f91c5
3 ###############################################################################
4 # Copyright (c) 2000-2015 Ericsson Telecom AB
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Eclipse Public License v1.0
7 # which accompanies this distribution, and is available at
8 # http://www.eclipse.org/legal/epl-v10.html
9 ###############################################################################
12 # hide next line from expect \
13 if [ "xy" != "x`expect -c 'puts "y
"'`" ]; then
14 # hide next line from expect \
15 echo "$0 requires 'expect'. Please install 'expect' and make sure it is in the PATH.";
16 # hide next line from expect \
18 # hide next line from expect \
24 # the next line restarts using expect \
27 #####################################################
29 ## EXPECT script to automate TTCN-3 testing ##
31 ## ETH/RUS Tibor Csöndes 2003.05.22. v1.1 ##
32 ## ETH/RZX Janos Zoltan Szabo 2005.01.01. v1.2 ##
33 ## ETH/RZX Tibor Csöndes 2005.03.23. v1.3 ##
34 ## ETH/RZR Csaba Ráduly 2010.04.06. v1.4 ##
35 ## ETH/XZD Jeno Balasko 2010.10.14 v1.5 ##
36 ## ETH/XZD Jeno Balasko 2011.11.23 v1.6 ##
37 ## ETH/XZR Adam Delic 2012.02.22 v1.7 ##
38 #####################################################
40 puts
"ttcn3_start: Starting the test suite"
42 # Procedure for waiting the command prompt of MC
44 proc wait_mc_prompt
{} {
48 -i $mctr_id -exact "$prompt" {
49 } -i $mctr_id -re "^$prompt.*\r\n" {
52 } -i $mctr_id -re "^.*\r\n" {
56 puts
"ttcn3_start: error: MC has terminated unexpectedly"
62 # Procedure for cleaning up after a fatal error
64 proc error_cleanup
{error_msg error_retcode
} {
66 puts
"ttcn3_start: error: $error_msg"
67 send
-i $mctr_id "exit\r"
68 expect
-i $mctr_id eof
75 # procedure for parsing and extracting options from argv
76 # http://wiki.tcl.tk/17342
77 proc getopt
{_argv name
{_var
""} {default
""}} {
78 upvar
1 $_argv argv
$_var var
79 set pos
[lsearch
-regexp $argv ^
$name]
82 # It would be better to use operator "ne" instead of "!=", but
83 # rhea has only Tcl 8.3.1 (vintage 2001) which doesn't understand it
85 set var
[lindex
$argv [incr to
]]
87 set argv
[lreplace
$argv $pos $to]
90 if {[llength
[info level
0]] == 5} {set var
$default}
98 # Checking the number of arguments
100 if {[llength
$argv] < 1} {
101 puts
"usage: ttcn3_start \[-ip host_ip_address\] executable \[file.cfg\] {module_name\[.testcase_name\]}"
106 # Setting the executable name variable ETS from argument
108 set first_arg
[lindex
$argv 0]
110 if {[file exists
$first_arg]} {
112 } elseif
{[file exists
$first_arg.exe
]} {
113 set ETS
$first_arg.exe
115 puts
"ttcn3_start: cannot find executable $first_arg"
120 # Setting ETS_basename: executable name without extension
122 if {[string tolower
[string range
$ETS [expr [string length
$ETS] - 4] end
]] == ".exe"} {
123 set ETS_basename
[string range
$ETS 0 [expr [string length
$ETS] - 5]]
125 set ETS_basename
$ETS
128 if {[string index
$ETS 0] != "/"} {
129 # Add a ./ prefix if ETS is a relative pathname
133 # Setting the configuration file variable config_file
135 if {[llength
$argv] > 1 && [file exists
[lindex
$argv 1]]} {
136 set config_file
[lindex
$argv 1]
139 puts
"ttcn3_start: warning: no configuration file was specified or the file name was misspelled"
141 if {[file exists
$ETS_basename.cfg
]} {
142 set config_file
$ETS_basename.cfg
143 puts
"ttcn3_start: note: using default configuration file $ETS_basename.cfg"
145 # if 2nd parameter exists then it must be an existing test case
146 if {[llength
$argv] > 1} {
147 # run $ETS -l to list test cases and check the 2nd parameter against that list
148 # if its not in the list stop with an error
149 # (the control part is also in the list but it works as if it was a testcase)
150 set second_argument
[lindex
$argv 1]
154 # split into testcases on newlines
155 set testcase_names
[split $expect_out(buffer
)]
156 foreach testcase_name
$testcase_names {
157 if {$second_argument==$testcase_name} {
162 if {$tc_name_found==0} {
163 puts
"ttcn3_start: error: the second parameter is neither a configuration file nor an existing test case"
170 # Checking TTCN3_DIR environment variable and setting mctr_cli
172 if {[info exists env
(TTCN3_DIR
)]} {
173 set mctr
$env(TTCN3_DIR
)/bin
/mctr_cli
175 puts
"ttcn3_start: warning: TTCN3_DIR environment variable is not set"
181 # Setting the hostname
183 set hostname
[info hostname
]
188 # Start Main Controller
190 if {[info exists config_file
]} {
191 spawn
$mctr $config_file
196 set mctr_id
$spawn_id
198 -re "Listening on( IP address )?(\[a-zA-Z0-9\.:%\]*)( and)? TCP port (\[0-9\]+)\..*\r\n" {
202 } elseif
{ $expect_out(2,string
) != "" } {
203 set hostname
$expect_out(2,string
)
206 puts
"$hostname is the default"
208 set port
$expect_out(4,string
)
210 } -re "Entering batch mode\..*\r" {
211 puts
"ttcn3_start: error: this script cannot be used when MC is run in batch mode"
212 puts
" hint: Remove option NumHCs from section \[MAIN_CONTROLLER\] of the"
213 puts
" configuration file."
214 exec kill -KILL [exp_pid
]
218 -re "Error was found.*\r" {
219 puts
"Please check the error message above"
225 puts
"ttcn3_start: The Main controller exited unexpectedly. In case of license problem you can order license at ttcn.ericsson.se"
230 # Start Host controller
232 spawn
$ETS $hostname $port
235 -i $hc_id -exact "TTCN-3 Host Controller" {
236 } -i $hc_id -re ".*\r" {
239 error_cleanup
"program $ETS is not a TTCN-3 executable in parallel mode" 6
244 -i $hc_id -re "Dynamic test case error" {
245 error_cleanup
"program $ETS could not connect to the MC" 7
246 } -i $hc_id -re ".*\r" {
248 } -i $mctr_id "New HC connected from " {
250 error_cleanup
"Host Controller with id $hc_id stopped unexpectedly" 10
255 # Create Main Test Component
257 send
-i $mctr_id "cmtc\r"
259 -i $mctr_id -re "MTC is created\..*\r\n" {
261 } -i $mctr_id -re "Cannot create MTC" {
262 error_cleanup
"the MTC cannot be created. " 8
263 } -i $mctr_id -re "No such host:\..*\r\n" {
264 error_cleanup
"the MTC cannot be created on an unknown host. " 9
266 error_cleanup
"Something went wrong... " 10
270 # Start Main Test Component
272 if {$start_index < [llength
$argv]} {
273 # Use the list of test cases given in the command line.
274 for {set i
$start_index} {$i < [llength
$argv]} {incr i
} {
275 send
-i $mctr_id "smtc [lindex $argv $i]\r"
277 -i $hc_id -re ".*\r" {
279 } -i $mctr_id -exact "Test execution finished." {
280 } -i $mctr_id -exact "MTC terminated." {
281 error_cleanup
"the MTC terminated unexpectedly" 10
285 } elseif
{[info exists config_file
]} {
286 # The configuration file is present. Use its [EXECUTE] section.
287 send
-i $mctr_id "smtc\r"
289 -i $hc_id -re ".*\r" {
291 } -i $mctr_id -exact "Execution of \[EXECUTE\] section finished." {
292 } -i $mctr_id -exact "No \[EXECUTE\] section was given in the configuration file." {
293 } -i $mctr_id -exact "MTC terminated." {
294 error_cleanup
"the MTC terminated unexpectedly" 10
298 # There is neither testcase name nor configuration file.
299 # Use the name of the executable as smtc argument.
300 set last_slash
[string last
"/" $ETS_basename]
301 if {$last_slash == -1} {
302 set module_name
$ETS_basename
304 set module_name
[string range
$ETS_basename [expr $last_slash + 1] end
]
306 send
-i $mctr_id "smtc $module_name\r"
308 -i $hc_id -re ".*\r" {
310 } -i $mctr_id -exact "Test execution finished." {
311 } -i $mctr_id -exact "MTC terminated." {
312 error_cleanup
"the MTC terminated unexpectedly" 10
318 # Exit Main Test Component
320 send
-i $mctr_id "emtc\r"
321 expect
-i $mctr_id -re "MTC terminated\..*\r\n"
324 # Quit from Main Controller
326 send
-i $mctr_id "exit\r"
328 # Catch the last lines of the output
332 expect
-i $mctr_id eof
338 # Wait until both MC and HC terminate
This page took 0.04269 seconds and 5 git commands to generate.