Merge aosp-toolchain/gcc/gcc-4_9 changes.
[official-gcc.git] / gcc-4_9 / gcc / testsuite / go.test / go-test.exp
blob25e38f08c06a2d2d6392aaa7340a51810c45ee22
1 # Copyright (C) 2009-2014 Free Software Foundation, Inc.
2 # Written by Ian Lance Taylor <iant@google.com>.
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.
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.
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/>.
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.
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
36 load_lib go-dg.exp
37 load_lib go-torture.exp
38 load_lib target-supports.exp
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
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
59 if { [gets $f2 line2] >= 0 } {
60 verbose -log "output mismatch: $file1 shorter than $file2"
61 set ok 0
63 close $f1
64 close $f2
65 if { ! $ok } {
66 fail $testname
67 } else {
68 pass $testname
72 # Implement errchk
73 proc errchk { test opts } {
74 global dg-do-what-default
75 global DEFAULT_GOCFLAGS
76 global runtests
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"
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
94 # Combine quoted strings in comments, so that
95 # // ERROR "first error" "second error"
96 # turns into
97 # // ERROR "first error|second error"
98 # This format is used by the master testsuite to recognize
99 # multiple errors on a single line. We don't require that all
100 # the errors be present, but we do want to accept any of them.
101 set changed ""
102 while { $changed != $copy_line } {
103 set changed $copy_line
104 regsub "\(// \[^\"\]*\"\[^\"\]*\)\" \"" $copy_line "\\1|" out_line
105 set copy_line $out_line
108 regsub "// \(GCCGO_\)?ERROR \"\(\[^\"\]*\)\".*$" $copy_line "// \{ dg-error \"\\2\" \}" out_line
109 if [string match "*dg-error*\\\[*" $out_line] {
110 set index [string first "dg-error" $out_line]
111 regsub -start $index -all "\\\\\\\[" $out_line "\\\\\\\\\\\[" out_line
113 if [string match "*dg-error*\\\]*" $out_line] {
114 set index [string first "dg-error" $out_line]
115 regsub -start $index -all "\\\\\\\]" $out_line "\\\\\\\\\\\]" out_line
117 if [string match "*dg-error*.\**" $out_line] {
118 # I worked out the right number of backslashes by
119 # experimentation, not analysis.
120 regsub -all "\\.\\*" $out_line "\\\\\[ -~\\\\\]*" out_line
122 if [string match "*dg-error*\\\[?\\\]*" $out_line] {
123 set index [string first "dg-error" $out_line]
124 regsub -all "\\\[\(.\)\\\]" $out_line "\\\\\[\\1\\\\\]" out_line
126 if [string match "*dg-error*\{*" $out_line] {
127 set index [string first "dg-error" $out_line]
128 regsub -start $index -all "\(\[^\\\\]\)\{" $out_line "\\1\\\\\[\\\{\\\\\]" out_line
130 if [string match "*dg-error*\}*\}" $out_line] {
131 set index [string first "dg-error" $out_line]
132 regsub -start $index -all "\(\[^\\\\]\)\}\(.\)" $out_line "\\1\\\\\[\\\}\\\\\]\\2" out_line
134 if [string match "*dg-error*\(*" $out_line] {
135 set index [string first "dg-error" $out_line]
136 regsub -start $index -all "\\\\\\\(" $out_line "\\\\\[\\\(\\\\\]" out_line
138 if [string match "*dg-error*\)*\}" $out_line] {
139 set index [string first "dg-error" $out_line]
140 regsub -start $index -all "\\\\\\\)\(.\)" $out_line "\\\\\[\\\)\\\\\]\\1" out_line
142 # Special case for bug332, in which the error message wants to
143 # match the file name, which is not what dg-error expects.
144 if [string match "*dg-error*bug332*" $out_line] {
145 set index [string first "dg-error" $out_line]
146 regsub -start $index "bug332" $out_line "undefined type" out_line
148 puts $fdout $out_line
150 close $fdin
151 close $fdout
153 set hold_runtests $runtests
154 set runtests "go-test.exp"
155 go-dg-runtest $filename "-fno-show-column $DEFAULT_GOCFLAGS $opts"
156 set runtests $hold_runtests
158 file delete $filename
159 set dg-do-what-default ${saved-dg-do-what-default}
162 # This is an execution test which should fail.
163 proc go-execute-xfail { test } {
164 global DEFAULT_GOCFLAGS
165 global runtests
167 set filename [file tail $test]
168 set fdin [open $test r]
169 set fdout [open $filename w]
170 puts $fdout "// { dg-do run { xfail *-*-* } }"
171 while { [gets $fdin copy_line] >= 0 } {
172 puts $fdout $copy_line
174 close $fdin
175 close $fdout
177 set hold_runtests $runtests
178 set runtests "go-test.exp"
179 go-dg-runtest $filename "-w $DEFAULT_GOCFLAGS"
180 set runtests $hold_runtests
182 file delete $filename
185 # N.B. Keep in sync with libgo/configure.ac.
186 proc go-set-goarch { } {
187 global target_triplet
189 switch -glob $target_triplet {
190 "aarch64*-*-*" {
191 set goarch "arm64"
193 "alpha*-*-*" {
194 set goarch "alpha"
196 "arm*-*-*" -
197 "ep9312*-*-*" -
198 "strongarm*-*-*" -
199 "xscale-*-*" {
200 set goarch "arm"
202 "i?86-*-*" -
203 "x86_64-*-*" {
204 if [check_effective_target_ia32] {
205 set goarch "386"
206 } else {
207 set goarch "amd64"
210 "mips*-*-*" {
211 if [check_no_compiler_messages mipso32 assembly {
212 #if _MIPS_SIM != _ABIO32
213 #error FOO
214 #endif
215 }] {
216 set goarch "mipso32"
217 } elseif [check_no_compiler_messages mipsn32 assembly {
218 #if _MIPS_SIM != _ABIN32
219 #error FOO
220 #endif
221 }] {
222 set goarch "mipsn32"
223 } elseif [check_no_compiler_messages mipsn64 assembly {
224 #if _MIPS_SIM != _ABI64
225 #error FOO
226 #endif
227 }] {
228 set goarch "mipsn64"
229 } elseif [check_no_compiler_messages mipso64 assembly {
230 #if _MIPS_SIM != _ABIO64
231 #error FOO
232 #endif
233 }] {
234 set goarch "mipso64"
235 } else {
236 perror "$target_triplet: unrecognized MIPS ABI"
237 return ""
240 "powerpc*-*-*" {
241 if [check_effective_target_ilp32] {
242 set goarch "ppc"
243 } else {
244 if [istarget "powerpc64le-*-*"] {
245 set goarch "ppc64le"
246 } else {
247 set goarch "ppc64"
251 "sparc*-*-*" {
252 if [check_effective_target_ilp32] {
253 set goarch "sparc"
254 } else {
255 set goarch "sparc64"
258 default {
259 perror "$target_triplet: unhandled architecture"
260 return ""
263 verbose -log "Setting GOARCH=$goarch" 1
264 setenv GOARCH $goarch
267 # Take a list of files and return a lists of lists, where each list is
268 # the set of files in the same package.
269 proc go-find-packages { test name files } {
270 set packages [list]
271 foreach f $files {
272 set fd [open $f r]
273 while 1 {
274 if { [gets $fd line] < 0 } {
275 close $fd
276 clone_output "$test: could not read $f"
277 unresolved $name
278 return [list]
281 if { [regexp "^package (\\w+)" $line match package] } {
282 set len [llength $packages]
283 for { set i 0 } { $i < $len } { incr i } {
284 set p [lindex $packages $i]
285 if { [lindex $p 0] == $package } {
286 lappend p $f
287 lset packages $i $p
288 break
291 if { $i >= $len } {
292 lappend packages [list $package $f]
295 close $fd
296 break
300 return $packages
303 proc go-gc-tests { } {
304 global srcdir subdir
305 global runtests
306 global GCC_UNDER_TEST
307 global TOOL_OPTIONS
308 global TORTURE_OPTIONS
309 global dg-do-what-default
310 global go_compile_args
311 global go_execute_args
312 global target_triplet
314 # If a testcase doesn't have special options, use these.
315 global DEFAULT_GOCFLAGS
316 if ![info exists DEFAULT_GOCFLAGS] {
317 set DEFAULT_GOCFLAGS " -pedantic-errors"
320 set options ""
321 lappend options "additional_flags=$DEFAULT_GOCFLAGS"
323 # Set GOARCH for tests that need it.
324 go-set-goarch
326 # Running all the torture options takes too long and, since the
327 # frontend ignores the standard options, it doesn't significantly
328 # improve testing.
329 set saved_torture_options $TORTURE_OPTIONS
330 set TORTURE_OPTIONS [list { -O2 -g }]
332 set saved-dg-do-what-default ${dg-do-what-default}
334 set testdir [pwd]
336 set tests [lsort [find $srcdir/$subdir *.go]]
337 foreach test $tests {
338 if ![runtest_file_p $runtests $test] {
339 continue
342 # Skip the files in bench; they are not tests.
343 if [string match "*go.test/test/bench/*" $test] {
344 continue
347 # Skip the files in stress; they are not tests.
348 if [string match "*go.test/test/stress/*" $test] {
349 continue
352 # Skip the files in safe; gccgo does not support safe mode.
353 if [string match "*go.test/test/safe/*" $test] {
354 continue
357 # Skip files in sub-subdirectories: they are components of
358 # other tests.
359 if [string match "*go.test/test/*/*/*" $test] {
360 continue
363 # Skip files in *.dir subdirectories: they are components of
364 # other tests.
365 if [string match "*go.test/test/*.dir/*" $test] {
366 continue
369 set name [dg-trim-dirname $srcdir $test]
371 # Skip certain tests if target is RTEMS OS.
372 if [istarget "*-*-rtems*"] {
373 if { [string match "*go.test/test/args.go" $test] \
374 || [string match "*go.test/test/env.go" $test] } {
375 untested "$name: uses the command-line or environment variables"
376 continue
379 if { [string match "*go.test/test/stack.go" $test] \
380 || [string match "*go.test/test/peano.go" $test] \
381 || [string match "*go.test/test/chan/goroutines.go" $test] } {
382 untested "$name: has very high memory requirement"
383 continue
387 # Handle certain tests in a target-dependant way.
388 if { [istarget "alpha*-*-*"] || [istarget "sparc*-*-solaris*"] || [istarget "powerpc*-*-*"] } {
389 if { [string match "*go.test/test/nilptr.go" $test] } {
390 untested $test
391 continue
395 if { [file tail $test] == "init1.go" } {
396 # This tests whether GC runs during init, which for gccgo
397 # it currently does not.
398 untested $name
399 continue
402 if { [file tail $test] == "closure.go" } {
403 # This tests whether function closures do any memory
404 # allocation, which for gccgo they currently do.
405 untested $name
406 continue
409 if { ( [file tail $test] == "select2.go" \
410 || [file tail $test] == "stack.go" \
411 || [file tail $test] == "peano.go" ) \
412 && ! [check_effective_target_split_stack] } {
413 # These tests fails on targets without split stack.
414 untested $name
415 continue
418 if [string match "*go.test/test/rotate\[0123\].go" $test] {
419 # These tests produces a temporary file that takes too long
420 # to compile--5 minutes on my laptop without optimization.
421 # When compiling without optimization it tests nothing
422 # useful, since the point of the test is to see whether
423 # the compiler generates rotate instructions.
424 untested $name
425 continue
428 if { [file tail $test] == "bug347.go" \
429 || [file tail $test] == "bug348.go" } {
430 # These tests don't work if the functions are inlined.
431 set TORTURE_OPTIONS [list { -O0 -g }]
434 set fd [open $test r]
436 set lines_ok 1
438 while 1 {
439 if { [gets $fd test_line] < 0 } {
440 close $fd
441 clone_output "$test: could not read first line"
442 unresolved $name
443 set lines_ok 0
444 break
447 if { [ string match "*nacl*exit 0*" $test_line ] \
448 || [ string match "*exit 0*nacl*" $test_line ] \
449 || [ string match "*Android*exit 0*" $test_line ] \
450 || [ string match "*exit 0*Android*" $test_line ] \
451 || [ string match "*\"\$GOOS\" == windows*" $test_line ] } {
452 continue
455 if { [ string match "// +build *" $test_line ] } {
456 if { [ string match "*[getenv GOARCH]*" $test_line ] } {
457 continue
459 if { [ string match "*linux*" $test_line ] } {
460 continue
462 if { [ string match "*!windows*" $test_line ] } {
463 continue
465 close $fd
466 unsupported $name
467 set lines_ok 0
470 break
473 if { $lines_ok == 0 } {
474 continue
477 set lineno 1
478 set test_line1 $test_line
480 while { [eval "string match \"//*&&\" \${test_line$lineno}"] } {
481 set lineno [expr $lineno + 1]
482 if { [eval "gets \$fd test_line$lineno"] < 0 } {
483 close $fd
484 clone_output "$test: could not read line $lineno"
485 unresolved $name
486 set lines_ok 0
487 break
490 if { $lines_ok == 0 } {
491 continue
494 close $fd
496 set go_compile_args ""
497 set go_execute_args ""
498 if { [regexp "// run (\[^|&>2\].*)\$" $test_line match progargs] \
499 && ! [string match "*.go*" "$progargs"] } {
500 set go_execute_args $progargs
501 verbose -log "$test: go_execute_args is $go_execute_args"
502 set index [string last " $progargs" $test_line]
503 set test_line [string replace $test_line $index end]
504 } elseif { [string match "*go.test/test/chan/goroutines.go" $test] \
505 && [getenv GCCGO_RUN_ALL_TESTS] == "" } {
506 # goroutines.go spawns by default 10000 threads, which is too much
507 # for many OSes.
508 if { [getenv GCC_TEST_RUN_EXPENSIVE] == "" } {
509 set go_execute_args 64
510 } elseif { ![is_remote host] && ![is_remote target] } {
511 # When using low ulimit -u limit, use maximum of
512 # a quarter of that limit and 10000 even when running expensive
513 # tests, otherwise parallel tests might fail after fork failures.
514 set nproc [lindex [remote_exec host {sh -c ulimit\ -u}] 1]
515 if { [string is integer -strict $nproc] } {
516 set nproc [expr $nproc / 4]
517 if { $nproc > 10000 } { set nproc 10000 }
518 if { $nproc < 16 } { set nproc 16 }
519 set go_execute_args $nproc
522 if { "$go_execute_args" != "" } {
523 verbose -log "$test: go_execute_args is $go_execute_args"
527 if { $test_line == "// compile"
528 || $test_line == "// echo bug395 is broken # takes 90+ seconds to break" } {
529 # This is a vanilla compile test.
530 set dg-do-what-default "assemble"
531 go-dg-runtest $test "-w $DEFAULT_GOCFLAGS"
532 } elseif { $test_line == "// run"
533 || $test_line == "// \$G \$F.go && \$L \$F.\$A && ./\$A.out" } {
534 # This is a vanilla execution test.
535 go-torture-execute $test
536 file delete core [glob -nocomplain core.*]
537 } elseif { $test_line == "// build" } {
538 # This is a vanilla compile and link test.
539 set dg-do-what-default "link"
540 go-dg-runtest $test "-w $DEFAULT_GOCFLAGS"
541 } elseif { [string match "// runoutput*" $test_line] \
542 || ($test_line == "// \$G \$D/\$F.go && \$L \$F.\$A &&"
543 && $test_line2 == "// ./\$A.out >tmp.go && \$G tmp.go && \$L -o \$A.out1 tmp.\$A && ./\$A.out1") } {
544 # Run the test to get a .go program to run.
545 set go_execute_args ""
546 set hold_runtests $runtests
547 set runtests "go-test.exp"
548 set files [list]
549 if { [string match "// runoutput*" $test_line] } {
550 set args ""
551 regsub "// runoutput\(.*\)" $test_line "\\1" args
552 foreach f $args {
553 lappend files "[file dirname $test]/$f"
556 set dg-do-what-default "link"
557 dg-test -keep-output $test "-O" "$files -w $DEFAULT_GOCFLAGS"
558 set output_file "./[file rootname [file tail $test]].exe"
559 set base "[file rootname [file tail $test]]"
560 if [isnative] {
561 if { [catch "exec $output_file >$base-out.go"] != 0 } {
562 fail "$name execution"
563 } else {
564 pass "$name execution"
565 file delete $base-out.x
566 # Disable optimizations as some of these tests
567 # take a long time to compile.
568 set TORTURE_OPTIONS [list { -O0 -g -fno-var-tracking-assignments }]
569 go-torture-execute "./$base-out.go"
571 file delete $base-out.go
573 file delete $output_file
574 set runtests $hold_runtests
575 } elseif { $test_line == "// cmpout" \
576 || $test_line == "// (\$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out 2>&1 | cmp - \$D/\$F.out)" } {
577 # This is an execution test for which we need to check the
578 # program output.
579 set hold_runtests $runtests
580 set runtests "go-test.exp"
581 set dg-do-what-default "link"
582 dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
583 set output_file "./[file rootname [file tail $test]].exe"
584 set base "[file rootname [file tail $test]]"
585 if [isnative] {
586 verbose -log "$output_file >$base.p 2>&1"
587 if { [catch "exec $output_file 2>$base.p" catcherr] != 0 } {
588 verbose -log $catcherr
589 fail "$name execution"
590 untested "$name compare"
591 } else {
592 pass "$name execution"
593 regsub "\\.go$" $test ".out" expect
594 filecmp $expect $base.p "$name compare"
596 file delete $base.p
597 } else {
598 untested "$name execution"
599 untested "$name compare"
601 set runtests $hold_runtests
602 } elseif { [string match "// \$G \$D/\$F.go && \$L \$F.\$A && ! ./\$A.out || echo BUG: *" \
603 $test_line] } {
604 go-execute-xfail $test
605 } elseif { $test_line == "// errorcheck" } {
606 errchk $test ""
607 } elseif { $test_line == "// errorcheckdir" } {
608 set hold_runtests $runtests
609 set runtests "go-test.exp"
610 set dir "[file rootname $test].dir"
611 set files [lsort [glob "$dir/*.go"]]
612 set packages [go-find-packages $test $name $files]
613 if { [llength $packages] > 0 } {
614 set dg-do-what-default "assemble"
615 set del [list]
616 set last [lindex $packages end]
617 set packages [lreplace $packages end end]
618 foreach p $packages {
619 dg-test -keep-output [lrange $p 1 end] "-O" "-w $DEFAULT_GOCFLAGS"
620 lappend del "[file rootname [file tail [lindex $p 1]]].o"
622 errchk [lindex $last 1] "[lrange $last 2 end]"
623 foreach f $del {
624 file delete $f
627 set runtests $hold_runtests
628 } elseif { [string match "// errorcheckoutput*" $test_line] } {
629 # Run the test to get a .go program to error check.
630 set go_execute_args ""
631 set hold_runtests $runtests
632 set runtests "go-test.exp"
633 set files [list]
634 regsub "// errorcheckoutput\(.*\)" $test_line "\\1" args
635 foreach f $args {
636 lappend files "[file dirname $test]/$f"
638 set dg-do-what-default "link"
639 dg-test -keep-output $test "-O" "$files -w $DEFAULT_GOCFLAGS"
640 set output_file "./[file rootname [file tail $test]].exe"
641 set base "[file rootname [file tail $test]]"
642 if [isnative] {
643 if { [catch "exec $output_file >$base-out.go"] != 0 } {
644 fail "$name execution"
645 } else {
646 pass "$name execution"
647 errchk "$base-out.go" ""
649 file delete $base-out.go
651 file delete $output_file
652 set runtests $hold_runtests
653 } elseif { $test_line == "// compiledir" } {
654 set hold_runtests $runtests
655 set runtests "go-test.exp"
656 set dg-do-what-default "assemble"
657 set dir "[file rootname $test].dir"
658 set del {}
659 foreach f [lsort [glob "$dir/*.go"]] {
660 dg-test -keep-output $f "-O" "-w $DEFAULT_GOCFLAGS"
661 lappend del "[file rootname [file tail $f]].o"
663 foreach f $del {
664 file delete $f
666 set runtests $hold_runtests
667 } elseif { $test_line == "// rundir" } {
668 set hold_runtests $runtests
669 set runtests "go-test.exp"
670 set dir "[file rootname $test].dir"
671 set files [lsort [glob "$dir/*.go"]]
672 set packages [go-find-packages $test $name $files]
673 if { [llength $packages] > 0 } {
674 set dg-do-what-default "assemble"
675 set del [list]
676 set last [lindex $packages end]
677 set packages [lreplace $packages end end]
678 foreach p $packages {
679 dg-test -keep-output [lrange $p 1 end] "-O" "-w $DEFAULT_GOCFLAGS"
680 lappend del "[file rootname [file tail [lindex $p 1]]].o"
682 set dg-do-what-default "link"
683 set go_compile_args $del
684 go-torture-execute [lrange $last 1 end]
685 foreach f $del {
686 file delete $f
689 set runtests $hold_runtests
690 } elseif { $test_line == "// rundircmpout" } {
691 set hold_runtests $runtests
692 set runtests "go-test.exp"
693 set dir "[file rootname $test].dir"
694 set files [lsort [glob "$dir/*.go"]]
695 set packages [go-find-packages $test $name $files]
696 if { [llength $packages] > 0 } {
697 set dg-do-what-default "assemble"
698 set del [list]
699 set last [lindex $packages end]
700 set packages [lreplace $packages end end]
701 foreach p $packages {
702 dg-test -keep-output [lrange $p 1 end] "-O" "-w $DEFAULT_GOCFLAGS"
703 lappend del "[file rootname [file tail [lindex $p 1]]].o"
705 set dg-do-what-default "link"
706 dg-test -keep-output [lrange $last 1 end] "$del -O" "-w $DEFAULT_GOCFLAGS"
707 set base "[file rootname [file tail [lindex $last 1]]]"
708 set output_file "./$base.exe"
709 lappend del $output_file
710 if [isnative] {
711 verbose -log "$output_file >$base.p 2>&1"
712 if { [catch "exec $output_file 2>$base.p" catcherr] != 0 } {
713 verbose -log $catcherr
714 fail "$name execution"
715 untested "$name compare"
716 } else {
717 pass "$name execution"
718 regsub "\\.go$" "$test" ".out" expect
719 filecmp $expect $base.p "$name compare"
721 lappend del $base.p
723 foreach f $del {
724 file delete $f
727 set runtests $hold_runtests
728 } elseif { "$test_line" == ""
729 || [string match "// true*" $test_line]
730 || [string match "// skip*" $test_line] } {
731 # Not a real test, just ignore.
732 } elseif { [string match \
733 "// \$G \$D/\$F.dir/bug0.go && errchk \$G \$D/\$F.dir/bug1.go" \
734 $test_line] \
735 || [string match \
736 "// \$G \$D/\$F.dir/io.go && errchk \$G -e \$D/\$F.dir/main.go" \
737 $test_line] } {
738 if { [string match \
739 "// \$G \$D/\$F.dir/bug0.go && errchk \$G \$D/\$F.dir/bug1.go" \
740 $test_line] } {
741 set name1 "bug0.go"
742 set name2 "bug1.go"
743 } elseif { [string match \
744 "// \$G \$D/\$F.dir/io.go && errchk \$G -e \$D/\$F.dir/main.go" \
745 $test_line] } {
746 set name1 "io.go"
747 set name2 "main.go"
749 set hold_runtests $runtests
750 set runtests "go-test.exp"
751 set dg-do-what-default "assemble"
752 regsub "\\.go$" $test ".dir/$name1" file1
753 dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
754 regsub "\\.go$" $test ".dir/$name2" file2
755 errchk $file2 ""
756 file delete "[file rootname [file tail $file1]].o"
757 set runtests $hold_runtests
758 } elseif { [string match \
759 "// \$G \$D/\${F}1.go && errchk \$G \$D/\$F.go" \
760 $test_line ] } {
761 set hold_runtests $runtests
762 set runtests "go-test.exp"
763 set dg-do-what-default "assemble"
764 regsub "\\.go$" $test "1.go" file1
765 dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
766 errchk $test ""
767 file delete "[file rootname [file tail $file1]].o"
768 set runtests $hold_runtests
769 } elseif { [string match \
770 "// \$G \$D/\$F.dir/bug0.go && \$G \$D/\$F.dir/bug1.go && errchk \$G \$D/\$F.dir/bug2.go" \
771 $test_line] } {
772 set hold_runtests $runtests
773 set runtests "go-test.exp"
774 set dg-do-what-default "assemble"
775 regsub "\\.go$" $test ".dir/bug0.go" file1
776 dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
777 regsub "\\.go$" $test ".dir/bug1.go" file2
778 dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
779 regsub "\\.go$" $test ".dir/bug2.go" file3
780 errchk $file3 ""
781 file delete "[file rootname [file tail $file1]].o"
782 file delete "[file rootname [file tail $file2]].o"
783 set runtests $hold_runtests
784 } elseif { [string match \
785 "// \$G \$D/bug160.dir/x.go && \$G \$D/bug160.dir/y.go && \$L y.\$A && ./\$A.out" \
786 $test_line] \
787 || [string match \
788 "// \$G \$D/\$F.dir/p.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out" \
789 $test_line] \
790 || $test_line == "// \$G \$D/\$F.dir/p1.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out" \
791 || $test_line == "// \$G \$D/\$F.dir/lib.go && \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out" \
792 || $test_line == "// \$G \$D/method4a.go && \$G \$D/\$F.go && \$L \$F.\$A && ./$\A.out" } {
793 if { [string match \
794 "// \$G \$D/bug160.dir/x.go && \$G \$D/bug160.dir/y.go && \$L y.\$A && ./\$A.out" \
795 $test_line] } {
796 set name1 "x.go"
797 set name2 "y.go"
798 } elseif { [string match \
799 "// \$G \$D/\$F.dir/p.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out" \
800 $test_line] } {
801 set name1 "p.go"
802 set name2 "main.go"
803 } elseif { $test_line == "// \$G \$D/\$F.dir/p1.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out" } {
804 set name1 "p1.go"
805 set name2 "main.go"
806 } elseif { $test_line == "// \$G \$D/\$F.dir/lib.go && \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out" } {
807 set name1 "lib.go"
808 set name2 ""
809 } elseif { $test_line == "// \$G \$D/method4a.go && \$G \$D/\$F.go && \$L \$F.\$A && ./$\A.out" } {
810 set name1 "method4a.go"
811 set name2 ""
813 set hold_runtests $runtests
814 set runtests "go-test.exp"
815 set dg-do-what-default "assemble"
816 regsub "\\.go$" $test ".dir/$name1" file1
817 if { $name1 == "method4a.go" } {
818 set file1 "[file dirname $test]/method4a.go"
820 dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
821 set ofile1 "[file rootname [file tail $file1]].o"
822 regsub "\\.go$" $test ".dir/$name2" file2
823 if { $name2 == "" } {
824 set file2 $test
826 dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
827 set ofile2 "[file rootname [file tail $file2]].o"
828 set dg-do-what-default "link"
829 set output_file "./[file rootname [file tail $test]].exe"
830 set comp_output [go_target_compile "$ofile1 $ofile2" \
831 $output_file "executable" "$options"]
832 set comp_output [go-dg-prune $target_triplet $comp_output]
833 verbose -log $comp_output
834 set result [go_load "$output_file" "" ""]
835 set status [lindex $result 0]
836 $status $name
837 file delete $ofile1 $ofile2 $output_file
838 set runtests $hold_runtests
839 } elseif { $test_line == "// \$G \$D/\$F.dir/one.go && \$G \$D/\$F.dir/two.go && \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out" } {
840 set hold_runtests $runtests
841 set runtests "go-test.exp"
842 set dg-do-what-default "assemble"
843 regsub "\\.go$" $test ".dir/one.go" file1
844 dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
845 set ofile1 "[file rootname [file tail $file1]].o"
846 regsub "\\.go$" $test ".dir/two.go" file2
847 dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
848 set ofile2 "[file rootname [file tail $file2]].o"
849 dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
850 set ofile3 "[file rootname [file tail $test]].o"
851 set dg-do-what-default "link"
852 set output_file "./[file rootname [file tail $test]].exe"
853 set comp_output [go_target_compile "$ofile1 $ofile2 $ofile3" \
854 $output_file "executable" "$options"]
855 set comp_output [go-dg-prune $target_triplet $comp_output]
856 verbose -log $comp_output
857 set result [go_load "$output_file" "" ""]
858 set status [lindex $result 0]
859 $status $name
860 file delete $ofile1 $ofile2 $ofile3 $output_file
861 set runtests $hold_runtests
862 } elseif { [string match \
863 "// \$G \$D/embed0.go && \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out" \
864 $test_line ] } {
865 set hold_runtests $runtests
866 set runtests "go-test.exp"
867 set dg-do-what-default "assemble"
868 regsub "/\[^/\]*$" $test "/embed0.go" file1
869 dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
870 set ofile1 "[file rootname [file tail $file1]].o"
871 dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
872 set ofile2 "[file rootname [file tail $test]].o"
873 set output_file "./[file rootname [file tail $test]].exe"
874 set comp_output [go_target_compile "$ofile1 $ofile2" \
875 $output_file "executable" "$options"]
876 set comp_output [go-dg-prune $target_triplet $comp_output]
877 if [string match "" $comp_output] {
878 set result [go_load "$output_file" "" ""]
879 set status [lindex $result 0]
880 $status $name
881 } else {
882 verbose -log $comp_output
883 fail $name
885 file delete $ofile1 $ofile2 $output_file
886 set runtests $hold_runtests
887 } elseif { [string match \
888 "// \$G \$D/\$F.dir/lib.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out || echo BUG*" \
889 $test_line ] || \
890 [string match \
891 "// \$G \$D/\$F.dir/p.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out || echo BUG*" \
892 $test_line ] } {
893 if { [string match \
894 "// \$G \$D/\$F.dir/lib.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out || echo BUG*" \
895 $test_line ] } {
896 set name1 "lib.go"
897 set name2 "main.go"
898 } elseif { [string match \
899 "// \$G \$D/\$F.dir/p.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out || echo BUG*" \
900 $test_line ] } {
901 set name1 "p.go"
902 set name2 "main.go"
904 set hold_runtests $runtests
905 set runtests "go-test.exp"
906 set dg-do-what-default "assemble"
907 regsub "\\.go$" $test ".dir/$name1" file1
908 dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
909 set ofile1 "[file rootname [file tail $file1]].o"
910 regsub "\\.go$" $test ".dir/$name2" file2
911 dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
912 set ofile2 "[file rootname [file tail $file2]].o"
913 set dg-do-what-default "link"
914 set output_file "./[file rootname [file tail $file2]].exe"
915 set comp_output [go_target_compile "$ofile1 $ofile2" \
916 $output_file "executable" "$options"]
917 set comp_output [go-dg-prune $target_triplet $comp_output]
918 if [string match "" $comp_output] {
919 set result [go_load "$output_file" "" ""]
920 set status [lindex $result 0]
921 $status $name
922 } else {
923 verbose -log $comp_output
924 fail $name
926 file delete $ofile1 $ofile2 $output_file
927 set runtests $hold_runtests
928 } elseif { $test_line == "// \$G \$D/\$F.dir/bug0.go &&" \
929 && $test_line2 == "// \$G \$D/\$F.dir/bug1.go &&" \
930 && $test_line3 == "// \$G \$D/\$F.dir/bug2.go &&" \
931 && $test_line4 == "// errchk \$G -e \$D/\$F.dir/bug3.go &&" \
932 && $test_line5 == "// \$L bug2.\$A &&" \
933 && [string match "// ./\$A.out || echo BUG*" $test_line6] } {
934 set hold_runtests $runtests
935 set runtests "go-test.exp"
936 set dg-do-what-default "assemble"
937 regsub "\\.go$" $test ".dir/bug0.go" file0
938 dg-test -keep-output $file0 "-O -fgo-prefix=bug0" "-w $DEFAULT_GOCFLAGS"
939 set ofile0 "[file rootname [file tail $file0]].o"
940 regsub "\\.go$" $test ".dir/bug1.go" file1
941 dg-test -keep-output $file1 "-O -fgo-prefix=bug1" "-w $DEFAULT_GOCFLAGS"
942 set ofile1 "[file rootname [file tail $file1]].o"
943 regsub "\\.go$" $test ".dir/bug2.go" file2
944 dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
945 set ofile2 "[file rootname [file tail $file2]].o"
946 regsub "\\.go$" $test ".dir/bug3.go" file3
947 errchk $file3 ""
948 set output_file "./[file rootname [file tail $test]].exe"
949 set comp_output [go_target_compile "$ofile0 $ofile1 $ofile2" \
950 $output_file "executable" "$options"]
951 set comp-output [go-dg-prune $target_triplet $comp_output]
952 if [string match "" $comp_output] {
953 set result [go_load "$output_file" "" ""]
954 set status [lindex $result 0]
955 $status $name
956 } else {
957 verbose -log $comp_output
958 fail $name
960 file delete $ofile0 $ofile1 $ofile2 $output_file
961 set runtests $hold_runtests
962 } elseif { $test_line == "// \$G \$D/import2.go && \$G \$D/\$F\.go" \
963 || $test_line == "// \$G \$D/recursive1.go && \$G \$D/\$F.go" } {
964 if { $test_line == "// \$G \$D/import2.go && \$G \$D/\$F\.go" } {
965 set name1 "import2.go"
966 } elseif { $test_line == "// \$G \$D/recursive1.go && \$G \$D/\$F.go" } {
967 set name1 "recursive1.go"
969 set hold_runtests $runtests
970 set runtests "go-test.exp"
971 set dg-do-what-default "assemble"
972 regsub "/\[^/\]*$" $test "/${name1}" file1
973 dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
974 set ofile1 "[file rootname [file tail $file1]].o"
975 dg-test $test "-O" "-w $DEFAULT_GOCFLAGS"
976 file delete $ofile1
977 set runtests $hold_runtests
978 } elseif { $test_line == "// \$G \$D/ddd2.go && \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out" } {
979 set hold_runtests $runtests
980 set runtests "go-test.exp"
981 set dg-do-what-default "assemble"
982 regsub "/\[^/\]*$" $test "/ddd2.go" file1
983 dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
984 set ofile1 "[file rootname [file tail $file1]].o"
985 dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
986 set ofile2 "[file rootname [file tail $test]].o"
987 set output_file "./[file rootname [file tail $test]].exe"
988 set comp_output [go_target_compile "$ofile1 $ofile2" \
989 $output_file "executable" "$options"]
990 set comp_output [go-dg-prune $target_triplet $comp_output]
991 if [string match "" $comp_output] {
992 set result [go_load "$output_file" "" ""]
993 set status [lindex $result 0]
994 $status $name
995 } else {
996 verbose -log $comp_output
997 fail $name
999 file delete $ofile1 $ofile2 $output_file
1000 set runtests $hold_runtests
1001 } elseif { $test_line == "// run cmplxdivide1.go" } {
1002 regsub "/\[^/\]*$" $test "/cmplxdivide1.go" test2
1003 set output_file "./[file rootname [file tail $test]].o"
1004 set comp_output [go_target_compile "$test $test2" \
1005 $output_file "executable" "$options"]
1006 set comp_output [go-dg-prune $target_triplet $comp_output]
1007 if [string match "" $comp_output] {
1008 set result [go_load "$output_file" "" ""]
1009 set status [lindex $result 0]
1010 $status $name
1011 } else {
1012 verbose -log $comp_output
1013 fail $name
1015 file delete $output_file
1016 } elseif { $test_line == "// \$G \$D/\$F.go && \$L \$F.\$A &&" \
1017 && $test_line2 == "// ./\$A.out -pass 0 >tmp.go && \$G tmp.go && \$L -o \$A.out1 tmp.\$A && ./\$A.out1 &&" \
1018 && $test_line3 == "// ./\$A.out -pass 1 >tmp.go && errchk \$G -e tmp.go &&" \
1019 && $test_line4 == "// ./\$A.out -pass 2 >tmp.go && errchk \$G -e tmp.go" } {
1020 set go_execute_args ""
1021 set hold_runtests $runtests
1022 set runtests "go-test.exp"
1023 set dg-do-what-default "link"
1024 dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
1025 set output_file "./[file rootname [file tail $test]].exe"
1026 if [isnative] {
1027 if { [catch "exec $output_file -pass 0 >tmp.go"] != 0 } {
1028 fail "$name execution 0"
1029 } else {
1030 pass "$name execution 0"
1031 file delete tmp.x
1032 # Disable optimizations as this test takes a long time
1033 # to compile.
1034 set TORTURE_OPTIONS [list { -O0 -g -fno-var-tracking-assignments }]
1035 go-torture-execute "./tmp.go"
1037 if { [catch "exec $output_file -pass 1 >tmp.go"] != 0 } {
1038 fail "$name execution 1"
1039 } else {
1040 pass "$name execution 1"
1041 errchk tmp.go ""
1043 if { [catch "exec $output_file -pass 2 >tmp.go"] != 0 } {
1044 fail "$name execution 2"
1045 } else {
1046 pass "$name execution 2"
1047 errchk tmp.go ""
1049 file delete tmp.go
1051 file delete $output_file
1052 set runtests $hold_runtests
1053 } elseif { $test_line == "// \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out >tmp.go &&" \
1054 && $test_line2 == "// errchk \$G -e tmp.go" } {
1055 set go_execute_args ""
1056 set hold_runtests $runtests
1057 set runtests "go-test.exp"
1058 set dg-do-what-default "link"
1059 dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
1060 set output_file "./[file rootname [file tail $test]].exe"
1061 if [isnative] {
1062 if { [catch "exec $output_file >tmp.go"] != 0 } {
1063 fail "$name execution"
1064 } else {
1065 pass "$name execution"
1066 file delete tmp.x
1067 errchk tmp.go ""
1070 file delete $output_file
1071 set runtests $hold_runtests
1072 } elseif { $test_line == "// errchk \$G -e \$D/\$F.dir/\[ab\].go" } {
1073 regsub "\\.go$" $test ".dir/a.go" file1
1074 regsub "\\.go$" $test ".dir/b.go" file2
1075 errchk "$file1" "$file2"
1076 } elseif { $test_line == "// \$G -N -o slow.\$A \$D/bug369.dir/pkg.go &&" \
1077 && $test_line2 == "// \$G -o fast.\$A \$D/bug369.dir/pkg.go &&" \
1078 && $test_line3 == "// run" } {
1079 set hold_runtests $runtests
1080 set runtests "go-test.exp"
1081 set dg-do-what-default "assemble"
1082 regsub "\\.go$" $test ".dir/pkg.go" file1
1083 dg-test -keep-output $file1 "" "-fgo-prefix=slow -w $DEFAULT_GOCFLAGS"
1084 set ofile1 "[file rootname [file tail $file1]].o"
1085 file rename -force $ofile1 slow.o
1086 dg-test -keep-output $file1 "-O2" "-fgo-prefix=fast -w $DEFAULT_GOCFLAGS"
1087 file rename -force $ofile1 fast.o
1088 set ofile2 "[file rootname [file tail $test]].o"
1089 dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
1090 set output_file "./[file rootname [file tail $test]].exe"
1091 set comp_output [go_target_compile "$ofile2 slow.o fast.o" \
1092 $output_file "executable" "$options"]
1093 set comp_output [go-dg-prune $target_triplet $comp_output]
1094 if [string match "" $comp_output] {
1095 set result [go_load "$output_file" "" ""]
1096 set status [lindex $result 0]
1097 $status $name
1098 } else {
1099 verbose -log $comp_output
1100 fail $name
1102 file delete slow.o fast.o $ofile2 $output_file
1103 set runtests $hold_runtests
1104 } elseif { [string match \
1105 "// \$G \$D/\$F.dir/pkg.go && \$G \$D/\$F.go || echo *" \
1106 $test_line ] } {
1107 set hold_runtests $runtests
1108 set runtests "go-test.exp"
1109 set dg-do-what-default "assemble"
1110 regsub "\\.go$" $test ".dir/pkg.go" file1
1111 dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
1112 dg-test $test "-O" "-w $DEFAULT_GOCFLAGS"
1113 file delete "[file rootname [file tail $file1]].o"
1114 set runtests $hold_runtests
1115 } elseif { [string match "// \$G \$D/\$F.dir/one.go && \$G \$D/\$F.dir/two.go || echo BUG*" \
1116 $test_line ] } {
1117 set hold_runtests $runtests
1118 set runtests "go-test.exp"
1119 set dg-do-what-default "assemble"
1120 regsub "\\.go$" $test ".dir/one.go" file1
1121 dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
1122 set ofile1 "[file rootname [file tail $file1]].o"
1123 regsub "\\.go$" $test ".dir/two.go" file2
1124 dg-test $file2 "-O" "-w $DEFAULT_GOCFLAGS"
1125 file delete $ofile1
1126 set runtests $hold_runtests
1127 } elseif { $test_line == "// \$G \$D/bug302.dir/p.go && pack grc pp.a p.\$A && \$G \$D/bug302.dir/main.go" \
1128 || $test_line == "// \$G \$D/empty.go && errchk \$G \$D/\$F.go" } {
1129 # These tests import the same package under two different
1130 # names, which gccgo does not support.
1131 } elseif { $test_line == "// \$G -S \$D/\$F.go | egrep initdone >/dev/null && echo BUG sinit || true" } {
1132 # This tests whether initializers are written out
1133 # statically. gccgo does not provide a way to test that,
1134 # as an initializer will be generated for any code which
1135 # has global variables which need to be registered as GC
1136 # roots.
1137 } elseif { $test_line == "// errorcheck -0 -m"
1138 || $test_line == "// errorcheck -0 -m -l" } {
1139 # This tests debug output of the gc compiler, which is
1140 # meaningless for gccgo.
1141 } elseif { $test_line == "// \[ \$A == 6 \] || errchk \$G -e \$D/\$F.go" \
1142 || $test_line == "// \[ \$A != 6 \] || errchk \$G -e \$D/\$F.go" } {
1143 # This tests specific handling of the gc compiler on types
1144 # that are too large. It is target specific in a way I
1145 # haven't bothered to check for here.
1146 } elseif { $test_line == "// \$G \$D/\$F.go && \$L -X main.tbd hello \$F.\$A && ./\$A.out" } {
1147 # This tests the gc ld -X option, which gccgo does not
1148 # support.
1149 } 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"
1150 || $test_line == "// \$G \$D/pkg.go && pack grcS pkg.a pkg.\$A 2> /dev/null && rm pkg.\$A && \$G -I. -u \$D/main.go" } {
1151 # This tests the gc -u option, which gccgo does not
1152 # support.
1153 } elseif { $test_line == "// errorcheck -0 -N -d=nil" \
1154 || $test_line == "// errorcheck -0 -d=nil" } {
1155 # This tests gc nil pointer checks using -d=nil, which
1156 # gccgo does not support.
1157 } else {
1158 clone_output "$name: unrecognized test line: $test_line"
1159 unsupported $name
1162 set go_compile_args ""
1163 set go_execute_args ""
1164 set TORTURE_OPTIONS [list { -O2 -g }]
1167 set dg-do-what-default ${saved-dg-do-what-default}
1168 set TORTURE_OPTIONS $saved_torture_options
1171 go-gc-tests