/usr/bin/ttcn3_start is in eclipse-titan 6.3.1-1build1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | #!/bin/sh
###############################################################################
# Copyright (c) 2000-2015 Ericsson Telecom AB
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
###############################################################################
# hide next line from expect \
if [ "xy" != "x`expect -c 'puts "y"'`" ]; then
# hide next line from expect \
echo "$0 requires 'expect'. Please install 'expect' and make sure it is in the PATH.";
# hide next line from expect \
exit 1
# hide next line from expect \
fi
# the next line restarts using expect \
exec expect "$0" "$@"
#####################################################
## ##
## EXPECT script to automate TTCN-3 testing ##
## ##
## ETH/RUS Tibor Csöndes 2003.05.22. v1.1 ##
## ETH/RZX Janos Zoltan Szabo 2005.01.01. v1.2 ##
## ETH/RZX Tibor Csöndes 2005.03.23. v1.3 ##
## ETH/RZR Csaba Ráduly 2010.04.06. v1.4 ##
## ETH/XZD Jeno Balasko 2010.10.14 v1.5 ##
## ETH/XZD Jeno Balasko 2011.11.23 v1.6 ##
## ETH/XZR Adam Delic 2012.02.22 v1.7 ##
#####################################################
puts "ttcn3_start: Starting the test suite"
# Procedure for waiting the command prompt of MC
proc wait_mc_prompt {} {
global mctr_id
set prompt "MC2> "
expect {
-i $mctr_id -exact "$prompt" {
} -i $mctr_id -re "^$prompt.*\r\n" {
send -i $mctr_id "\r"
exp_continue
} -i $mctr_id -re "^.*\r\n" {
exp_continue
} -i $mctr_id eof {
wait -i $mctr_id
puts "ttcn3_start: error: MC has terminated unexpectedly"
exit 5
}
}
}
# Procedure for cleaning up after a fatal error
proc error_cleanup {error_msg error_retcode} {
global mctr_id hc_id
puts "ttcn3_start: error: $error_msg"
send -i $mctr_id "exit\r"
expect -i $mctr_id eof
expect -i $hc_id eof
wait -i $hc_id
wait -i $mctr_id
exit $error_retcode
}
# procedure for parsing and extracting options from argv
# http://wiki.tcl.tk/17342
proc getopt {_argv name {_var ""} {default ""}} {
upvar 1 $_argv argv $_var var
set pos [lsearch -regexp $argv ^$name]
if {$pos>=0} {
set to $pos
# It would be better to use operator "ne" instead of "!=", but
# rhea has only Tcl 8.3.1 (vintage 2001) which doesn't understand it
if {$_var != ""} {
set var [lindex $argv [incr to]]
}
set argv [lreplace $argv $pos $to]
return 1
} else {
if {[llength [info level 0]] == 5} {set var $default}
return 0
}
}
set ip ""
getopt argv -ip ip
# Checking the number of arguments
if {[llength $argv] < 1} {
puts "usage: ttcn3_start \[-ip host_ip_address\] executable \[file.cfg\] {module_name\[.testcase_name\]}"
exit 2
}
# Setting the executable name variable ETS from argument
set first_arg [lindex $argv 0]
if {[file exists $first_arg]} {
set ETS $first_arg
} elseif {[file exists $first_arg.exe]} {
set ETS $first_arg.exe
} else {
puts "ttcn3_start: cannot find executable $first_arg"
exit 3
}
# Setting ETS_basename: executable name without extension
if {[string tolower [string range $ETS [expr [string length $ETS] - 4] end]] == ".exe"} {
set ETS_basename [string range $ETS 0 [expr [string length $ETS] - 5]]
} else {
set ETS_basename $ETS
}
if {[string index $ETS 0] != "/"} {
# Add a ./ prefix if ETS is a relative pathname
set ETS ./$ETS
}
# Setting the configuration file variable config_file
if {[llength $argv] > 1 && [file exists [lindex $argv 1]]} {
set config_file [lindex $argv 1]
set start_index 2
} else {
puts "ttcn3_start: warning: no configuration file was specified or the file name was misspelled"
set start_index 1
if {[file exists $ETS_basename.cfg]} {
set config_file $ETS_basename.cfg
puts "ttcn3_start: note: using default configuration file $ETS_basename.cfg"
}
# if 2nd parameter exists then it must be an existing test case
if {[llength $argv] > 1} {
# run $ETS -l to list test cases and check the 2nd parameter against that list
# if its not in the list stop with an error
# (the control part is also in the list but it works as if it was a testcase)
set second_argument [lindex $argv 1]
spawn $ETS -l
expect eof
set tc_name_found 0
# split into testcases on newlines
set testcase_names [split $expect_out(buffer)]
foreach testcase_name $testcase_names {
if {$second_argument==$testcase_name} {
set tc_name_found 1
break
}
}
if {$tc_name_found==0} {
puts "ttcn3_start: error: the second parameter is neither a configuration file nor an existing test case"
exit 11
}
}
}
# Checking TTCN3_DIR environment variable and setting mctr_cli
if {[info exists env(TTCN3_DIR)]} {
set mctr $env(TTCN3_DIR)/bin/mctr_cli
} else {
puts "ttcn3_start: warning: TTCN3_DIR environment variable is not set"
set mctr mctr_cli
}
set timeout -1
# Setting the hostname
set hostname [info hostname]
if { $ip != "" } {
set hostname $ip
}
# Start Main Controller
if {[info exists config_file]} {
spawn $mctr $config_file
} else {
spawn $mctr
}
set mctr_id $spawn_id
expect {
-re "Listening on( IP address )?(\[a-zA-Z0-9\.:%\]*)( and)? TCP port (\[0-9\]+)\..*\r\n" {
if { $ip != "" } {
set hostname $ip
puts ">>> Branch 1"
} elseif { $expect_out(2,string) != "" } {
set hostname $expect_out(2,string)
puts ">>>Branch 2"
} else {
puts "$hostname is the default"
}
set port $expect_out(4,string)
wait_mc_prompt
} -re "Entering batch mode\..*\r" {
puts "ttcn3_start: error: this script cannot be used when MC is run in batch mode"
puts " hint: Remove option NumHCs from section \[MAIN_CONTROLLER\] of the"
puts " configuration file."
exec kill -KILL [exp_pid]
wait -i $mctr_id
exit 4
}
-re "Error was found.*\r" {
puts "Please check the error message above"
exit 4
}
eof {
spawn $mctr -v
expect eof
puts "ttcn3_start: The Main controller exited unexpectedly. In case of license problem you can order license at ttcn.ericsson.se"
exit 4
}
}
# Start Host controller
spawn $ETS $hostname $port
set hc_id $spawn_id
expect {
-i $hc_id -exact "TTCN-3 Host Controller" {
} -i $hc_id -re ".*\r" {
exp_continue
} -i $hc_id eof {
error_cleanup "program $ETS is not a TTCN-3 executable in parallel mode" 6
}
}
expect {
-i $hc_id -re "Dynamic test case error" {
error_cleanup "program $ETS could not connect to the MC" 7
} -i $hc_id -re ".*\r" {
exp_continue
} -i $mctr_id "New HC connected from " {
} -i $hc_id eof {
error_cleanup "Host Controller with id $hc_id stopped unexpectedly" 10
}
}
# Create Main Test Component
send -i $mctr_id "cmtc\r"
expect {
-i $mctr_id -re "MTC is created\..*\r\n" {
wait_mc_prompt
} -i $mctr_id -re "Cannot create MTC" {
error_cleanup "the MTC cannot be created. " 8
} -i $mctr_id -re "No such host:\..*\r\n" {
error_cleanup "the MTC cannot be created on an unknown host. " 9
} -i $hc_id eof {
error_cleanup "Something went wrong... " 10
}
}
# Start Main Test Component
if {$start_index < [llength $argv]} {
# Use the list of test cases given in the command line.
for {set i $start_index} {$i < [llength $argv]} {incr i} {
send -i $mctr_id "smtc [lindex $argv $i]\r"
expect {
-i $hc_id -re ".*\r" {
exp_continue
} -i $mctr_id -exact "Test execution finished." {
} -i $mctr_id -exact "MTC terminated." {
error_cleanup "the MTC terminated unexpectedly" 10
}
}
}
} elseif {[info exists config_file]} {
# The configuration file is present. Use its [EXECUTE] section.
send -i $mctr_id "smtc\r"
expect {
-i $hc_id -re ".*\r" {
exp_continue
} -i $mctr_id -exact "Execution of \[EXECUTE\] section finished." {
} -i $mctr_id -exact "No \[EXECUTE\] section was given in the configuration file." {
} -i $mctr_id -exact "MTC terminated." {
error_cleanup "the MTC terminated unexpectedly" 10
}
}
} else {
# There is neither testcase name nor configuration file.
# Use the name of the executable as smtc argument.
set last_slash [string last "/" $ETS_basename]
if {$last_slash == -1} {
set module_name $ETS_basename
} else {
set module_name [string range $ETS_basename [expr $last_slash + 1] end]
}
send -i $mctr_id "smtc $module_name\r"
expect {
-i $hc_id -re ".*\r" {
exp_continue
} -i $mctr_id -exact "Test execution finished." {
} -i $mctr_id -exact "MTC terminated." {
error_cleanup "the MTC terminated unexpectedly" 10
}
}
}
# Exit Main Test Component
send -i $mctr_id "emtc\r"
expect -i $mctr_id -re "MTC terminated\..*\r\n"
wait_mc_prompt
# Quit from Main Controller
send -i $mctr_id "exit\r"
# Catch the last lines of the output
expect {
-i $hc_id eof {
expect -i $mctr_id eof
} -i $mctr_id eof {
expect -i $hc_id eof
}
}
# Wait until both MC and HC terminate
wait -i $hc_id
wait -i $mctr_id
|