OSDN Git Service

Update Go testsuite to release r60.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / go.test / go-test.exp
1 #   Copyright (C) 2009, 2010, 2011 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 # // $G $D/$F.go && $L $F.$A && ./$A.out
30 # // $G $D/$F.go && $L $F.$A || echo BUG: known to fail incorrectly
31 # // $G $D/$F.go && echo BUG: compilation succeeds incorrectly
32 # // $G $D/$F.go || echo BUG: compilation should succeed
33
34 load_lib go-dg.exp
35 load_lib go-torture.exp
36
37 # Implement errchk
38 proc errchk { test opts } {
39     global dg-do-what-default
40     global DEFAULT_GOCFLAGS
41     global runtests
42
43     set saved-dg-do-what-default ${dg-do-what-default}
44     set dg-do-what-default compile
45     set filename [file tail $test]
46     if { "$filename" == "$test" } {
47         set filename "errchk-$filename"
48     }
49     set fdin [open $test r]
50     fconfigure $fdin -encoding binary
51     set fdout [open $filename w]
52     fconfigure $fdout -encoding binary
53     while { [gets $fdin copy_line] >= 0 } {
54         if [string match "*////*" $copy_line] {
55             puts $fdout $copy_line
56             continue
57         }
58         regsub "// \(GCCGO_\)?ERROR \"\(\[^\"\]*\)\".*$" $copy_line "// \{ dg-error \"\\2\" \}" out_line
59         if [string match "*dg-error*.\**" $out_line] {
60             # I worked out the right number of backslashes by
61             # experimentation, not analysis.
62             regsub -all "\\.\\*" $out_line "\\\\\[ -~\\\\\]*" out_line
63         }
64         if [string match "*dg-error*\{*" $out_line] {
65             set index [string first "dg-error" $out_line]
66             regsub -start $index -all "\{" $out_line "\\\\\[\\\{\\\\\]" out_line
67         }
68         if [string match "*dg-error*\}*\}" $out_line] {
69             set index [string first "dg-error" $out_line]
70             regsub -start $index -all "\}\(.\)" $out_line "\\\\\[\\\}\\\\\]\\1" out_line
71         }
72         if [string match "*dg-error*\(*" $out_line] {
73             set index [string first "dg-error" $out_line]
74             regsub -start $index -all "\\\\\\\(" $out_line "\\\\\[\\\(\\\\\]" out_line
75         }
76         if [string match "*dg-error*\)*\}" $out_line] {
77             set index [string first "dg-error" $out_line]
78             regsub -start $index -all "\\\\\\\)\(.\)" $out_line "\\\\\[\\\)\\\\\]\\1" out_line
79         }
80         if [string match "*dg-error*\[.\]*" $out_line] {
81             set index [string first "dg-error" $out_line]
82             regsub -all "\\\[\\.\\\]" $out_line "\\\\\[.\\\\\]" out_line
83         }
84         # Special case for bug332, in which the error message wants to
85         # match the file name, which is not what dg-error expects.
86         if [string match "*dg-error*bug332*" $out_line] {
87             set index [string first "dg-error" $out_line]
88             regsub -start $index "bug332" $out_line "undefined type" out_line
89         }
90         puts $fdout $out_line
91     }
92     close $fdin
93     close $fdout
94
95     set hold_runtests $runtests
96     set runtests "go-test.exp"
97     go-dg-runtest $filename "-fno-show-column $DEFAULT_GOCFLAGS $opts"
98     set runtests $hold_runtests
99
100     file delete $filename
101     set dg-do-what-default ${saved-dg-do-what-default}
102 }
103
104 # This is an execution test which should fail.
105 proc go-execute-xfail { test } {
106     global DEFAULT_GOCFLAGS
107     global runtests
108
109     set filename [file tail $test]
110     set fdin [open $test r]
111     set fdout [open $filename w]
112     puts $fdout "// { dg-do run { xfail *-*-* } }"
113     while { [gets $fdin copy_line] >= 0 } {
114         puts $fdout $copy_line
115     }
116     close $fdin
117     close $fdout
118
119     set hold_runtests $runtests
120     set runtests "go-test.exp"
121     go-dg-runtest $filename "-w $DEFAULT_GOCFLAGS"
122     set runtests $hold_runtests
123
124     file delete $filename
125 }
126
127 # N.B. Keep in sync with libgo/configure.ac.
128 proc go-set-goarch { } {
129     global target_triplet
130
131     switch -glob $target_triplet {
132         "alpha*-*-*" {
133             set goarch "alpha"
134         }
135         "arm*-*-*" -
136         "ep9312*-*-*" -
137         "strongarm*-*-*" -
138         "xscale-*-*" {
139             set goarch "arm"
140         }
141         "i?86-*-*" -
142         "x86_64-*-*" {
143             if [check_effective_target_ia32] {
144                 set goarch "386"
145             } else {
146                 set goarch "amd64"
147             }
148         }
149         "mips*-*-*" {
150             if [check_no_compiler_messages mipso32 assembly {
151                 #if _MIPS_SIM != _ABIO32
152                 #error FOO
153                 #endif
154             }] {
155                 set goarch "mipso32"
156             } elseif [check_no_compiler_messages mipsn32 assembly {
157                 #if _MIPS_SIM != _ABIN32
158                 #error FOO
159                 #endif
160             }] {
161                 set goarch "mipsn32"
162             } elseif [check_no_compiler_messages mipsn64 assembly {
163                 #if _MIPS_SIM != _ABI64
164                 #error FOO
165                 #endif
166             }] {
167                 set goarch "mipsn64"
168             } elseif [check_no_compiler_messages mipso64 assembly {
169                 #if _MIPS_SIM != _ABIO64
170                 #error FOO
171                 #endif
172             }] {
173                 set goarch "mipso64"
174             } else {
175                 perror "$target_triplet: unrecognized MIPS ABI"
176                 return ""
177             }
178         }
179         "sparc*-*-*" {
180             if [check_effective_target_ilp32] {
181                 set goarch "sparc"
182             } else {
183                 set goarch "sparc64"
184             }
185         }
186         default {
187             perror "$target_triplet: unhandled architecture"
188             return ""
189         }       
190     }
191     verbose -log "Setting GOARCH=$goarch" 1
192     setenv GOARCH $goarch
193 }
194
195 proc go-gc-tests { } {
196     global srcdir subdir
197     global runtests
198     global GCC_UNDER_TEST
199     global TOOL_OPTIONS
200     global TORTURE_OPTIONS
201     global dg-do-what-default
202     global go_execute_args
203     global target_triplet
204
205     # If a testcase doesn't have special options, use these.
206     global DEFAULT_GOCFLAGS
207     if ![info exists DEFAULT_GOCFLAGS] {
208         set DEFAULT_GOCFLAGS " -pedantic-errors"
209     }
210
211     # Set GOARCH for tests that need it.
212     go-set-goarch
213
214     # Running all the torture options takes too long and, since the
215     # frontend ignores the standard options, it doesn't significantly
216     # improve testing.
217     set saved_torture_options $TORTURE_OPTIONS
218     set TORTURE_OPTIONS [ list { -O2 -g }]
219
220     set saved-dg-do-what-default ${dg-do-what-default}
221
222     set testdir [pwd]
223
224     set tests [lsort [find $srcdir/$subdir *.go]]
225     foreach test $tests {
226         if ![runtest_file_p $runtests $test] {
227             continue
228         }
229
230         # Skip the files in bench and garbage; they are not tests.
231         if [string match "*go.test/test/bench/*" $test] {
232             continue
233         }
234         if [string match "*go.test/test/garbage/*" $test] {
235             continue
236         }
237
238         # Skip files in sub-subdirectories: they are components of
239         # other tests.
240         if [string match "*go.test/test/*/*/*" $test] {
241             continue
242         }
243
244         set name [dg-trim-dirname $srcdir $test]
245
246         # Skip certain tests if target is RTEMS OS.
247         if [istarget "*-*-rtems*"] {
248             if { [string match "*go.test/test/args.go" \
249                    $test] \
250                  || [string match "*go.test/test/env.go" \
251                    $test] } {
252                     untested "$name: uses the command-line or environment variables"
253                     continue
254             }
255
256             if { [string match "*go.test/test/stack.go" \
257                    $test] \
258                  || [string match "*go.test/test/peano.go" \
259                    $test] \
260                  || [string match "*go.test/test/chan/goroutines.go" \
261                    $test] } {
262                     untested "$name: has very high memory requirement"
263                     continue
264             }
265         }
266
267         if { [string match "*bug347*" $test] \
268                  || [string match "*bug348*" $test] } {
269             # These bugs rely on runtime.Caller which currently fails.
270             untested $name
271             continue
272         }
273
274         set fd [open $test r]
275
276         set lines_ok 1
277
278         while 1 {
279             if { [gets $fd test_line] < 0 } {
280                 close $fd
281                 clone_output "$test: could not read first line"
282                 unresolved $name
283                 set lines_ok 0
284                 break
285             }
286
287             if { [ string match "*nacl*exit 0*" $test_line ] \
288                      || [ string match "*exit 0*nacl*" $test_line ] \
289                      || [ string match "*Android*exit 0*" $test_line ] \
290                      || [ string match "*exit 0*Android*" $test_line ] } {
291                 continue
292             }
293
294             break
295         }
296
297         if { $lines_ok == 0 } {
298             continue
299         }
300
301         set lineno 1
302         set test_line1 $test_line
303
304         while { [eval "string match \"//*&&\" \${test_line$lineno}"] } {
305             set lineno [expr $lineno + 1]
306             if { [eval "gets \$fd test_line$lineno"] < 0 } {
307                 close $fd
308                 clone_output "$test: could not read line $lineno"
309                 unresolved $name
310                 set lines_ok 0
311                 break
312             }
313         }
314         if { $lines_ok == 0 } {
315             continue
316         }
317
318         close $fd
319
320         set go_execute_args ""
321         if { [regexp ".*\\\$A.out (\[^|&>\].*)\$" $test_line match progargs] } {
322             set go_execute_args $progargs
323             verbose -log "$test: go_execute_args is $go_execute_args"
324             set index [string last " $progargs" $test_line]
325             set test_line [string replace $test_line $index end]
326         } elseif { [string match "*go.test/test/chan/goroutines.go" $test] \
327                    && [getenv GCCGO_RUN_ALL_TESTS] == "" } {
328             # goroutines.go spawns by default 10000 threads, which is too much
329             # for many OSes.
330             if { [getenv GCC_TEST_RUN_EXPENSIVE] == "" } {
331                 set go_execute_args 64
332             } elseif { ![is_remote host] && ![is_remote target] } {
333                 # When using low ulimit -u limit, use maximum of
334                 # a quarter of that limit and 10000 even when running expensive
335                 # tests, otherwise parallel tests might fail after fork failures.
336                 set nproc [lindex [remote_exec host {sh -c ulimit\ -u}] 1]
337                 if { [string is integer -strict $nproc] } {
338                         set nproc [expr $nproc / 4]
339                         if { $nproc > 10000 } { set nproc 10000 }
340                         if { $nproc < 16 } { set nproc 16 }
341                         set go_execute_args $nproc
342                 }
343             }
344             if { "$go_execute_args" != "" } {
345                 verbose -log "$test: go_execute_args is $go_execute_args"
346             }
347         }
348
349         if { $test_line == "// \$G \$D/\$F\.go && \$L \$F\.\$A && \./\$A\.out >tmp.go &&" \
350              && $test_line2 == "// \$G tmp\.go && \$L tmp\.\$A && \./\$A\.out || echo BUG: 64bit" } {
351             # 64bit.go is a special case.
352             set go_execute_args ""
353             set hold_runtests $runtests
354             set runtests "go-test.exp"
355             set dg-do-what-default "link"
356             dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
357             set output_file "./[file rootname [file tail $test]].exe"
358             set base "[file rootname [file tail $test]]"
359             if [isnative] {
360                 if { [catch "exec $output_file >$base-out.go"] != 0 } {
361                     fail "$name execution"
362                 } else {
363                     pass "$name execution"
364                     file delete $base-out.x
365                     go-torture-execute "./$base-out.go"
366                 }
367                 file delete $base-out.go
368             }
369             file delete $output_file
370             set runtests $hold_runtests
371         } elseif { $test_line == "// \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out" \
372                    || $test_line == "// \$G \$F.go && \$L \$F.\$A && ./\$A.out" \
373                    || $test_line == "// \$G \$F.go && \$L \$F.\$A &&./\$A.out" \
374                    || $test_line == "// \$G \$D/\$F.go && \$L \$F.\$A && \$A.out" \
375                    || [string match \
376                            "// \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out || echo BUG*" \
377                            $test_line]
378                    || [string match \
379                            "// \$G \$F.go && \$L \$F.\$A && (./\$A.out || echo BUG*" \
380                            $test_line]
381                    || [string match \
382                            "// \$G \$D/\$F.go && \$L \$F.\$A && (./\$A.out || echo BUG*" \
383                            $test_line]
384                    || [string match \
385                            "// \$G \$F.go && \$L \$F.\$A && GOMAXPROCS=* ./\$A.out" \
386                            $test_line]
387                    || [string match \
388                            "// \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out >* || echo BUG*" \
389                            $test_line] } {
390             # This is a vanilla execution test.
391             go-torture-execute $test
392             file delete core [glob -nocomplain core.*]
393         } elseif { [string match \
394                         "// \$G \$D/\$F.go && \$L \$F.\$A || echo BUG*" \
395                         $test_line] \
396                    || [string match "// \$G \$F.go && \$L \$F.\$A  #*" \
397                            $test_line]
398                    || $test_line == "// \$G \$D/\$F.go && \$L \$F.\$A" } {
399             # This is a vanilla compile and link test.
400             set dg-do-what-default "link"
401             go-dg-runtest $test "-w $DEFAULT_GOCFLAGS"
402         } elseif { [string match "// \$G \$D/\$F.go" $test_line] \
403                    || [string match "// \$G \$D/\$F.go || echo BUG*" \
404                            $test_line] \
405                    || [string match "// \$G \$F.go || echo BUG*" \
406                            $test_line] \
407                    || [string match "// ! \$G \$D/\$F.go && echo BUG*" \
408                            $test_line] } {
409             # This is a vanilla compile test.
410             set dg-do-what-default "assemble"
411             go-dg-runtest $test "-w $DEFAULT_GOCFLAGS"
412         } elseif { [string match "// \$G \$D/\$F.go && echo BUG*" \
413                         $test_line] \
414                    || $test_line == "// ! \$G \$D/\$F.go >/dev/null" \
415                    || $test_line == "// ! \$G \$D/\$F.go" \
416                    || $test_line == "// ! \$G \$F.go" \
417                    || [string match "// ! \$G \$D/\$F.go || echo BUG*" \
418                         $test_line] } {
419             # This is a compile test which should fail.
420             set dg-do-what-default "assemble"
421             setup_xfail "*-*-*"
422             go-dg-runtest $test "-w $DEFAULT_GOCFLAGS"
423         } elseif { [string match "// \$G \$D/\$F.go && \$L \$F.\$A && ! ./\$A.out" \
424                         $test_line] \
425                    || [string match "// \$G \$D/\$F.go && \$L \$F.\$A && ! ./\$A.out || echo BUG: *" \
426                         $test_line] \
427                    || [string match "// \$G \$D/\$F.go && \$L \$F.\$A && (! ./\$A.out || echo BUG: *" \
428                         $test_line] \
429                    || ($test_line == "// \$G \$D/\$F.go && \$L \$F.\$A &&"
430                        && $test_line2 == "//    ((! sh -c ./\$A.out) >/dev/null 2>&1 || echo BUG: should fail)") } {
431             go-execute-xfail $test
432         } elseif { [string match "// errchk \$G \$F.go" $test_line] \
433                     || [string match "// errchk \$G -e \$F.go" $test_line] \
434                     || [string match "// errchk \$G \$D/\$F.go" $test_line] \
435                     || [string match "//errchk \$G \$D/\$F.go" $test_line] \
436                     || [string match "// errchk \$G -e \$D/\$F.go" \
437                             $test_line] \
438                     || [string match "// ! errchk \$G \$D/\$F.go" $test_line] \
439                     || [string match "// ! errchk \$G -e \$D/\$F.go" \
440                             $test_line] \
441                     || [string match "// errchk \$G \$F.go || true" \
442                             $test_line] \
443                     || [string match "// errchk \$G \$D/\$F.go || true" \
444                             $test_line] \
445                     || [string match "// errchk \$G -e \$D/\$F.go || true" \
446                             $test_line] \
447                     || [string match "// errchk \$G \$D/\$F.go || echo BUG*" \
448                             $test_line] } {
449             errchk $test ""
450         } elseif { [string match \
451                         "// \$G \$D/\$F.dir/bug0.go && \$G \$D/\$F.dir/bug1.go || echo BUG*" \
452                         $test_line] } {
453             set hold_runtests $runtests
454             set runtests "go-test.exp"
455             set dg-do-what-default "assemble"
456             regsub "\\.go$" $test ".dir/bug0.go" file1
457             dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
458             regsub "\\.go$" $test ".dir/bug1.go" file2
459             dg-test $file2 "-O" "-w $DEFAULT_GOCFLAGS"
460             file delete "[file rootname [file tail $file1]].o"
461             set runtests $hold_runtests
462         } elseif { [string match \
463                         "// \$G \$D/\$F.dir/bug0.go && errchk \$G \$D/\$F.dir/bug1.go" \
464                         $test_line] \
465                        || [string match \
466                                "// \$G \$D/\$F.dir/p1.go && \$G \$D/\$F.dir/p2.go" \
467                                $test_line] \
468                        || [string match \
469                                "// \$G \$D/\$F.dir/b.go && \$G \$D/\$F.dir/a.go" \
470                                $test_line] } {
471             if { [string match \
472                       "// \$G \$D/\$F.dir/bug0.go && errchk \$G \$D/\$F.dir/bug1.go" \
473                       $test_line] } {
474                 set name1 "bug0.go"
475                 set name2 "bug1.go"
476             } elseif { [string match \
477                       "// \$G \$D/\$F.dir/p1.go && \$G \$D/\$F.dir/p2.go" \
478                       $test_line] } {
479                 set name1 "p1.go"
480                 set name2 "p2.go"
481             } else {
482                 set name1 "b.go"
483                 set name2 "a.go"
484             }
485             set hold_runtests $runtests
486             set runtests "go-test.exp"
487             set dg-do-what-default "assemble"
488             regsub "\\.go$" $test ".dir/$name1" file1
489             dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
490             regsub "\\.go$" $test ".dir/$name2" file2
491             errchk $file2 ""
492             file delete "[file rootname [file tail $file1]].o"
493             set runtests $hold_runtests
494         } elseif { [string match \
495                         "// \$G \$D/\$F.dir/bug0.go && (! \$G \$D/\$F.dir/bug1.go || echo BUG*" \
496                         $test_line] } {
497             set hold_runtests $runtests
498             set runtests "go-test.exp"
499             set dg-do-what-default "assemble"
500             regsub "\\.go$" $test ".dir/bug0.go" file1
501             dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
502             regsub "\\.go$" $test ".dir/bug1.go" file2
503             setup_xfail "*-*-*"
504             dg-test $file2 "-O" "-w $DEFAULT_GOCFLAGS"
505             file delete "[file rootname [file tail $file1]].o"
506             set runtests $hold_runtests
507         } elseif { [string match \
508                         "// \$G \$D/\$F.dir/bug0.go && \$G \$D/\$F.dir/bug1.go && (! \$G \$D/\$F.dir/bug2.go || echo BUG*" \
509                         $test_line] } {
510             set hold_runtests $runtests
511             set runtests "go-test.exp"
512             set dg-do-what-default "assemble"
513             regsub "\\.go$" $test ".dir/bug0.go" file1
514             dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
515             regsub "\\.go$" $test ".dir/bug1.go" file2
516             dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
517             regsub "\\.go$" $test ".dir/bug2.go" file3
518             setup_xfail "*-*-*"
519             dg-test $file3 "-O" "-w $DEFAULT_GOCFLAGS"
520             file delete "[file rootname [file tail $file1]].o"
521             file delete "[file rootname [file tail $file2]].o"
522             set runtests $hold_runtests
523         } elseif { [string match \
524                         "// \$G \$D/\$F.dir/bug0.go && \$G \$D/\$F.dir/bug1.go && errchk \$G \$D/\$F.dir/bug2.go" \
525                         $test_line] } {
526             set hold_runtests $runtests
527             set runtests "go-test.exp"
528             set dg-do-what-default "assemble"
529             regsub "\\.go$" $test ".dir/bug0.go" file1
530             dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
531             regsub "\\.go$" $test ".dir/bug1.go" file2
532             dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
533             regsub "\\.go$" $test ".dir/bug2.go" file3
534             errchk $file3 ""
535             file delete "[file rootname [file tail $file1]].o"
536             file delete "[file rootname [file tail $file2]].o"
537             set runtests $hold_runtests
538         } elseif { [string match \
539                         "// \$G \$D/bug160.dir/x.go && \$G \$D/bug160.dir/y.go && \$L y.\$A && ./\$A.out" \
540                         $test_line] } {
541             set hold_runtests $runtests
542             set runtests "go-test.exp"
543             set dg-do-what-default "assemble"
544             regsub "\\.go$" $test ".dir/x.go" file1
545             dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
546             set ofile1 "[file rootname [file tail $file1]].o"
547             regsub "\\.go$" $test ".dir/y.go" file2
548             dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
549             set ofile2 "[file rootname [file tail $file2]].o"
550             set dg-do-what-default "link"
551             set output_file "./[file rootname [file tail $test]].exe"
552             set comp_output [go_target_compile "$ofile1 $ofile2" \
553                                  $output_file "executable" "$DEFAULT_GOCFLAGS"]
554             set comp_output [go-dg-prune $target_triplet $comp_output]
555             verbose -log $comp_output
556             set result [go_load "$output_file" "" ""]
557             set status [lindex $result 0]
558             $status $name
559             file delete $ofile1 $ofile2 $output_file
560             set runtests $hold_runtests
561         } elseif { [string match \
562                         "// \$G \$D/bug191.dir/a.go && \$G \$D/bug191.dir/b.go && \$G \$D/\$F.go && \$L \$F.\$A" \
563                         $test_line] } {
564             set hold_runtests $runtests
565             set runtests "go-test.exp"
566             set dg-do-what-default "assemble"
567             regsub "\\.go$" $test ".dir/a.go" file1
568             dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
569             set ofile1 "[file rootname [file tail $file1]].o"
570             regsub "\\.go$" $test ".dir/b.go" file2
571             dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
572             set ofile2 "[file rootname [file tail $file2]].o"
573             dg-test -keep-output "$test" "-O" "-w $DEFAULT_GOCFLAGS"
574             set ofile3 "[file rootname [file tail $test]].o"
575             set dg-do-what-default "link"
576             set output_file "./[file rootname [file tail $test]].exe"
577             set comp_output [go_target_compile "$ofile1 $ofile2 $ofile3" \
578                                  $output_file "executable" "$DEFAULT_GOCFLAGS"]
579             set comp_output [go-dg-prune $target_triplet $comp_output]
580             if [string match "" $comp_output] {
581                 pass $name
582             } else {
583                 verbose -log $comp_output
584                 fail $name
585             }
586             file delete $ofile1 $ofile2 $ofile3 $output_file
587             set runtests $hold_runtests
588         } elseif { [string match \
589                         "// \$G \$D/embed0.go && \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out" \
590                         $test_line ] } {
591             set hold_runtests $runtests
592             set runtests "go-test.exp"
593             set dg-do-what-default "assemble"
594             regsub "/\[^/\]*$" $test "/embed0.go" file1
595             dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
596             set ofile1 "[file rootname [file tail $file1]].o"
597             dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
598             set ofile2 "[file rootname [file tail $test]].o"
599             set output_file "./[file rootname [file tail $test]].exe"
600             set comp_output [go_target_compile "$ofile1 $ofile2" \
601                                  $output_file "executable" "$DEFAULT_GOCFLAGS"]
602             set comp_output [go-dg-prune $target_triplet $comp_output]
603             if [string match "" $comp_output] {
604                 set result [go_load "$output_file" "" ""]
605                 set status [lindex $result 0]
606                 $status $name
607             } else {
608                 verbose -log $comp_output
609                 fail $name
610             }
611             file delete $ofile1 $ofile2 $output_file
612             set runtests $hold_runtests
613         } elseif { [string match \
614                         "// \$G \$D/\$F.dir/lib.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out || echo BUG*" \
615                         $test_line ] } {
616             set hold_runtests $runtests
617             set runtests "go-test.exp"
618             set dg-do-what-default "assemble"
619             regsub "\\.go$" $test ".dir/lib.go" file1
620             dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
621             set ofile1 "[file rootname [file tail $file1]].o"
622             regsub "\\.go$" $test ".dir/main.go" file2
623             dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
624             set ofile2 "[file rootname [file tail $file2]].o"
625             set dg-do-what-default "link"
626             set output_file "./[file rootname [file tail $file2]].exe"
627             set comp_output [go_target_compile "$ofile1 $ofile2" \
628                                  $output_file "executable" "$DEFAULT_GOCFLAGS"]
629             set comp_output [go-dg-prune $target_triplet $comp_output]
630             if [string match "" $comp_output] {
631                 set result [go_load "$output_file" "" ""]
632                 set status [lindex $result 0]
633                 $status $name
634             } else {
635                 verbose -log $comp_output
636                 fail $name
637             }
638             file delete $ofile1 $ofile2 $output_file
639             set runtests $hold_runtests
640         } elseif { [string match \
641                         "// \$G \$D/\$F.dir/chanbug.go && \$G -I. \$D/\$F.dir/chanbug2.go" \
642                         $test_line] } {
643             set hold_runtests $runtests
644             set runtests "go-test.exp"
645             set dg-do-what-default "assemble"
646             regsub "\\.go$" $test ".dir/chanbug.go" file1
647             dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
648             regsub "\\.go$" $test ".dir/chanbug2.go" file2
649             dg-test $file2 "-O" "-w $DEFAULT_GOCFLAGS"
650             file delete "[file rootname [file tail $file1]].o"
651             set runtests $hold_runtests
652         } elseif { [string match \
653                         "// (! \$G \$D/\$F.go) | grep 'initialization loop' *" \
654                         $test_line] } {
655             set dg-do-what-default "assemble"
656             setup_xfail "*-*-*"
657             go-dg-runtest $test "-w $DEFAULT_GOCFLAGS"
658         } elseif { [string match \
659                         "// \$G \$D/\$F.dir/x.go && errchk \$G \$D/\$F.dir/y.go" \
660                         $test_line] } {
661             set hold_runtests $runtests
662             set runtests "go-test.exp"
663             set dg-do-what-default "assemble"
664             regsub "\\.go$" $test ".dir/x.go" file1
665             dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
666             regsub "\\.go$" $test ".dir/y.go" file2
667             errchk $file2 ""
668             file delete "[file rootname [file tail $file1]].o"
669             set runtests $hold_runtests
670         } elseif { [string match "// true*" $test_line] } {
671             # Not a real test, just ignore.
672         } elseif { $test_line == "// \$G \$D/\$F.dir/bug0.go &&" \
673                        && $test_line2 == "// \$G \$D/\$F.dir/bug1.go &&" \
674                        && $test_line3 == "// \$G \$D/\$F.dir/bug2.go &&" \
675                        && $test_line4 == "// errchk \$G -e \$D/\$F.dir/bug3.go &&" \
676                        && $test_line5 == "// \$L bug2.\$A &&" \
677                        && [string match "// ./\$A.out || echo BUG*" $test_line6] } {
678             set hold_runtests $runtests
679             set runtests "go-test.exp"
680             set dg-do-what-default "assemble"
681             regsub "\\.go$" $test ".dir/bug0.go" file0
682             dg-test -keep-output $file0 "-O -fgo-prefix=bug0" "-w $DEFAULT_GOCFLAGS"
683             set ofile0 "[file rootname [file tail $file0]].o"
684             regsub "\\.go$" $test ".dir/bug1.go" file1
685             dg-test -keep-output $file1 "-O -fgo-prefix=bug1" "-w $DEFAULT_GOCFLAGS"
686             set ofile1 "[file rootname [file tail $file1]].o"
687             regsub "\\.go$" $test ".dir/bug2.go" file2
688             dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
689             set ofile2 "[file rootname [file tail $file2]].o"
690             regsub "\\.go$" $test ".dir/bug3.go" file3
691             errchk $file3 ""
692             set output_file "./[file rootname [file tail $test]].exe"
693             set comp_output [go_target_compile "$ofile0 $ofile1 $ofile2" \
694                                  $output_file "executable" "$DEFAULT_GOCFLAGS"]
695             set comp-output [go-dg-prune $target_triplet $comp_output]
696             if [string match "" $comp_output] {
697                 set result [go_load "$output_file" "" ""]
698                 set status [lindex $result 0]
699                 $status $name
700             } else {
701                 verbose -log $comp_output
702                 fail $name
703             }
704             file delete $ofile0 $ofile1 $ofile2 $output_file
705             set runtests $hold_runtests
706         } elseif { $test_line == "// \$G \$D/import2.go && \$G \$D/\$F\.go" } {
707             set hold_runtests $runtests
708             set runtests "go-test.exp"
709             set dg-do-what-default "assemble"
710             regsub "/\[^/\]*$" $test "/import2.go" file1
711             dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
712             set ofile1 "[file rootname [file tail $file1]].o"
713             dg-test $test "-O" "-w $DEFAULT_GOCFLAGS"
714             file delete $ofile1
715             set runtests $hold_runtests
716         } elseif { $test_line == "// \$G \$D/ddd2.go && \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out" } {
717             set hold_runtests $runtests
718             set runtests "go-test.exp"
719             set dg-do-what-default "assemble"
720             regsub "/\[^/\]*$" $test "/ddd2.go" file1
721             dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
722             set ofile1 "[file rootname [file tail $file1]].o"
723             dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
724             set ofile2 "[file rootname [file tail $test]].o"
725             set output_file "./[file rootname [file tail $test]].exe"
726             set comp_output [go_target_compile "$ofile1 $ofile2" \
727                                  $output_file "executable" "$DEFAULT_GOCFLAGS"]
728             set comp_output [go-dg-prune $target_triplet $comp_output]
729             if [string match "" $comp_output] {
730                 set result [go_load "$output_file" "" ""]
731                 set status [lindex $result 0]
732                 $status $name
733             } else {
734                 verbose -log $comp_output
735                 fail $name
736             }
737             file delete $ofile1 $ofile2 $output_file
738             set runtests $hold_runtests
739         } elseif { $test_line == "// \$G \$D/\$F.go \$D/cmplxdivide1.go && \$L \$D/\$F.\$A && ./\$A.out" } {
740             regsub "/\[^/\]*$" $test "/cmplxdivide1.go" test2
741             set output_file "./[file rootname [file tail $test]].o"
742             set comp_output [go_target_compile "$test $test2" \
743                              $output_file "executable" "$DEFAULT_GOCFLAGS"]
744             set comp_output [go-dg-prune $target_triplet $comp_output]
745             if [string match "" $comp_output] {
746                 set result [go_load "$output_file" "" ""]
747                 set status [lindex $result 0]
748                 $status $name
749             } else {
750                 verbose -log $comp_output
751                 fail $name
752             }
753             file delete $output_file
754         } elseif { $test_line == "// \$G \$D/\$F.go && \$L \$F.\$A &&" \
755                        && $test_line2 == "// ./\$A.out -pass 0 >tmp.go && \$G tmp.go && \$L -o \$A.out1 tmp.\$A && ./\$A.out1 &&" \
756                        && $test_line3 == "// ./\$A.out -pass 1 >tmp.go && errchk \$G -e tmp.go &&" \
757                        && $test_line4 == "// ./\$A.out -pass 2 >tmp.go && errchk \$G -e tmp.go" } {
758             set go_execute_args ""
759             set hold_runtests $runtests
760             set runtests "go-test.exp"
761             set dg-do-what-default "link"
762             dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
763             set output_file "./[file rootname [file tail $test]].exe"
764             if [isnative] {
765                 if { [catch "exec $output_file -pass 0 >tmp.go"] != 0 } {
766                     fail "$name execution 0"
767                 } else {
768                     pass "$name execution 0"
769                     file delete tmp.x
770                     go-torture-execute "./tmp.go"
771                 }
772                 if { [catch "exec $output_file -pass 1 >tmp.go"] != 0 } {
773                     fail "$name execution 1"
774                 } else {
775                     pass "$name execution 1"
776                     errchk tmp.go ""
777                 }
778                 if { [catch "exec $output_file -pass 2 >tmp.go"] != 0 } {
779                     fail "$name execution 2"
780                 } else {
781                     pass "$name execution 2"
782                     errchk tmp.go ""
783                 }
784                 file delete tmp.go
785             }
786             file delete $output_file
787             set runtests $hold_runtests
788         } elseif { $test_line == "// \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out >tmp.go &&" \
789                         && $test_line2 == "// errchk \$G -e tmp.go" } {
790             set go_execute_args ""
791             set hold_runtests $runtests
792             set runtests "go-test.exp"
793             set dg-do-what-default "link"
794             dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
795             set output_file "./[file rootname [file tail $test]].exe"
796             if [isnative] {
797                 if { [catch "exec $output_file >tmp.go"] != 0 } {
798                     fail "$name execution"
799                 } else {
800                     pass "$name execution"
801                     file delete tmp.x
802                     errchk tmp.go ""
803                 }
804             }
805             file delete $output_file
806             set runtests $hold_runtests
807         } elseif { [string match \
808                         "// \$G \$D/\$F.dir/p.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ! ./\$A.out || echo BUG*" \
809                         $test_line] } {
810             set hold_runtests $runtests
811             set runtests "go-test.exp"
812             set dg-do-what-default "assemble"
813             regsub "\\.go$" $test ".dir/p.go" file1
814             dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
815             set ofile1 "[file rootname [file tail $file1]].o"
816             regsub "\\.go$" $test ".dir/main.go" file2
817             dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
818             set ofile2 "[file rootname [file tail $file2]].o"
819             set output_file "./[file rootname [file tail $test]].exe"
820             set comp_output [go_target_compile "$ofile1 $ofile2" \
821                                  $output_file "executable" "$DEFAULT_GOCFLAGS"]
822             set comp_output [go-dg-prune $target_triplet $comp_output]
823             if [string match "" $comp_output] {
824                 setup_xfail "*-*-*"
825                 set result [go_load "$output_file" "" ""]
826                 set status [lindex $result 0]
827                 $status $name
828             } else {
829                 verbose -log $comp_output
830                 fail $name
831             }
832             file delete $ofile1 $ofile2 $output_file
833             set runtests $hold_runtests
834         } elseif { $test_line == "// \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out >tmp.go &&"
835                    && $test_line2 == "// \$G tmp.go && \$L tmp.\$A && ./\$A.out || echo BUG: select5" } {
836             set go_execute_args ""
837             set hold_runtests $runtests
838             set runtests "go-test.exp"
839             set dg-do-what-default "link"
840             dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
841             set output_file "./[file rootname [file tail $test]].exe"
842             set base "[file rootname [file tail $test]]"
843             if [isnative] {
844                 if { [catch "exec $output_file > $base-out.go"] != 0 } {
845                     fail "$name execution"
846                 } else {
847                     pass "$name execution"
848                     file delete $base-out.x
849                     go-torture-execute "./$base-out.go"
850                 }
851                 # file delete $base-out.go
852             }
853             file delete $output_file
854             set runtests $hold_runtests
855         } elseif { $test_line == "// errchk \$G -e \$D/\$F.dir/\[ab\].go" } {
856             regsub "\\.go$" $test ".dir/a.go" file1
857             regsub "\\.go$" $test ".dir/b.go" file2
858             errchk "$file1" "$file2"
859         } elseif { $test_line == "// # generated by cmplxdivide.c" } {
860             # Ignore.
861         } elseif { $test_line == "// \$G \$D/bug302.dir/p.go && gopack grc pp.a p.\$A && \$G \$D/bug302.dir/main.go" \
862                    || $test_line == "// \$G \$D/empty.go && errchk \$G \$D/\$F.go" } {
863             # These tests import the same package under two different
864             # names, which gccgo does not support.
865         } elseif { $test_line == "// \$G -S \$D/\$F.go | egrep initdone >/dev/null && echo FAIL || true" } {
866             # This tests whether initializers are written out
867             # statically.  gccgo does not provide a way to test that,
868             # as an initializer will be generated for any code which
869             # has global variables which need to be registered as GC
870             # roots.
871         } else {
872             clone_output "$name: unrecognized test line: $test_line"
873             unsupported $name
874         }
875
876         set go_execute_args ""
877     }
878
879     set dg-do-what-default ${saved-dg-do-what-default}
880     set TORTURE_OPTIONS $saved_torture_options
881 }
882
883 go-gc-tests