From: Ian Lance Taylor Date: Fri, 18 Dec 2020 05:33:51 +0000 (-0800) Subject: Go testsuite: handle +build lines correctly X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=dc00689332f023d959a8e9f01368f59b756a7017;p=gcc.git Go testsuite: handle +build lines correctly Update the Go testsuite driver to handle +build lines as is done in the upstream repo, and update some tests to the upstream repo copy using +build lines with "gc" and "!gccgo" as appropriate. * go.test/go-test.exp (go-set-goos): New procedure. (go-gc-match): New procedure. (go-gc-tests): Call go-set-goos. Use go-gc-match to handle +build lines. Look for +build lines beyond first line of file. --- diff --git a/gcc/testsuite/go.test/go-test.exp b/gcc/testsuite/go.test/go-test.exp index c1b27c09236..c7d5c724f9b 100644 --- a/gcc/testsuite/go.test/go-test.exp +++ b/gcc/testsuite/go.test/go-test.exp @@ -255,6 +255,53 @@ proc go-set-goarch { } { setenv GOARCH $goarch } +# This be kept in sync with libgo/configure.ac. +proc go-set-goos { } { + global target_triplet + + switch -glob $target_triplet { + "*-*-darwin*" { + set goos "darwin" + } + "*-*-freebsd*" { + set goos "freebsd" + } + "*-*-irix6*" { + set goos "irix" + } + "*-*-linux*" { + set goos "linux" + } + "*-*-netbsd*" { + set goos "netbsd" + } + "*-*-openbsd*" { + set goos "openbsd" + } + "*-*-dragonfly*" { + set goos "dragonfly" + } + "*-*-rtems*" { + set goos "rtems" + } + "*-*-solaris2*" { + set goos "solaris" + } + "*-*-aix*" { + set goos "aix" + } + "*-*-gnu*" { + set goos "hurd" + } + default { + perror "$target_triplet: unhandled GOOS" + return + } + } + verbose -log "Setting GOOS=$goos" 1 + setenv GOOS $goos +} + # Take a list of files and return a lists of lists, where each list is # the set of files in the same package. proc go-find-packages { test name files } { @@ -291,6 +338,27 @@ proc go-find-packages { test name files } { return $packages } +proc go-gc-match { name } { + verbose -log "go-gc-match $name" + set idx [string first "," $name] + if { $idx >= 0 } { + set left [string range $name 0 [expr $idx - 1]] + set right [string range $name [expr $idx + 1] end] + return [expr [go-gc-match $left] && [go-gc-match $right]] + } + if { [string index $name 0] == "!" && [string index $name 1] == "!" } { + return 0 + } + if { [string index $name 0] == "!" } { + return [expr ! [go-gc-match [string range $name 1 end]]] + } + if { $name == [getenv GOARCH] || $name == [getenv GOOS] || $name == "gccgo" } { + return 1 + } + + return 0 +} + proc go-gc-tests { } { global srcdir subdir global runtests @@ -311,8 +379,9 @@ proc go-gc-tests { } { set options "" lappend options "additional_flags=$DEFAULT_GOCFLAGS" - # Set GOARCH for tests that need it. + # Set GOARCH and GOOS for tests that need it. go-set-goarch + go-set-goos # Running all the torture options takes too long and, since the # frontend ignores the standard options, it doesn't significantly @@ -432,73 +501,61 @@ proc go-gc-tests { } { set lines_ok 1 + set test_line "" while 1 { - if { [gets $fd test_line] < 0 } { - close $fd - clone_output "$test: could not read first line" + if { [gets $fd file_line] < 0 } { + if [eof $fd] { + break + } + clone_output "$test: read failed" 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 ] \ - || [ string match "*\"\$GOOS\" == windows*" $test_line ] } { + if { [ string match "*nacl*exit 0*" $file_line ] \ + || [ string match "*exit 0*nacl*" $file_line ] \ + || [ string match "*Android*exit 0*" $file_line ] \ + || [ string match "*exit 0*Android*" $file_line ] \ + || [ string match "*\"\$GOOS\" == windows*" $file_line ] } { continue } - if { [ string match "// +build *" $test_line ] } { - set matches_pos 0 - set matches_neg 0 - if { [ regexp -line "\[ \][getenv GOARCH]\(\[ \]\|\$\)" $test_line ] } { - set matches_pos 1 - } elseif { [ regexp -line "\[ \]\![getenv GOARCH]\(\[ \]\|\$\)" $test_line ] } { - set matches_neg 1 - } elseif { [ regexp -line "\[ \]linux\(\[ \]\|\$\)" $test_line ] } { - set matches_pos 1 - } elseif { [ regexp -line "\[ \]\!linux\(\[ \]\|\$\)" $test_line ] } { - set matches_neg 1 - } elseif { [ regexp -line "\[ \]\!windows\(\[ \]\|\$\)" $test_line ] } { - set matches_pos 1 - } elseif { [ regexp -line "\[ \]windows\(\[ \]\|\$\)" $test_line ] } { - set matches_neg 1 + if ![string match "// *" $file_line] { + if { $file_line != "" } { + break } - if { $matches_pos == 1 && $matches_neg == 0 } { + continue + } + + if { [ string match "// +build *" $file_line ] } { + set words [split $file_line] + set matches 0 + for { set idx 2 } { $idx < [llength $words] } { incr idx } { + if { [go-gc-match [lindex $words $idx]] } { + set matches 1 + break + } + } + if { $matches == 1 } { continue } - close $fd unsupported $name set lines_ok 0 + break } - break - } - - if { $lines_ok == 0 } { - continue + if { $test_line == "" } { + set test_line $file_line + } } - set lineno 1 - set test_line1 $test_line + close $fd - 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 - # runtest_file_p is already run above, and the code below can run # runtest_file_p again, make sure everything for this test is # performed if the above runtest_file_p decided this runtest diff --git a/gcc/testsuite/go.test/test/fixedbugs/bug302.go b/gcc/testsuite/go.test/test/fixedbugs/bug302.go index 87f9d4ef70c..a2ab661277a 100644 --- a/gcc/testsuite/go.test/test/fixedbugs/bug302.go +++ b/gcc/testsuite/go.test/test/fixedbugs/bug302.go @@ -1,4 +1,4 @@ -// +build !nacl,!js +// +build !nacl,!js,gc // run // Copyright 2010 The Go Authors. All rights reserved. diff --git a/gcc/testsuite/go.test/test/fixedbugs/bug369.go b/gcc/testsuite/go.test/test/fixedbugs/bug369.go index 9316f7aad0b..83f638d0463 100644 --- a/gcc/testsuite/go.test/test/fixedbugs/bug369.go +++ b/gcc/testsuite/go.test/test/fixedbugs/bug369.go @@ -1,4 +1,4 @@ -// +build !nacl,!js,!windows +// +build !nacl,!js,!windows,gc // run // Copyright 2011 The Go Authors. All rights reserved. diff --git a/gcc/testsuite/go.test/test/fixedbugs/issue10607.go b/gcc/testsuite/go.test/test/fixedbugs/issue10607.go index 6f4717d8202..448a37dcac2 100644 --- a/gcc/testsuite/go.test/test/fixedbugs/issue10607.go +++ b/gcc/testsuite/go.test/test/fixedbugs/issue10607.go @@ -1,4 +1,4 @@ -// +build linux,!ppc64,!riscv64 +// +build linux,!ppc64,!riscv64,gc // run // Copyright 2015 The Go Authors. All rights reserved. diff --git a/gcc/testsuite/go.test/test/fixedbugs/issue11771.go b/gcc/testsuite/go.test/test/fixedbugs/issue11771.go index 99d7060d44e..c95dd6ba396 100644 --- a/gcc/testsuite/go.test/test/fixedbugs/issue11771.go +++ b/gcc/testsuite/go.test/test/fixedbugs/issue11771.go @@ -1,4 +1,4 @@ -// +build !nacl,!js +// +build !nacl,!js,gc // run // Copyright 2015 The Go Authors. All rights reserved. diff --git a/gcc/testsuite/go.test/test/fixedbugs/issue13268.go b/gcc/testsuite/go.test/test/fixedbugs/issue13268.go index fcb69c90682..53a82d5074a 100644 --- a/gcc/testsuite/go.test/test/fixedbugs/issue13268.go +++ b/gcc/testsuite/go.test/test/fixedbugs/issue13268.go @@ -1,3 +1,4 @@ +// +build gc // run // Copyright 2015 The Go Authors. All rights reserved. diff --git a/gcc/testsuite/go.test/test/fixedbugs/issue14636.go b/gcc/testsuite/go.test/test/fixedbugs/issue14636.go index 6797046e02b..06fd193dae0 100644 --- a/gcc/testsuite/go.test/test/fixedbugs/issue14636.go +++ b/gcc/testsuite/go.test/test/fixedbugs/issue14636.go @@ -1,4 +1,4 @@ -// +build !nacl,!js,!android +// +build !nacl,!js,!android,gc // run // Copyright 2016 The Go Authors. All rights reserved. diff --git a/gcc/testsuite/go.test/test/fixedbugs/issue16037_run.go b/gcc/testsuite/go.test/test/fixedbugs/issue16037_run.go index d05e3f7f314..68104a90007 100644 --- a/gcc/testsuite/go.test/test/fixedbugs/issue16037_run.go +++ b/gcc/testsuite/go.test/test/fixedbugs/issue16037_run.go @@ -1,4 +1,4 @@ -// +build !nacl,!js,!android +// +build !nacl,!js,!android,!gccgo // run // Copyright 2016 The Go Authors. All rights reserved. diff --git a/gcc/testsuite/go.test/test/fixedbugs/issue19658.go b/gcc/testsuite/go.test/test/fixedbugs/issue19658.go index b2539629df0..bab409c6c03 100644 --- a/gcc/testsuite/go.test/test/fixedbugs/issue19658.go +++ b/gcc/testsuite/go.test/test/fixedbugs/issue19658.go @@ -1,4 +1,4 @@ -// +build !nacl,!js +// +build !nacl,!js,!gccgo // run // Copyright 2017 The Go Authors. All rights reserved. diff --git a/gcc/testsuite/go.test/test/fixedbugs/issue21317.go b/gcc/testsuite/go.test/test/fixedbugs/issue21317.go index f4ec4223713..32b660c1639 100644 --- a/gcc/testsuite/go.test/test/fixedbugs/issue21317.go +++ b/gcc/testsuite/go.test/test/fixedbugs/issue21317.go @@ -1,3 +1,4 @@ +// +build !js,gc // run // Copyright 2017 The Go Authors. All rights reserved. @@ -16,15 +17,10 @@ import ( "log" "os" "os/exec" - "runtime" "strings" ) func main() { - if runtime.Compiler != "gc" || runtime.GOOS == "js" { - return - } - f, err := ioutil.TempFile("", "issue21317.go") if err != nil { log.Fatal(err) diff --git a/gcc/testsuite/go.test/test/fixedbugs/issue21576.go b/gcc/testsuite/go.test/test/fixedbugs/issue21576.go index ae6161ccf52..3f9b1ba008a 100644 --- a/gcc/testsuite/go.test/test/fixedbugs/issue21576.go +++ b/gcc/testsuite/go.test/test/fixedbugs/issue21576.go @@ -1,6 +1,6 @@ // run -// +build !nacl,!js +// +build !nacl,!js,!gccgo // Copyright 2019 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/gcc/testsuite/go.test/test/fixedbugs/issue22660.go b/gcc/testsuite/go.test/test/fixedbugs/issue22660.go index 44ba42ac968..9ce9c4d732e 100644 --- a/gcc/testsuite/go.test/test/fixedbugs/issue22660.go +++ b/gcc/testsuite/go.test/test/fixedbugs/issue22660.go @@ -1,3 +1,4 @@ +// +build !js,gc // run // Copyright 2017 The Go Authors. All rights reserved. @@ -14,15 +15,10 @@ import ( "os" "os/exec" "path/filepath" - "runtime" "strings" ) func main() { - if runtime.GOOS == "js" { - return // no file system available on builders - } - f, err := ioutil.TempFile("", "issue22660.go") if err != nil { log.Fatal(err) diff --git a/gcc/testsuite/go.test/test/fixedbugs/issue33275_run.go b/gcc/testsuite/go.test/test/fixedbugs/issue33275_run.go index f3e2e14f392..ed03dccf4c8 100644 --- a/gcc/testsuite/go.test/test/fixedbugs/issue33275_run.go +++ b/gcc/testsuite/go.test/test/fixedbugs/issue33275_run.go @@ -1,4 +1,4 @@ -// +build !nacl,!js +// +build !nacl,!js,!gccgo // run // Copyright 2019 The Go Authors. All rights reserved. diff --git a/gcc/testsuite/go.test/test/fixedbugs/issue33555.go b/gcc/testsuite/go.test/test/fixedbugs/issue33555.go index 7debd2049cd..c1fcd2a79b3 100644 --- a/gcc/testsuite/go.test/test/fixedbugs/issue33555.go +++ b/gcc/testsuite/go.test/test/fixedbugs/issue33555.go @@ -1,4 +1,4 @@ -// +build !nacl,!js +// +build !nacl,!js,!gccgo // run // Copyright 2019 The Go Authors. All rights reserved. diff --git a/gcc/testsuite/go.test/test/fixedbugs/issue36437.go b/gcc/testsuite/go.test/test/fixedbugs/issue36437.go index f96544beff8..c7a11d27a89 100644 --- a/gcc/testsuite/go.test/test/fixedbugs/issue36437.go +++ b/gcc/testsuite/go.test/test/fixedbugs/issue36437.go @@ -1,6 +1,6 @@ // run -// +build !nacl,!js +// +build !nacl,!js,gc // Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/gcc/testsuite/go.test/test/fixedbugs/issue9355.go b/gcc/testsuite/go.test/test/fixedbugs/issue9355.go index ab3369d415d..319a2a90df9 100644 --- a/gcc/testsuite/go.test/test/fixedbugs/issue9355.go +++ b/gcc/testsuite/go.test/test/fixedbugs/issue9355.go @@ -1,3 +1,4 @@ +// +build !js,gc // run // Copyright 2014 The Go Authors. All rights reserved. @@ -13,14 +14,9 @@ import ( "os/exec" "path/filepath" "regexp" - "runtime" ) func main() { - if runtime.Compiler != "gc" || runtime.GOOS == "js" { - return - } - err := os.Chdir(filepath.Join("fixedbugs", "issue9355.dir")) check(err) diff --git a/gcc/testsuite/go.test/test/fixedbugs/issue9862_run.go b/gcc/testsuite/go.test/test/fixedbugs/issue9862_run.go index 299e8095450..c956c7f7bd5 100644 --- a/gcc/testsuite/go.test/test/fixedbugs/issue9862_run.go +++ b/gcc/testsuite/go.test/test/fixedbugs/issue9862_run.go @@ -1,4 +1,4 @@ -// +build !nacl,!js +// +build !nacl,!js,gc // run // Copyright 2015 The Go Authors. All rights reserved. diff --git a/gcc/testsuite/go.test/test/run.go b/gcc/testsuite/go.test/test/run.go index 4abf32d25c8..db3e9f6c2fc 100644 --- a/gcc/testsuite/go.test/test/run.go +++ b/gcc/testsuite/go.test/test/run.go @@ -438,7 +438,7 @@ func (ctxt *context) match(name string) bool { } } - if name == ctxt.GOOS || name == ctxt.GOARCH { + if name == ctxt.GOOS || name == ctxt.GOARCH || name == "gc" { return true }