2 # Expect script for Chill Regression Tests
3 # Copyright (C) 1993, 1996, 1997 Free Software Foundation
5 # This file is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 # Written by Jeffrey Wheat (cassidy@cygnus.com)
23 # chill support library procedures and testsuite specific instructions
27 # default_chill_version
28 # extract and print the version number of the chill compiler
29 # exits if compiler does not exist
31 proc default_chill_version { } {
34 # ignore any arguments after the command
35 set compiler [lindex $GCC_UNDER_TEST 0]
37 # verify that the compiler exists
38 if {[which $compiler] != 0} then {
39 set tmp [ exec $compiler -v ]
40 regexp "version.*$" $tmp version
42 if [info exists version] then {
43 clone_output "[which $compiler] $version\n"
46 warning "$compiler does not exist"
53 # compile the specified file
57 # return 1 on failure with $result containing compiler output
58 # exit with -1 if compiler doesn't exist
61 # 1 - indicate compile in progress
62 # 2 - indicate compile, target name
63 # 3 - indicate compile, target name, exec command, and result
65 proc chill_compile { src obj } {
78 set dumpfile [file rootname $obj].cmp ;# name of file to dump stderr in
80 # verify that the compiler exists
81 if { [which $GCC_UNDER_TEST] == 0 } then {
82 warning "$GCC_UNDER_TEST does not exist"
86 if { $verbose == 1 } then {
87 send_user "Compiling... "
89 verbose " - CMPL: Compiling [file tail $src]" 2
92 # if object type is a grt file, then only build a grant file
93 if [string match "*.grt" $obj] then {
94 set cflags [concat $cflags -fgrant-only]
98 set commandline "$GCC_UNDER_TEST $cflags -I$subdir -c $src"
100 # write command line to logfile
101 send_log "\n### EXEC: $commandline\n"
103 # tell us whats going on if verbose
104 verbose "### EXEC: $commandline" 3
106 # exec the compiler with the appropriate flags
107 set errno [catch "exec $commandline" result]
109 # dump compiler's stderr output into $dumpfile - this is a gross hack
110 set dumpfile [open $dumpfile w+]; puts $dumpfile $result; close $dumpfile
112 # log any compiler output unless its null
113 if ![string match "" $result] then { send_log "\n$result\n" }
120 # link the specified files
123 # return 0 on success
124 # return 1 on failure with $result containing compiler output
125 # exit with -1 if compiler doesn't exist
128 # 1 - indicate linking in progress
129 # 2 - indicate linking, target name
130 # 3 - indicate linking, target name, exec command, and result
132 proc chill_link { target } {
133 global GCC_UNDER_TEST
147 # verify that the compiler exists
148 if { [which $GCC_UNDER_TEST] == 0 } then {
149 warning "$GCC_UNDER_TEST does not exist"
153 if { $verbose == 1 } then {
154 send_user "Linking... "
156 verbose " - LINK: Linking [file tail $target]" 2
159 # verify that the object exists
160 if ![file exists $target.o] then {
162 set result "file $target.o doesn't exist"
167 set commandline "$GCC_UNDER_TEST $CFLAGS -o $target $target.o $objs $crt0 $libs"
169 # write command line to logfile
170 send_log "\n### EXEC: $commandline\n"
172 # tell us whats going on if we are verbose
173 verbose "### EXEC: $commandline" 3
175 # link the objects, sending any linker output to $result
176 set errno [catch "exec $commandline > $tmptarget.lnk" result]
178 # log any linker output unless its null
179 if ![string match "" $result] then { send_log "\n$result\n" }
184 # default_chill_start
186 proc default_chill_start { } {
192 if { $verbose > 1 } then { send_user "Configuring testsuite... " }
194 # tmpdir is obtained from $objdir/site.exp. if not, set it to /tmp
195 if ![info exists tmpdir] then { set tmpdir /tmp }
197 # save and convert $srcdir to an absolute pathname, stomp on the old value
198 # stomp on $subdir and set to the absolute path to the subdirectory
199 global osrcdir; set osrcdir $srcdir; set srcdir [cd $srcdir; pwd]
200 global osubdir; set osubdir $subdir; set subdir $srcdir/$subdir
202 # cd the temporary directory, $tmpdir
203 cd $tmpdir; verbose "### PWD: [pwd]" 5
205 # copy init files to the tmpdir
206 foreach initfile [glob -nocomplain $subdir/*.init] {
207 set targfile $tmpdir/[file tail [file rootname $initfile]]
208 verbose "### EXEC: cp $initfile $targfile" 5
209 if [catch "exec cp $initfile $targfile"] then {
210 send_user "\nConfigure failed.\n"
214 if { $verbose > 1 } then { send_user "Configuring finished.\n" }
221 proc default_chill_exit { } {
228 # reset directory variables
229 set srcdir $osrcdir; set subdir $osubdir
231 # remove all generated targets and objects
232 verbose "### EXEC: rm -f $tmpdir/*" 3
233 catch "exec rm -f $tmpdir/*" result
235 # change back to the main object directory
237 verbose "### SANITY: [pwd]" 5
242 # compare two files line-by-line
245 # return 0 on success
246 # return 1 if different
247 # return -1 if output file doesn't exist
250 # 1 - indicate diffing in progress
251 # 2 - indicate diffing, target names
252 # 3 - indicate diffing, target names, and result
254 proc chill_diff { file_1 file_2 } {
266 if { $verbose == 1 } then {
267 send_user "Diffing... "
269 verbose " - DIFF: Diffing [file tail $file_1] [file tail $file_2]" 2
272 # write command line to logfile
273 send_log "### EXEC: diff $file_1 $file_2\n"
275 # tell us whats going on if we are verbose
276 verbose "### EXEC: diff $file_1 $file_2" 3
278 # verify file exists and open it
279 if [file exists $file_1] then {
280 set file_a [open $file_1 r]
282 set errno -1; set result "$file_1 doesn't exist"
286 # verify file exists and is not zero length, and then open it
287 if [file exists $file_2] then {
288 if [file size $file_2]!=0 then {
289 set file_b [open $file_2 r]
291 set errno -1; set result "$file_2 is zero bytes"; return
294 set errno -1; set result "$file_2 doesn't exist"; return
297 # spoof the diff routine
298 lappend list_a $target
300 while { [gets $file_a line] != $eof } {
301 if [regexp "^#.*$" $line] then {
309 # spoof the diff routine
310 lappend list_b $target
312 while { [gets $file_b line] != $eof } {
313 if [regexp "^#.*$" $line] then {
316 # use [file tail $line] to strip off pathname
317 lappend list_b [file tail $line]
322 for { set i 0 } { $i < [llength $list_a] } { incr i } {
323 set line_a [lindex $list_a $i]
324 set line_b [lindex $list_b $i]
326 if [string compare $line_a $line_b] then {
328 set count [expr $i+1]
329 set linenum [format %dc%d $count $count]
331 verbose "< $line_a" 3
333 verbose "> $line_b" 3
335 send_log "$file_1: < $count: $line_a\n"
336 send_log "$file_2: > $count: $line_b\n"
337 set result "differences found"
345 # a wrapper around the framework fail proc
347 proc chill_fail { target result } {
350 if { $verbose == 1 } then { send_user "\n" }
352 verbose "--------------------------------------------------" 3
353 verbose "### RESULT: $result" 3
358 # a wrapper around the framework fail proc
360 proc chill_pass { target } {
363 if { $verbose == 1 } then { send_user "\n" }