summaryrefslogtreecommitdiff
path: root/gcc/testsuite/go.test/go-test.exp
blob: 19cc0dfc4d352807eae229ddfe351bdc0e04d9af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
#   Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc.
#   Written by Ian Lance Taylor <iant@google.com>.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GCC; see the file COPYING3.  If not see
# <http://www.gnu.org/licenses/>.


# Test using the testsuite for the gc Go compiler.  In these tests the
# first line is a shell script to run.  That line expects the
# following environment variables to be set:
#   A   The file extension of the object file and the name of the executable
#   G   The name of the compiler
#   L   The name of the linker
#   F   The basename of the test
#   D   The directory of the test.
#
# Typical command lines:
# // $G $D/$F.go && $L $F.$A && ./$A.out
# // $G $D/$F.go && $L $F.$A || echo BUG: known to fail incorrectly
# // $G $D/$F.go && echo BUG: compilation succeeds incorrectly
# // $G $D/$F.go || echo BUG: compilation should succeed

load_lib go-dg.exp
load_lib go-torture.exp

# Implement errchk
proc errchk { test } {
    global dg-do-what-default
    global DEFAULT_GOCFLAGS
    global runtests

    set saved-dg-do-what-default ${dg-do-what-default}
    set dg-do-what-default compile
    set filename [file tail $test]
    if { "$filename" == "$test" } {
	set filename "errchk-$filename"
    }
    set fdin [open $test r]
    fconfigure $fdin -encoding binary
    set fdout [open $filename w]
    fconfigure $fdout -encoding binary
    while { [gets $fdin copy_line] >= 0 } {
	regsub "// \(GCCGO_\)?ERROR \"\(\[^\"\]*\)\".*$" $copy_line "// \{ dg-error \"\\2\" \}" out_line
	if [string match "*dg-error*.\**" $out_line] {
	    # I worked out the right number of backslashes by
	    # experimentation, not analysis.
	    regsub -all "\\.\\*" $out_line "\\\\\[ -~\\\\\]*" out_line
	}
	if [string match "*dg-error*\{*" $out_line] {
	    set index [string first "dg-error" $out_line]
	    regsub -start $index -all "\{" $out_line "\\\\\[\\\{\\\\\]" out_line
	}
	if [string match "*dg-error*\}*\}" $out_line] {
	    set index [string first "dg-error" $out_line]
	    regsub -start $index -all "\}\(.\)" $out_line "\\\\\[\\\}\\\\\]\\1" out_line
	}
	if [string match "*dg-error*\[.\]*" $out_line] {
	    set index [string first "dg-error" $out_line]
	    regsub -all "\\\[\\.\\\]" $out_line "\\\\\[.\\\\\]" out_line
	}
	puts $fdout $out_line
    }
    close $fdin
    close $fdout

    set hold_runtests $runtests
    set runtests "go-test.exp"
    go-dg-runtest $filename "-fno-show-column $DEFAULT_GOCFLAGS"
    set runtests $hold_runtests

    file delete $filename
    set dg-do-what-default ${saved-dg-do-what-default}
}

# This is an execution test which should fail.
proc go-execute-xfail { test } {
    global DEFAULT_GOCFLAGS
    global runtests

    set filename [file tail $test]
    set fdin [open $test r]
    set fdout [open $filename w]
    puts $fdout "// { dg-do run { xfail *-*-* } }"
    while { [gets $fdin copy_line] >= 0 } {
	puts $fdout $copy_line
    }
    close $fdin
    close $fdout

    set hold_runtests $runtests
    set runtests "go-test.exp"
    go-dg-runtest $filename "-w $DEFAULT_GOCFLAGS"
    set runtests $hold_runtests

    file delete $filename
}

# N.B. Keep in sync with libgo/configure.ac.
proc go-set-goarch { } {
    global target_triplet

    switch -glob $target_triplet {
	"arm*-*-*" -
	"ep9312*-*-*" -
	"strongarm*-*-*" -
	"xscale-*-*" {
	    set goarch "arm"
	}
	"i?86-*-*" -
	"x86_64-*-*" {
	    if [check_effective_target_ilp32] {
		set goarch "386"
	    } else {
		set goarch "amd64"
	    }
	}
	"sparc*-*-*" {
	    if [check_effective_target_ilp32] {
		set goarch "sparc"
	    } else {
		set goarch "sparcv9"
	    }
	}
	default {
	    perror "$target_triplet: unhandled architecture"
	    return ""
	}	
    }
    verbose -log "Setting GOARCH=$goarch" 1
    setenv GOARCH $goarch
}

proc go-gc-tests { } {
    global srcdir subdir
    global runtests
    global GCC_UNDER_TEST
    global TOOL_OPTIONS
    global TORTURE_OPTIONS
    global dg-do-what-default
    global go_execute_args
    global target_triplet

    # If a testcase doesn't have special options, use these.
    global DEFAULT_GOCFLAGS
    if ![info exists DEFAULT_GOCFLAGS] {
	set DEFAULT_GOCFLAGS " -pedantic-errors"
    }

    # Set GOARCH for tests that need it.
    go-set-goarch

    # Running all the torture options takes too long and, since the
    # frontend ignores the standard options, it doesn't significantly
    # improve testing.
    set saved_torture_options $TORTURE_OPTIONS
    set TORTURE_OPTIONS [ list { -O2 -g }]

    set saved-dg-do-what-default ${dg-do-what-default}

    set testdir [pwd]

    set tests [lsort [find $srcdir/$subdir *.go]]
    foreach test $tests {
	if ![runtest_file_p $runtests $test] {
	    continue
	}

	# Skip the files in bench and garbage; they are not tests.
	if [string match "*go.test/test/bench/*" $test] {
	    continue
	}
	if [string match "*go.test/test/garbage/*" $test] {
	    continue
	}

	# Skip files in sub-subdirectories: they are components of
	# other tests.
	if [string match "*go.test/test/*/*/*" $test] {
	    continue
	}

	set name [dg-trim-dirname $srcdir $test]

	# Skip certain tests if target is RTEMS OS.
	if [istarget "*-*-rtems*"] {
	    if { [string match "*go.test/test/args.go" \
		   $test] \
		 || [string match "*go.test/test/env.go" \
		   $test] } {
		    untested "$name: uses the command-line or environment variables"
		    continue
	    }

	    if { [string match "*go.test/test/stack.go" \
		   $test] \
		 || [string match "*go.test/test/peano.go" \
		   $test] \
		 || [string match "*go.test/test/chan/goroutines.go" \
		   $test] } {
		    untested "$name: has very high memory requirement"
		    continue
	    }
	}

	set fd [open $test r]

	set lines_ok 1

	while 1 {
	    if { [gets $fd test_line] < 0 } {
		close $fd
		clone_output "$test: could not read first line"
		unresolved $name
		set lines_ok 0
		break
	    }

	    if { [ string match "*nacl*exit 0*" $test_line ] \
		     || [ string match "*exit 0*nacl*" $test_line ] \
		     || [ string match "*Android*exit 0*" $test_line ] \
		     || [ string match "*exit 0*Android*" $test_line ] } {
		continue
	    }

	    break
	}

	if { $lines_ok == 0 } {
	    continue
	}

	set lineno 1
	set test_line1 $test_line

	while { [eval "string match \"//*&&\" \${test_line$lineno}"] } {
	    set lineno [expr $lineno + 1]
	    if { [eval "gets \$fd test_line$lineno"] < 0 } {
		close $fd
		clone_output "$test: could not read line $lineno"
		unresolved $name
		set lines_ok 0
		break
	    }
	}
	if { $lines_ok == 0 } {
	    continue
	}

	close $fd

	set go_execute_args ""
	if { [regexp ".*\\\$A.out (\[^|&>\].*)\$" $test_line match progargs] } {
	    set go_execute_args $progargs
	    verbose -log "$test: go_execute_args is $go_execute_args"
	    set index [string last " $progargs" $test_line]
	    set test_line [string replace $test_line $index end]
	} elseif { [string match "*go.test/test/chan/goroutines.go" $test] \
		   && [getenv GCCGO_RUN_ALL_TESTS] == "" } {
	    # goroutines.go spawns by default 10000 threads, which is too much
	    # for many OSes.
	    if { [getenv GCC_TEST_RUN_EXPENSIVE] == "" } {
		set go_execute_args 64
	    } elseif { ![is_remote host] && ![is_remote target] } {
		# When using low ulimit -u limit, use maximum of
		# a quarter of that limit and 10000 even when running expensive
		# tests, otherwise parallel tests might fail after fork failures.
		set nproc [lindex [remote_exec host {sh -c ulimit\ -u}] 1]
		if { [string is integer -strict $nproc] } {
			set nproc [expr $nproc / 4]
			if { $nproc > 10000 } { set nproc 10000 }
			if { $nproc < 16 } { set nproc 16 }
			set go_execute_args $nproc
		}
	    }
	    if { "$go_execute_args" != "" } {
		verbose -log "$test: go_execute_args is $go_execute_args"
	    }
	}

	if { $test_line == "// \$G \$D/\$F\.go && \$L \$F\.\$A && \./\$A\.out >tmp.go &&" \
	     && $test_line2 == "// \$G tmp\.go && \$L tmp\.\$A && \./\$A\.out || echo BUG: 64bit" } {
	    # 64bit.go is a special case.
	    set go_execute_args ""
	    set hold_runtests $runtests
	    set runtests "go-test.exp"
	    set dg-do-what-default "link"
	    dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
	    set output_file "./[file rootname [file tail $test]].exe"
	    set base "[file rootname [file tail $test]]"
	    if [isnative] {
		if { [catch "exec $output_file >$base-out.go"] != 0 } {
		    fail "$name execution"
		} else {
		    pass "$name execution"
		    file delete $base-out.x
		    go-torture-execute "./$base-out.go"
		}
		file delete $base-out.go
	    }
	    file delete $output_file
	    set runtests $hold_runtests
	} elseif { $test_line == "// \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out" \
		   || $test_line == "// \$G \$F.go && \$L \$F.\$A && ./\$A.out" \
		   || $test_line == "// \$G \$F.go && \$L \$F.\$A &&./\$A.out" \
		   || $test_line == "// \$G \$D/\$F.go && \$L \$F.\$A && \$A.out" \
		   || [string match \
			   "// \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out || echo BUG*" \
			   $test_line]
		   || [string match \
			   "// \$G \$F.go && \$L \$F.\$A && (./\$A.out || echo BUG*" \
			   $test_line]
		   || [string match \
			   "// \$G \$D/\$F.go && \$L \$F.\$A && (./\$A.out || echo BUG*" \
			   $test_line]
		   || [string match \
			   "// \$G \$F.go && \$L \$F.\$A && GOMAXPROCS=* ./\$A.out" \
			   $test_line]
		   || [string match \
			   "// \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out >* || echo BUG*" \
			   $test_line] } {
	    # This is a vanilla execution test.
	    go-torture-execute $test
	    file delete core [glob -nocomplain core.*]
	} elseif { [string match \
			"// \$G \$D/\$F.go && \$L \$F.\$A || echo BUG*" \
			$test_line] \
		   || [string match "// \$G \$F.go && \$L \$F.\$A  #*" \
			   $test_line] } {
	    # This is a vanilla compile and link test.
	    set dg-do-what-default "link"
	    go-dg-runtest $test "-w $DEFAULT_GOCFLAGS"
	} elseif { [string match "// \$G \$D/\$F.go" $test_line] \
		   || [string match "// \$G \$D/\$F.go || echo BUG*" \
			   $test_line] \
		   || [string match "// \$G \$F.go || echo BUG*" \
			   $test_line] \
		   || [string match "// ! \$G \$D/\$F.go && echo BUG*" \
			   $test_line] } {
	    # This is a vanilla compile test.
	    set dg-do-what-default "assemble"
	    go-dg-runtest $test "-w $DEFAULT_GOCFLAGS"
	} elseif { [string match "// \$G \$D/\$F.go && echo BUG*" \
			$test_line] \
		   || $test_line == "// ! \$G \$D/\$F.go >/dev/null" \
		   || $test_line == "// ! \$G \$D/\$F.go" \
		   || $test_line == "// ! \$G \$F.go" \
	           || [string match "// ! \$G \$D/\$F.go || echo BUG*" \
			$test_line] } {
	    # This is a compile test which should fail.
	    set dg-do-what-default "assemble"
	    setup_xfail "*-*-*"
	    go-dg-runtest $test "-w $DEFAULT_GOCFLAGS"
	} elseif { [string match "// \$G \$D/\$F.go && \$L \$F.\$A && ! ./\$A.out" \
			$test_line] \
		   || [string match "// \$G \$D/\$F.go && \$L \$F.\$A && ! ./\$A.out || echo BUG: *" \
			$test_line] \
		   || [string match "// \$G \$D/\$F.go && \$L \$F.\$A && (! ./\$A.out || echo BUG: *" \
			$test_line] \
		   || ($test_line == "// \$G \$D/\$F.go && \$L \$F.\$A &&"
		       && $test_line2 == "//	((! sh -c ./\$A.out) >/dev/null 2>&1 || echo BUG: should fail)") } {
	    go-execute-xfail $test
	} elseif { [string match "// errchk \$G \$F.go" $test_line] \
		    || [string match "// errchk \$G -e \$F.go" $test_line] \
		    || [string match "// errchk \$G \$D/\$F.go" $test_line] \
		    || [string match "//errchk \$G \$D/\$F.go" $test_line] \
		    || [string match "// errchk \$G -e \$D/\$F.go" \
			    $test_line] \
		    || [string match "// ! errchk \$G \$D/\$F.go" $test_line] \
		    || [string match "// ! errchk \$G -e \$D/\$F.go" \
			    $test_line] \
		    || [string match "// errchk \$G \$F.go || true" \
			    $test_line] \
		    || [string match "// errchk \$G \$D/\$F.go || true" \
			    $test_line] \
		    || [string match "// errchk \$G -e \$D/\$F.go || true" \
			    $test_line] \
		    || [string match "// errchk \$G \$D/\$F.go || echo BUG*" \
			    $test_line] } {
	    errchk $test
	} elseif { [string match \
			"// \$G \$D/\$F.dir/bug0.go && \$G \$D/\$F.dir/bug1.go || echo BUG*" \
			$test_line] } {
	    set hold_runtests $runtests
	    set runtests "go-test.exp"
	    set dg-do-what-default "assemble"
	    regsub "\\.go$" $test ".dir/bug0.go" file1
	    dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
	    regsub "\\.go$" $test ".dir/bug1.go" file2
	    dg-test $file2 "-O" "-w $DEFAULT_GOCFLAGS"
	    file delete "[file rootname [file tail $file1]].o"
	    set runtests $hold_runtests
	} elseif { [string match \
			"// \$G \$D/\$F.dir/bug0.go && errchk \$G \$D/\$F.dir/bug1.go" \
			$test_line] \
		       || [string match \
			       "// \$G \$D/\$F.dir/p1.go && \$G \$D/\$F.dir/p2.go" \
			       $test_line] } {
	    if { [string match \
		      "// \$G \$D/\$F.dir/p1.go && \$G \$D/\$F.dir/p2.go" \
		      $test_line] } {
		set name1 "p1.go"
		set name2 "p2.go"
	    } else {
		set name1 "bug0.go"
		set name2 "bug1.go"
	    }
	    set hold_runtests $runtests
	    set runtests "go-test.exp"
	    set dg-do-what-default "assemble"
	    regsub "\\.go$" $test ".dir/$name1" file1
	    dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
	    regsub "\\.go$" $test ".dir/$name2" file2
	    errchk $file2
	    file delete "[file rootname [file tail $file1]].o"
	    set runtests $hold_runtests
	} elseif { [string match \
			"// \$G \$D/\$F.dir/bug0.go && (! \$G \$D/\$F.dir/bug1.go || echo BUG*" \
			$test_line] } {
	    set hold_runtests $runtests
	    set runtests "go-test.exp"
	    set dg-do-what-default "assemble"
	    regsub "\\.go$" $test ".dir/bug0.go" file1
	    dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
	    regsub "\\.go$" $test ".dir/bug1.go" file2
	    setup_xfail "*-*-*"
	    dg-test $file2 "-O" "-w $DEFAULT_GOCFLAGS"
	    file delete "[file rootname [file tail $file1]].o"
	    set runtests $hold_runtests
	} elseif { [string match \
			"// \$G \$D/\$F.dir/bug0.go && \$G \$D/\$F.dir/bug1.go && (! \$G \$D/\$F.dir/bug2.go || echo BUG*" \
			$test_line] } {
	    set hold_runtests $runtests
	    set runtests "go-test.exp"
	    set dg-do-what-default "assemble"
	    regsub "\\.go$" $test ".dir/bug0.go" file1
	    dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
	    regsub "\\.go$" $test ".dir/bug1.go" file2
	    dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
	    regsub "\\.go$" $test ".dir/bug2.go" file3
	    setup_xfail "*-*-*"
	    dg-test $file3 "-O" "-w $DEFAULT_GOCFLAGS"
	    file delete "[file rootname [file tail $file1]].o"
	    file delete "[file rootname [file tail $file2]].o"
	    set runtests $hold_runtests
	} elseif { [string match \
			"// \$G \$D/\$F.dir/bug0.go && \$G \$D/\$F.dir/bug1.go && errchk \$G \$D/\$F.dir/bug2.go" \
			$test_line] } {
	    set hold_runtests $runtests
	    set runtests "go-test.exp"
	    set dg-do-what-default "assemble"
	    regsub "\\.go$" $test ".dir/bug0.go" file1
	    dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
	    regsub "\\.go$" $test ".dir/bug1.go" file2
	    dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
	    regsub "\\.go$" $test ".dir/bug2.go" file3
	    errchk $file3
	    file delete "[file rootname [file tail $file1]].o"
	    file delete "[file rootname [file tail $file2]].o"
	    set runtests $hold_runtests
	} elseif { [string match \
			"// \$G \$D/bug160.dir/x.go && \$G \$D/bug160.dir/y.go && \$L y.\$A && ./\$A.out" \
			$test_line] } {
	    set hold_runtests $runtests
	    set runtests "go-test.exp"
	    set dg-do-what-default "assemble"
	    regsub "\\.go$" $test ".dir/x.go" file1
	    dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
	    set ofile1 "[file rootname [file tail $file1]].o"
	    regsub "\\.go$" $test ".dir/y.go" file2
	    dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
	    set ofile2 "[file rootname [file tail $file2]].o"
	    set dg-do-what-default "link"
	    set output_file "./[file rootname [file tail $test]].exe"
	    set comp_output [go_target_compile "$ofile1 $ofile2" \
				 $output_file "executable" "$DEFAULT_GOCFLAGS"]
	    set comp_output [go-dg-prune $target_triplet $comp_output]
	    verbose -log $comp_output
	    set result [go_load "$output_file" "" ""]
	    set status [lindex $result 0]
	    $status $name
	    file delete $ofile1 $ofile2 $output_file
	    set runtests $hold_runtests
	} elseif { [string match \
			"// \$G \$D/bug191.dir/a.go && \$G \$D/bug191.dir/b.go && \$G \$D/\$F.go && \$L \$F.\$A" \
			$test_line] } {
	    set hold_runtests $runtests
	    set runtests "go-test.exp"
	    set dg-do-what-default "assemble"
	    regsub "\\.go$" $test ".dir/a.go" file1
	    dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
	    set ofile1 "[file rootname [file tail $file1]].o"
	    regsub "\\.go$" $test ".dir/b.go" file2
	    dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
	    set ofile2 "[file rootname [file tail $file2]].o"
	    dg-test -keep-output "$test" "-O" "-w $DEFAULT_GOCFLAGS"
	    set ofile3 "[file rootname [file tail $test]].o"
	    set dg-do-what-default "link"
	    set output_file "./[file rootname [file tail $test]].exe"
	    set comp_output [go_target_compile "$ofile1 $ofile2 $ofile3" \
				 $output_file "executable" "$DEFAULT_GOCFLAGS"]
	    set comp_output [go-dg-prune $target_triplet $comp_output]
	    if [string match "" $comp_output] {
		pass $name
	    } else {
		verbose -log $comp_output
		fail $name
	    }
	    file delete $ofile1 $ofile2 $ofile3 $output_file
	    set runtests $hold_runtests
	} elseif { [string match \
			"// \$G \$D/embed0.go && \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out" \
			$test_line ] } {
	    set hold_runtests $runtests
	    set runtests "go-test.exp"
	    set dg-do-what-default "assemble"
	    regsub "/\[^/\]*$" $test "/embed0.go" file1
	    dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
	    set ofile1 "[file rootname [file tail $file1]].o"
	    dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
	    set ofile2 "[file rootname [file tail $test]].o"
	    set output_file "./[file rootname [file tail $test]].exe"
	    set comp_output [go_target_compile "$ofile1 $ofile2" \
				 $output_file "executable" "$DEFAULT_GOCFLAGS"]
	    set comp_output [go-dg-prune $target_triplet $comp_output]
	    if [string match "" $comp_output] {
		set result [go_load "$output_file" "" ""]
		set status [lindex $result 0]
		$status $name
	    } else {
		verbose -log $comp_output
		fail $name
	    }
	    file delete $ofile1 $ofile2 $output_file
	    set runtests $hold_runtests
	} elseif { [string match \
			"// \$G \$D/\$F.dir/chanbug.go && \$G -I. \$D/\$F.dir/chanbug2.go" \
			$test_line] } {
	    set hold_runtests $runtests
	    set runtests "go-test.exp"
	    set dg-do-what-default "assemble"
	    regsub "\\.go$" $test ".dir/chanbug.go" file1
	    dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
	    regsub "\\.go$" $test ".dir/chanbug2.go" file2
	    dg-test $file2 "-O" "-w $DEFAULT_GOCFLAGS"
	    file delete "[file rootname [file tail $file1]].o"
	    set runtests $hold_runtests
	} elseif { [string match \
			"// (! \$G \$D/\$F.go) | grep 'initialization loop' *" \
			$test_line] } {
	    set dg-do-what-default "assemble"
	    setup_xfail "*-*-*"
	    go-dg-runtest $test "-w $DEFAULT_GOCFLAGS"
	} elseif { [string match \
			"// \$G \$D/\$F.dir/x.go && errchk \$G \$D/\$F.dir/y.go" \
			$test_line] } {
	    set hold_runtests $runtests
	    set runtests "go-test.exp"
	    set dg-do-what-default "assemble"
	    regsub "\\.go$" $test ".dir/x.go" file1
	    dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
	    regsub "\\.go$" $test ".dir/y.go" file2
	    errchk $file2
	    file delete "[file rootname [file tail $file1]].o"
	    set runtests $hold_runtests
	} elseif { [string match "// true*" $test_line] } {
	    # Not a real test, just ignore.
	} elseif { $test_line == "// \$G \$D/\$F.dir/bug0.go &&" \
		       && $test_line2 == "// \$G \$D/\$F.dir/bug1.go &&" \
		       && $test_line3 == "// \$G \$D/\$F.dir/bug2.go &&" \
		       && $test_line4 == "// errchk \$G -e \$D/\$F.dir/bug3.go &&" \
		       && $test_line5 == "// \$L bug2.\$A &&" \
		       && [string match "// ./\$A.out || echo BUG*" $test_line6] } {
	    set hold_runtests $runtests
	    set runtests "go-test.exp"
	    set dg-do-what-default "assemble"
	    regsub "\\.go$" $test ".dir/bug0.go" file0
	    dg-test -keep-output $file0 "-O -fgo-prefix=bug0" "-w $DEFAULT_GOCFLAGS"
	    set ofile0 "[file rootname [file tail $file0]].o"
	    regsub "\\.go$" $test ".dir/bug1.go" file1
	    dg-test -keep-output $file1 "-O -fgo-prefix=bug1" "-w $DEFAULT_GOCFLAGS"
	    set ofile1 "[file rootname [file tail $file1]].o"
	    regsub "\\.go$" $test ".dir/bug2.go" file2
	    dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
	    set ofile2 "[file rootname [file tail $file2]].o"
	    regsub "\\.go$" $test ".dir/bug3.go" file3
	    errchk $file3
	    set output_file "./[file rootname [file tail $test]].exe"
	    set comp_output [go_target_compile "$ofile0 $ofile1 $ofile2" \
				 $output_file "executable" "$DEFAULT_GOCFLAGS"]
	    set comp-output [go-dg-prune $target_triplet $comp_output]
	    if [string match "" $comp_output] {
		set result [go_load "$output_file" "" ""]
		set status [lindex $result 0]
		$status $name
	    } else {
		verbose -log $comp_output
		fail $name
	    }
	    file delete $ofile0 $ofile1 $ofile2 $output_file
	    set runtests $hold_runtests
	} elseif { $test_line == "// \$G \$D/import2.go && \$G \$D/\$F\.go" } {
	    set hold_runtests $runtests
	    set runtests "go-test.exp"
	    set dg-do-what-default "assemble"
	    regsub "/\[^/\]*$" $test "/import2.go" file1
	    dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
	    set ofile1 "[file rootname [file tail $file1]].o"
	    dg-test $test "-O" "-w $DEFAULT_GOCFLAGS"
	    file delete $ofile1
	    set runtests $hold_runtests
	} elseif { $test_line == "// \$G \$D/ddd2.go && \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out" } {
	    set hold_runtests $runtests
	    set runtests "go-test.exp"
	    set dg-do-what-default "assemble"
	    regsub "/\[^/\]*$" $test "/ddd2.go" file1
	    dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
	    set ofile1 "[file rootname [file tail $file1]].o"
	    dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
	    set ofile2 "[file rootname [file tail $test]].o"
	    set output_file "./[file rootname [file tail $test]].exe"
	    set comp_output [go_target_compile "$ofile1 $ofile2" \
				 $output_file "executable" "$DEFAULT_GOCFLAGS"]
	    set comp_output [go-dg-prune $target_triplet $comp_output]
	    if [string match "" $comp_output] {
		set result [go_load "$output_file" "" ""]
		set status [lindex $result 0]
		$status $name
	    } else {
		verbose -log $comp_output
		fail $name
	    }
	    file delete $ofile1 $ofile2 $output_file
	    set runtests $hold_runtests
	} elseif { $test_line == "// \$G \$D/\$F.go \$D/cmplxdivide1.go && \$L \$D/\$F.\$A && ./\$A.out" } {
	    regsub "/\[^/\]*$" $test "/cmplxdivide1.go" test2
	    set output_file "./[file rootname [file tail $test]].o"
	    set comp_output [go_target_compile "$test $test2" \
			     $output_file "executable" "$DEFAULT_GOCFLAGS"]
	    set comp_output [go-dg-prune $target_triplet $comp_output]
	    if [string match "" $comp_output] {
		set result [go_load "$output_file" "" ""]
		set status [lindex $result 0]
		$status $name
	    } else {
		verbose -log $comp_output
		fail $name
	    }
	    file delete $output_file
	} elseif { $test_line == "// \$G \$D/\$F.go && \$L \$F.\$A &&" \
		       && $test_line2 == "// ./\$A.out -pass 0 >tmp.go && \$G tmp.go && \$L -o tmp1.\$A tmp.\$A && ./tmp1.\$A &&" \
		       && $test_line3 == "// ./\$A.out -pass 1 >tmp.go && errchk \$G -e tmp.go &&" \
		       && $test_line4 == "// ./\$A.out -pass 2 >tmp.go && errchk \$G -e tmp.go" } {
	    set go_execute_args ""
	    set hold_runtests $runtests
	    set runtests "go-test.exp"
	    set dg-do-what-default "link"
	    dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
	    set output_file "./[file rootname [file tail $test]].exe"
	    if [isnative] {
		if { [catch "exec $output_file -pass 0 >tmp.go"] != 0 } {
		    fail "$name execution 0"
		} else {
		    pass "$name execution 0"
		    file delete tmp.x
		    go-torture-execute "./tmp.go"
		}
		if { [catch "exec $output_file -pass 1 >tmp.go"] != 0 } {
		    fail "$name execution 1"
		} else {
		    pass "$name execution 1"
		    errchk tmp.go
		}
		if { [catch "exec $output_file -pass 2 >tmp.go"] != 0 } {
		    fail "$name execution 2"
		} else {
		    pass "$name execution 2"
		    errchk tmp.go
		}
		file delete tmp.go
	    }
	    file delete $output_file
	    set runtests $hold_runtests
	} elseif { $test_line == "// \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out >tmp.go &&" \
			&& $test_line2 == "// errchk \$G -e tmp.go" } {
	    set go_execute_args ""
	    set hold_runtests $runtests
	    set runtests "go-test.exp"
	    set dg-do-what-default "link"
	    dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
	    set output_file "./[file rootname [file tail $test]].exe"
	    if [isnative] {
		if { [catch "exec $output_file >tmp.go"] != 0 } {
		    fail "$name execution"
		} else {
		    pass "$name execution"
		    file delete tmp.x
		    errchk tmp.go
		}
	    }
	    file delete $output_file
	    set runtests $hold_runtests
	} elseif { $test_line == "// # generated by cmplxdivide.c" } {
	    # Ignore.
	} elseif { $test_line == "// \$G \$D/bug302.dir/p.go && gopack grc pp.a p.\$A && \$G \$D/bug302.dir/main.go" \
		   || $test_line == "// \$G \$D/empty.go && errchk \$G \$D/\$F.go" } {
	    # These tests import the same package under two different
	    # names, which gccgo does not support.
	} elseif { $test_line == "// \$G -S \$D/\$F.go | egrep initdone >/dev/null && echo FAIL || true" } {
	    # This tests whether initializers are written out
	    # statically.  gccgo does not provide a way to test that,
	    # as an initializer will be generated for any code which
	    # has global variables which need to be registered as GC
	    # roots.
	} else {
	    clone_output "$name: unrecognized test line: $test_line"
	    unsupported $name
	}

	set go_execute_args ""
    }

    set dg-do-what-default ${saved-dg-do-what-default}
    set TORTURE_OPTIONS $saved_torture_options
}

go-gc-tests