1# See the file LICENSE for redistribution information. 2# 3# Copyright (c) 2000-2009 Oracle. All rights reserved. 4# 5# $Id$ 6# 7# This is a very cut down version of wrap.tcl. We don't want to 8# use wrap.tcl because that will create yet another Tcl subprocess 9# to execute the test. We want to open the test program directly 10# here so that we get the pid for the program (not the Tcl shell) 11# and watch_procs can kill the program if needed. 12 13source ./include.tcl 14source $test_path/test.tcl 15 16# Arguments: 17if { $argc != 2 } { 18 puts "FAIL: wrap_reptest.tcl: Usage: wrap_reptest.tcl argfile log" 19 exit 20} 21 22set argfile [lindex $argv 0] 23set logfile [lindex $argv 1] 24 25# Create a sentinel file to mark our creation and signal that watch_procs 26# should look for us. 27set parentpid [pid] 28set parentsentinel $testdir/begin.$parentpid 29set f [open $parentsentinel w] 30close $f 31 32# Create a Tcl subprocess that will actually run the test. 33set argf [open $argfile r] 34set progargs [read $argf] 35close $argf 36set cmd [open "| $util_path/db_reptest $progargs >& $logfile" w] 37set childpid [pid $cmd] 38 39puts "Script watcher process $parentpid launching db_reptest process $childpid to $logfile." 40set childsentinel $testdir/begin.$childpid 41set f [open $childsentinel w] 42close $f 43 44# Close the pipe. This will flush the above commands and actually run the 45# test, and will also return an error a la exec if anything bad happens 46# to the subprocess. The magic here is that closing a pipe blocks 47# and waits for the exit of processes in the pipeline, at least according 48# to Ousterhout (p. 115). 49set ret [catch {close $cmd} res] 50 51# Write ending sentinel files--we're done. 52set f [open $testdir/end.$childpid w] 53close $f 54set f [open $testdir/end.$parentpid w] 55close $f 56 57error_check_good "($childpid: db_reptest $progargs: logfile $logfile)"\ 58 $ret 0 59exit $ret 60