1 # Copyright (C) 2009-2021 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:
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
37 load_lib go-torture.exp
38 load_lib target-supports.exp
41 proc filecmp { file1 file2 testname } {
42 set f1 [open $file1 r]
43 set f2 [open $file2 r]
45 while { [gets $f1 line1] >= 0 } {
46 if { [gets $f2 line2] < 0 } {
47 verbose -log "output mismatch: $file2 shorter than $file1"
51 if { $line1 != $line2 } {
52 verbose -log "output mismatch comparing $file1 and $file2"
53 verbose -log "expected \"$line1\""
54 verbose -log "got \"$line2\""
59 if { [gets $f2 line2] >= 0 } {
60 verbose -log "output mismatch: $file1 shorter than $file2"
73 proc errchk { test opts } {
74 global dg-do-what-default
75 global DEFAULT_GOCFLAGS
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
94 # Combine quoted strings in comments, so that
95 # // ERROR "first error" "second error"
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.
102 while { $changed != $copy_line } {
103 set changed $copy_line
104 regsub {(// [^"]*"[^"]*)" "} $copy_line {\1|} out_line
105 set copy_line $out_line
108 set index [string first // $copy_line]
109 set eindex [string first ERROR $copy_line]
110 if { $index >= 0 && $eindex > $index } {
111 # We're putting the regexp in curly braces, so replace any
112 # curly braces in the regexp with hex escapes.
113 regsub -start $index -all "\{" $copy_line {\x7b} copy_line
114 regsub -start $index -all "\}" $copy_line {\x7d} copy_line
116 # Replace .* with [ -~]* because .* will eat newlines.
117 # We can't easily use (?n) because this regexp will appear
118 # in the middle of a large regexp.
119 regsub -all {\.\*} $copy_line {[ -~]*} copy_line
125 # // { dg-error {string} }
126 # The latter is what go-dg-runtest expects.
127 regsub {// (GCCGO_)?ERROR "([^"]*)"([^"]*)$} $copy_line "// \{ dg-error \{\\2\} \}\\3" out_line
129 puts $fdout $out_line
134 set hold_runtests $runtests
135 set runtests "go-test.exp"
136 go-dg-runtest $filename "" "-fno-show-column $DEFAULT_GOCFLAGS $opts"
137 set runtests $hold_runtests
139 file delete $filename
140 set dg-do-what-default ${saved-dg-do-what-default}
143 # This is an execution test which should fail.
144 proc go-execute-xfail { test } {
145 global DEFAULT_GOCFLAGS
148 set filename [file tail $test]
149 set fdin [open $test r]
150 set fdout [open $filename w]
151 puts $fdout "// { dg-do run { xfail *-*-* } }"
152 while { [gets $fdin copy_line] >= 0 } {
153 puts $fdout $copy_line
158 set hold_runtests $runtests
159 set runtests "go-test.exp"
160 go-dg-runtest $filename "" "-w $DEFAULT_GOCFLAGS"
161 set runtests $hold_runtests
163 file delete $filename
166 # N.B. Keep in sync with libgo/configure.ac.
167 proc go-set-goarch { } {
168 global target_triplet
170 switch -glob $target_triplet {
185 if [check_effective_target_ia32] {
187 } elseif [check_effective_target_x32] {
188 set goarch "amd64p32"
194 if [check_no_compiler_messages mipso32 assembly {
195 #if _MIPS_SIM != _ABIO32
200 } elseif [check_no_compiler_messages mipsn32 assembly {
201 #if _MIPS_SIM != _ABIN32
205 set goarch "mips64p32"
206 } elseif [check_no_compiler_messages mipsn64 assembly {
207 #if _MIPS_SIM != _ABI64
213 perror "$target_triplet: unrecognized MIPS ABI"
217 if [istarget "mips*el-*-*"] {
222 if [check_effective_target_ilp32] {
225 if [istarget "powerpc64le-*-*"] {
236 if [check_effective_target_ilp32] {
243 if [check_effective_target_ilp32] {
250 perror "$target_triplet: unhandled architecture"
254 verbose -log "Setting GOARCH=$goarch" 1
255 setenv GOARCH $goarch
258 # This be kept in sync with libgo/configure.ac.
259 proc go-set-goos { } {
260 global target_triplet
262 switch -glob $target_triplet {
297 perror "$target_triplet: unhandled GOOS"
301 verbose -log "Setting GOOS=$goos" 1
305 # Take a list of files and return a lists of lists, where each list is
306 # the set of files in the same package.
307 proc go-find-packages { test name files } {
312 if { [gets $fd line] < 0 } {
314 clone_output "$test: could not read $f"
319 if { [regexp "^package (\\w+)" $line match package] } {
320 set len [llength $packages]
321 for { set i 0 } { $i < $len } { incr i } {
322 set p [lindex $packages $i]
323 if { [lindex $p 0] == $package } {
330 lappend packages [list $package $f]
341 proc go-gc-match { name } {
342 verbose -log "go-gc-match $name"
343 set idx [string first "," $name]
345 set left [string range $name 0 [expr $idx - 1]]
346 set right [string range $name [expr $idx + 1] end]
347 return [expr [go-gc-match $left] && [go-gc-match $right]]
349 if { [string index $name 0] == "!" && [string index $name 1] == "!" } {
352 if { [string index $name 0] == "!" } {
353 return [expr ! [go-gc-match [string range $name 1 end]]]
355 if { $name == [getenv GOARCH] || $name == [getenv GOOS] || $name == "gccgo" } {
362 proc go-gc-tests { } {
365 global GCC_UNDER_TEST
367 global TORTURE_OPTIONS
368 global dg-do-what-default
369 global go_compile_args
370 global go_execute_args
371 global target_triplet
373 # If a testcase doesn't have special options, use these.
374 global DEFAULT_GOCFLAGS
375 if ![info exists DEFAULT_GOCFLAGS] {
376 set DEFAULT_GOCFLAGS " -pedantic-errors"
380 lappend options "additional_flags=$DEFAULT_GOCFLAGS"
382 # Set GOARCH and GOOS for tests that need it.
386 # Running all the torture options takes too long and, since the
387 # frontend ignores the standard options, it doesn't significantly
389 set saved_torture_options $TORTURE_OPTIONS
390 set TORTURE_OPTIONS [list { -O2 -g }]
392 set saved-dg-do-what-default ${dg-do-what-default}
396 set tests [lsort [find $srcdir/$subdir *.go]]
397 foreach test $tests {
398 if ![runtest_file_p $runtests $test] {
402 # Skip the files in bench; they are not tests.
403 if [string match "*go.test/test/bench/*" $test] {
407 # Skip the files in stress; they are not tests.
408 if [string match "*go.test/test/stress/*" $test] {
412 # Skip the files in safe; gccgo does not support safe mode.
413 if [string match "*go.test/test/safe/*" $test] {
417 # Skip files in sub-subdirectories: they are components of
419 if [string match "*go.test/test/*/*/*" $test] {
423 # Skip files in *.dir subdirectories: they are components of
425 if [string match "*go.test/test/*.dir/*" $test] {
429 set name [dg-trim-dirname $srcdir $test]
431 # Skip certain tests if target is RTEMS OS.
432 if [istarget "*-*-rtems*"] {
433 if { [string match "*go.test/test/args.go" $test] \
434 || [string match "*go.test/test/env.go" $test] } {
435 untested "$name: uses the command-line or environment variables"
439 if { [string match "*go.test/test/stack.go" $test] \
440 || [string match "*go.test/test/peano.go" $test] \
441 || [string match "*go.test/test/chan/goroutines.go" $test] } {
442 untested "$name: has very high memory requirement"
447 # Handle certain tests in a target-dependant way.
448 if { [istarget "alpha*-*-*"] || [istarget "sparc*-*-solaris*"] || [istarget "powerpc*-*-*"] || [istarget "s390*-*-*"] } {
449 if { [string match "*go.test/test/nilptr.go" $test] } {
455 if [check_effective_target_pie_enabled] {
460 if { [file tail $test] == "init1.go" } {
461 # This tests whether GC runs during init, which for gccgo
462 # it currently does not.
467 if { [file tail $test] == "closure.go" } {
468 # This tests whether function closures do any memory
469 # allocation, which for gccgo they currently do.
474 if { ( [file tail $test] == "select2.go" \
475 || [file tail $test] == "stack.go" \
476 || [file tail $test] == "peano.go" \
477 || [file tail $test] == "nilptr2.go" ) \
478 && ! [check_effective_target_split_stack] } {
479 # These tests fails on targets without split stack.
484 if [string match "*go.test/test/rotate\[0123\].go" $test] {
485 # These tests produces a temporary file that takes too long
486 # to compile--5 minutes on my laptop without optimization.
487 # When compiling without optimization it tests nothing
488 # useful, since the point of the test is to see whether
489 # the compiler generates rotate instructions.
494 if { [file tail $test] == "bug347.go" \
495 || [file tail $test] == "bug348.go" } {
496 # These tests don't work if the functions are inlined.
497 set TORTURE_OPTIONS [list { -O0 -g }]
500 set fd [open $test r]
506 if { [gets $fd file_line] < 0 } {
510 clone_output "$test: read failed"
516 if { [ string match "*nacl*exit 0*" $file_line ] \
517 || [ string match "*exit 0*nacl*" $file_line ] \
518 || [ string match "*Android*exit 0*" $file_line ] \
519 || [ string match "*exit 0*Android*" $file_line ] \
520 || [ string match "*\"\$GOOS\" == windows*" $file_line ] } {
524 if ![string match "// *" $file_line] {
525 if { $file_line != "" } {
531 if { [ string match "// +build *" $file_line ] } {
532 set words [split $file_line]
534 for { set idx 2 } { $idx < [llength $words] } { incr idx } {
535 if { [go-gc-match [lindex $words $idx]] } {
540 if { $matches == 1 } {
548 if { $test_line == "" } {
549 set test_line $file_line
555 if { $lines_ok == 0 } {
559 # runtest_file_p is already run above, and the code below can run
560 # runtest_file_p again, make sure everything for this test is
561 # performed if the above runtest_file_p decided this runtest
562 # instance should execute the test
563 gcc_parallel_test_enable 0
565 set go_compile_args ""
566 set go_execute_args ""
567 if { [regexp "// run (\[^|&>2\].*)\$" $test_line match progargs] \
568 && ! [string match "*.go*" "$progargs"] } {
569 set go_execute_args $progargs
570 verbose -log "$test: go_execute_args is $go_execute_args"
571 set index [string last " $progargs" $test_line]
572 set test_line [string replace $test_line $index end]
573 } elseif { [string match "*go.test/test/chan/goroutines.go" $test] \
574 && [getenv GCCGO_RUN_ALL_TESTS] == "" } {
575 # goroutines.go spawns by default 10000 threads, which is too much
577 if { [getenv GCC_TEST_RUN_EXPENSIVE] == "" } {
578 set go_execute_args 64
579 } elseif { ![is_remote host] && ![is_remote target] } {
580 # When using low ulimit -u limit, use maximum of
581 # a quarter of that limit and 10000 even when running expensive
582 # tests, otherwise parallel tests might fail after fork failures.
583 set nproc [lindex [remote_exec host {sh -c ulimit\ -u}] 1]
584 if { [string is integer -strict $nproc] } {
585 set nproc [expr $nproc / 4]
586 if { $nproc > 10000 } { set nproc 10000 }
587 if { $nproc < 16 } { set nproc 16 }
588 set go_execute_args $nproc
591 if { "$go_execute_args" != "" } {
592 verbose -log "$test: go_execute_args is $go_execute_args"
596 if { $test_line == "// compile"
597 || $test_line == "// echo bug395 is broken # takes 90+ seconds to break" } {
598 # This is a vanilla compile test.
599 set dg-do-what-default "assemble"
600 go-dg-runtest $test "" "-w $DEFAULT_GOCFLAGS"
601 } elseif { $test_line == "// run"
602 || $test_line == "// \$G \$F.go && \$L \$F.\$A && ./\$A.out" } {
603 # This is a vanilla execution test.
604 go-torture-execute $test
605 file delete core [glob -nocomplain core.*]
606 } elseif { $test_line == "// build" } {
607 # This is a vanilla compile and link test.
608 set dg-do-what-default "link"
609 go-dg-runtest $test "" "-w $DEFAULT_GOCFLAGS"
610 } elseif { [string match "// runoutput*" $test_line] \
611 || ($test_line == "// \$G \$D/\$F.go && \$L \$F.\$A &&"
612 && $test_line2 == "// ./\$A.out >tmp.go && \$G tmp.go && \$L -o \$A.out1 tmp.\$A && ./\$A.out1") } {
613 # Run the test to get a .go program to run.
614 set go_execute_args ""
615 set hold_runtests $runtests
616 set runtests "go-test.exp"
618 if { [string match "// runoutput*" $test_line] } {
620 regsub "// runoutput\(.*\)" $test_line "\\1" args
622 lappend files "[file dirname $test]/$f"
625 set dg-do-what-default "link"
626 dg-test -keep-output $test "-O" "$files -w $DEFAULT_GOCFLAGS"
627 set output_file "./[file rootname [file tail $test]].exe"
628 set base "[file rootname [file tail $test]]"
630 if { [catch "exec $output_file >$base-out.go"] != 0 } {
631 fail "$name execution"
633 pass "$name execution"
634 file delete $base-out.x
635 # Disable optimizations as some of these tests
636 # take a long time to compile.
637 set TORTURE_OPTIONS [list { -O0 -g -fno-var-tracking-assignments }]
638 go-torture-execute "./$base-out.go"
640 file delete $base-out.go
642 file delete $output_file
643 set runtests $hold_runtests
644 } elseif { $test_line == "// cmpout" \
645 || $test_line == "// (\$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out 2>&1 | cmp - \$D/\$F.out)" } {
646 # This is an execution test for which we need to check the
648 set hold_runtests $runtests
649 set runtests "go-test.exp"
650 set dg-do-what-default "link"
651 dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
652 set output_file "./[file rootname [file tail $test]].exe"
653 set base "[file rootname [file tail $test]]"
655 verbose -log "$output_file >$base.p 2>&1"
656 if { [catch "exec $output_file 2>$base.p" catcherr] != 0 } {
657 verbose -log $catcherr
658 fail "$name execution"
659 untested "$name compare"
661 pass "$name execution"
662 regsub "\\.go$" $test ".out" expect
663 filecmp $expect $base.p "$name compare"
664 file delete $output_file
668 untested "$name execution"
669 untested "$name compare"
671 set runtests $hold_runtests
672 } elseif { [string match "// \$G \$D/\$F.go && \$L \$F.\$A && ! ./\$A.out || echo BUG: *" \
674 go-execute-xfail $test
675 } elseif { $test_line == "// errorcheck" } {
677 } elseif { $test_line == "// errorcheckdir" || $test_line == "// errorcheckdir -n" } {
678 set hold_runtests $runtests
679 set runtests "go-test.exp"
680 set dir "[file rootname $test].dir"
681 set files [lsort [glob "$dir/*.go"]]
682 set packages [go-find-packages $test $name $files]
683 if { [llength $packages] > 0 } {
684 set dg-do-what-default "assemble"
686 set last [lindex $packages end]
687 set packages [lreplace $packages end end]
688 foreach p $packages {
689 dg-test -keep-output [lrange $p 1 end] "-O -I." "-w $DEFAULT_GOCFLAGS"
690 lappend del "[file rootname [file tail [lindex $p 1]]].o"
692 errchk [lindex $last 1] "[lrange $last 2 end]"
697 set runtests $hold_runtests
698 } elseif { [string match "// errorcheckoutput*" $test_line] } {
699 # Run the test to get a .go program to error check.
700 set go_execute_args ""
701 set hold_runtests $runtests
702 set runtests "go-test.exp"
704 regsub "// errorcheckoutput\(.*\)" $test_line "\\1" args
706 lappend files "[file dirname $test]/$f"
708 set dg-do-what-default "link"
709 dg-test -keep-output $test "-O" "$files -w $DEFAULT_GOCFLAGS"
710 set output_file "./[file rootname [file tail $test]].exe"
711 set base "[file rootname [file tail $test]]"
713 if { [catch "exec $output_file >$base-out.go"] != 0 } {
714 fail "$name execution"
716 pass "$name execution"
717 errchk "$base-out.go" ""
719 file delete $base-out.go
721 file delete $output_file
722 set runtests $hold_runtests
723 } elseif { $test_line == "// compiledir" } {
724 set hold_runtests $runtests
725 set runtests "go-test.exp"
726 set dg-do-what-default "assemble"
727 set dir "[file rootname $test].dir"
728 set files [lsort [glob "$dir/*.go"]]
729 set packages [go-find-packages $test $name $files]
730 if { [llength $packages] > 0 } {
732 foreach p $packages {
733 dg-test -keep-output [lindex $p 1] "[lrange $p 2 end] -O -I." "-w $DEFAULT_GOCFLAGS"
734 lappend del "[file rootname [file tail [lindex $p 1]]].o"
740 set runtests $hold_runtests
741 } elseif { $test_line == "// rundir" } {
742 set hold_runtests $runtests
743 set runtests "go-test.exp"
744 set dir "[file rootname $test].dir"
745 set files [lsort [glob "$dir/*.go"]]
746 set packages [go-find-packages $test $name $files]
747 if { [llength $packages] > 0 } {
748 set dg-do-what-default "assemble"
750 set last [lindex $packages end]
751 set packages [lreplace $packages end end]
752 foreach p $packages {
753 dg-test -keep-output [lrange $p 1 end] "-O -I." "-w $DEFAULT_GOCFLAGS"
754 lappend del "[file rootname [file tail [lindex $p 1]]].o"
756 set dg-do-what-default "link"
757 set go_compile_args ""
758 append go_compile_args [lrange $last 2 end]
759 append go_compile_args $del
760 go-torture-execute [lindex $last 1]
765 set runtests $hold_runtests
766 } elseif { $test_line == "// rundircmpout" } {
767 set hold_runtests $runtests
768 set runtests "go-test.exp"
769 set dir "[file rootname $test].dir"
770 set files [lsort [glob "$dir/*.go"]]
771 set packages [go-find-packages $test $name $files]
772 if { [llength $packages] > 0 } {
773 set dg-do-what-default "assemble"
775 set last [lindex $packages end]
776 set packages [lreplace $packages end end]
777 foreach p $packages {
778 dg-test -keep-output [lrange $p 1 end] "-O -I." "-w $DEFAULT_GOCFLAGS"
779 lappend del "[file rootname [file tail [lindex $p 1]]].o"
781 set dg-do-what-default "link"
782 dg-test -keep-output [lrange $last 1 end] "$del -O -I." "-w $DEFAULT_GOCFLAGS"
783 set base "[file rootname [file tail [lindex $last 1]]]"
784 set output_file "./$base.exe"
785 lappend del $output_file
787 verbose -log "$output_file >$base.p 2>&1"
788 if { [catch "exec $output_file 2>$base.p" catcherr] != 0 } {
789 verbose -log $catcherr
790 fail "$name execution"
791 untested "$name compare"
793 pass "$name execution"
794 regsub "\\.go$" "$test" ".out" expect
795 filecmp $expect $base.p "$name compare"
803 set runtests $hold_runtests
804 } elseif { "$test_line" == ""
805 || [string match "// true*" $test_line]
806 || [string match "// skip*" $test_line] } {
807 # Not a real test, just ignore.
808 } elseif { [string match \
809 "// \$G \$D/\$F.dir/bug0.go && errchk \$G \$D/\$F.dir/bug1.go" \
812 "// \$G \$D/\$F.dir/io.go && errchk \$G -e \$D/\$F.dir/main.go" \
815 "// \$G \$D/\$F.dir/bug0.go && errchk \$G \$D/\$F.dir/bug1.go" \
819 } elseif { [string match \
820 "// \$G \$D/\$F.dir/io.go && errchk \$G -e \$D/\$F.dir/main.go" \
825 set hold_runtests $runtests
826 set runtests "go-test.exp"
827 set dg-do-what-default "assemble"
828 regsub "\\.go$" $test ".dir/$name1" file1
829 dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
830 regsub "\\.go$" $test ".dir/$name2" file2
832 file delete "[file rootname [file tail $file1]].o"
833 set runtests $hold_runtests
834 } elseif { [string match \
835 "// \$G \$D/\${F}1.go && errchk \$G \$D/\$F.go" \
837 set hold_runtests $runtests
838 set runtests "go-test.exp"
839 set dg-do-what-default "assemble"
840 regsub "\\.go$" $test "1.go" file1
841 dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
843 file delete "[file rootname [file tail $file1]].o"
844 set runtests $hold_runtests
845 } elseif { [string match \
846 "// \$G \$D/\$F.dir/bug0.go && \$G \$D/\$F.dir/bug1.go && errchk \$G \$D/\$F.dir/bug2.go" \
848 set hold_runtests $runtests
849 set runtests "go-test.exp"
850 set dg-do-what-default "assemble"
851 regsub "\\.go$" $test ".dir/bug0.go" file1
852 dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
853 regsub "\\.go$" $test ".dir/bug1.go" file2
854 dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
855 regsub "\\.go$" $test ".dir/bug2.go" file3
857 file delete "[file rootname [file tail $file1]].o"
858 file delete "[file rootname [file tail $file2]].o"
859 set runtests $hold_runtests
860 } elseif { [string match \
861 "// \$G \$D/bug160.dir/x.go && \$G \$D/bug160.dir/y.go && \$L y.\$A && ./\$A.out" \
864 "// \$G \$D/\$F.dir/p.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out" \
866 || $test_line == "// \$G \$D/\$F.dir/p1.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out" \
867 || $test_line == "// \$G \$D/\$F.dir/lib.go && \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out" \
868 || $test_line == "// \$G \$D/method4a.go && \$G \$D/\$F.go && \$L \$F.\$A && ./$\A.out" } {
870 "// \$G \$D/bug160.dir/x.go && \$G \$D/bug160.dir/y.go && \$L y.\$A && ./\$A.out" \
874 } elseif { [string match \
875 "// \$G \$D/\$F.dir/p.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out" \
879 } elseif { $test_line == "// \$G \$D/\$F.dir/p1.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out" } {
882 } elseif { $test_line == "// \$G \$D/\$F.dir/lib.go && \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out" } {
885 } elseif { $test_line == "// \$G \$D/method4a.go && \$G \$D/\$F.go && \$L \$F.\$A && ./$\A.out" } {
886 set name1 "method4a.go"
889 set hold_runtests $runtests
890 set runtests "go-test.exp"
891 set dg-do-what-default "assemble"
892 regsub "\\.go$" $test ".dir/$name1" file1
893 if { $name1 == "method4a.go" } {
894 set file1 "[file dirname $test]/method4a.go"
896 dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
897 set ofile1 "[file rootname [file tail $file1]].o"
898 regsub "\\.go$" $test ".dir/$name2" file2
899 if { $name2 == "" } {
902 dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
903 set ofile2 "[file rootname [file tail $file2]].o"
904 set dg-do-what-default "link"
905 set output_file "./[file rootname [file tail $test]].exe"
906 set comp_output [go_target_compile "$ofile1 $ofile2" \
907 $output_file "executable" "$options"]
908 set comp_output [go-dg-prune $target_triplet $comp_output]
909 verbose -log $comp_output
910 set result [go_load "$output_file" "" ""]
911 set status [lindex $result 0]
913 file delete $ofile1 $ofile2 $output_file
914 set runtests $hold_runtests
915 } elseif { $test_line == "// \$G \$D/\$F.dir/one.go && \$G \$D/\$F.dir/two.go && \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out" } {
916 set hold_runtests $runtests
917 set runtests "go-test.exp"
918 set dg-do-what-default "assemble"
919 regsub "\\.go$" $test ".dir/one.go" file1
920 dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
921 set ofile1 "[file rootname [file tail $file1]].o"
922 regsub "\\.go$" $test ".dir/two.go" file2
923 dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
924 set ofile2 "[file rootname [file tail $file2]].o"
925 dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
926 set ofile3 "[file rootname [file tail $test]].o"
927 set dg-do-what-default "link"
928 set output_file "./[file rootname [file tail $test]].exe"
929 set comp_output [go_target_compile "$ofile1 $ofile2 $ofile3" \
930 $output_file "executable" "$options"]
931 set comp_output [go-dg-prune $target_triplet $comp_output]
932 verbose -log $comp_output
933 set result [go_load "$output_file" "" ""]
934 set status [lindex $result 0]
936 file delete $ofile1 $ofile2 $ofile3 $output_file
937 set runtests $hold_runtests
938 } elseif { [string match \
939 "// \$G \$D/embed0.go && \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out" \
941 set hold_runtests $runtests
942 set runtests "go-test.exp"
943 set dg-do-what-default "assemble"
944 regsub "/\[^/\]*$" $test "/embed0.go" file1
945 dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
946 set ofile1 "[file rootname [file tail $file1]].o"
947 dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
948 set ofile2 "[file rootname [file tail $test]].o"
949 set output_file "./[file rootname [file tail $test]].exe"
950 set comp_output [go_target_compile "$ofile1 $ofile2" \
951 $output_file "executable" "$options"]
952 set comp_output [go-dg-prune $target_triplet $comp_output]
953 if [string match "" $comp_output] {
954 set result [go_load "$output_file" "" ""]
955 set status [lindex $result 0]
958 verbose -log $comp_output
961 file delete $ofile1 $ofile2 $output_file
962 set runtests $hold_runtests
963 } elseif { [string match \
964 "// \$G \$D/\$F.dir/lib.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out || echo BUG*" \
967 "// \$G \$D/\$F.dir/p.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out || echo BUG*" \
970 "// \$G \$D/\$F.dir/lib.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out || echo BUG*" \
974 } elseif { [string match \
975 "// \$G \$D/\$F.dir/p.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out || echo BUG*" \
980 set hold_runtests $runtests
981 set runtests "go-test.exp"
982 set dg-do-what-default "assemble"
983 regsub "\\.go$" $test ".dir/$name1" file1
984 dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
985 set ofile1 "[file rootname [file tail $file1]].o"
986 regsub "\\.go$" $test ".dir/$name2" file2
987 dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
988 set ofile2 "[file rootname [file tail $file2]].o"
989 set dg-do-what-default "link"
990 set output_file "./[file rootname [file tail $file2]].exe"
991 set comp_output [go_target_compile "$ofile1 $ofile2" \
992 $output_file "executable" "$options"]
993 set comp_output [go-dg-prune $target_triplet $comp_output]
994 if [string match "" $comp_output] {
995 set result [go_load "$output_file" "" ""]
996 set status [lindex $result 0]
999 verbose -log $comp_output
1002 file delete $ofile1 $ofile2 $output_file
1003 set runtests $hold_runtests
1004 } elseif { $test_line == "// \$G \$D/\$F.dir/bug0.go &&" \
1005 && $test_line2 == "// \$G \$D/\$F.dir/bug1.go &&" \
1006 && $test_line3 == "// \$G \$D/\$F.dir/bug2.go &&" \
1007 && $test_line4 == "// errchk \$G -e \$D/\$F.dir/bug3.go &&" \
1008 && $test_line5 == "// \$L bug2.\$A &&" \
1009 && [string match "// ./\$A.out || echo BUG*" $test_line6] } {
1010 set hold_runtests $runtests
1011 set runtests "go-test.exp"
1012 set dg-do-what-default "assemble"
1013 regsub "\\.go$" $test ".dir/bug0.go" file0
1014 dg-test -keep-output $file0 "-O -fgo-prefix=bug0" "-w $DEFAULT_GOCFLAGS"
1015 set ofile0 "[file rootname [file tail $file0]].o"
1016 regsub "\\.go$" $test ".dir/bug1.go" file1
1017 dg-test -keep-output $file1 "-O -fgo-prefix=bug1" "-w $DEFAULT_GOCFLAGS"
1018 set ofile1 "[file rootname [file tail $file1]].o"
1019 regsub "\\.go$" $test ".dir/bug2.go" file2
1020 dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
1021 set ofile2 "[file rootname [file tail $file2]].o"
1022 regsub "\\.go$" $test ".dir/bug3.go" file3
1024 set output_file "./[file rootname [file tail $test]].exe"
1025 set comp_output [go_target_compile "$ofile0 $ofile1 $ofile2" \
1026 $output_file "executable" "$options"]
1027 set comp-output [go-dg-prune $target_triplet $comp_output]
1028 if [string match "" $comp_output] {
1029 set result [go_load "$output_file" "" ""]
1030 set status [lindex $result 0]
1033 verbose -log $comp_output
1036 file delete $ofile0 $ofile1 $ofile2 $output_file
1037 set runtests $hold_runtests
1038 } elseif { $test_line == "// \$G \$D/import2.go && \$G \$D/\$F\.go" \
1039 || $test_line == "// \$G \$D/recursive1.go && \$G \$D/\$F.go" } {
1040 if { $test_line == "// \$G \$D/import2.go && \$G \$D/\$F\.go" } {
1041 set name1 "import2.go"
1042 } elseif { $test_line == "// \$G \$D/recursive1.go && \$G \$D/\$F.go" } {
1043 set name1 "recursive1.go"
1045 set hold_runtests $runtests
1046 set runtests "go-test.exp"
1047 set dg-do-what-default "assemble"
1048 regsub "/\[^/\]*$" $test "/${name1}" file1
1049 dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
1050 set ofile1 "[file rootname [file tail $file1]].o"
1051 dg-test $test "-O" "-w $DEFAULT_GOCFLAGS"
1053 set runtests $hold_runtests
1054 } elseif { $test_line == "// \$G \$D/ddd2.go && \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out" } {
1055 set hold_runtests $runtests
1056 set runtests "go-test.exp"
1057 set dg-do-what-default "assemble"
1058 regsub "/\[^/\]*$" $test "/ddd2.go" file1
1059 dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
1060 set ofile1 "[file rootname [file tail $file1]].o"
1061 dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
1062 set ofile2 "[file rootname [file tail $test]].o"
1063 set output_file "./[file rootname [file tail $test]].exe"
1064 set comp_output [go_target_compile "$ofile1 $ofile2" \
1065 $output_file "executable" "$options"]
1066 set comp_output [go-dg-prune $target_triplet $comp_output]
1067 if [string match "" $comp_output] {
1068 set result [go_load "$output_file" "" ""]
1069 set status [lindex $result 0]
1072 verbose -log $comp_output
1075 file delete $ofile1 $ofile2 $output_file
1076 set runtests $hold_runtests
1077 } elseif { $test_line == "// run cmplxdivide1.go" } {
1078 regsub "/\[^/\]*$" $test "/cmplxdivide1.go" test2
1079 set output_file "./[file rootname [file tail $test]].o"
1080 set comp_output [go_target_compile "$test $test2" \
1081 $output_file "executable" "$options"]
1082 set comp_output [go-dg-prune $target_triplet $comp_output]
1083 if [string match "" $comp_output] {
1084 set result [go_load "$output_file" "" ""]
1085 set status [lindex $result 0]
1088 verbose -log $comp_output
1091 file delete $output_file
1092 } elseif { $test_line == "// \$G \$D/\$F.go && \$L \$F.\$A &&" \
1093 && $test_line2 == "// ./\$A.out -pass 0 >tmp.go && \$G tmp.go && \$L -o \$A.out1 tmp.\$A && ./\$A.out1 &&" \
1094 && $test_line3 == "// ./\$A.out -pass 1 >tmp.go && errchk \$G -e tmp.go &&" \
1095 && $test_line4 == "// ./\$A.out -pass 2 >tmp.go && errchk \$G -e tmp.go" } {
1096 set go_execute_args ""
1097 set hold_runtests $runtests
1098 set runtests "go-test.exp"
1099 set dg-do-what-default "link"
1100 dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
1101 set output_file "./[file rootname [file tail $test]].exe"
1103 if { [catch "exec $output_file -pass 0 >tmp.go"] != 0 } {
1104 fail "$name execution 0"
1106 pass "$name execution 0"
1108 # Disable optimizations as this test takes a long time
1110 set TORTURE_OPTIONS [list { -O0 -g -fno-var-tracking-assignments }]
1111 go-torture-execute "./tmp.go"
1113 if { [catch "exec $output_file -pass 1 >tmp.go"] != 0 } {
1114 fail "$name execution 1"
1116 pass "$name execution 1"
1119 if { [catch "exec $output_file -pass 2 >tmp.go"] != 0 } {
1120 fail "$name execution 2"
1122 pass "$name execution 2"
1127 file delete $output_file
1128 set runtests $hold_runtests
1129 } elseif { $test_line == "// \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out >tmp.go &&" \
1130 && $test_line2 == "// errchk \$G -e tmp.go" } {
1131 set go_execute_args ""
1132 set hold_runtests $runtests
1133 set runtests "go-test.exp"
1134 set dg-do-what-default "link"
1135 dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
1136 set output_file "./[file rootname [file tail $test]].exe"
1138 if { [catch "exec $output_file >tmp.go"] != 0 } {
1139 fail "$name execution"
1141 pass "$name execution"
1146 file delete $output_file
1147 set runtests $hold_runtests
1148 } elseif { $test_line == "// errchk \$G -e \$D/\$F.dir/\[ab\].go" } {
1149 regsub "\\.go$" $test ".dir/a.go" file1
1150 regsub "\\.go$" $test ".dir/b.go" file2
1151 errchk "$file1" "$file2"
1152 } elseif { $test_line == "// \$G -N -o slow.\$A \$D/bug369.dir/pkg.go &&" \
1153 && $test_line2 == "// \$G -o fast.\$A \$D/bug369.dir/pkg.go &&" \
1154 && $test_line3 == "// run" } {
1155 set hold_runtests $runtests
1156 set runtests "go-test.exp"
1157 set dg-do-what-default "assemble"
1158 regsub "\\.go$" $test ".dir/pkg.go" file1
1159 dg-test -keep-output $file1 "" "-fgo-prefix=slow -w $DEFAULT_GOCFLAGS"
1160 set ofile1 "[file rootname [file tail $file1]].o"
1161 file rename -force $ofile1 slow.o
1162 dg-test -keep-output $file1 "-O2" "-fgo-prefix=fast -w $DEFAULT_GOCFLAGS"
1163 file rename -force $ofile1 fast.o
1164 set ofile2 "[file rootname [file tail $test]].o"
1165 dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
1166 set output_file "./[file rootname [file tail $test]].exe"
1167 set comp_output [go_target_compile "$ofile2 slow.o fast.o" \
1168 $output_file "executable" "$options"]
1169 set comp_output [go-dg-prune $target_triplet $comp_output]
1170 if [string match "" $comp_output] {
1171 set result [go_load "$output_file" "" ""]
1172 set status [lindex $result 0]
1175 verbose -log $comp_output
1178 file delete slow.o fast.o $ofile2 $output_file
1179 set runtests $hold_runtests
1180 } elseif { [string match \
1181 "// \$G \$D/\$F.dir/pkg.go && \$G \$D/\$F.go || echo *" \
1183 set hold_runtests $runtests
1184 set runtests "go-test.exp"
1185 set dg-do-what-default "assemble"
1186 regsub "\\.go$" $test ".dir/pkg.go" file1
1187 dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
1188 dg-test $test "-O" "-w $DEFAULT_GOCFLAGS"
1189 file delete "[file rootname [file tail $file1]].o"
1190 set runtests $hold_runtests
1191 } elseif { [string match "// \$G \$D/\$F.dir/one.go && \$G \$D/\$F.dir/two.go || echo BUG*" \
1193 set hold_runtests $runtests
1194 set runtests "go-test.exp"
1195 set dg-do-what-default "assemble"
1196 regsub "\\.go$" $test ".dir/one.go" file1
1197 dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
1198 set ofile1 "[file rootname [file tail $file1]].o"
1199 regsub "\\.go$" $test ".dir/two.go" file2
1200 dg-test $file2 "-O" "-w $DEFAULT_GOCFLAGS"
1202 set runtests $hold_runtests
1203 } elseif { $test_line == "// \$G \$D/bug302.dir/p.go && pack grc pp.a p.\$A && \$G \$D/bug302.dir/main.go" \
1204 || $test_line == "// \$G \$D/empty.go && errchk \$G \$D/\$F.go" } {
1205 # These tests import the same package under two different
1206 # names, which gccgo does not support.
1207 } elseif { $test_line == "// \$G -S \$D/\$F.go | egrep initdone >/dev/null && echo BUG sinit || true" } {
1208 # This tests whether initializers are written out
1209 # statically. gccgo does not provide a way to test that,
1210 # as an initializer will be generated for any code which
1211 # has global variables which need to be registered as GC
1213 } elseif { $test_line == "// errorcheck -0 -m"
1214 || $test_line == "// errorcheck -0 -m -l" } {
1215 # This tests debug output of the gc compiler, which is
1216 # meaningless for gccgo.
1217 } elseif { $test_line == "// \[ \$A == 6 \] || errchk \$G -e \$D/\$F.go" \
1218 || $test_line == "// \[ \$A != 6 \] || errchk \$G -e \$D/\$F.go" } {
1219 # This tests specific handling of the gc compiler on types
1220 # that are too large. It is target specific in a way I
1221 # haven't bothered to check for here.
1222 } elseif { $test_line == "// \$G \$D/\$F.go && \$L -X main.tbd hello \$F.\$A && ./\$A.out" } {
1223 # This tests the gc ld -X option, which gccgo does not
1225 } 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"
1226 || $test_line == "// \$G \$D/pkg.go && pack grcS pkg.a pkg.\$A 2> /dev/null && rm pkg.\$A && \$G -I. -u \$D/main.go" } {
1227 # This tests the gc -u option, which gccgo does not
1229 } elseif { $test_line == "// errorcheck -0 -N -d=nil" \
1230 || $test_line == "// errorcheck -0 -d=nil" } {
1231 # This tests gc nil pointer checks using -d=nil, which
1232 # gccgo does not support.
1234 clone_output "$name: unrecognized test line: $test_line"
1238 set go_compile_args ""
1239 set go_execute_args ""
1240 set TORTURE_OPTIONS [list { -O2 -g }]
1241 gcc_parallel_test_enable 1
1244 set dg-do-what-default ${saved-dg-do-what-default}
1245 set TORTURE_OPTIONS $saved_torture_options