Imported Upstream version 4.8.1
[platform/upstream/gcc48.git] / gcc / testsuite / go.test / go-test.exp
1 #   Copyright (C) 2009-2013 Free Software Foundation, Inc.
2 #   Written by Ian Lance Taylor <iant@google.com>.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GCC; see the file COPYING3.  If not see
16 # <http://www.gnu.org/licenses/>.
17
18
19 # Test using the testsuite for the gc Go compiler.  In these tests the
20 # first line is a shell script to run.  That line expects the
21 # following environment variables to be set:
22 #   A   The file extension of the object file and the name of the executable
23 #   G   The name of the compiler
24 #   L   The name of the linker
25 #   F   The basename of the test
26 #   D   The directory of the test.
27 #
28 # Typical command lines:
29 # // compile
30 # // run
31 # // $G $D/$F.go && $L $F.$A && ./$A.out
32 # // $G $D/$F.go && $L $F.$A || echo BUG: known to fail incorrectly
33 # // $G $D/$F.go && echo BUG: compilation succeeds incorrectly
34 # // $G $D/$F.go || echo BUG: compilation should succeed
35
36 load_lib go-dg.exp
37 load_lib go-torture.exp
38 load_lib target-supports.exp
39
40 # Compare two files
41 proc filecmp { file1 file2 testname } {
42     set f1 [open $file1 r]
43     set f2 [open $file2 r]
44     set ok 1
45     while { [gets $f1 line1] >= 0 } {
46         if { [gets $f2 line2] < 0 } {
47             verbose -log "output mismatch: $file2 shorter than $file1"
48             set ok 0
49             break
50         }
51         if { $line1 != $line2 } {
52             verbose -log "output mismatch comparing $file1 and $file2"
53             verbose -log "expected \"$line1\""
54             verbose -log "got      \"$line2\""
55             set ok 0
56             break
57         }
58     }
59     if { [gets $f2 line2] >= 0 } {
60         verbose -log "output mismatch: $file1 shorter than $file2"
61         set ok 0
62     }
63     close $f1
64     close $f2
65     if { ! $ok } {
66         fail $testname
67     } else {
68         pass $testname
69     }
70 }
71
72 # Implement errchk
73 proc errchk { test opts } {
74     global dg-do-what-default
75     global DEFAULT_GOCFLAGS
76     global runtests
77
78     set saved-dg-do-what-default ${dg-do-what-default}
79     set dg-do-what-default compile
80     set filename [file tail $test]
81     if { "$filename" == "$test" } {
82         set filename "errchk-$filename"
83     }
84     set fdin [open $test r]
85     fconfigure $fdin -encoding binary
86     set fdout [open $filename w]
87     fconfigure $fdout -encoding binary
88     while { [gets $fdin copy_line] >= 0 } {
89         if [string match "*////*" $copy_line] {
90             puts $fdout $copy_line
91             continue
92         }
93         regsub "// \(GCCGO_\)?ERROR \"\(\[^\"\]*\)\".*$" $copy_line "// \{ dg-error \"\\2\" \}" out_line
94         if [string match "*dg-error*\\\[*" $out_line] {
95             set index [string first "dg-error" $out_line]
96             regsub -start $index -all "\\\\\\\[" $out_line "\\\\\\\\\\\[" out_line
97         }
98         if [string match "*dg-error*\\\]*" $out_line] {
99             set index [string first "dg-error" $out_line]
100             regsub -start $index -all "\\\\\\\]" $out_line "\\\\\\\\\\\]" out_line
101         }
102         if [string match "*dg-error*.\**" $out_line] {
103             # I worked out the right number of backslashes by
104             # experimentation, not analysis.
105             regsub -all "\\.\\*" $out_line "\\\\\[ -~\\\\\]*" out_line
106         }
107         if [string match "*dg-error*\\\[?\\\]*" $out_line] {
108             set index [string first "dg-error" $out_line]
109             regsub -all "\\\[\(.\)\\\]" $out_line "\\\\\[\\1\\\\\]" out_line
110         }
111         if [string match "*dg-error*\{*" $out_line] {
112             set index [string first "dg-error" $out_line]
113             regsub -start $index -all "\(\[^\\\\]\)\{" $out_line "\\1\\\\\[\\\{\\\\\]" out_line
114         }
115         if [string match "*dg-error*\}*\}" $out_line] {
116             set index [string first "dg-error" $out_line]
117             regsub -start $index -all "\(\[^\\\\]\)\}\(.\)" $out_line "\\1\\\\\[\\\}\\\\\]\\2" out_line
118         }
119         if [string match "*dg-error*\(*" $out_line] {
120             set index [string first "dg-error" $out_line]
121             regsub -start $index -all "\\\\\\\(" $out_line "\\\\\[\\\(\\\\\]" out_line
122         }
123         if [string match "*dg-error*\)*\}" $out_line] {
124             set index [string first "dg-error" $out_line]
125             regsub -start $index -all "\\\\\\\)\(.\)" $out_line "\\\\\[\\\)\\\\\]\\1" out_line
126         }
127         # Special case for bug332, in which the error message wants to
128         # match the file name, which is not what dg-error expects.
129         if [string match "*dg-error*bug332*" $out_line] {
130             set index [string first "dg-error" $out_line]
131             regsub -start $index "bug332" $out_line "undefined type" out_line
132         }
133         puts $fdout $out_line
134     }
135     close $fdin
136     close $fdout
137
138     set hold_runtests $runtests
139     set runtests "go-test.exp"
140     go-dg-runtest $filename "-fno-show-column $DEFAULT_GOCFLAGS $opts"
141     set runtests $hold_runtests
142
143     file delete $filename
144     set dg-do-what-default ${saved-dg-do-what-default}
145 }
146
147 # This is an execution test which should fail.
148 proc go-execute-xfail { test } {
149     global DEFAULT_GOCFLAGS
150     global runtests
151
152     set filename [file tail $test]
153     set fdin [open $test r]
154     set fdout [open $filename w]
155     puts $fdout "// { dg-do run { xfail *-*-* } }"
156     while { [gets $fdin copy_line] >= 0 } {
157         puts $fdout $copy_line
158     }
159     close $fdin
160     close $fdout
161
162     set hold_runtests $runtests
163     set runtests "go-test.exp"
164     go-dg-runtest $filename "-w $DEFAULT_GOCFLAGS"
165     set runtests $hold_runtests
166
167     file delete $filename
168 }
169
170 # N.B. Keep in sync with libgo/configure.ac.
171 proc go-set-goarch { } {
172     global target_triplet
173
174     switch -glob $target_triplet {
175         "alpha*-*-*" {
176             set goarch "alpha"
177         }
178         "arm*-*-*" -
179         "ep9312*-*-*" -
180         "strongarm*-*-*" -
181         "xscale-*-*" {
182             set goarch "arm"
183         }
184         "i?86-*-*" -
185         "x86_64-*-*" {
186             if [check_effective_target_ia32] {
187                 set goarch "386"
188             } else {
189                 set goarch "amd64"
190             }
191         }
192         "mips*-*-*" {
193             if [check_no_compiler_messages mipso32 assembly {
194                 #if _MIPS_SIM != _ABIO32
195                 #error FOO
196                 #endif
197             }] {
198                 set goarch "mipso32"
199             } elseif [check_no_compiler_messages mipsn32 assembly {
200                 #if _MIPS_SIM != _ABIN32
201                 #error FOO
202                 #endif
203             }] {
204                 set goarch "mipsn32"
205             } elseif [check_no_compiler_messages mipsn64 assembly {
206                 #if _MIPS_SIM != _ABI64
207                 #error FOO
208                 #endif
209             }] {
210                 set goarch "mipsn64"
211             } elseif [check_no_compiler_messages mipso64 assembly {
212                 #if _MIPS_SIM != _ABIO64
213                 #error FOO
214                 #endif
215             }] {
216                 set goarch "mipso64"
217             } else {
218                 perror "$target_triplet: unrecognized MIPS ABI"
219                 return ""
220             }
221         }
222         "powerpc*-*-*" {
223             if [check_effective_target_ilp32] {
224                 set goarch "ppc"
225             } else {
226                 set goarch "ppc64"
227             }
228         }
229         "sparc*-*-*" {
230             if [check_effective_target_ilp32] {
231                 set goarch "sparc"
232             } else {
233                 set goarch "sparc64"
234             }
235         }
236         default {
237             perror "$target_triplet: unhandled architecture"
238             return ""
239         }       
240     }
241     verbose -log "Setting GOARCH=$goarch" 1
242     setenv GOARCH $goarch
243 }
244
245 proc go-gc-tests { } {
246     global srcdir subdir
247     global runtests
248     global GCC_UNDER_TEST
249     global TOOL_OPTIONS
250     global TORTURE_OPTIONS
251     global dg-do-what-default
252     global go_compile_args
253     global go_execute_args
254     global target_triplet
255
256     # If a testcase doesn't have special options, use these.
257     global DEFAULT_GOCFLAGS
258     if ![info exists DEFAULT_GOCFLAGS] {
259         set DEFAULT_GOCFLAGS " -pedantic-errors"
260     }
261
262     set options ""
263     lappend options "additional_flags=$DEFAULT_GOCFLAGS"
264
265     # Set GOARCH for tests that need it.
266     go-set-goarch
267
268     # Running all the torture options takes too long and, since the
269     # frontend ignores the standard options, it doesn't significantly
270     # improve testing.
271     set saved_torture_options $TORTURE_OPTIONS
272     set TORTURE_OPTIONS [list { -O2 -g }]
273
274     set saved-dg-do-what-default ${dg-do-what-default}
275
276     set testdir [pwd]
277
278     set tests [lsort [find $srcdir/$subdir *.go]]
279     foreach test $tests {
280         if ![runtest_file_p $runtests $test] {
281             continue
282         }
283
284         # Skip the files in bench; they are not tests.
285         if [string match "*go.test/test/bench/*" $test] {
286             continue
287         }
288
289         # Skip files in sub-subdirectories: they are components of
290         # other tests.
291         if [string match "*go.test/test/*/*/*" $test] {
292             continue
293         }
294
295         set name [dg-trim-dirname $srcdir $test]
296
297         # Skip certain tests if target is RTEMS OS.
298         if [istarget "*-*-rtems*"] {
299             if { [string match "*go.test/test/args.go" $test] \
300                  || [string match "*go.test/test/env.go" $test] } {
301                     untested "$name: uses the command-line or environment variables"
302                     continue
303             }
304
305             if { [string match "*go.test/test/stack.go" $test] \
306                  || [string match "*go.test/test/peano.go" $test] \
307                  || [string match "*go.test/test/chan/goroutines.go" $test] } {
308                     untested "$name: has very high memory requirement"
309                     continue
310             }
311         }
312
313         # Handle certain tests in a target-dependant way.
314         if { [istarget "alpha*-*-*"] || [istarget "sparc*-*-solaris*"] || [istarget "powerpc*-*-*"] } {
315             if { [string match "*go.test/test/nilptr.go" $test] } {
316                 untested $test
317                 continue
318             }
319         }
320
321         if { [file tail $test] == "init1.go" } {
322             # This tests whether GC runs during init, which for gccgo
323             # it currently does not.
324             untested $name
325             continue
326         }
327
328         if { [file tail $test] == "closure.go" } {
329             # This tests whether function closures do any memory
330             # allocation, which for gccgo they currently do.
331             untested $name
332             continue
333         }
334
335         if { ( [file tail $test] == "select2.go" \
336                    || [file tail $test] == "stack.go" ) \
337                  && ! [check_effective_target_split_stack] } {
338             # chan/select2.go fails on targets without split stack,
339             # because they allocate a large stack segment that blows
340             # out the memory calculations.
341             untested $name
342             continue
343         }
344
345         if { [file tail $test] == "rotate.go" } {
346             # This test produces a temporary file that takes too long
347             # to compile--5 minutes on my laptop without optimization.
348             # When compiling without optimization it tests nothing
349             # useful, since the point of the test is to see whether
350             # the compiler generates rotate instructions.
351             untested $name
352             continue
353         }
354
355         if { [file tail $test] == "bug347.go" \
356                  || [file tail $test] == "bug348.go" } {
357             # These tests don't work if the functions are inlined.
358             set TORTURE_OPTIONS [list { -O0 -g }]
359         }
360
361         set fd [open $test r]
362
363         set lines_ok 1
364
365         while 1 {
366             if { [gets $fd test_line] < 0 } {
367                 close $fd
368                 clone_output "$test: could not read first line"
369                 unresolved $name
370                 set lines_ok 0
371                 break
372             }
373
374             if { [ string match "*nacl*exit 0*" $test_line ] \
375                      || [ string match "*exit 0*nacl*" $test_line ] \
376                      || [ string match "*Android*exit 0*" $test_line ] \
377                      || [ string match "*exit 0*Android*" $test_line ] \
378                      || [ string match "*\"\$GOOS\" == windows*" $test_line ] } {
379                 continue
380             }
381
382             break
383         }
384
385         if { $lines_ok == 0 } {
386             continue
387         }
388
389         set lineno 1
390         set test_line1 $test_line
391
392         while { [eval "string match \"//*&&\" \${test_line$lineno}"] } {
393             set lineno [expr $lineno + 1]
394             if { [eval "gets \$fd test_line$lineno"] < 0 } {
395                 close $fd
396                 clone_output "$test: could not read line $lineno"
397                 unresolved $name
398                 set lines_ok 0
399                 break
400             }
401         }
402         if { $lines_ok == 0 } {
403             continue
404         }
405
406         close $fd
407
408         set go_compile_args ""
409         set go_execute_args ""
410         if { [regexp ".*\\\$A.out (\[^|&>2\].*)\$" $test_line match progargs] } {
411             set go_execute_args $progargs
412             verbose -log "$test: go_execute_args is $go_execute_args"
413             set index [string last " $progargs" $test_line]
414             set test_line [string replace $test_line $index end]
415         } elseif { [string match "*go.test/test/chan/goroutines.go" $test] \
416                    && [getenv GCCGO_RUN_ALL_TESTS] == "" } {
417             # goroutines.go spawns by default 10000 threads, which is too much
418             # for many OSes.
419             if { [getenv GCC_TEST_RUN_EXPENSIVE] == "" } {
420                 set go_execute_args 64
421             } elseif { ![is_remote host] && ![is_remote target] } {
422                 # When using low ulimit -u limit, use maximum of
423                 # a quarter of that limit and 10000 even when running expensive
424                 # tests, otherwise parallel tests might fail after fork failures.
425                 set nproc [lindex [remote_exec host {sh -c ulimit\ -u}] 1]
426                 if { [string is integer -strict $nproc] } {
427                         set nproc [expr $nproc / 4]
428                         if { $nproc > 10000 } { set nproc 10000 }
429                         if { $nproc < 16 } { set nproc 16 }
430                         set go_execute_args $nproc
431                 }
432             }
433             if { "$go_execute_args" != "" } {
434                 verbose -log "$test: go_execute_args is $go_execute_args"
435             }
436         }
437
438         if { $test_line == "// compile"
439              || $test_line == "// echo bug395 is broken  # takes 90+ seconds to break" } {
440             # This is a vanilla compile test.
441             set dg-do-what-default "assemble"
442             go-dg-runtest $test "-w $DEFAULT_GOCFLAGS"
443         } elseif { $test_line == "// run"
444                    || $test_line == "// \$G \$F.go && \$L \$F.\$A && ./\$A.out" } {
445             # This is a vanilla execution test.
446             go-torture-execute $test
447             file delete core [glob -nocomplain core.*]
448         } elseif { $test_line == "// build" } {
449             # This is a vanilla compile and link test.
450             set dg-do-what-default "link"
451             go-dg-runtest $test "-w $DEFAULT_GOCFLAGS"
452         } elseif { [string match "// runoutput*" $test_line] \
453                        || ($test_line == "// \$G \$D/\$F.go && \$L \$F.\$A &&"
454                            && $test_line2 == "// ./\$A.out >tmp.go && \$G tmp.go && \$L -o \$A.out1 tmp.\$A && ./\$A.out1") } {
455             # Run the test to get a .go program to run.
456             set go_execute_args ""
457             set hold_runtests $runtests
458             set runtests "go-test.exp"
459             set files [list]
460             if { [string match "// runoutput*" $test_line] } {
461                 set args ""
462                 regsub "// runoutput\(.*\)" $test_line "\\1" args
463                 foreach f $args {
464                     lappend files "[file dirname $test]/$f"
465                 }
466             }
467             set dg-do-what-default "link"
468             dg-test -keep-output $test "-O" "$files -w $DEFAULT_GOCFLAGS"
469             set output_file "./[file rootname [file tail $test]].exe"
470             set base "[file rootname [file tail $test]]"
471             if [isnative] {
472                 if { [catch "exec $output_file >$base-out.go"] != 0 } {
473                     fail "$name execution"
474                 } else {
475                     pass "$name execution"
476                     file delete $base-out.x
477                     # Disable optimizations as some of these tests
478                     # take a long time to compile.
479                     set TORTURE_OPTIONS [list { -O0 -g -fno-var-tracking-assignments }]
480                     go-torture-execute "./$base-out.go"
481                 }
482                 file delete $base-out.go
483             }
484             file delete $output_file
485             set runtests $hold_runtests
486         } elseif { $test_line == "// cmpout" \
487                    || $test_line == "// (\$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out 2>&1 | cmp - \$D/\$F.out)" } {
488             # This is an execution test for which we need to check the
489             # program output.
490             set hold_runtests $runtests
491             set runtests "go-test.exp"
492             set dg-do-what-default "link"
493             dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
494             set output_file "./[file rootname [file tail $test]].exe"
495             set base "[file rootname [file tail $test]]"
496             if [isnative] {
497                 verbose -log "$output_file >$base.p 2>&1"
498                 if { [catch "exec $output_file 2>$base.p" catcherr] != 0 } {
499                     verbose -log $catcherr
500                     fail "$name execution"
501                     untested "$name compare"
502                 } else {
503                     pass "$name execution"
504                     regsub "\\.go$" $test ".out" expect
505                     filecmp $expect $base.p "$name compare"
506                 }
507                 file delete $base.p
508             } else {
509                 untested "$name execution"
510                 untested "$name compare"
511             }
512             set runtests $hold_runtests
513         } elseif { [string match "// \$G \$D/\$F.go && \$L \$F.\$A && ! ./\$A.out || echo BUG: *" \
514                     $test_line] } {
515             go-execute-xfail $test
516         } elseif { $test_line == "// errorcheck" } {
517             errchk $test ""
518         } elseif { [string match "// errorcheckoutput*" $test_line] } {
519             # Run the test to get a .go program to error check.
520             set go_execute_args ""
521             set hold_runtests $runtests
522             set runtests "go-test.exp"
523             set files [list]
524             regsub "// errorcheckoutput\(.*\)" $test_line "\\1" args
525             foreach f $args {
526                 lappend files "[file dirname $test]/$f"
527             }
528             set dg-do-what-default "link"
529             dg-test -keep-output $test "-O" "$files -w $DEFAULT_GOCFLAGS"
530             set output_file "./[file rootname [file tail $test]].exe"
531             set base "[file rootname [file tail $test]]"
532             if [isnative] {
533                 if { [catch "exec $output_file >$base-out.go"] != 0 } {
534                     fail "$name execution"
535                 } else {
536                     pass "$name execution"
537                     errchk "$base-out.go" ""
538                 }
539                 file delete $base-out.go
540             }
541             file delete $output_file
542             set runtests $hold_runtests
543         } elseif { $test_line == "// compiledir" } {
544             set hold_runtests $runtests
545             set runtests "go-test.exp"
546             set dg-do-what-default "assemble"
547             set dir "[file rootname $test].dir"
548             set del {}
549             foreach f [lsort [glob "$dir/*.go"]] {
550                 dg-test -keep-output $f "-O" "-w $DEFAULT_GOCFLAGS"
551                 lappend del "[file rootname [file tail $f]].o"
552             }
553             foreach f $del {
554                 file delete $f
555             }
556             set runtests $hold_runtests
557         } elseif { $test_line == "// rundir" } {
558             set hold_runtests $runtests
559             set runtests "go-test.exp"
560             set dg-do-what-default "assemble"
561             set dir "[file rootname $test].dir"
562             set del {}
563             set files [lsort [glob "$dir/*.go"]]
564             set last [lindex $files end]
565             set files [lreplace $files end end]
566             foreach f $files {
567                 dg-test -keep-output $f "-O" "-w $DEFAULT_GOCFLAGS"
568                 lappend del "[file rootname [file tail $f]].o"
569             }
570             set dg-do-what-default "link"
571             set go_compile_args $del
572             go-torture-execute $last
573             foreach f $del {
574                 file delete $f
575             }
576             set runtests $hold_runtests
577         } elseif { "$test_line" == ""
578                    || [string match "// true*" $test_line]
579                    || [string match "// skip*" $test_line] } {
580             # Not a real test, just ignore.
581         } elseif { [string match \
582                         "// \$G \$D/\$F.dir/bug0.go && errchk \$G \$D/\$F.dir/bug1.go" \
583                         $test_line] \
584                        || [string match \
585                                "// \$G \$D/\$F.dir/io.go && errchk \$G -e \$D/\$F.dir/main.go" \
586                                $test_line] } {
587             if { [string match \
588                       "// \$G \$D/\$F.dir/bug0.go && errchk \$G \$D/\$F.dir/bug1.go" \
589                       $test_line] } {
590                 set name1 "bug0.go"
591                 set name2 "bug1.go"
592             } elseif { [string match \
593                             "// \$G \$D/\$F.dir/io.go && errchk \$G -e \$D/\$F.dir/main.go" \
594                             $test_line] } {
595                 set name1 "io.go"
596                 set name2 "main.go"
597             }
598             set hold_runtests $runtests
599             set runtests "go-test.exp"
600             set dg-do-what-default "assemble"
601             regsub "\\.go$" $test ".dir/$name1" file1
602             dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
603             regsub "\\.go$" $test ".dir/$name2" file2
604             errchk $file2 ""
605             file delete "[file rootname [file tail $file1]].o"
606             set runtests $hold_runtests
607         } elseif { [string match \
608                         "// \$G \$D/\${F}1.go && errchk \$G \$D/\$F.go" \
609                         $test_line ] } {
610             set hold_runtests $runtests
611             set runtests "go-test.exp"
612             set dg-do-what-default "assemble"
613             regsub "\\.go$" $test "1.go" file1
614             dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
615             errchk $test ""
616             file delete "[file rootname [file tail $file1]].o"
617             set runtests $hold_runtests
618         } elseif { [string match \
619                         "// \$G \$D/\$F.dir/bug0.go && \$G \$D/\$F.dir/bug1.go && errchk \$G \$D/\$F.dir/bug2.go" \
620                         $test_line] } {
621             set hold_runtests $runtests
622             set runtests "go-test.exp"
623             set dg-do-what-default "assemble"
624             regsub "\\.go$" $test ".dir/bug0.go" file1
625             dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
626             regsub "\\.go$" $test ".dir/bug1.go" file2
627             dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
628             regsub "\\.go$" $test ".dir/bug2.go" file3
629             errchk $file3 ""
630             file delete "[file rootname [file tail $file1]].o"
631             file delete "[file rootname [file tail $file2]].o"
632             set runtests $hold_runtests
633         } elseif { [string match \
634                         "// \$G \$D/bug160.dir/x.go && \$G \$D/bug160.dir/y.go && \$L y.\$A && ./\$A.out" \
635                         $test_line] \
636                        || [string match \
637                                "// \$G \$D/\$F.dir/p.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out" \
638                                $test_line] \
639                        || $test_line == "// \$G \$D/\$F.dir/p1.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out" \
640                        || $test_line == "// \$G \$D/\$F.dir/lib.go && \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out" \
641                        || $test_line == "// \$G \$D/method4a.go && \$G \$D/\$F.go && \$L \$F.\$A && ./$\A.out" } {
642             if { [string match \
643                         "// \$G \$D/bug160.dir/x.go && \$G \$D/bug160.dir/y.go && \$L y.\$A && ./\$A.out" \
644                       $test_line] } {
645                 set name1 "x.go"
646                 set name2 "y.go"
647             } elseif { [string match \
648                            "// \$G \$D/\$F.dir/p.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out" \
649                             $test_line] } {
650                 set name1 "p.go"
651                 set name2 "main.go"
652             } elseif { $test_line == "// \$G \$D/\$F.dir/p1.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out" } {
653                 set name1 "p1.go"
654                 set name2 "main.go"
655             } elseif { $test_line == "// \$G \$D/\$F.dir/lib.go && \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out" } {
656                 set name1 "lib.go"
657                 set name2 ""
658             } elseif { $test_line == "// \$G \$D/method4a.go && \$G \$D/\$F.go && \$L \$F.\$A && ./$\A.out" } {
659                 set name1 "method4a.go"
660                 set name2 ""
661             }
662             set hold_runtests $runtests
663             set runtests "go-test.exp"
664             set dg-do-what-default "assemble"
665             regsub "\\.go$" $test ".dir/$name1" file1
666             if { $name1 == "method4a.go" } {
667                 set file1 "[file dirname $test]/method4a.go"
668             }
669             dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
670             set ofile1 "[file rootname [file tail $file1]].o"
671             regsub "\\.go$" $test ".dir/$name2" file2
672             if { $name2 == "" } {
673                 set file2 $test
674             }
675             dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
676             set ofile2 "[file rootname [file tail $file2]].o"
677             set dg-do-what-default "link"
678             set output_file "./[file rootname [file tail $test]].exe"
679             set comp_output [go_target_compile "$ofile1 $ofile2" \
680                                  $output_file "executable" "$options"]
681             set comp_output [go-dg-prune $target_triplet $comp_output]
682             verbose -log $comp_output
683             set result [go_load "$output_file" "" ""]
684             set status [lindex $result 0]
685             $status $name
686             file delete $ofile1 $ofile2 $output_file
687             set runtests $hold_runtests
688         } elseif { $test_line == "// \$G \$D/\$F.dir/one.go && \$G \$D/\$F.dir/two.go && \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out" } {
689             set hold_runtests $runtests
690             set runtests "go-test.exp"
691             set dg-do-what-default "assemble"
692             regsub "\\.go$" $test ".dir/one.go" file1
693             dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
694             set ofile1 "[file rootname [file tail $file1]].o"
695             regsub "\\.go$" $test ".dir/two.go" file2
696             dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
697             set ofile2 "[file rootname [file tail $file2]].o"
698             dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
699             set ofile3 "[file rootname [file tail $test]].o"
700             set dg-do-what-default "link"
701             set output_file "./[file rootname [file tail $test]].exe"
702             set comp_output [go_target_compile "$ofile1 $ofile2 $ofile3" \
703                                  $output_file "executable" "$options"]
704             set comp_output [go-dg-prune $target_triplet $comp_output]
705             verbose -log $comp_output
706             set result [go_load "$output_file" "" ""]
707             set status [lindex $result 0]
708             $status $name
709             file delete $ofile1 $ofile2 $ofile3 $output_file
710             set runtests $hold_runtests
711         } elseif { [string match \
712                         "// \$G \$D/bug191.dir/a.go && \$G \$D/bug191.dir/b.go && \$G \$D/\$F.go && \$L \$F.\$A" \
713                         $test_line] } {
714             set hold_runtests $runtests
715             set runtests "go-test.exp"
716             set dg-do-what-default "assemble"
717             regsub "\\.go$" $test ".dir/a.go" file1
718             dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
719             set ofile1 "[file rootname [file tail $file1]].o"
720             regsub "\\.go$" $test ".dir/b.go" file2
721             dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
722             set ofile2 "[file rootname [file tail $file2]].o"
723             dg-test -keep-output "$test" "-O" "-w $DEFAULT_GOCFLAGS"
724             set ofile3 "[file rootname [file tail $test]].o"
725             set dg-do-what-default "link"
726             set output_file "./[file rootname [file tail $test]].exe"
727             set comp_output [go_target_compile "$ofile1 $ofile2 $ofile3" \
728                                  $output_file "executable" "$options"]
729             set comp_output [go-dg-prune $target_triplet $comp_output]
730             if [string match "" $comp_output] {
731                 pass $name
732             } else {
733                 verbose -log $comp_output
734                 fail $name
735             }
736             file delete $ofile1 $ofile2 $ofile3 $output_file
737             set runtests $hold_runtests
738         } elseif { [string match \
739                         "// \$G \$D/embed0.go && \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out" \
740                         $test_line ] } {
741             set hold_runtests $runtests
742             set runtests "go-test.exp"
743             set dg-do-what-default "assemble"
744             regsub "/\[^/\]*$" $test "/embed0.go" file1
745             dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
746             set ofile1 "[file rootname [file tail $file1]].o"
747             dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
748             set ofile2 "[file rootname [file tail $test]].o"
749             set output_file "./[file rootname [file tail $test]].exe"
750             set comp_output [go_target_compile "$ofile1 $ofile2" \
751                                  $output_file "executable" "$options"]
752             set comp_output [go-dg-prune $target_triplet $comp_output]
753             if [string match "" $comp_output] {
754                 set result [go_load "$output_file" "" ""]
755                 set status [lindex $result 0]
756                 $status $name
757             } else {
758                 verbose -log $comp_output
759                 fail $name
760             }
761             file delete $ofile1 $ofile2 $output_file
762             set runtests $hold_runtests
763         } elseif { [string match \
764                         "// \$G \$D/\$F.dir/lib.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out || echo BUG*" \
765                         $test_line ] || \
766                        [string match \
767                             "// \$G \$D/\$F.dir/p.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out || echo BUG*" \
768                             $test_line ] } {
769             if { [string match \
770                       "// \$G \$D/\$F.dir/lib.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out || echo BUG*" \
771                       $test_line ] } {
772                 set name1 "lib.go"
773                 set name2 "main.go"
774             } elseif { [string match \
775                             "// \$G \$D/\$F.dir/p.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out || echo BUG*" \
776                             $test_line ] } {
777                 set name1 "p.go"
778                 set name2 "main.go"
779             }
780             set hold_runtests $runtests
781             set runtests "go-test.exp"
782             set dg-do-what-default "assemble"
783             regsub "\\.go$" $test ".dir/$name1" file1
784             dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
785             set ofile1 "[file rootname [file tail $file1]].o"
786             regsub "\\.go$" $test ".dir/$name2" file2
787             dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
788             set ofile2 "[file rootname [file tail $file2]].o"
789             set dg-do-what-default "link"
790             set output_file "./[file rootname [file tail $file2]].exe"
791             set comp_output [go_target_compile "$ofile1 $ofile2" \
792                                  $output_file "executable" "$options"]
793             set comp_output [go-dg-prune $target_triplet $comp_output]
794             if [string match "" $comp_output] {
795                 set result [go_load "$output_file" "" ""]
796                 set status [lindex $result 0]
797                 $status $name
798             } else {
799                 verbose -log $comp_output
800                 fail $name
801             }
802             file delete $ofile1 $ofile2 $output_file
803             set runtests $hold_runtests
804         } elseif { $test_line == "// \$G \$D/\$F.dir/bug0.go &&" \
805                        && $test_line2 == "// \$G \$D/\$F.dir/bug1.go &&" \
806                        && $test_line3 == "// \$G \$D/\$F.dir/bug2.go &&" \
807                        && $test_line4 == "// errchk \$G -e \$D/\$F.dir/bug3.go &&" \
808                        && $test_line5 == "// \$L bug2.\$A &&" \
809                        && [string match "// ./\$A.out || echo BUG*" $test_line6] } {
810             set hold_runtests $runtests
811             set runtests "go-test.exp"
812             set dg-do-what-default "assemble"
813             regsub "\\.go$" $test ".dir/bug0.go" file0
814             dg-test -keep-output $file0 "-O -fgo-prefix=bug0" "-w $DEFAULT_GOCFLAGS"
815             set ofile0 "[file rootname [file tail $file0]].o"
816             regsub "\\.go$" $test ".dir/bug1.go" file1
817             dg-test -keep-output $file1 "-O -fgo-prefix=bug1" "-w $DEFAULT_GOCFLAGS"
818             set ofile1 "[file rootname [file tail $file1]].o"
819             regsub "\\.go$" $test ".dir/bug2.go" file2
820             dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
821             set ofile2 "[file rootname [file tail $file2]].o"
822             regsub "\\.go$" $test ".dir/bug3.go" file3
823             errchk $file3 ""
824             set output_file "./[file rootname [file tail $test]].exe"
825             set comp_output [go_target_compile "$ofile0 $ofile1 $ofile2" \
826                                  $output_file "executable" "$options"]
827             set comp-output [go-dg-prune $target_triplet $comp_output]
828             if [string match "" $comp_output] {
829                 set result [go_load "$output_file" "" ""]
830                 set status [lindex $result 0]
831                 $status $name
832             } else {
833                 verbose -log $comp_output
834                 fail $name
835             }
836             file delete $ofile0 $ofile1 $ofile2 $output_file
837             set runtests $hold_runtests
838         } elseif { $test_line == "// \$G \$D/import2.go && \$G \$D/\$F\.go" \
839                        || $test_line == "// \$G \$D/recursive1.go && \$G \$D/\$F.go" } {
840             if { $test_line == "// \$G \$D/import2.go && \$G \$D/\$F\.go" } {
841                 set name1 "import2.go"
842             } elseif { $test_line == "// \$G \$D/recursive1.go && \$G \$D/\$F.go" } {
843                 set name1 "recursive1.go"
844             }
845             set hold_runtests $runtests
846             set runtests "go-test.exp"
847             set dg-do-what-default "assemble"
848             regsub "/\[^/\]*$" $test "/${name1}" file1
849             dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
850             set ofile1 "[file rootname [file tail $file1]].o"
851             dg-test $test "-O" "-w $DEFAULT_GOCFLAGS"
852             file delete $ofile1
853             set runtests $hold_runtests
854         } elseif { $test_line == "// \$G \$D/ddd2.go && \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out" } {
855             set hold_runtests $runtests
856             set runtests "go-test.exp"
857             set dg-do-what-default "assemble"
858             regsub "/\[^/\]*$" $test "/ddd2.go" file1
859             dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
860             set ofile1 "[file rootname [file tail $file1]].o"
861             dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
862             set ofile2 "[file rootname [file tail $test]].o"
863             set output_file "./[file rootname [file tail $test]].exe"
864             set comp_output [go_target_compile "$ofile1 $ofile2" \
865                                  $output_file "executable" "$options"]
866             set comp_output [go-dg-prune $target_triplet $comp_output]
867             if [string match "" $comp_output] {
868                 set result [go_load "$output_file" "" ""]
869                 set status [lindex $result 0]
870                 $status $name
871             } else {
872                 verbose -log $comp_output
873                 fail $name
874             }
875             file delete $ofile1 $ofile2 $output_file
876             set runtests $hold_runtests
877         } elseif { $test_line == "// run cmplxdivide1.go" } {
878             regsub "/\[^/\]*$" $test "/cmplxdivide1.go" test2
879             set output_file "./[file rootname [file tail $test]].o"
880             set comp_output [go_target_compile "$test $test2" \
881                                  $output_file "executable" "$options"]
882             set comp_output [go-dg-prune $target_triplet $comp_output]
883             if [string match "" $comp_output] {
884                 set result [go_load "$output_file" "" ""]
885                 set status [lindex $result 0]
886                 $status $name
887             } else {
888                 verbose -log $comp_output
889                 fail $name
890             }
891             file delete $output_file
892         } elseif { $test_line == "// \$G \$D/\$F.go && \$L \$F.\$A &&" \
893                        && $test_line2 == "// ./\$A.out -pass 0 >tmp.go && \$G tmp.go && \$L -o \$A.out1 tmp.\$A && ./\$A.out1 &&" \
894                        && $test_line3 == "// ./\$A.out -pass 1 >tmp.go && errchk \$G -e tmp.go &&" \
895                        && $test_line4 == "// ./\$A.out -pass 2 >tmp.go && errchk \$G -e tmp.go" } {
896             set go_execute_args ""
897             set hold_runtests $runtests
898             set runtests "go-test.exp"
899             set dg-do-what-default "link"
900             dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
901             set output_file "./[file rootname [file tail $test]].exe"
902             if [isnative] {
903                 if { [catch "exec $output_file -pass 0 >tmp.go"] != 0 } {
904                     fail "$name execution 0"
905                 } else {
906                     pass "$name execution 0"
907                     file delete tmp.x
908                     # Disable optimizations as this test takes a long time
909                     # to compile.
910                     set TORTURE_OPTIONS [list { -O0 -g -fno-var-tracking-assignments }]
911                     go-torture-execute "./tmp.go"
912                 }
913                 if { [catch "exec $output_file -pass 1 >tmp.go"] != 0 } {
914                     fail "$name execution 1"
915                 } else {
916                     pass "$name execution 1"
917                     errchk tmp.go ""
918                 }
919                 if { [catch "exec $output_file -pass 2 >tmp.go"] != 0 } {
920                     fail "$name execution 2"
921                 } else {
922                     pass "$name execution 2"
923                     errchk tmp.go ""
924                 }
925                 file delete tmp.go
926             }
927             file delete $output_file
928             set runtests $hold_runtests
929         } elseif { $test_line == "// \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out >tmp.go &&" \
930                         && $test_line2 == "// errchk \$G -e tmp.go" } {
931             set go_execute_args ""
932             set hold_runtests $runtests
933             set runtests "go-test.exp"
934             set dg-do-what-default "link"
935             dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
936             set output_file "./[file rootname [file tail $test]].exe"
937             if [isnative] {
938                 if { [catch "exec $output_file >tmp.go"] != 0 } {
939                     fail "$name execution"
940                 } else {
941                     pass "$name execution"
942                     file delete tmp.x
943                     errchk tmp.go ""
944                 }
945             }
946             file delete $output_file
947             set runtests $hold_runtests
948         } elseif { $test_line == "// errchk \$G -e \$D/\$F.dir/\[ab\].go" } {
949             regsub "\\.go$" $test ".dir/a.go" file1
950             regsub "\\.go$" $test ".dir/b.go" file2
951             errchk "$file1" "$file2"
952         } elseif { $test_line == "// \$G \$D/\$F.go \$D/z*.go && \$L \$F.\$A && ./\$A.out" } {
953             set dir [file dirname $test]
954             set go_compile_args [glob $dir/z*.go]
955             go-torture-execute $test
956         } elseif { $test_line == "// \$G -N -o slow.\$A \$D/bug369.dir/pkg.go &&" \
957                        && $test_line2 == "// \$G -o fast.\$A \$D/bug369.dir/pkg.go &&" \
958                        && $test_line3 == "// run" } {
959             set hold_runtests $runtests
960             set runtests "go-test.exp"
961             set dg-do-what-default "assemble"
962             regsub "\\.go$" $test ".dir/pkg.go" file1
963             dg-test -keep-output $file1 "" "-fgo-prefix=slow -w $DEFAULT_GOCFLAGS"
964             set ofile1 "[file rootname [file tail $file1]].o"
965             file rename -force $ofile1 slow.o
966             dg-test -keep-output $file1 "-O2" "-fgo-prefix=fast -w $DEFAULT_GOCFLAGS"
967             file rename -force $ofile1 fast.o
968             set ofile2 "[file rootname [file tail $test]].o"
969             dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
970             set output_file "./[file rootname [file tail $test]].exe"
971             set comp_output [go_target_compile "$ofile2 slow.o fast.o" \
972                                  $output_file "executable" "$options"]
973             set comp_output [go-dg-prune $target_triplet $comp_output]
974             if [string match "" $comp_output] {
975                 set result [go_load "$output_file" "" ""]
976                 set status [lindex $result 0]
977                 $status $name
978             } else {
979                 verbose -log $comp_output
980                 fail $name
981             }
982             file delete slow.o fast.o $ofile2 $output_file
983             set runtests $hold_runtests
984         } elseif { [string match \
985                         "// \$G \$D/\$F.dir/pkg.go && \$G \$D/\$F.go || echo *" \
986                         $test_line ] } {
987             set hold_runtests $runtests
988             set runtests "go-test.exp"
989             set dg-do-what-default "assemble"
990             regsub "\\.go$" $test ".dir/pkg.go" file1
991             dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
992             dg-test $test "-O" "-w $DEFAULT_GOCFLAGS"
993             file delete "[file rootname [file tail $file1]].o"
994             set runtests $hold_runtests
995         } elseif { [string match "// \$G \$D/\$F.dir/one.go && \$G \$D/\$F.dir/two.go || echo BUG*" \
996                         $test_line ] } {
997             set hold_runtests $runtests
998             set runtests "go-test.exp"
999             set dg-do-what-default "assemble"
1000             regsub "\\.go$" $test ".dir/one.go" file1
1001             dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
1002             set ofile1 "[file rootname [file tail $file1]].o"
1003             regsub "\\.go$" $test ".dir/two.go" file2
1004             dg-test $file2 "-O" "-w $DEFAULT_GOCFLAGS"
1005             file delete $ofile1
1006             set runtests $hold_runtests
1007         } elseif { $test_line == "// \$G \$D/bug302.dir/p.go && pack grc pp.a p.\$A && \$G \$D/bug302.dir/main.go" \
1008                    || $test_line == "// \$G \$D/empty.go && errchk \$G \$D/\$F.go" } {
1009             # These tests import the same package under two different
1010             # names, which gccgo does not support.
1011         } elseif { $test_line == "// \$G -S \$D/\$F.go | egrep initdone >/dev/null && echo BUG sinit || true" } {
1012             # This tests whether initializers are written out
1013             # statically.  gccgo does not provide a way to test that,
1014             # as an initializer will be generated for any code which
1015             # has global variables which need to be registered as GC
1016             # roots.
1017         } elseif { $test_line == "// errorcheck -0 -m"
1018                    || $test_line == "// errorcheck -0 -m -l" } { 
1019             # This tests debug output of the gc compiler, which is
1020             # meaningless for gccgo.
1021         } elseif { $test_line == "// \[ \$A == 6 \] || errchk \$G -e \$D/\$F.go" \
1022                        || $test_line == "// \[ \$A != 6 \]  || errchk \$G -e \$D/\$F.go" } {
1023             # This tests specific handling of the gc compiler on types
1024             # that are too large.  It is target specific in a way I
1025             # haven't bothered to check for here.
1026         } elseif { $test_line == "// \$G \$D/\$F.go && \$L -X main.tbd hello \$F.\$A && ./\$A.out" } {
1027             # This tests the gc ld -X option, which gccgo does not
1028             # support.
1029         } elseif { $test_line == "// \$G \$D/pkg.go && pack grc pkg.a pkg.\$A 2> /dev/null && rm pkg.\$A && errchk \$G -I. -u \$D/main.go"
1030                    || $test_line == "// \$G \$D/pkg.go && pack grcS pkg.a pkg.\$A 2> /dev/null && rm pkg.\$A && \$G -I. -u \$D/main.go" } {
1031             # This tests the gc -u option, which gccgo does not
1032             # support.
1033         } else {
1034             clone_output "$name: unrecognized test line: $test_line"
1035             unsupported $name
1036         }
1037
1038         set go_compile_args ""
1039         set go_execute_args ""
1040         set TORTURE_OPTIONS [list { -O2 -g }]
1041     }
1042
1043     set dg-do-what-default ${saved-dg-do-what-default}
1044     set TORTURE_OPTIONS $saved_torture_options
1045 }
1046
1047 go-gc-tests