1 # Copyright (C) 2009-2013 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
93 regsub "// \(GCCGO_\)?ERROR \"\(\[^\"\]*\)\".*$" $copy_line "// \{ dg-error \"\\2\" \}" out_line
94 if [string match "*dg-error*\\\[*" $out_line] {
95 set index [string first "dg-error" $out_line]
96 regsub -start $index -all "\\\\\\\[" $out_line "\\\\\\\\\\\[" out_line
98 if [string match "*dg-error*\\\]*" $out_line] {
99 set index [string first "dg-error" $out_line]
100 regsub -start $index -all "\\\\\\\]" $out_line "\\\\\\\\\\\]" out_line
102 if [string match "*dg-error*.\**" $out_line] {
103 # I worked out the right number of backslashes by
104 # experimentation, not analysis.
105 regsub -all "\\.\\*" $out_line "\\\\\[ -~\\\\\]*" out_line
107 if [string match "*dg-error*\\\[?\\\]*" $out_line] {
108 set index [string first "dg-error" $out_line]
109 regsub -all "\\\[\(.\)\\\]" $out_line "\\\\\[\\1\\\\\]" out_line
111 if [string match "*dg-error*\{*" $out_line] {
112 set index [string first "dg-error" $out_line]
113 regsub -start $index -all "\(\[^\\\\]\)\{" $out_line "\\1\\\\\[\\\{\\\\\]" out_line
115 if [string match "*dg-error*\}*\}" $out_line] {
116 set index [string first "dg-error" $out_line]
117 regsub -start $index -all "\(\[^\\\\]\)\}\(.\)" $out_line "\\1\\\\\[\\\}\\\\\]\\2" out_line
119 if [string match "*dg-error*\(*" $out_line] {
120 set index [string first "dg-error" $out_line]
121 regsub -start $index -all "\\\\\\\(" $out_line "\\\\\[\\\(\\\\\]" out_line
123 if [string match "*dg-error*\)*\}" $out_line] {
124 set index [string first "dg-error" $out_line]
125 regsub -start $index -all "\\\\\\\)\(.\)" $out_line "\\\\\[\\\)\\\\\]\\1" out_line
127 # Special case for bug332, in which the error message wants to
128 # match the file name, which is not what dg-error expects.
129 if [string match "*dg-error*bug332*" $out_line] {
130 set index [string first "dg-error" $out_line]
131 regsub -start $index "bug332" $out_line "undefined type" out_line
133 puts $fdout $out_line
138 set hold_runtests $runtests
139 set runtests "go-test.exp"
140 go-dg-runtest $filename "-fno-show-column $DEFAULT_GOCFLAGS $opts"
141 set runtests $hold_runtests
143 file delete $filename
144 set dg-do-what-default ${saved-dg-do-what-default}
147 # This is an execution test which should fail.
148 proc go-execute-xfail { test } {
149 global DEFAULT_GOCFLAGS
152 set filename [file tail $test]
153 set fdin [open $test r]
154 set fdout [open $filename w]
155 puts $fdout "// { dg-do run { xfail *-*-* } }"
156 while { [gets $fdin copy_line] >= 0 } {
157 puts $fdout $copy_line
162 set hold_runtests $runtests
163 set runtests "go-test.exp"
164 go-dg-runtest $filename "-w $DEFAULT_GOCFLAGS"
165 set runtests $hold_runtests
167 file delete $filename
170 # N.B. Keep in sync with libgo/configure.ac.
171 proc go-set-goarch { } {
172 global target_triplet
174 switch -glob $target_triplet {
186 if [check_effective_target_ia32] {
193 if [check_no_compiler_messages mipso32 assembly {
194 #if _MIPS_SIM != _ABIO32
199 } elseif [check_no_compiler_messages mipsn32 assembly {
200 #if _MIPS_SIM != _ABIN32
205 } elseif [check_no_compiler_messages mipsn64 assembly {
206 #if _MIPS_SIM != _ABI64
211 } elseif [check_no_compiler_messages mipso64 assembly {
212 #if _MIPS_SIM != _ABIO64
218 perror "$target_triplet: unrecognized MIPS ABI"
223 if [check_effective_target_ilp32] {
230 if [check_effective_target_ilp32] {
237 perror "$target_triplet: unhandled architecture"
241 verbose -log "Setting GOARCH=$goarch" 1
242 setenv GOARCH $goarch
245 proc go-gc-tests { } {
248 global GCC_UNDER_TEST
250 global TORTURE_OPTIONS
251 global dg-do-what-default
252 global go_compile_args
253 global go_execute_args
254 global target_triplet
256 # If a testcase doesn't have special options, use these.
257 global DEFAULT_GOCFLAGS
258 if ![info exists DEFAULT_GOCFLAGS] {
259 set DEFAULT_GOCFLAGS " -pedantic-errors"
263 lappend options "additional_flags=$DEFAULT_GOCFLAGS"
265 # Set GOARCH for tests that need it.
268 # Running all the torture options takes too long and, since the
269 # frontend ignores the standard options, it doesn't significantly
271 set saved_torture_options $TORTURE_OPTIONS
272 set TORTURE_OPTIONS [list { -O2 -g }]
274 set saved-dg-do-what-default ${dg-do-what-default}
278 set tests [lsort [find $srcdir/$subdir *.go]]
279 foreach test $tests {
280 if ![runtest_file_p $runtests $test] {
284 # Skip the files in bench; they are not tests.
285 if [string match "*go.test/test/bench/*" $test] {
289 # Skip files in sub-subdirectories: they are components of
291 if [string match "*go.test/test/*/*/*" $test] {
295 set name [dg-trim-dirname $srcdir $test]
297 # Skip certain tests if target is RTEMS OS.
298 if [istarget "*-*-rtems*"] {
299 if { [string match "*go.test/test/args.go" $test] \
300 || [string match "*go.test/test/env.go" $test] } {
301 untested "$name: uses the command-line or environment variables"
305 if { [string match "*go.test/test/stack.go" $test] \
306 || [string match "*go.test/test/peano.go" $test] \
307 || [string match "*go.test/test/chan/goroutines.go" $test] } {
308 untested "$name: has very high memory requirement"
313 # Handle certain tests in a target-dependant way.
314 if { [istarget "alpha*-*-*"] || [istarget "sparc*-*-solaris*"] || [istarget "powerpc*-*-*"] } {
315 if { [string match "*go.test/test/nilptr.go" $test] } {
321 if { [file tail $test] == "init1.go" } {
322 # This tests whether GC runs during init, which for gccgo
323 # it currently does not.
328 if { [file tail $test] == "closure.go" } {
329 # This tests whether function closures do any memory
330 # allocation, which for gccgo they currently do.
335 if { ( [file tail $test] == "select2.go" \
336 || [file tail $test] == "stack.go" ) \
337 && ! [check_effective_target_split_stack] } {
338 # chan/select2.go fails on targets without split stack,
339 # because they allocate a large stack segment that blows
340 # out the memory calculations.
345 if { [file tail $test] == "rotate.go" } {
346 # This test produces a temporary file that takes too long
347 # to compile--5 minutes on my laptop without optimization.
348 # When compiling without optimization it tests nothing
349 # useful, since the point of the test is to see whether
350 # the compiler generates rotate instructions.
355 if { [file tail $test] == "bug347.go" \
356 || [file tail $test] == "bug348.go" } {
357 # These tests don't work if the functions are inlined.
358 set TORTURE_OPTIONS [list { -O0 -g }]
361 set fd [open $test r]
366 if { [gets $fd test_line] < 0 } {
368 clone_output "$test: could not read first line"
374 if { [ string match "*nacl*exit 0*" $test_line ] \
375 || [ string match "*exit 0*nacl*" $test_line ] \
376 || [ string match "*Android*exit 0*" $test_line ] \
377 || [ string match "*exit 0*Android*" $test_line ] \
378 || [ string match "*\"\$GOOS\" == windows*" $test_line ] } {
385 if { $lines_ok == 0 } {
390 set test_line1 $test_line
392 while { [eval "string match \"//*&&\" \${test_line$lineno}"] } {
393 set lineno [expr $lineno + 1]
394 if { [eval "gets \$fd test_line$lineno"] < 0 } {
396 clone_output "$test: could not read line $lineno"
402 if { $lines_ok == 0 } {
408 set go_compile_args ""
409 set go_execute_args ""
410 if { [regexp ".*\\\$A.out (\[^|&>2\].*)\$" $test_line match progargs] } {
411 set go_execute_args $progargs
412 verbose -log "$test: go_execute_args is $go_execute_args"
413 set index [string last " $progargs" $test_line]
414 set test_line [string replace $test_line $index end]
415 } elseif { [string match "*go.test/test/chan/goroutines.go" $test] \
416 && [getenv GCCGO_RUN_ALL_TESTS] == "" } {
417 # goroutines.go spawns by default 10000 threads, which is too much
419 if { [getenv GCC_TEST_RUN_EXPENSIVE] == "" } {
420 set go_execute_args 64
421 } elseif { ![is_remote host] && ![is_remote target] } {
422 # When using low ulimit -u limit, use maximum of
423 # a quarter of that limit and 10000 even when running expensive
424 # tests, otherwise parallel tests might fail after fork failures.
425 set nproc [lindex [remote_exec host {sh -c ulimit\ -u}] 1]
426 if { [string is integer -strict $nproc] } {
427 set nproc [expr $nproc / 4]
428 if { $nproc > 10000 } { set nproc 10000 }
429 if { $nproc < 16 } { set nproc 16 }
430 set go_execute_args $nproc
433 if { "$go_execute_args" != "" } {
434 verbose -log "$test: go_execute_args is $go_execute_args"
438 if { $test_line == "// compile"
439 || $test_line == "// echo bug395 is broken # takes 90+ seconds to break" } {
440 # This is a vanilla compile test.
441 set dg-do-what-default "assemble"
442 go-dg-runtest $test "-w $DEFAULT_GOCFLAGS"
443 } elseif { $test_line == "// run"
444 || $test_line == "// \$G \$F.go && \$L \$F.\$A && ./\$A.out" } {
445 # This is a vanilla execution test.
446 go-torture-execute $test
447 file delete core [glob -nocomplain core.*]
448 } elseif { $test_line == "// build" } {
449 # This is a vanilla compile and link test.
450 set dg-do-what-default "link"
451 go-dg-runtest $test "-w $DEFAULT_GOCFLAGS"
452 } elseif { [string match "// runoutput*" $test_line] \
453 || ($test_line == "// \$G \$D/\$F.go && \$L \$F.\$A &&"
454 && $test_line2 == "// ./\$A.out >tmp.go && \$G tmp.go && \$L -o \$A.out1 tmp.\$A && ./\$A.out1") } {
455 # Run the test to get a .go program to run.
456 set go_execute_args ""
457 set hold_runtests $runtests
458 set runtests "go-test.exp"
460 if { [string match "// runoutput*" $test_line] } {
462 regsub "// runoutput\(.*\)" $test_line "\\1" args
464 lappend files "[file dirname $test]/$f"
467 set dg-do-what-default "link"
468 dg-test -keep-output $test "-O" "$files -w $DEFAULT_GOCFLAGS"
469 set output_file "./[file rootname [file tail $test]].exe"
470 set base "[file rootname [file tail $test]]"
472 if { [catch "exec $output_file >$base-out.go"] != 0 } {
473 fail "$name execution"
475 pass "$name execution"
476 file delete $base-out.x
477 # Disable optimizations as some of these tests
478 # take a long time to compile.
479 set TORTURE_OPTIONS [list { -O0 -g -fno-var-tracking-assignments }]
480 go-torture-execute "./$base-out.go"
482 file delete $base-out.go
484 file delete $output_file
485 set runtests $hold_runtests
486 } elseif { $test_line == "// cmpout" \
487 || $test_line == "// (\$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out 2>&1 | cmp - \$D/\$F.out)" } {
488 # This is an execution test for which we need to check the
490 set hold_runtests $runtests
491 set runtests "go-test.exp"
492 set dg-do-what-default "link"
493 dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
494 set output_file "./[file rootname [file tail $test]].exe"
495 set base "[file rootname [file tail $test]]"
497 verbose -log "$output_file >$base.p 2>&1"
498 if { [catch "exec $output_file 2>$base.p" catcherr] != 0 } {
499 verbose -log $catcherr
500 fail "$name execution"
501 untested "$name compare"
503 pass "$name execution"
504 regsub "\\.go$" $test ".out" expect
505 filecmp $expect $base.p "$name compare"
509 untested "$name execution"
510 untested "$name compare"
512 set runtests $hold_runtests
513 } elseif { [string match "// \$G \$D/\$F.go && \$L \$F.\$A && ! ./\$A.out || echo BUG: *" \
515 go-execute-xfail $test
516 } elseif { $test_line == "// errorcheck" } {
518 } elseif { [string match "// errorcheckoutput*" $test_line] } {
519 # Run the test to get a .go program to error check.
520 set go_execute_args ""
521 set hold_runtests $runtests
522 set runtests "go-test.exp"
524 regsub "// errorcheckoutput\(.*\)" $test_line "\\1" args
526 lappend files "[file dirname $test]/$f"
528 set dg-do-what-default "link"
529 dg-test -keep-output $test "-O" "$files -w $DEFAULT_GOCFLAGS"
530 set output_file "./[file rootname [file tail $test]].exe"
531 set base "[file rootname [file tail $test]]"
533 if { [catch "exec $output_file >$base-out.go"] != 0 } {
534 fail "$name execution"
536 pass "$name execution"
537 errchk "$base-out.go" ""
539 file delete $base-out.go
541 file delete $output_file
542 set runtests $hold_runtests
543 } elseif { $test_line == "// compiledir" } {
544 set hold_runtests $runtests
545 set runtests "go-test.exp"
546 set dg-do-what-default "assemble"
547 set dir "[file rootname $test].dir"
549 foreach f [lsort [glob "$dir/*.go"]] {
550 dg-test -keep-output $f "-O" "-w $DEFAULT_GOCFLAGS"
551 lappend del "[file rootname [file tail $f]].o"
556 set runtests $hold_runtests
557 } elseif { $test_line == "// rundir" } {
558 set hold_runtests $runtests
559 set runtests "go-test.exp"
560 set dg-do-what-default "assemble"
561 set dir "[file rootname $test].dir"
563 set files [lsort [glob "$dir/*.go"]]
564 set last [lindex $files end]
565 set files [lreplace $files end end]
567 dg-test -keep-output $f "-O" "-w $DEFAULT_GOCFLAGS"
568 lappend del "[file rootname [file tail $f]].o"
570 set dg-do-what-default "link"
571 set go_compile_args $del
572 go-torture-execute $last
576 set runtests $hold_runtests
577 } elseif { "$test_line" == ""
578 || [string match "// true*" $test_line]
579 || [string match "// skip*" $test_line] } {
580 # Not a real test, just ignore.
581 } elseif { [string match \
582 "// \$G \$D/\$F.dir/bug0.go && errchk \$G \$D/\$F.dir/bug1.go" \
585 "// \$G \$D/\$F.dir/io.go && errchk \$G -e \$D/\$F.dir/main.go" \
588 "// \$G \$D/\$F.dir/bug0.go && errchk \$G \$D/\$F.dir/bug1.go" \
592 } elseif { [string match \
593 "// \$G \$D/\$F.dir/io.go && errchk \$G -e \$D/\$F.dir/main.go" \
598 set hold_runtests $runtests
599 set runtests "go-test.exp"
600 set dg-do-what-default "assemble"
601 regsub "\\.go$" $test ".dir/$name1" file1
602 dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
603 regsub "\\.go$" $test ".dir/$name2" file2
605 file delete "[file rootname [file tail $file1]].o"
606 set runtests $hold_runtests
607 } elseif { [string match \
608 "// \$G \$D/\${F}1.go && errchk \$G \$D/\$F.go" \
610 set hold_runtests $runtests
611 set runtests "go-test.exp"
612 set dg-do-what-default "assemble"
613 regsub "\\.go$" $test "1.go" file1
614 dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
616 file delete "[file rootname [file tail $file1]].o"
617 set runtests $hold_runtests
618 } elseif { [string match \
619 "// \$G \$D/\$F.dir/bug0.go && \$G \$D/\$F.dir/bug1.go && errchk \$G \$D/\$F.dir/bug2.go" \
621 set hold_runtests $runtests
622 set runtests "go-test.exp"
623 set dg-do-what-default "assemble"
624 regsub "\\.go$" $test ".dir/bug0.go" file1
625 dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
626 regsub "\\.go$" $test ".dir/bug1.go" file2
627 dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
628 regsub "\\.go$" $test ".dir/bug2.go" file3
630 file delete "[file rootname [file tail $file1]].o"
631 file delete "[file rootname [file tail $file2]].o"
632 set runtests $hold_runtests
633 } elseif { [string match \
634 "// \$G \$D/bug160.dir/x.go && \$G \$D/bug160.dir/y.go && \$L y.\$A && ./\$A.out" \
637 "// \$G \$D/\$F.dir/p.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out" \
639 || $test_line == "// \$G \$D/\$F.dir/p1.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out" \
640 || $test_line == "// \$G \$D/\$F.dir/lib.go && \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out" \
641 || $test_line == "// \$G \$D/method4a.go && \$G \$D/\$F.go && \$L \$F.\$A && ./$\A.out" } {
643 "// \$G \$D/bug160.dir/x.go && \$G \$D/bug160.dir/y.go && \$L y.\$A && ./\$A.out" \
647 } elseif { [string match \
648 "// \$G \$D/\$F.dir/p.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out" \
652 } elseif { $test_line == "// \$G \$D/\$F.dir/p1.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out" } {
655 } elseif { $test_line == "// \$G \$D/\$F.dir/lib.go && \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out" } {
658 } elseif { $test_line == "// \$G \$D/method4a.go && \$G \$D/\$F.go && \$L \$F.\$A && ./$\A.out" } {
659 set name1 "method4a.go"
662 set hold_runtests $runtests
663 set runtests "go-test.exp"
664 set dg-do-what-default "assemble"
665 regsub "\\.go$" $test ".dir/$name1" file1
666 if { $name1 == "method4a.go" } {
667 set file1 "[file dirname $test]/method4a.go"
669 dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
670 set ofile1 "[file rootname [file tail $file1]].o"
671 regsub "\\.go$" $test ".dir/$name2" file2
672 if { $name2 == "" } {
675 dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
676 set ofile2 "[file rootname [file tail $file2]].o"
677 set dg-do-what-default "link"
678 set output_file "./[file rootname [file tail $test]].exe"
679 set comp_output [go_target_compile "$ofile1 $ofile2" \
680 $output_file "executable" "$options"]
681 set comp_output [go-dg-prune $target_triplet $comp_output]
682 verbose -log $comp_output
683 set result [go_load "$output_file" "" ""]
684 set status [lindex $result 0]
686 file delete $ofile1 $ofile2 $output_file
687 set runtests $hold_runtests
688 } elseif { $test_line == "// \$G \$D/\$F.dir/one.go && \$G \$D/\$F.dir/two.go && \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out" } {
689 set hold_runtests $runtests
690 set runtests "go-test.exp"
691 set dg-do-what-default "assemble"
692 regsub "\\.go$" $test ".dir/one.go" file1
693 dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
694 set ofile1 "[file rootname [file tail $file1]].o"
695 regsub "\\.go$" $test ".dir/two.go" file2
696 dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
697 set ofile2 "[file rootname [file tail $file2]].o"
698 dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
699 set ofile3 "[file rootname [file tail $test]].o"
700 set dg-do-what-default "link"
701 set output_file "./[file rootname [file tail $test]].exe"
702 set comp_output [go_target_compile "$ofile1 $ofile2 $ofile3" \
703 $output_file "executable" "$options"]
704 set comp_output [go-dg-prune $target_triplet $comp_output]
705 verbose -log $comp_output
706 set result [go_load "$output_file" "" ""]
707 set status [lindex $result 0]
709 file delete $ofile1 $ofile2 $ofile3 $output_file
710 set runtests $hold_runtests
711 } elseif { [string match \
712 "// \$G \$D/bug191.dir/a.go && \$G \$D/bug191.dir/b.go && \$G \$D/\$F.go && \$L \$F.\$A" \
714 set hold_runtests $runtests
715 set runtests "go-test.exp"
716 set dg-do-what-default "assemble"
717 regsub "\\.go$" $test ".dir/a.go" file1
718 dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
719 set ofile1 "[file rootname [file tail $file1]].o"
720 regsub "\\.go$" $test ".dir/b.go" file2
721 dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
722 set ofile2 "[file rootname [file tail $file2]].o"
723 dg-test -keep-output "$test" "-O" "-w $DEFAULT_GOCFLAGS"
724 set ofile3 "[file rootname [file tail $test]].o"
725 set dg-do-what-default "link"
726 set output_file "./[file rootname [file tail $test]].exe"
727 set comp_output [go_target_compile "$ofile1 $ofile2 $ofile3" \
728 $output_file "executable" "$options"]
729 set comp_output [go-dg-prune $target_triplet $comp_output]
730 if [string match "" $comp_output] {
733 verbose -log $comp_output
736 file delete $ofile1 $ofile2 $ofile3 $output_file
737 set runtests $hold_runtests
738 } elseif { [string match \
739 "// \$G \$D/embed0.go && \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out" \
741 set hold_runtests $runtests
742 set runtests "go-test.exp"
743 set dg-do-what-default "assemble"
744 regsub "/\[^/\]*$" $test "/embed0.go" file1
745 dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
746 set ofile1 "[file rootname [file tail $file1]].o"
747 dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
748 set ofile2 "[file rootname [file tail $test]].o"
749 set output_file "./[file rootname [file tail $test]].exe"
750 set comp_output [go_target_compile "$ofile1 $ofile2" \
751 $output_file "executable" "$options"]
752 set comp_output [go-dg-prune $target_triplet $comp_output]
753 if [string match "" $comp_output] {
754 set result [go_load "$output_file" "" ""]
755 set status [lindex $result 0]
758 verbose -log $comp_output
761 file delete $ofile1 $ofile2 $output_file
762 set runtests $hold_runtests
763 } elseif { [string match \
764 "// \$G \$D/\$F.dir/lib.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out || echo BUG*" \
767 "// \$G \$D/\$F.dir/p.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out || echo BUG*" \
770 "// \$G \$D/\$F.dir/lib.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out || echo BUG*" \
774 } elseif { [string match \
775 "// \$G \$D/\$F.dir/p.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out || echo BUG*" \
780 set hold_runtests $runtests
781 set runtests "go-test.exp"
782 set dg-do-what-default "assemble"
783 regsub "\\.go$" $test ".dir/$name1" file1
784 dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
785 set ofile1 "[file rootname [file tail $file1]].o"
786 regsub "\\.go$" $test ".dir/$name2" file2
787 dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
788 set ofile2 "[file rootname [file tail $file2]].o"
789 set dg-do-what-default "link"
790 set output_file "./[file rootname [file tail $file2]].exe"
791 set comp_output [go_target_compile "$ofile1 $ofile2" \
792 $output_file "executable" "$options"]
793 set comp_output [go-dg-prune $target_triplet $comp_output]
794 if [string match "" $comp_output] {
795 set result [go_load "$output_file" "" ""]
796 set status [lindex $result 0]
799 verbose -log $comp_output
802 file delete $ofile1 $ofile2 $output_file
803 set runtests $hold_runtests
804 } elseif { $test_line == "// \$G \$D/\$F.dir/bug0.go &&" \
805 && $test_line2 == "// \$G \$D/\$F.dir/bug1.go &&" \
806 && $test_line3 == "// \$G \$D/\$F.dir/bug2.go &&" \
807 && $test_line4 == "// errchk \$G -e \$D/\$F.dir/bug3.go &&" \
808 && $test_line5 == "// \$L bug2.\$A &&" \
809 && [string match "// ./\$A.out || echo BUG*" $test_line6] } {
810 set hold_runtests $runtests
811 set runtests "go-test.exp"
812 set dg-do-what-default "assemble"
813 regsub "\\.go$" $test ".dir/bug0.go" file0
814 dg-test -keep-output $file0 "-O -fgo-prefix=bug0" "-w $DEFAULT_GOCFLAGS"
815 set ofile0 "[file rootname [file tail $file0]].o"
816 regsub "\\.go$" $test ".dir/bug1.go" file1
817 dg-test -keep-output $file1 "-O -fgo-prefix=bug1" "-w $DEFAULT_GOCFLAGS"
818 set ofile1 "[file rootname [file tail $file1]].o"
819 regsub "\\.go$" $test ".dir/bug2.go" file2
820 dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
821 set ofile2 "[file rootname [file tail $file2]].o"
822 regsub "\\.go$" $test ".dir/bug3.go" file3
824 set output_file "./[file rootname [file tail $test]].exe"
825 set comp_output [go_target_compile "$ofile0 $ofile1 $ofile2" \
826 $output_file "executable" "$options"]
827 set comp-output [go-dg-prune $target_triplet $comp_output]
828 if [string match "" $comp_output] {
829 set result [go_load "$output_file" "" ""]
830 set status [lindex $result 0]
833 verbose -log $comp_output
836 file delete $ofile0 $ofile1 $ofile2 $output_file
837 set runtests $hold_runtests
838 } elseif { $test_line == "// \$G \$D/import2.go && \$G \$D/\$F\.go" \
839 || $test_line == "// \$G \$D/recursive1.go && \$G \$D/\$F.go" } {
840 if { $test_line == "// \$G \$D/import2.go && \$G \$D/\$F\.go" } {
841 set name1 "import2.go"
842 } elseif { $test_line == "// \$G \$D/recursive1.go && \$G \$D/\$F.go" } {
843 set name1 "recursive1.go"
845 set hold_runtests $runtests
846 set runtests "go-test.exp"
847 set dg-do-what-default "assemble"
848 regsub "/\[^/\]*$" $test "/${name1}" file1
849 dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
850 set ofile1 "[file rootname [file tail $file1]].o"
851 dg-test $test "-O" "-w $DEFAULT_GOCFLAGS"
853 set runtests $hold_runtests
854 } elseif { $test_line == "// \$G \$D/ddd2.go && \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out" } {
855 set hold_runtests $runtests
856 set runtests "go-test.exp"
857 set dg-do-what-default "assemble"
858 regsub "/\[^/\]*$" $test "/ddd2.go" file1
859 dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
860 set ofile1 "[file rootname [file tail $file1]].o"
861 dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
862 set ofile2 "[file rootname [file tail $test]].o"
863 set output_file "./[file rootname [file tail $test]].exe"
864 set comp_output [go_target_compile "$ofile1 $ofile2" \
865 $output_file "executable" "$options"]
866 set comp_output [go-dg-prune $target_triplet $comp_output]
867 if [string match "" $comp_output] {
868 set result [go_load "$output_file" "" ""]
869 set status [lindex $result 0]
872 verbose -log $comp_output
875 file delete $ofile1 $ofile2 $output_file
876 set runtests $hold_runtests
877 } elseif { $test_line == "// run cmplxdivide1.go" } {
878 regsub "/\[^/\]*$" $test "/cmplxdivide1.go" test2
879 set output_file "./[file rootname [file tail $test]].o"
880 set comp_output [go_target_compile "$test $test2" \
881 $output_file "executable" "$options"]
882 set comp_output [go-dg-prune $target_triplet $comp_output]
883 if [string match "" $comp_output] {
884 set result [go_load "$output_file" "" ""]
885 set status [lindex $result 0]
888 verbose -log $comp_output
891 file delete $output_file
892 } elseif { $test_line == "// \$G \$D/\$F.go && \$L \$F.\$A &&" \
893 && $test_line2 == "// ./\$A.out -pass 0 >tmp.go && \$G tmp.go && \$L -o \$A.out1 tmp.\$A && ./\$A.out1 &&" \
894 && $test_line3 == "// ./\$A.out -pass 1 >tmp.go && errchk \$G -e tmp.go &&" \
895 && $test_line4 == "// ./\$A.out -pass 2 >tmp.go && errchk \$G -e tmp.go" } {
896 set go_execute_args ""
897 set hold_runtests $runtests
898 set runtests "go-test.exp"
899 set dg-do-what-default "link"
900 dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
901 set output_file "./[file rootname [file tail $test]].exe"
903 if { [catch "exec $output_file -pass 0 >tmp.go"] != 0 } {
904 fail "$name execution 0"
906 pass "$name execution 0"
908 # Disable optimizations as this test takes a long time
910 set TORTURE_OPTIONS [list { -O0 -g -fno-var-tracking-assignments }]
911 go-torture-execute "./tmp.go"
913 if { [catch "exec $output_file -pass 1 >tmp.go"] != 0 } {
914 fail "$name execution 1"
916 pass "$name execution 1"
919 if { [catch "exec $output_file -pass 2 >tmp.go"] != 0 } {
920 fail "$name execution 2"
922 pass "$name execution 2"
927 file delete $output_file
928 set runtests $hold_runtests
929 } elseif { $test_line == "// \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out >tmp.go &&" \
930 && $test_line2 == "// errchk \$G -e tmp.go" } {
931 set go_execute_args ""
932 set hold_runtests $runtests
933 set runtests "go-test.exp"
934 set dg-do-what-default "link"
935 dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
936 set output_file "./[file rootname [file tail $test]].exe"
938 if { [catch "exec $output_file >tmp.go"] != 0 } {
939 fail "$name execution"
941 pass "$name execution"
946 file delete $output_file
947 set runtests $hold_runtests
948 } elseif { $test_line == "// errchk \$G -e \$D/\$F.dir/\[ab\].go" } {
949 regsub "\\.go$" $test ".dir/a.go" file1
950 regsub "\\.go$" $test ".dir/b.go" file2
951 errchk "$file1" "$file2"
952 } elseif { $test_line == "// \$G \$D/\$F.go \$D/z*.go && \$L \$F.\$A && ./\$A.out" } {
953 set dir [file dirname $test]
954 set go_compile_args [glob $dir/z*.go]
955 go-torture-execute $test
956 } elseif { $test_line == "// \$G -N -o slow.\$A \$D/bug369.dir/pkg.go &&" \
957 && $test_line2 == "// \$G -o fast.\$A \$D/bug369.dir/pkg.go &&" \
958 && $test_line3 == "// run" } {
959 set hold_runtests $runtests
960 set runtests "go-test.exp"
961 set dg-do-what-default "assemble"
962 regsub "\\.go$" $test ".dir/pkg.go" file1
963 dg-test -keep-output $file1 "" "-fgo-prefix=slow -w $DEFAULT_GOCFLAGS"
964 set ofile1 "[file rootname [file tail $file1]].o"
965 file rename -force $ofile1 slow.o
966 dg-test -keep-output $file1 "-O2" "-fgo-prefix=fast -w $DEFAULT_GOCFLAGS"
967 file rename -force $ofile1 fast.o
968 set ofile2 "[file rootname [file tail $test]].o"
969 dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
970 set output_file "./[file rootname [file tail $test]].exe"
971 set comp_output [go_target_compile "$ofile2 slow.o fast.o" \
972 $output_file "executable" "$options"]
973 set comp_output [go-dg-prune $target_triplet $comp_output]
974 if [string match "" $comp_output] {
975 set result [go_load "$output_file" "" ""]
976 set status [lindex $result 0]
979 verbose -log $comp_output
982 file delete slow.o fast.o $ofile2 $output_file
983 set runtests $hold_runtests
984 } elseif { [string match \
985 "// \$G \$D/\$F.dir/pkg.go && \$G \$D/\$F.go || echo *" \
987 set hold_runtests $runtests
988 set runtests "go-test.exp"
989 set dg-do-what-default "assemble"
990 regsub "\\.go$" $test ".dir/pkg.go" file1
991 dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
992 dg-test $test "-O" "-w $DEFAULT_GOCFLAGS"
993 file delete "[file rootname [file tail $file1]].o"
994 set runtests $hold_runtests
995 } elseif { [string match "// \$G \$D/\$F.dir/one.go && \$G \$D/\$F.dir/two.go || echo BUG*" \
997 set hold_runtests $runtests
998 set runtests "go-test.exp"
999 set dg-do-what-default "assemble"
1000 regsub "\\.go$" $test ".dir/one.go" file1
1001 dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
1002 set ofile1 "[file rootname [file tail $file1]].o"
1003 regsub "\\.go$" $test ".dir/two.go" file2
1004 dg-test $file2 "-O" "-w $DEFAULT_GOCFLAGS"
1006 set runtests $hold_runtests
1007 } elseif { $test_line == "// \$G \$D/bug302.dir/p.go && pack grc pp.a p.\$A && \$G \$D/bug302.dir/main.go" \
1008 || $test_line == "// \$G \$D/empty.go && errchk \$G \$D/\$F.go" } {
1009 # These tests import the same package under two different
1010 # names, which gccgo does not support.
1011 } elseif { $test_line == "// \$G -S \$D/\$F.go | egrep initdone >/dev/null && echo BUG sinit || true" } {
1012 # This tests whether initializers are written out
1013 # statically. gccgo does not provide a way to test that,
1014 # as an initializer will be generated for any code which
1015 # has global variables which need to be registered as GC
1017 } elseif { $test_line == "// errorcheck -0 -m"
1018 || $test_line == "// errorcheck -0 -m -l" } {
1019 # This tests debug output of the gc compiler, which is
1020 # meaningless for gccgo.
1021 } elseif { $test_line == "// \[ \$A == 6 \] || errchk \$G -e \$D/\$F.go" \
1022 || $test_line == "// \[ \$A != 6 \] || errchk \$G -e \$D/\$F.go" } {
1023 # This tests specific handling of the gc compiler on types
1024 # that are too large. It is target specific in a way I
1025 # haven't bothered to check for here.
1026 } elseif { $test_line == "// \$G \$D/\$F.go && \$L -X main.tbd hello \$F.\$A && ./\$A.out" } {
1027 # This tests the gc ld -X option, which gccgo does not
1029 } elseif { $test_line == "// \$G \$D/pkg.go && pack grc pkg.a pkg.\$A 2> /dev/null && rm pkg.\$A && errchk \$G -I. -u \$D/main.go"
1030 || $test_line == "// \$G \$D/pkg.go && pack grcS pkg.a pkg.\$A 2> /dev/null && rm pkg.\$A && \$G -I. -u \$D/main.go" } {
1031 # This tests the gc -u option, which gccgo does not
1034 clone_output "$name: unrecognized test line: $test_line"
1038 set go_compile_args ""
1039 set go_execute_args ""
1040 set TORTURE_OPTIONS [list { -O2 -g }]
1043 set dg-do-what-default ${saved-dg-do-what-default}
1044 set TORTURE_OPTIONS $saved_torture_options