| 1 |
############################################################################## |
| 2 |
# Modules Revision 3.0 |
| 3 |
# Providing a flexible user environment |
| 4 |
# |
| 5 |
# File: config/%M% |
| 6 |
# Revision: %I% |
| 7 |
# First Edition: 1995/12/06 |
| 8 |
# Last Mod.: %U%, %G% |
| 9 |
# |
| 10 |
# Authors: Jens Hamisch, [email protected] |
| 11 |
# |
| 12 |
# Description: Testuite initialization |
| 13 |
# Command: |
| 14 |
# Sub-Command: |
| 15 |
# |
| 16 |
# Comment: %C{ |
| 17 |
# Initialization of the testsuite. Definition of |
| 18 |
# globally used start procedures for the test |
| 19 |
# target. |
| 20 |
# }C% |
| 21 |
# |
| 22 |
############################################################################## |
| 23 |
|
| 24 |
# |
| 25 |
# modulecmd_xxx_ -- run modulecmd |
| 26 |
# |
| 27 |
|
| 28 |
# alternative method to collect stdout and stderr from command execution (on |
| 29 |
# Tcl>=8.6): use channel pipe instead of saving these outputs in file |
| 30 |
if {[lindex [lsort -dictionary [list 8.6 [info tclversion]]] 1] eq [info tclversion]} { |
| 31 |
|
| 32 |
# catch background errors, like a modulecmd process killed by a signal that |
| 33 |
# makes readpipe raise an uncaught CHILDKILLED error from its event handler. |
| 34 |
# without this catching procedure defined, such an error leaves the endpipe |
| 35 |
# variable unset and the vwait call in modulecmd_xxx_ hangs forever |
| 36 |
proc bgerror {msg} { |
| 37 |
send_user "ERROR: background error caught: $msg\n" |
| 38 |
# release ongoing command wait to make related test fail right away |
| 39 |
set ::endpipe error |
| 40 |
} |
| 41 |
|
| 42 |
proc readpipe {p1 p2 varname {exit_varname {}}} { |
| 43 |
append ::$varname [read $p1] |
| 44 |
if {[eof $p1]} { |
| 45 |
fconfigure $p1 -blocking 1 |
| 46 |
try { |
| 47 |
close $p1 |
| 48 |
} on ok {output} { |
| 49 |
if {[string length $exit_varname]} { |
| 50 |
set ::$exit_varname 0 |
| 51 |
} |
| 52 |
} trap {CHILDSTATUS} {output options} { |
| 53 |
if {[string length $exit_varname]} { |
| 54 |
set ::$exit_varname [lindex [dict get $options -errorcode] end] |
| 55 |
} |
| 56 |
} |
| 57 |
if {$p2 ni [chan names]} { |
| 58 |
set ::endpipe ok |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
proc modulecmd_xxx_ {command {input noinput} {launcher {}}} { |
| 64 |
global MODULECMD |
| 65 |
global TCLSH |
| 66 |
global verbose |
| 67 |
global shell |
| 68 |
global comp_output |
| 69 |
global comp_error |
| 70 |
global comp_exit |
| 71 |
global errorCode |
| 72 |
|
| 73 |
if {[info exists ::endpipe]} { |
| 74 |
unset ::endpipe |
| 75 |
} |
| 76 |
|
| 77 |
if ![info exists command] then { |
| 78 |
unresolved "internal testsuite error: no module command specified" |
| 79 |
} |
| 80 |
|
| 81 |
set cmdlist [list] |
| 82 |
if {[llength $launcher]} { |
| 83 |
lappend cmdlist {*}$launcher |
| 84 |
} |
| 85 |
lappend cmdlist $TCLSH $MODULECMD $shell |
| 86 |
|
| 87 |
# check if asked not to split passed command line |
| 88 |
if {[string first "NOCMDSPLIT" $command] == 0} { |
| 89 |
lappend cmdlist [string range $command 10 end] |
| 90 |
} else { |
| 91 |
# preserve argument including space character |
| 92 |
foreach cmdelt [split [string map {{\ } {<SPACE>}} $command] { }] { |
| 93 |
lappend cmdlist [string map {<SPACE> { }} $cmdelt] |
| 94 |
} |
| 95 |
} |
| 96 |
if {$input ne {noinput}} { |
| 97 |
lappend cmdlist << $input |
| 98 |
} |
| 99 |
|
| 100 |
if { $verbose > 1 } { |
| 101 |
send_user "starting [lrange $cmdlist 1 end]\n" |
| 102 |
} |
| 103 |
|
| 104 |
# create pipes |
| 105 |
lassign [chan pipe] rdstderr wrstderr |
| 106 |
|
| 107 |
# run command in separate thread |
| 108 |
lappend cmdlist 2>@ $wrstderr |
| 109 |
set rdstdout [open "|$cmdlist"] |
| 110 |
|
| 111 |
# fetch output asynchronously |
| 112 |
fileevent $rdstdout readable [list readpipe $rdstdout $rdstderr comp_output comp_exit] |
| 113 |
fconfigure $rdstdout -blocking 0 |
| 114 |
fileevent $rdstderr readable [list readpipe $rdstderr $rdstdout comp_error] |
| 115 |
fconfigure $rdstderr -blocking 0 |
| 116 |
|
| 117 |
close $wrstderr |
| 118 |
|
| 119 |
vwait endpipe |
| 120 |
} |
| 121 |
|
| 122 |
} else { |
| 123 |
|
| 124 |
proc modulecmd_xxx_ {command {input noinput} {launcher {}}} { |
| 125 |
global MODULECMD |
| 126 |
global TCLSH |
| 127 |
global verbose |
| 128 |
global shell |
| 129 |
global comp_output |
| 130 |
global comp_error |
| 131 |
global comp_exit |
| 132 |
global errorCode |
| 133 |
|
| 134 |
if ![info exists command] then { |
| 135 |
unresolved "internal testsuite error: no module command specified" |
| 136 |
} |
| 137 |
|
| 138 |
set cmdlist [list] |
| 139 |
if {[llength $launcher]} { |
| 140 |
lappend cmdlist {*}$launcher |
| 141 |
} |
| 142 |
lappend cmdlist $TCLSH $MODULECMD $shell |
| 143 |
|
| 144 |
# check if asked not to split passed command line |
| 145 |
if {[string first "NOCMDSPLIT" $command] == 0} { |
| 146 |
lappend cmdlist [string range $command 10 end] |
| 147 |
} else { |
| 148 |
# preserve argument including space character |
| 149 |
foreach cmdelt [split [string map {{\ } {<SPACE>}} $command] { }] { |
| 150 |
lappend cmdlist [string map {<SPACE> { }} $cmdelt] |
| 151 |
} |
| 152 |
} |
| 153 |
lappend cmdlist 2> test321.err > test321.out |
| 154 |
if {$input ne {noinput}} { |
| 155 |
lappend cmdlist << $input |
| 156 |
} |
| 157 |
|
| 158 |
if { $verbose > 1 } { |
| 159 |
send_user "starting [lrange $cmdlist 1 end]\n" |
| 160 |
} |
| 161 |
|
| 162 |
if [catch { |
| 163 |
set comp_output [{*}$cmdlist] |
| 164 |
} ] { |
| 165 |
set comp_exit [lindex $errorCode 2] |
| 166 |
} else { |
| 167 |
set comp_exit 0 |
| 168 |
} |
| 169 |
|
| 170 |
catch { |
| 171 |
set errfile [ open test321.err ] |
| 172 |
read $errfile |
| 173 |
} comp_error |
| 174 |
catch { close $errfile } |
| 175 |
catch { file delete test321.err } |
| 176 |
|
| 177 |
catch { |
| 178 |
set outfile [ open test321.out ] |
| 179 |
read $outfile |
| 180 |
} comp_output |
| 181 |
catch { close $outfile } |
| 182 |
catch { file delete test321.out } |
| 183 |
} |
| 184 |
|
| 185 |
} |
| 186 |
|
| 187 |
|
| 188 |
# |
| 189 |
# Test procedure to check a module installation |
| 190 |
# |
| 191 |
|
| 192 |
# alternative method to collect stdout and stderr from command execution (on |
| 193 |
# Tcl>=8.6): use channel pipe instead of saving these outputs in file |
| 194 |
if {[lindex [lsort -dictionary [list 8.6 [info tclversion]]] 1] eq [info tclversion]} { |
| 195 |
|
| 196 |
proc install_test_xxx_ {command} { |
| 197 |
global verbose |
| 198 |
global autoinit_script |
| 199 |
global shell |
| 200 |
global autoinit_mode |
| 201 |
global shell_list |
| 202 |
global shell_test |
| 203 |
global shell_path |
| 204 |
global shell_opts |
| 205 |
global shell_init |
| 206 |
global shell_level |
| 207 |
global subshell |
| 208 |
|
| 209 |
global comp_output |
| 210 |
global comp_error |
| 211 |
global comp_exit |
| 212 |
global errorCode |
| 213 |
|
| 214 |
if {[info exists ::endpipe]} { |
| 215 |
unset ::endpipe |
| 216 |
} |
| 217 |
|
| 218 |
if {![info exists command]} { |
| 219 |
unresolved "internal testsuite error: no command specified" |
| 220 |
} |
| 221 |
if {![info exists shell_path($shell)]} { |
| 222 |
unresolved "internal testsuite error: no shell path found for '$shell' shell" |
| 223 |
} |
| 224 |
if {![info exists shell_test($shell)]} { |
| 225 |
unresolved "internal testsuite error: no install test script set for '$shell' shell" |
| 226 |
} |
| 227 |
if {![info exists shell_init($shell)]} { |
| 228 |
unresolved "internal testsuite error: no init script set for '$shell' shell" |
| 229 |
} |
| 230 |
if {![info exists autoinit_script]} { |
| 231 |
unresolved "internal testsuite error: no autoinit script set" |
| 232 |
} |
| 233 |
if {![info exists shell_level]} { |
| 234 |
set level "top" |
| 235 |
} else { |
| 236 |
set level $shell_level |
| 237 |
} |
| 238 |
if {![info exists subshell]} { |
| 239 |
set sub "$shell" |
| 240 |
} else { |
| 241 |
set sub $subshell |
| 242 |
} |
| 243 |
|
| 244 |
set cmd_to_exec [list $shell_path($shell)] |
| 245 |
if {[info exists shell_opts($shell)]} { |
| 246 |
lappend cmd_to_exec $shell_opts($shell) |
| 247 |
} |
| 248 |
|
| 249 |
if {$shell eq "cmake"} { |
| 250 |
lappend cmd_to_exec "-Dinitfile='$shell_init($shell)'" |
| 251 |
lappend cmd_to_exec "-Dcmdlist='$command'" |
| 252 |
lappend cmd_to_exec "-P" |
| 253 |
lappend cmd_to_exec $shell_test($shell) |
| 254 |
if {$verbose} { |
| 255 |
send_user " ... Testing '$cmd_to_exec'\n" |
| 256 |
} |
| 257 |
} else { |
| 258 |
lappend cmd_to_exec $shell_test($shell) |
| 259 |
if {$autoinit_mode} { |
| 260 |
set autoinit_verb "autoinit " |
| 261 |
lappend cmd_to_exec $autoinit_script |
| 262 |
} else { |
| 263 |
set autoinit_verb "" |
| 264 |
lappend cmd_to_exec $shell_init($shell) |
| 265 |
} |
| 266 |
|
| 267 |
if {[lsearch -exact $shell_list $shell] != -1} { |
| 268 |
lappend cmd_to_exec $level $shell_path($sub) $command |
| 269 |
if {$verbose} { |
| 270 |
send_user " ... Testing '$shell [file tail $shell_test($shell)]\ |
| 271 |
$autoinit_verb$level $sub $command'\n" |
| 272 |
} |
| 273 |
} else { |
| 274 |
lappend cmd_to_exec $command |
| 275 |
if {$verbose} { |
| 276 |
send_user " ... Testing '$shell [file tail $shell_test($shell)]\ |
| 277 |
$autoinit_verb$command'\n" |
| 278 |
} |
| 279 |
} |
| 280 |
} |
| 281 |
if { $verbose > 1 } { |
| 282 |
send_user "starting $cmd_to_exec\n" |
| 283 |
} |
| 284 |
|
| 285 |
# create pipes |
| 286 |
lassign [chan pipe] rdstderr wrstderr |
| 287 |
|
| 288 |
# run command in separate thread |
| 289 |
lappend cmd_to_exec 2>@ $wrstderr |
| 290 |
set rdstdout [open "|$cmd_to_exec"] |
| 291 |
|
| 292 |
# fetch output asynchronously |
| 293 |
fileevent $rdstdout readable [list readpipe $rdstdout $rdstderr comp_output comp_exit] |
| 294 |
fconfigure $rdstdout -blocking 0 |
| 295 |
fileevent $rdstderr readable [list readpipe $rdstderr $rdstdout comp_error] |
| 296 |
fconfigure $rdstderr -blocking 0 |
| 297 |
|
| 298 |
close $wrstderr |
| 299 |
|
| 300 |
vwait endpipe |
| 301 |
|
| 302 |
if {$shell eq {ruby}} { |
| 303 |
set comp_error [regsub -all -line {^.* warning: Insecure world writable dir .*(\n|$)} $comp_error {}] |
| 304 |
set comp_error [regsub -all -line {^`RubyGems' were not loaded\.(\n|$)} $comp_error {}] |
| 305 |
} |
| 306 |
} |
| 307 |
|
| 308 |
} else { |
| 309 |
|
| 310 |
proc install_test_xxx_ {command} { |
| 311 |
global verbose |
| 312 |
global autoinit_script |
| 313 |
global shell |
| 314 |
global autoinit_mode |
| 315 |
global shell_list |
| 316 |
global shell_test |
| 317 |
global shell_path |
| 318 |
global shell_opts |
| 319 |
global shell_init |
| 320 |
global shell_level |
| 321 |
global subshell |
| 322 |
|
| 323 |
global comp_output |
| 324 |
global comp_error |
| 325 |
global comp_exit |
| 326 |
global errorCode |
| 327 |
|
| 328 |
if {![info exists command]} { |
| 329 |
unresolved "internal testsuite error: no command specified" |
| 330 |
} |
| 331 |
if {![info exists shell_path($shell)]} { |
| 332 |
unresolved "internal testsuite error: no shell path found for '$shell' shell" |
| 333 |
} |
| 334 |
if {![info exists shell_test($shell)]} { |
| 335 |
unresolved "internal testsuite error: no install test script set for '$shell' shell" |
| 336 |
} |
| 337 |
if {![info exists shell_init($shell)]} { |
| 338 |
unresolved "internal testsuite error: no init script set for '$shell' shell" |
| 339 |
} |
| 340 |
if {![info exists autoinit_script]} { |
| 341 |
unresolved "internal testsuite error: no autoinit script set" |
| 342 |
} |
| 343 |
if {![info exists shell_level]} { |
| 344 |
set level "top" |
| 345 |
} else { |
| 346 |
set level $shell_level |
| 347 |
} |
| 348 |
if {![info exists subshell]} { |
| 349 |
set sub "$shell" |
| 350 |
} else { |
| 351 |
set sub $subshell |
| 352 |
} |
| 353 |
|
| 354 |
set cmd_to_exec [list $shell_path($shell)] |
| 355 |
if {[info exists shell_opts($shell)]} { |
| 356 |
lappend cmd_to_exec $shell_opts($shell) |
| 357 |
} |
| 358 |
|
| 359 |
if {$shell eq "cmake"} { |
| 360 |
lappend cmd_to_exec "-Dinitfile='$shell_init($shell)'" |
| 361 |
lappend cmd_to_exec "-Dcmdlist='$command'" |
| 362 |
lappend cmd_to_exec "-P" |
| 363 |
lappend cmd_to_exec $shell_test($shell) |
| 364 |
if {$verbose} { |
| 365 |
send_user " ... Testing '$cmd_to_exec'\n" |
| 366 |
} |
| 367 |
} else { |
| 368 |
lappend cmd_to_exec $shell_test($shell) |
| 369 |
if {$autoinit_mode} { |
| 370 |
set autoinit_verb "autoinit " |
| 371 |
lappend cmd_to_exec $autoinit_script |
| 372 |
} else { |
| 373 |
set autoinit_verb "" |
| 374 |
lappend cmd_to_exec $shell_init($shell) |
| 375 |
} |
| 376 |
|
| 377 |
if {[lsearch -exact $shell_list $shell] != -1} { |
| 378 |
lappend cmd_to_exec $level $shell_path($sub) $command |
| 379 |
if {$verbose} { |
| 380 |
send_user " ... Testing '$shell [file tail $shell_test($shell)]\ |
| 381 |
$autoinit_verb$level $sub $command'\n" |
| 382 |
} |
| 383 |
} else { |
| 384 |
lappend cmd_to_exec $command |
| 385 |
if {$verbose} { |
| 386 |
send_user " ... Testing '$shell [file tail $shell_test($shell)]\ |
| 387 |
$autoinit_verb$command'\n" |
| 388 |
} |
| 389 |
} |
| 390 |
} |
| 391 |
if { $verbose > 1 } { |
| 392 |
send_user "starting $cmd_to_exec\n" |
| 393 |
} |
| 394 |
|
| 395 |
# now need to capture the exit return code. |
| 396 |
if [catch { |
| 397 |
set comp_output [exec {*}$cmd_to_exec 2> test321.err > test321.out ] |
| 398 |
} ] { |
| 399 |
set comp_exit [lindex $errorCode 2] |
| 400 |
} else { |
| 401 |
set comp_exit 0 |
| 402 |
} |
| 403 |
|
| 404 |
catch { |
| 405 |
set errfile [ open test321.err ] |
| 406 |
read $errfile |
| 407 |
} comp_error |
| 408 |
catch { close $errfile } |
| 409 |
catch { file delete test321.err } |
| 410 |
|
| 411 |
if {$shell eq {ruby}} { |
| 412 |
set comp_error [regsub -all -line {^.* warning: Insecure world writable dir .*(\n|$)} $comp_error {}] |
| 413 |
} |
| 414 |
|
| 415 |
catch { |
| 416 |
set outfile [ open test321.out ] |
| 417 |
read $outfile |
| 418 |
} comp_output |
| 419 |
catch { close $outfile } |
| 420 |
catch { file delete test321.out } |
| 421 |
} |
| 422 |
|
| 423 |
} |
| 424 |
|
| 425 |
# |
| 426 |
# Test procedure to lint script files |
| 427 |
# |
| 428 |
|
| 429 |
# alternative method to collect stdout and stderr from command execution (on |
| 430 |
# Tcl>=8.6): use channel pipe instead of saving these outputs in file |
| 431 |
if {[lindex [lsort -dictionary [list 8.6 [info tclversion]]] 1] eq [info tclversion]} { |
| 432 |
|
| 433 |
proc lint_test_xxx_ {filepath} { |
| 434 |
if {[info exists ::endpipe]} { |
| 435 |
unset ::endpipe |
| 436 |
} |
| 437 |
|
| 438 |
# global variable ::shell corresponds to linter command to use |
| 439 |
if {[auto_execok $::shell] eq {}} { |
| 440 |
untested "linter command '$::shell' not found" |
| 441 |
return |
| 442 |
} |
| 443 |
|
| 444 |
# prepare command to execute |
| 445 |
set cmd_to_exec [list $::shell] |
| 446 |
if {[info exists ::linter_opts]} { |
| 447 |
lappend cmd_to_exec {*}$::linter_opts |
| 448 |
} |
| 449 |
lappend cmd_to_exec $filepath |
| 450 |
|
| 451 |
if {$::verbose} { |
| 452 |
send_user " ... Testing '$::shell $filepath\n" |
| 453 |
} |
| 454 |
if {$::verbose > 1} { |
| 455 |
send_user "starting $cmd_to_exec\n" |
| 456 |
} |
| 457 |
|
| 458 |
# create pipes |
| 459 |
lassign [chan pipe] rdstdout wrstdout |
| 460 |
lassign [chan pipe] rdstderr wrstderr |
| 461 |
|
| 462 |
# fetch output asynchronously |
| 463 |
fileevent $rdstdout readable [list readpipe $rdstdout $rdstderr comp_output] |
| 464 |
fconfigure $rdstdout -blocking 0 |
| 465 |
fileevent $rdstderr readable [list readpipe $rdstderr $rdstdout comp_error] |
| 466 |
fconfigure $rdstderr -blocking 0 |
| 467 |
|
| 468 |
# run command in separate thread |
| 469 |
lappend cmd_to_exec >@ $wrstdout 2>@ $wrstderr |
| 470 |
if [catch { |
| 471 |
exec {*}$cmd_to_exec |
| 472 |
} ] { |
| 473 |
set ::comp_exit [lindex $::errorCode 2] |
| 474 |
} else { |
| 475 |
set ::comp_exit 0 |
| 476 |
} |
| 477 |
close $wrstdout |
| 478 |
close $wrstderr |
| 479 |
|
| 480 |
vwait endpipe |
| 481 |
} |
| 482 |
|
| 483 |
} else { |
| 484 |
|
| 485 |
# expect 'lint' testsuite to be run only on Tcl>=8.6 |
| 486 |
proc lint_test_xxx_ {filepath} { |
| 487 |
unsupported {lint testsuite not supported on Tcl<8.5} |
| 488 |
} |
| 489 |
|
| 490 |
} |