2 # Test-specific TCL procedures required by DejaGNU.
3 # Copyright (C) 1994, 2005, 2007, 2010, 2011 Free Software Foundation,
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # Modified by David MacKenzie <djm@gnu.ai.mit.edu> from the gcc files
20 # written by Rob Savoye <rob@cygnus.com>.
23 verbose "base_dir is $base_dir" 2
26 set dir "$base_dir/.."
27 set path "$dir/$objfile"
28 if ![file exists $path] then {
29 error "$path does not exist"
31 set XARGS [findfile $base_dir/../xargs [transform xargs]]
37 set XARGS [findfile $base_dir/../xargs $base_dir/../xargs [transform xargs]]
38 if [ string match "/*" $XARGS ] {
39 verbose "XARGS is set to $XARGS" 1
41 error "Failed to find a binary to test"
45 if ![info exists XARGSFLAGS] then {
50 # Extract and print the version number of xargs.
51 proc xargs_version {} {
55 if {[which $XARGS] != 0} then {
56 set tmp [ eval exec $XARGS $XARGSFLAGS --version </dev/null | sed 1q ]
59 warning "$XARGS, program does not exist"
63 # Run xargs and leave the output in $comp_output.
64 # Called by individual test scripts.
65 proc xargs_start { passfail options {infile ""} {errh ""} {command ""} } {
71 if {[which $XARGS] == 0} then {
72 error "$XARGS, program does not exist"
76 set scriptname [uplevel {info script}]
77 set testbase [file rootname $scriptname]
78 set testname [file tail $testbase]
80 if {[string match "\[0-9\]*" $passfail]} then {
81 set execrc "$passfail"
82 } elseif {[string match "p*" $passfail]} then {
84 } elseif {[string match "f*" $passfail]} then {
87 fail "$testname, failure in testing framework: passfail=$passfail"
91 set outfile "$testbase.xo"
92 if {$infile != ""} then {
93 set infile "[file dirname [file dirname $testbase]]/inputs/$infile"
98 if {[string match "s*" $errh]} then {
101 set errfile "$testbase.xe"
104 catch "exec rm -f xargs.out xargs.err"
106 if {$command != ""} then {
107 set cmd "$command < $infile > xargs.out 2> xargs.err"
109 set cmd "$XARGS $XARGSFLAGS $options < $infile > xargs.out 2> xargs.err"
113 send_user "Spawning \"$cmd\"\n"
117 if {[catch "exec $cmd" comp_output]} then {
118 if {[lindex $::errorCode 0] == "CHILDSTATUS"} then {
119 set status [lindex $::errorCode 2]
121 fail "$testname, failure in testing framework, $comp_output"
126 catch "exec cat xargs.err" comp_error
128 if {$execrc != $status} then {
129 if {$status == 0} then {
130 fail "$testname, unexpected success"
131 } elseif {$execrc == 0} then {
132 fail "$testname, unexpected failure, $comp_output, $comp_error"
134 fail "$testname, expected exit code $execrc, but got exit code $status"
138 # ok, at least exit code match.
140 if [file exists $outfile] then {
141 set cmp_cmd "cmp xargs.out $outfile"
142 send_log "$cmp_cmd\n"
143 catch "exec $cmp_cmd" cmpout
144 if {$cmpout != ""} then {
146 catch "exec diff -u xargs.out $outfile" diffs
147 send_log "stdout diffs: $diffs\n"
148 fail "$testname, wrong stdout output: $cmpout"
151 } elseif {[file size xargs.out] != 0} then {
152 fail "$testname, output on stdout should be empty"
156 # if stderr check is enabled,
157 if {$errfile != ""} then {
158 if {[file exists $errfile]} then {
159 set cmp_cmd "cmp xargs.err $errfile"
160 send_log "$cmp_cmd\n"
161 catch "exec $cmp_cmd" cmperr
162 if {$cmperr != ""} then {
164 catch "exec diff -ua xargs.err $errfile" diffs
165 send_log "stderr diffs: $diffs\n"
166 fail "$testname, wrong stderr output: $cmperr"
169 } elseif {[file size xargs.err] != 0} then {
170 fail "$testname, output on stderr should be empty"
179 # Clean up (remove temporary files) before runtest exits.
181 catch "exec rm -f xargs.out xargs.err"