2012-03-21 18:14:44 +00:00
|
|
|
// skip
|
2012-02-21 03:28:49 +00:00
|
|
|
|
2016-04-10 21:32:26 +00:00
|
|
|
// Copyright 2012 The Go Authors. All rights reserved.
|
2012-02-21 03:28:49 +00:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// Run runs tests in the test directory.
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2021-07-02 22:42:20 +00:00
|
|
|
"encoding/json"
|
2012-02-21 03:28:49 +00:00
|
|
|
"errors"
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
2021-04-16 03:07:41 +00:00
|
|
|
"go/build"
|
2015-06-04 06:21:30 +00:00
|
|
|
"hash/fnv"
|
|
|
|
"io"
|
2020-11-04 23:20:17 +00:00
|
|
|
"io/fs"
|
2012-02-21 03:28:49 +00:00
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
2012-09-23 17:16:14 +00:00
|
|
|
"path"
|
2012-02-21 03:28:49 +00:00
|
|
|
"path/filepath"
|
|
|
|
"regexp"
|
|
|
|
"runtime"
|
|
|
|
"sort"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
2013-12-10 19:02:42 +00:00
|
|
|
"time"
|
2013-08-13 16:25:41 +00:00
|
|
|
"unicode"
|
2012-02-21 03:28:49 +00:00
|
|
|
)
|
|
|
|
|
2021-08-19 22:53:13 +00:00
|
|
|
// CompilerDefaultGLevel is the -G level used by default when not overridden by a
|
|
|
|
// command-line flag
|
|
|
|
const CompilerDefaultGLevel = 3
|
|
|
|
|
2012-02-21 03:28:49 +00:00
|
|
|
var (
|
2013-01-12 06:52:52 +00:00
|
|
|
verbose = flag.Bool("v", false, "verbose. if set, parallelism is set to 1.")
|
2016-03-11 05:10:52 +00:00
|
|
|
keep = flag.Bool("k", false, "keep. keep temporary directory.")
|
2013-01-12 06:52:52 +00:00
|
|
|
numParallel = flag.Int("n", runtime.NumCPU(), "number of parallel tests to run")
|
|
|
|
summary = flag.Bool("summary", false, "show summary of results")
|
2019-09-26 17:25:04 +00:00
|
|
|
allCodegen = flag.Bool("all_codegen", defaultAllCodeGen(), "run all goos/goarch for codegen")
|
2013-01-12 06:52:52 +00:00
|
|
|
showSkips = flag.Bool("show_skips", false, "show skipped tests")
|
2015-10-26 21:34:06 +00:00
|
|
|
runSkips = flag.Bool("run_skips", false, "run skipped tests (ignore skip and build tags)")
|
2015-10-27 01:54:19 +00:00
|
|
|
linkshared = flag.Bool("linkshared", false, "")
|
2015-02-19 19:00:11 +00:00
|
|
|
updateErrors = flag.Bool("update_errors", false, "update error messages in test file based on compiler output")
|
2013-01-12 06:52:52 +00:00
|
|
|
runoutputLimit = flag.Int("l", defaultRunOutputLimit(), "number of parallel runoutput tests to run")
|
2021-07-02 20:18:03 +00:00
|
|
|
force = flag.Bool("f", false, "ignore expected-failure test lists")
|
2021-06-24 21:32:21 +00:00
|
|
|
generics = flag.String("G", defaultGLevels, "a comma-separated list of -G compiler flags to test with")
|
2015-06-04 06:21:30 +00:00
|
|
|
|
|
|
|
shard = flag.Int("shard", 0, "shard index to run. Only applicable if -shards is non-zero.")
|
|
|
|
shards = flag.Int("shards", 0, "number of shards. If 0, all tests are run. This is used by the continuous build.")
|
2012-02-21 03:28:49 +00:00
|
|
|
)
|
|
|
|
|
2021-07-02 22:42:20 +00:00
|
|
|
type envVars struct {
|
|
|
|
GOOS string
|
|
|
|
GOARCH string
|
|
|
|
GOEXPERIMENT string
|
|
|
|
CGO_ENABLED string
|
|
|
|
}
|
|
|
|
|
|
|
|
var env = func() (res envVars) {
|
|
|
|
cmd := exec.Command("go", "env", "-json")
|
|
|
|
stdout, err := cmd.StdoutPipe()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("StdoutPipe:", err)
|
|
|
|
}
|
|
|
|
if err := cmd.Start(); err != nil {
|
|
|
|
log.Fatal("Start:", err)
|
|
|
|
}
|
|
|
|
if err := json.NewDecoder(stdout).Decode(&res); err != nil {
|
|
|
|
log.Fatal("Decode:", err)
|
|
|
|
}
|
|
|
|
if err := cmd.Wait(); err != nil {
|
|
|
|
log.Fatal("Wait:", err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}()
|
2021-06-24 21:32:21 +00:00
|
|
|
|
2021-07-02 22:42:20 +00:00
|
|
|
var unifiedEnabled, defaultGLevels = func() (bool, string) {
|
2021-06-24 21:32:21 +00:00
|
|
|
// TODO(mdempsky): This will give false negatives if the unified
|
|
|
|
// experiment is enabled by default, but presumably at that point we
|
|
|
|
// won't need to disable tests for it anymore anyway.
|
2021-07-02 22:42:20 +00:00
|
|
|
enabled := strings.Contains(","+env.GOEXPERIMENT+",", ",unified,")
|
2021-06-24 21:32:21 +00:00
|
|
|
|
2021-09-02 19:14:47 +00:00
|
|
|
// Test both -G=0 and -G=3 on the longtest builders, to make sure we
|
|
|
|
// don't accidentally break -G=0 mode until we're ready to remove it
|
|
|
|
// completely. But elsewhere, testing -G=3 alone should be enough.
|
|
|
|
glevels := "3"
|
|
|
|
if strings.Contains(os.Getenv("GO_BUILDER_NAME"), "longtest") {
|
|
|
|
glevels = "0,3"
|
2021-06-24 21:32:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return enabled, glevels
|
|
|
|
}()
|
|
|
|
|
2019-09-26 17:25:04 +00:00
|
|
|
// defaultAllCodeGen returns the default value of the -all_codegen
|
|
|
|
// flag. By default, we prefer to be fast (returning false), except on
|
|
|
|
// the linux-amd64 builder that's already very fast, so we get more
|
|
|
|
// test coverage on trybots. See https://golang.org/issue/34297.
|
|
|
|
func defaultAllCodeGen() bool {
|
|
|
|
return os.Getenv("GO_BUILDER_NAME") == "linux-amd64"
|
|
|
|
}
|
|
|
|
|
2012-02-21 03:28:49 +00:00
|
|
|
var (
|
2021-07-02 22:42:20 +00:00
|
|
|
goos = env.GOOS
|
|
|
|
goarch = env.GOARCH
|
|
|
|
cgoEnabled, _ = strconv.ParseBool(env.CGO_ENABLED)
|
2012-02-21 03:28:49 +00:00
|
|
|
|
|
|
|
// dirs are the directories to look for *.go files in.
|
|
|
|
// TODO(bradfitz): just use all directories?
|
2021-06-08 18:57:11 +00:00
|
|
|
dirs = []string{".", "ken", "chan", "interface", "syntax", "dwarf", "fixedbugs", "codegen", "runtime", "abi", "typeparam", "typeparam/mdempsky"}
|
2012-02-21 03:28:49 +00:00
|
|
|
|
|
|
|
// ratec controls the max number of tests running at a time.
|
|
|
|
ratec chan bool
|
|
|
|
|
|
|
|
// toRun is the channel of tests to run.
|
|
|
|
// It is nil until the first test is started.
|
|
|
|
toRun chan *test
|
2013-01-12 06:52:52 +00:00
|
|
|
|
|
|
|
// rungatec controls the max number of runoutput tests
|
|
|
|
// executed in parallel as they can each consume a lot of memory.
|
|
|
|
rungatec chan bool
|
2012-02-21 03:28:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// maxTests is an upper bound on the total number of tests.
|
|
|
|
// It is used as a channel buffer size to make sure sends don't block.
|
|
|
|
const maxTests = 5000
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
2012-03-07 04:43:25 +00:00
|
|
|
|
2021-05-17 20:59:25 +00:00
|
|
|
var glevels []int
|
|
|
|
for _, s := range strings.Split(*generics, ",") {
|
|
|
|
glevel, err := strconv.Atoi(s)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("invalid -G flag: %v", err)
|
|
|
|
}
|
|
|
|
glevels = append(glevels, glevel)
|
|
|
|
}
|
|
|
|
|
all: merge NaCl branch (part 1)
See golang.org/s/go13nacl for design overview.
This CL is the mostly mechanical changes from rsc's Go 1.2 based NaCl branch, specifically 39cb35750369 to 500771b477cf from https://code.google.com/r/rsc-go13nacl. This CL does not include working NaCl support, there are probably two or three more large merges to come.
CL 15750044 is not included as it involves more invasive changes to the linker which will need to be merged separately.
The exact change lists included are
15050047: syscall: support for Native Client
15360044: syscall: unzip implementation for Native Client
15370044: syscall: Native Client SRPC implementation
15400047: cmd/dist, cmd/go, go/build, test: support for Native Client
15410048: runtime: support for Native Client
15410049: syscall: file descriptor table for Native Client
15410050: syscall: in-memory file system for Native Client
15440048: all: update +build lines for Native Client port
15540045: cmd/6g, cmd/8g, cmd/gc: support for Native Client
15570045: os: support for Native Client
15680044: crypto/..., hash/crc32, reflect, sync/atomic: support for amd64p32
15690044: net: support for Native Client
15690048: runtime: support for fake time like on Go Playground
15690051: build: disable various tests on Native Client
LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/68150047
2014-02-25 14:47:42 +00:00
|
|
|
findExecCmd()
|
|
|
|
|
2014-05-28 05:01:08 +00:00
|
|
|
// Disable parallelism if printing or if using a simulator.
|
|
|
|
if *verbose || len(findExecCmd()) > 0 {
|
|
|
|
*numParallel = 1
|
2018-10-17 04:37:44 +00:00
|
|
|
*runoutputLimit = 1
|
2014-05-28 05:01:08 +00:00
|
|
|
}
|
|
|
|
|
2012-02-21 03:28:49 +00:00
|
|
|
ratec = make(chan bool, *numParallel)
|
2013-01-12 06:52:52 +00:00
|
|
|
rungatec = make(chan bool, *runoutputLimit)
|
2012-02-21 03:28:49 +00:00
|
|
|
|
|
|
|
var tests []*test
|
|
|
|
if flag.NArg() > 0 {
|
|
|
|
for _, arg := range flag.Args() {
|
|
|
|
if arg == "-" || arg == "--" {
|
2012-08-07 01:38:35 +00:00
|
|
|
// Permit running:
|
2012-02-21 03:28:49 +00:00
|
|
|
// $ go run run.go - env.go
|
|
|
|
// $ go run run.go -- env.go
|
2012-08-07 01:38:35 +00:00
|
|
|
// $ go run run.go - ./fixedbugs
|
|
|
|
// $ go run run.go -- ./fixedbugs
|
2012-02-21 03:28:49 +00:00
|
|
|
continue
|
|
|
|
}
|
2012-08-07 01:38:35 +00:00
|
|
|
if fi, err := os.Stat(arg); err == nil && fi.IsDir() {
|
|
|
|
for _, baseGoFile := range goFiles(arg) {
|
2021-05-17 20:59:25 +00:00
|
|
|
tests = append(tests, startTests(arg, baseGoFile, glevels)...)
|
2012-08-07 01:38:35 +00:00
|
|
|
}
|
|
|
|
} else if strings.HasSuffix(arg, ".go") {
|
|
|
|
dir, file := filepath.Split(arg)
|
2021-05-17 20:59:25 +00:00
|
|
|
tests = append(tests, startTests(dir, file, glevels)...)
|
2012-08-07 01:38:35 +00:00
|
|
|
} else {
|
|
|
|
log.Fatalf("can't yet deal with non-directory and non-go file %q", arg)
|
2012-02-21 03:28:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for _, dir := range dirs {
|
|
|
|
for _, baseGoFile := range goFiles(dir) {
|
2021-05-17 20:59:25 +00:00
|
|
|
tests = append(tests, startTests(dir, baseGoFile, glevels)...)
|
2012-02-21 03:28:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
failed := false
|
|
|
|
resCount := map[string]int{}
|
|
|
|
for _, test := range tests {
|
2014-08-01 20:34:36 +00:00
|
|
|
<-test.donec
|
2013-12-10 19:02:42 +00:00
|
|
|
status := "ok "
|
|
|
|
errStr := ""
|
2016-03-31 17:57:48 +00:00
|
|
|
if e, isSkip := test.err.(skipError); isSkip {
|
2013-12-10 19:02:42 +00:00
|
|
|
test.err = nil
|
2016-03-31 17:57:48 +00:00
|
|
|
errStr = "unexpected skip for " + path.Join(test.dir, test.gofile) + ": " + string(e)
|
2014-12-18 18:34:12 +00:00
|
|
|
status = "FAIL"
|
2013-12-10 19:02:42 +00:00
|
|
|
}
|
2012-02-21 03:28:49 +00:00
|
|
|
if test.err != nil {
|
|
|
|
errStr = test.err.Error()
|
2021-07-02 20:18:03 +00:00
|
|
|
if test.expectFail {
|
|
|
|
errStr += " (expected)"
|
|
|
|
} else {
|
|
|
|
status = "FAIL"
|
|
|
|
}
|
|
|
|
} else if test.expectFail {
|
|
|
|
status = "FAIL"
|
|
|
|
errStr = "unexpected success"
|
2012-02-21 03:28:49 +00:00
|
|
|
}
|
2013-12-10 19:02:42 +00:00
|
|
|
if status == "FAIL" {
|
2012-09-23 17:16:14 +00:00
|
|
|
failed = true
|
|
|
|
}
|
2013-12-10 19:02:42 +00:00
|
|
|
resCount[status]++
|
|
|
|
dt := fmt.Sprintf("%.3fs", test.dt.Seconds())
|
|
|
|
if status == "FAIL" {
|
2021-05-17 20:59:25 +00:00
|
|
|
fmt.Printf("# go run run.go -G=%v %s\n%s\nFAIL\t%s\t%s\n",
|
|
|
|
test.glevel,
|
2013-12-10 19:02:42 +00:00
|
|
|
path.Join(test.dir, test.gofile),
|
|
|
|
errStr, test.goFileName(), dt)
|
2012-02-21 03:28:49 +00:00
|
|
|
continue
|
2012-02-24 01:52:15 +00:00
|
|
|
}
|
2013-12-10 19:02:42 +00:00
|
|
|
if !*verbose {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
fmt.Printf("%s\t%s\t%s\n", status, test.goFileName(), dt)
|
2012-02-21 03:28:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if *summary {
|
|
|
|
for k, v := range resCount {
|
|
|
|
fmt.Printf("%5d %s\n", v, k)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if failed {
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-03 13:47:20 +00:00
|
|
|
// goTool reports the path of the go tool to use to run the tests.
|
|
|
|
// If possible, use the same Go used to run run.go, otherwise
|
|
|
|
// fallback to the go version found in the PATH.
|
|
|
|
func goTool() string {
|
|
|
|
var exeSuffix string
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
exeSuffix = ".exe"
|
|
|
|
}
|
|
|
|
path := filepath.Join(runtime.GOROOT(), "bin", "go"+exeSuffix)
|
|
|
|
if _, err := os.Stat(path); err == nil {
|
|
|
|
return path
|
|
|
|
}
|
|
|
|
// Just run "go" from PATH
|
|
|
|
return "go"
|
|
|
|
}
|
|
|
|
|
2015-06-04 06:21:30 +00:00
|
|
|
func shardMatch(name string) bool {
|
|
|
|
if *shards == 0 {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
h := fnv.New32()
|
|
|
|
io.WriteString(h, name)
|
|
|
|
return int(h.Sum32()%uint32(*shards)) == *shard
|
|
|
|
}
|
|
|
|
|
2012-02-21 03:28:49 +00:00
|
|
|
func goFiles(dir string) []string {
|
|
|
|
f, err := os.Open(dir)
|
2020-02-09 06:40:45 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2012-02-21 03:28:49 +00:00
|
|
|
dirnames, err := f.Readdirnames(-1)
|
2020-02-09 00:43:58 +00:00
|
|
|
f.Close()
|
2020-02-09 06:40:45 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2012-02-21 03:28:49 +00:00
|
|
|
names := []string{}
|
|
|
|
for _, name := range dirnames {
|
2015-06-04 06:21:30 +00:00
|
|
|
if !strings.HasPrefix(name, ".") && strings.HasSuffix(name, ".go") && shardMatch(name) {
|
2012-02-21 03:28:49 +00:00
|
|
|
names = append(names, name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sort.Strings(names)
|
|
|
|
return names
|
|
|
|
}
|
|
|
|
|
2012-10-06 07:23:31 +00:00
|
|
|
type runCmd func(...string) ([]byte, error)
|
|
|
|
|
2017-04-28 14:28:49 +00:00
|
|
|
func compileFile(runcmd runCmd, longname string, flags []string) (out []byte, err error) {
|
2018-03-03 13:47:20 +00:00
|
|
|
cmd := []string{goTool(), "tool", "compile", "-e"}
|
2017-04-28 14:28:49 +00:00
|
|
|
cmd = append(cmd, flags...)
|
2015-10-27 01:54:19 +00:00
|
|
|
if *linkshared {
|
|
|
|
cmd = append(cmd, "-dynlink", "-installsuffix=dynlink")
|
|
|
|
}
|
|
|
|
cmd = append(cmd, longname)
|
|
|
|
return runcmd(cmd...)
|
2012-10-06 07:23:31 +00:00
|
|
|
}
|
|
|
|
|
2018-05-30 16:46:59 +00:00
|
|
|
func compileInDir(runcmd runCmd, dir string, flags []string, localImports bool, names ...string) (out []byte, err error) {
|
|
|
|
cmd := []string{goTool(), "tool", "compile", "-e"}
|
|
|
|
if localImports {
|
|
|
|
// Set relative path for local imports and import search path to current dir.
|
|
|
|
cmd = append(cmd, "-D", ".", "-I", ".")
|
|
|
|
}
|
2016-03-11 05:10:52 +00:00
|
|
|
cmd = append(cmd, flags...)
|
2015-10-27 01:54:19 +00:00
|
|
|
if *linkshared {
|
|
|
|
cmd = append(cmd, "-dynlink", "-installsuffix=dynlink")
|
|
|
|
}
|
2013-01-02 20:31:49 +00:00
|
|
|
for _, name := range names {
|
|
|
|
cmd = append(cmd, filepath.Join(dir, name))
|
|
|
|
}
|
|
|
|
return runcmd(cmd...)
|
2012-10-06 07:23:31 +00:00
|
|
|
}
|
|
|
|
|
2019-03-22 19:24:36 +00:00
|
|
|
func linkFile(runcmd runCmd, goname string, ldflags []string) (err error) {
|
2015-05-21 17:28:17 +00:00
|
|
|
pfile := strings.Replace(goname, ".go", ".o", -1)
|
2018-03-03 13:47:20 +00:00
|
|
|
cmd := []string{goTool(), "tool", "link", "-w", "-o", "a.exe", "-L", "."}
|
2015-10-27 01:54:19 +00:00
|
|
|
if *linkshared {
|
|
|
|
cmd = append(cmd, "-linkshared", "-installsuffix=dynlink")
|
|
|
|
}
|
2019-03-22 19:24:36 +00:00
|
|
|
if ldflags != nil {
|
|
|
|
cmd = append(cmd, ldflags...)
|
|
|
|
}
|
2015-10-27 01:54:19 +00:00
|
|
|
cmd = append(cmd, pfile)
|
|
|
|
_, err = runcmd(cmd...)
|
2012-10-06 07:23:31 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2012-02-21 03:28:49 +00:00
|
|
|
// skipError describes why a test was skipped.
|
|
|
|
type skipError string
|
|
|
|
|
|
|
|
func (s skipError) Error() string { return string(s) }
|
|
|
|
|
|
|
|
// test holds the state of a test.
|
|
|
|
type test struct {
|
|
|
|
dir, gofile string
|
|
|
|
donec chan bool // closed when done
|
2014-08-01 20:34:36 +00:00
|
|
|
dt time.Duration
|
2021-05-17 20:59:25 +00:00
|
|
|
glevel int // what -G level this test should use
|
2014-08-01 20:34:36 +00:00
|
|
|
|
2016-09-22 17:50:16 +00:00
|
|
|
src string
|
2012-02-21 03:28:49 +00:00
|
|
|
|
|
|
|
tempDir string
|
|
|
|
err error
|
2021-07-02 20:18:03 +00:00
|
|
|
|
|
|
|
// expectFail indicates whether the (overall) test recipe is
|
|
|
|
// expected to fail under the current test configuration (e.g., -G=3
|
|
|
|
// or GOEXPERIMENT=unified).
|
|
|
|
expectFail bool
|
2012-02-21 03:28:49 +00:00
|
|
|
}
|
|
|
|
|
2021-07-02 20:18:03 +00:00
|
|
|
// initExpectFail initializes t.expectFail based on the build+test
|
2021-08-19 22:53:13 +00:00
|
|
|
// configuration.
|
|
|
|
func (t *test) initExpectFail(hasGFlag bool) {
|
2021-07-02 20:18:03 +00:00
|
|
|
if *force {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-08-19 22:53:13 +00:00
|
|
|
if t.glevel == 0 && !hasGFlag && !unifiedEnabled {
|
|
|
|
// tests should always pass when run w/o types2 (i.e., using the
|
|
|
|
// legacy typechecker, option -G=0).
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-07-02 20:18:03 +00:00
|
|
|
failureSets := []map[string]bool{types2Failures}
|
|
|
|
|
|
|
|
// Note: gccgo supports more 32-bit architectures than this, but
|
|
|
|
// hopefully the 32-bit failures are fixed before this matters.
|
|
|
|
switch goarch {
|
|
|
|
case "386", "arm", "mips", "mipsle":
|
|
|
|
failureSets = append(failureSets, types2Failures32Bit)
|
|
|
|
}
|
|
|
|
|
|
|
|
if unifiedEnabled {
|
|
|
|
failureSets = append(failureSets, unifiedFailures)
|
|
|
|
} else {
|
|
|
|
failureSets = append(failureSets, g3Failures)
|
|
|
|
}
|
|
|
|
|
|
|
|
filename := strings.Replace(t.goFileName(), "\\", "/", -1) // goFileName() uses \ on Windows
|
|
|
|
|
|
|
|
for _, set := range failureSets {
|
|
|
|
if set[filename] {
|
|
|
|
t.expectFail = true
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-06-17 04:41:28 +00:00
|
|
|
|
2021-05-17 20:59:25 +00:00
|
|
|
func startTests(dir, gofile string, glevels []int) []*test {
|
|
|
|
tests := make([]*test, len(glevels))
|
|
|
|
for i, glevel := range glevels {
|
|
|
|
t := &test{
|
|
|
|
dir: dir,
|
|
|
|
gofile: gofile,
|
|
|
|
glevel: glevel,
|
|
|
|
donec: make(chan bool, 1),
|
|
|
|
}
|
|
|
|
if toRun == nil {
|
|
|
|
toRun = make(chan *test, maxTests)
|
|
|
|
go runTests()
|
|
|
|
}
|
|
|
|
select {
|
|
|
|
case toRun <- t:
|
|
|
|
default:
|
|
|
|
panic("toRun buffer size (maxTests) is too small")
|
|
|
|
}
|
|
|
|
tests[i] = t
|
2012-02-21 03:28:49 +00:00
|
|
|
}
|
2021-05-17 20:59:25 +00:00
|
|
|
return tests
|
2012-02-21 03:28:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// runTests runs tests in parallel, but respecting the order they
|
|
|
|
// were enqueued on the toRun channel.
|
|
|
|
func runTests() {
|
|
|
|
for {
|
|
|
|
ratec <- true
|
|
|
|
t := <-toRun
|
|
|
|
go func() {
|
|
|
|
t.run()
|
|
|
|
<-ratec
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-07 06:54:39 +00:00
|
|
|
var cwd, _ = os.Getwd()
|
|
|
|
|
2012-02-21 03:28:49 +00:00
|
|
|
func (t *test) goFileName() string {
|
|
|
|
return filepath.Join(t.dir, t.gofile)
|
|
|
|
}
|
|
|
|
|
2012-07-30 19:12:05 +00:00
|
|
|
func (t *test) goDirName() string {
|
|
|
|
return filepath.Join(t.dir, strings.Replace(t.gofile, ".go", ".dir", -1))
|
|
|
|
}
|
|
|
|
|
2012-10-06 07:23:31 +00:00
|
|
|
func goDirFiles(longdir string) (filter []os.FileInfo, err error) {
|
|
|
|
files, dirErr := ioutil.ReadDir(longdir)
|
|
|
|
if dirErr != nil {
|
|
|
|
return nil, dirErr
|
|
|
|
}
|
|
|
|
for _, gofile := range files {
|
|
|
|
if filepath.Ext(gofile.Name()) == ".go" {
|
|
|
|
filter = append(filter, gofile)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-09-27 12:46:08 +00:00
|
|
|
var packageRE = regexp.MustCompile(`(?m)^package ([\p{Lu}\p{Ll}\w]+)`)
|
2013-01-02 20:31:49 +00:00
|
|
|
|
2019-03-22 19:24:36 +00:00
|
|
|
func getPackageNameFromSource(fn string) (string, error) {
|
|
|
|
data, err := ioutil.ReadFile(fn)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
pkgname := packageRE.FindStringSubmatch(string(data))
|
|
|
|
if pkgname == nil {
|
|
|
|
return "", fmt.Errorf("cannot find package name in %s", fn)
|
|
|
|
}
|
|
|
|
return pkgname[1], nil
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:33:04 +00:00
|
|
|
// If singlefilepkgs is set, each file is considered a separate package
|
|
|
|
// even if the package names are the same.
|
|
|
|
func goDirPackages(longdir string, singlefilepkgs bool) ([][]string, error) {
|
2013-01-02 20:31:49 +00:00
|
|
|
files, err := goDirFiles(longdir)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var pkgs [][]string
|
|
|
|
m := make(map[string]int)
|
|
|
|
for _, file := range files {
|
|
|
|
name := file.Name()
|
2019-03-22 19:24:36 +00:00
|
|
|
pkgname, err := getPackageNameFromSource(filepath.Join(longdir, name))
|
2020-02-09 06:40:45 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2019-03-22 19:24:36 +00:00
|
|
|
i, ok := m[pkgname]
|
2016-06-21 22:33:04 +00:00
|
|
|
if singlefilepkgs || !ok {
|
2013-01-02 20:31:49 +00:00
|
|
|
i = len(pkgs)
|
|
|
|
pkgs = append(pkgs, nil)
|
2019-03-22 19:24:36 +00:00
|
|
|
m[pkgname] = i
|
2013-01-02 20:31:49 +00:00
|
|
|
}
|
|
|
|
pkgs[i] = append(pkgs[i], name)
|
|
|
|
}
|
|
|
|
return pkgs, nil
|
|
|
|
}
|
2013-01-11 21:00:48 +00:00
|
|
|
|
2013-08-13 16:25:41 +00:00
|
|
|
type context struct {
|
2021-03-24 20:16:42 +00:00
|
|
|
GOOS string
|
|
|
|
GOARCH string
|
|
|
|
cgoEnabled bool
|
|
|
|
noOptEnv bool
|
2013-08-13 16:25:41 +00:00
|
|
|
}
|
|
|
|
|
2013-01-28 20:29:45 +00:00
|
|
|
// shouldTest looks for build tags in a source file and returns
|
|
|
|
// whether the file should be used according to the tags.
|
|
|
|
func shouldTest(src string, goos, goarch string) (ok bool, whyNot string) {
|
2015-10-26 21:34:06 +00:00
|
|
|
if *runSkips {
|
|
|
|
return true, ""
|
|
|
|
}
|
2013-01-28 20:29:45 +00:00
|
|
|
for _, line := range strings.Split(src, "\n") {
|
|
|
|
line = strings.TrimSpace(line)
|
|
|
|
if strings.HasPrefix(line, "//") {
|
|
|
|
line = line[2:]
|
|
|
|
} else {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
line = strings.TrimSpace(line)
|
|
|
|
if len(line) == 0 || line[0] != '+' {
|
|
|
|
continue
|
|
|
|
}
|
2018-09-24 16:48:54 +00:00
|
|
|
gcFlags := os.Getenv("GO_GCFLAGS")
|
2013-08-13 16:25:41 +00:00
|
|
|
ctxt := &context{
|
2021-03-24 20:16:42 +00:00
|
|
|
GOOS: goos,
|
|
|
|
GOARCH: goarch,
|
|
|
|
cgoEnabled: cgoEnabled,
|
|
|
|
noOptEnv: strings.Contains(gcFlags, "-N") || strings.Contains(gcFlags, "-l"),
|
2013-08-13 16:25:41 +00:00
|
|
|
}
|
2018-09-24 16:48:54 +00:00
|
|
|
|
2013-01-28 20:29:45 +00:00
|
|
|
words := strings.Fields(line)
|
|
|
|
if words[0] == "+build" {
|
2013-08-13 16:25:41 +00:00
|
|
|
ok := false
|
|
|
|
for _, word := range words[1:] {
|
|
|
|
if ctxt.match(word) {
|
|
|
|
ok = true
|
|
|
|
break
|
2013-01-28 20:29:45 +00:00
|
|
|
}
|
|
|
|
}
|
2013-08-13 16:25:41 +00:00
|
|
|
if !ok {
|
|
|
|
// no matching tag found.
|
|
|
|
return false, line
|
|
|
|
}
|
2013-01-28 20:29:45 +00:00
|
|
|
}
|
|
|
|
}
|
2013-08-13 16:25:41 +00:00
|
|
|
// no build tags
|
2013-01-28 20:29:45 +00:00
|
|
|
return true, ""
|
|
|
|
}
|
|
|
|
|
2013-08-13 16:25:41 +00:00
|
|
|
func (ctxt *context) match(name string) bool {
|
|
|
|
if name == "" {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if i := strings.Index(name, ","); i >= 0 {
|
|
|
|
// comma-separated list
|
|
|
|
return ctxt.match(name[:i]) && ctxt.match(name[i+1:])
|
|
|
|
}
|
|
|
|
if strings.HasPrefix(name, "!!") { // bad syntax, reject always
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if strings.HasPrefix(name, "!") { // negation
|
|
|
|
return len(name) > 1 && !ctxt.match(name[1:])
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tags must be letters, digits, underscores or dots.
|
|
|
|
// Unlike in Go identifiers, all digits are fine (e.g., "386").
|
|
|
|
for _, c := range name {
|
|
|
|
if !unicode.IsLetter(c) && !unicode.IsDigit(c) && c != '_' && c != '.' {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-14 17:25:31 +00:00
|
|
|
if strings.HasPrefix(name, "goexperiment.") {
|
2021-04-16 03:07:41 +00:00
|
|
|
for _, tag := range build.Default.ToolTags {
|
|
|
|
if tag == name {
|
|
|
|
return true
|
2021-02-24 17:55:52 +00:00
|
|
|
}
|
|
|
|
}
|
2021-04-16 03:07:41 +00:00
|
|
|
return false
|
2021-02-24 17:55:52 +00:00
|
|
|
}
|
|
|
|
|
2021-03-24 20:16:42 +00:00
|
|
|
if name == "cgo" && ctxt.cgoEnabled {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2020-12-17 22:03:07 +00:00
|
|
|
if name == ctxt.GOOS || name == ctxt.GOARCH || name == "gc" {
|
2013-08-13 16:25:41 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2018-09-24 16:48:54 +00:00
|
|
|
if ctxt.noOptEnv && name == "gcflags_noopt" {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2015-12-05 03:51:03 +00:00
|
|
|
if name == "test_run" {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2013-08-13 16:25:41 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2013-01-28 20:29:45 +00:00
|
|
|
func init() { checkShouldTest() }
|
|
|
|
|
2017-10-30 19:28:11 +00:00
|
|
|
// goGcflags returns the -gcflags argument to use with go build / go run.
|
2018-08-23 05:06:47 +00:00
|
|
|
// This must match the flags used for building the standard library,
|
2017-10-30 19:28:11 +00:00
|
|
|
// or else the commands will rebuild any needed packages (like runtime)
|
|
|
|
// over and over.
|
2021-05-17 20:59:25 +00:00
|
|
|
func (t *test) goGcflags() string {
|
|
|
|
flags := os.Getenv("GO_GCFLAGS")
|
2021-08-19 22:53:13 +00:00
|
|
|
if t.glevel != CompilerDefaultGLevel {
|
2021-05-17 20:59:25 +00:00
|
|
|
flags = fmt.Sprintf("%s -G=%v", flags, t.glevel)
|
|
|
|
}
|
|
|
|
return "-gcflags=all=" + flags
|
2017-10-30 19:28:11 +00:00
|
|
|
}
|
|
|
|
|
2021-05-17 20:59:25 +00:00
|
|
|
func (t *test) goGcflagsIsEmpty() bool {
|
2021-08-19 22:53:13 +00:00
|
|
|
return "" == os.Getenv("GO_GCFLAGS") && t.glevel == CompilerDefaultGLevel
|
2020-03-12 00:17:14 +00:00
|
|
|
}
|
|
|
|
|
2021-01-07 16:22:42 +00:00
|
|
|
var errTimeout = errors.New("command exceeded time limit")
|
|
|
|
|
2012-02-21 03:28:49 +00:00
|
|
|
// run runs a test.
|
|
|
|
func (t *test) run() {
|
2013-12-10 19:02:42 +00:00
|
|
|
start := time.Now()
|
|
|
|
defer func() {
|
|
|
|
t.dt = time.Since(start)
|
|
|
|
close(t.donec)
|
|
|
|
}()
|
2012-02-21 03:28:49 +00:00
|
|
|
|
|
|
|
srcBytes, err := ioutil.ReadFile(t.goFileName())
|
|
|
|
if err != nil {
|
|
|
|
t.err = err
|
|
|
|
return
|
|
|
|
}
|
|
|
|
t.src = string(srcBytes)
|
|
|
|
if t.src[0] == '\n' {
|
|
|
|
t.err = skipError("starts with newline")
|
|
|
|
return
|
|
|
|
}
|
2015-07-10 16:32:03 +00:00
|
|
|
|
|
|
|
// Execution recipe stops at first blank line.
|
2012-02-21 03:28:49 +00:00
|
|
|
pos := strings.Index(t.src, "\n\n")
|
|
|
|
if pos == -1 {
|
2021-01-04 19:05:17 +00:00
|
|
|
t.err = fmt.Errorf("double newline ending execution recipe not found in %s", t.goFileName())
|
2012-02-21 03:28:49 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
action := t.src[:pos]
|
2013-01-28 20:29:45 +00:00
|
|
|
if nl := strings.Index(action, "\n"); nl >= 0 && strings.Contains(action[:nl], "+build") {
|
|
|
|
// skip first line
|
|
|
|
action = action[nl+1:]
|
|
|
|
}
|
2020-02-09 06:40:45 +00:00
|
|
|
action = strings.TrimPrefix(action, "//")
|
2012-03-08 19:03:40 +00:00
|
|
|
|
2015-07-10 16:32:03 +00:00
|
|
|
// Check for build constraints only up to the actual code.
|
|
|
|
pkgPos := strings.Index(t.src, "\npackage")
|
|
|
|
if pkgPos == -1 {
|
|
|
|
pkgPos = pos // some files are intentionally malformed
|
|
|
|
}
|
|
|
|
if ok, why := shouldTest(t.src[:pkgPos], goos, goarch); !ok {
|
|
|
|
if *showSkips {
|
2016-09-22 17:50:16 +00:00
|
|
|
fmt.Printf("%-20s %-20s: %s\n", "skip", t.goFileName(), why)
|
2015-07-10 16:32:03 +00:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-03-18 15:35:45 +00:00
|
|
|
var args, flags, runenv []string
|
2016-11-10 21:03:47 +00:00
|
|
|
var tim int
|
2012-09-23 17:16:14 +00:00
|
|
|
wantError := false
|
2016-09-22 17:50:16 +00:00
|
|
|
wantAuto := false
|
2016-06-21 22:33:04 +00:00
|
|
|
singlefilepkgs := false
|
2019-03-22 19:24:36 +00:00
|
|
|
setpkgpaths := false
|
2018-05-30 16:46:59 +00:00
|
|
|
localImports := true
|
2021-06-11 16:54:40 +00:00
|
|
|
f, err := splitQuoted(action)
|
|
|
|
if err != nil {
|
|
|
|
t.err = fmt.Errorf("invalid test recipe: %v", err)
|
|
|
|
return
|
|
|
|
}
|
2012-03-07 06:54:39 +00:00
|
|
|
if len(f) > 0 {
|
|
|
|
action = f[0]
|
|
|
|
args = f[1:]
|
|
|
|
}
|
2012-02-21 03:28:49 +00:00
|
|
|
|
2016-06-21 22:33:04 +00:00
|
|
|
// TODO: Clean up/simplify this switch statement.
|
2012-02-21 03:28:49 +00:00
|
|
|
switch action {
|
2019-05-17 10:25:07 +00:00
|
|
|
case "compile", "compiledir", "build", "builddir", "buildrundir", "run", "buildrun", "runoutput", "rundir", "runindir", "asmcheck":
|
2016-09-22 17:50:16 +00:00
|
|
|
// nothing to do
|
2016-03-11 05:10:52 +00:00
|
|
|
case "errorcheckandrundir":
|
|
|
|
wantError = false // should be no error if also will run
|
2016-09-22 17:50:16 +00:00
|
|
|
case "errorcheckwithauto":
|
|
|
|
action = "errorcheck"
|
|
|
|
wantAuto = true
|
|
|
|
wantError = true
|
2012-11-07 20:33:54 +00:00
|
|
|
case "errorcheck", "errorcheckdir", "errorcheckoutput":
|
2012-09-23 17:16:14 +00:00
|
|
|
wantError = true
|
2012-03-21 18:14:44 +00:00
|
|
|
case "skip":
|
2015-10-26 21:34:06 +00:00
|
|
|
if *runSkips {
|
|
|
|
break
|
|
|
|
}
|
2012-03-21 18:14:44 +00:00
|
|
|
return
|
2012-02-21 03:28:49 +00:00
|
|
|
default:
|
|
|
|
t.err = skipError("skipped; unknown pattern: " + action)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-07-02 22:42:20 +00:00
|
|
|
goexp := env.GOEXPERIMENT
|
|
|
|
|
2016-06-21 22:33:04 +00:00
|
|
|
// collect flags
|
|
|
|
for len(args) > 0 && strings.HasPrefix(args[0], "-") {
|
|
|
|
switch args[0] {
|
2018-05-26 09:57:50 +00:00
|
|
|
case "-1":
|
|
|
|
wantError = true
|
2016-06-21 22:33:04 +00:00
|
|
|
case "-0":
|
|
|
|
wantError = false
|
|
|
|
case "-s":
|
|
|
|
singlefilepkgs = true
|
2019-03-22 19:24:36 +00:00
|
|
|
case "-P":
|
|
|
|
setpkgpaths = true
|
2018-05-30 16:46:59 +00:00
|
|
|
case "-n":
|
|
|
|
// Do not set relative path for local imports to current dir,
|
|
|
|
// e.g. do not pass -D . -I . to the compiler.
|
|
|
|
// Used in fixedbugs/bug345.go to allow compilation and import of local pkg.
|
|
|
|
// See golang.org/issue/25635
|
|
|
|
localImports = false
|
2016-11-10 21:03:47 +00:00
|
|
|
case "-t": // timeout in seconds
|
|
|
|
args = args[1:]
|
|
|
|
var err error
|
|
|
|
tim, err = strconv.Atoi(args[0])
|
|
|
|
if err != nil {
|
|
|
|
t.err = fmt.Errorf("need number of seconds for -t timeout, got %s instead", args[0])
|
|
|
|
}
|
2021-03-18 15:35:45 +00:00
|
|
|
case "-goexperiment": // set GOEXPERIMENT environment
|
|
|
|
args = args[1:]
|
2021-07-02 22:42:20 +00:00
|
|
|
if goexp != "" {
|
|
|
|
goexp += ","
|
|
|
|
}
|
|
|
|
goexp += args[0]
|
|
|
|
runenv = append(runenv, "GOEXPERIMENT="+goexp)
|
2016-11-10 21:03:47 +00:00
|
|
|
|
2016-06-21 22:33:04 +00:00
|
|
|
default:
|
|
|
|
flags = append(flags, args[0])
|
|
|
|
}
|
|
|
|
args = args[1:]
|
|
|
|
}
|
2016-12-05 23:41:04 +00:00
|
|
|
if action == "errorcheck" {
|
|
|
|
found := false
|
|
|
|
for i, f := range flags {
|
|
|
|
if strings.HasPrefix(f, "-d=") {
|
|
|
|
flags[i] = f + ",ssa/check/on"
|
|
|
|
found = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !found {
|
|
|
|
flags = append(flags, "-d=ssa/check/on")
|
|
|
|
}
|
|
|
|
}
|
2016-06-21 22:33:04 +00:00
|
|
|
|
2021-05-17 20:59:25 +00:00
|
|
|
type Tool int
|
|
|
|
|
|
|
|
const (
|
|
|
|
_ Tool = iota
|
|
|
|
AsmCheck
|
|
|
|
Build
|
|
|
|
Run
|
|
|
|
Compile
|
|
|
|
)
|
|
|
|
|
[dev.typeparams] test: fix and update run.go's generics testing
In a late change to golang.org/cl/320609, while going back and forth
on the meaning of the boolean result value for "checkFlags", I got one
of the cases wrong. As a result, rather than testing both default
flags and -G=3, we were (redundanly) testing default flags and -G=0.
I ran into this because in my local dev tree, I'm using types2 even
for -G=0, and evidently one of the recent types2 CLs changed the error
message in fixedbugs/issue10975.go. Fortunately, there haven't been
any other regressions despite lacking test coverage.
So this CL cleans things up a bit:
1. Fixes that test to use -lang=go1.17, so types2 reports the old
error message again.
2. Renames "checkFlags" to "validForGLevel" so the boolean result is
harder to get wrong.
3. Removes the blanket deny list of all -m tests, and instead adds the
specific tests that are still failing. This effectively extends -G=3
coverage to another 27 tests that were using -m but already passing,
so we can make sure they don't regress again.
4. Adds a -f flag to force running tests even if they're in the deny
list, to make it easier to test whether they're still failing without
having to edit run.go.
Change-Id: I058d9d90d81a92189e54c6f591d95fb617fede53
Reviewed-on: https://go-review.googlesource.com/c/go/+/322612
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-05-25 21:06:56 +00:00
|
|
|
// validForGLevel reports whether the current test is valid to run
|
|
|
|
// at the specified -G level. If so, it may update flags as
|
|
|
|
// necessary to test with -G.
|
|
|
|
validForGLevel := func(tool Tool) bool {
|
2021-06-17 04:41:28 +00:00
|
|
|
hasGFlag := false
|
[dev.typeparams] test: fix and update run.go's generics testing
In a late change to golang.org/cl/320609, while going back and forth
on the meaning of the boolean result value for "checkFlags", I got one
of the cases wrong. As a result, rather than testing both default
flags and -G=3, we were (redundanly) testing default flags and -G=0.
I ran into this because in my local dev tree, I'm using types2 even
for -G=0, and evidently one of the recent types2 CLs changed the error
message in fixedbugs/issue10975.go. Fortunately, there haven't been
any other regressions despite lacking test coverage.
So this CL cleans things up a bit:
1. Fixes that test to use -lang=go1.17, so types2 reports the old
error message again.
2. Renames "checkFlags" to "validForGLevel" so the boolean result is
harder to get wrong.
3. Removes the blanket deny list of all -m tests, and instead adds the
specific tests that are still failing. This effectively extends -G=3
coverage to another 27 tests that were using -m but already passing,
so we can make sure they don't regress again.
4. Adds a -f flag to force running tests even if they're in the deny
list, to make it easier to test whether they're still failing without
having to edit run.go.
Change-Id: I058d9d90d81a92189e54c6f591d95fb617fede53
Reviewed-on: https://go-review.googlesource.com/c/go/+/322612
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-05-25 21:06:56 +00:00
|
|
|
for _, flag := range flags {
|
|
|
|
if strings.Contains(flag, "-G") {
|
2021-06-17 04:41:28 +00:00
|
|
|
hasGFlag = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-02 04:06:27 +00:00
|
|
|
// In unified IR mode, run the test regardless of explicit -G flag.
|
|
|
|
if !unifiedEnabled && hasGFlag && t.glevel != CompilerDefaultGLevel {
|
2021-06-17 04:41:28 +00:00
|
|
|
// test provides explicit -G flag already; don't run again
|
|
|
|
if *verbose {
|
|
|
|
fmt.Printf("excl\t%s\n", t.goFileName())
|
[dev.typeparams] test: fix and update run.go's generics testing
In a late change to golang.org/cl/320609, while going back and forth
on the meaning of the boolean result value for "checkFlags", I got one
of the cases wrong. As a result, rather than testing both default
flags and -G=3, we were (redundanly) testing default flags and -G=0.
I ran into this because in my local dev tree, I'm using types2 even
for -G=0, and evidently one of the recent types2 CLs changed the error
message in fixedbugs/issue10975.go. Fortunately, there haven't been
any other regressions despite lacking test coverage.
So this CL cleans things up a bit:
1. Fixes that test to use -lang=go1.17, so types2 reports the old
error message again.
2. Renames "checkFlags" to "validForGLevel" so the boolean result is
harder to get wrong.
3. Removes the blanket deny list of all -m tests, and instead adds the
specific tests that are still failing. This effectively extends -G=3
coverage to another 27 tests that were using -m but already passing,
so we can make sure they don't regress again.
4. Adds a -f flag to force running tests even if they're in the deny
list, to make it easier to test whether they're still failing without
having to edit run.go.
Change-Id: I058d9d90d81a92189e54c6f591d95fb617fede53
Reviewed-on: https://go-review.googlesource.com/c/go/+/322612
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-05-25 21:06:56 +00:00
|
|
|
}
|
2021-06-17 04:41:28 +00:00
|
|
|
return false
|
[dev.typeparams] test: fix and update run.go's generics testing
In a late change to golang.org/cl/320609, while going back and forth
on the meaning of the boolean result value for "checkFlags", I got one
of the cases wrong. As a result, rather than testing both default
flags and -G=3, we were (redundanly) testing default flags and -G=0.
I ran into this because in my local dev tree, I'm using types2 even
for -G=0, and evidently one of the recent types2 CLs changed the error
message in fixedbugs/issue10975.go. Fortunately, there haven't been
any other regressions despite lacking test coverage.
So this CL cleans things up a bit:
1. Fixes that test to use -lang=go1.17, so types2 reports the old
error message again.
2. Renames "checkFlags" to "validForGLevel" so the boolean result is
harder to get wrong.
3. Removes the blanket deny list of all -m tests, and instead adds the
specific tests that are still failing. This effectively extends -G=3
coverage to another 27 tests that were using -m but already passing,
so we can make sure they don't regress again.
4. Adds a -f flag to force running tests even if they're in the deny
list, to make it easier to test whether they're still failing without
having to edit run.go.
Change-Id: I058d9d90d81a92189e54c6f591d95fb617fede53
Reviewed-on: https://go-review.googlesource.com/c/go/+/322612
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-05-25 21:06:56 +00:00
|
|
|
}
|
|
|
|
|
2021-08-19 22:53:13 +00:00
|
|
|
t.initExpectFail(hasGFlag)
|
2021-07-02 20:18:03 +00:00
|
|
|
|
2021-05-17 20:59:25 +00:00
|
|
|
switch tool {
|
|
|
|
case Build, Run:
|
|
|
|
// ok; handled in goGcflags
|
|
|
|
|
|
|
|
case Compile:
|
2021-06-17 04:41:28 +00:00
|
|
|
if !hasGFlag {
|
|
|
|
flags = append(flags, fmt.Sprintf("-G=%v", t.glevel))
|
|
|
|
}
|
2021-05-17 20:59:25 +00:00
|
|
|
|
|
|
|
default:
|
2021-09-08 21:03:53 +00:00
|
|
|
if t.glevel != CompilerDefaultGLevel {
|
|
|
|
// we don't know how to add -G for this test yet
|
|
|
|
if *verbose {
|
|
|
|
fmt.Printf("excl\t%s\n", t.goFileName())
|
|
|
|
}
|
|
|
|
return false
|
[dev.typeparams] test: fix and update run.go's generics testing
In a late change to golang.org/cl/320609, while going back and forth
on the meaning of the boolean result value for "checkFlags", I got one
of the cases wrong. As a result, rather than testing both default
flags and -G=3, we were (redundanly) testing default flags and -G=0.
I ran into this because in my local dev tree, I'm using types2 even
for -G=0, and evidently one of the recent types2 CLs changed the error
message in fixedbugs/issue10975.go. Fortunately, there haven't been
any other regressions despite lacking test coverage.
So this CL cleans things up a bit:
1. Fixes that test to use -lang=go1.17, so types2 reports the old
error message again.
2. Renames "checkFlags" to "validForGLevel" so the boolean result is
harder to get wrong.
3. Removes the blanket deny list of all -m tests, and instead adds the
specific tests that are still failing. This effectively extends -G=3
coverage to another 27 tests that were using -m but already passing,
so we can make sure they don't regress again.
4. Adds a -f flag to force running tests even if they're in the deny
list, to make it easier to test whether they're still failing without
having to edit run.go.
Change-Id: I058d9d90d81a92189e54c6f591d95fb617fede53
Reviewed-on: https://go-review.googlesource.com/c/go/+/322612
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-05-25 21:06:56 +00:00
|
|
|
}
|
2021-05-17 20:59:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2012-02-21 03:28:49 +00:00
|
|
|
t.makeTempDir()
|
2016-03-11 05:10:52 +00:00
|
|
|
if !*keep {
|
|
|
|
defer os.RemoveAll(t.tempDir)
|
|
|
|
}
|
2012-02-21 03:28:49 +00:00
|
|
|
|
|
|
|
err = ioutil.WriteFile(filepath.Join(t.tempDir, t.gofile), srcBytes, 0644)
|
2020-02-09 06:40:45 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2012-03-08 19:03:40 +00:00
|
|
|
|
2012-03-07 07:22:08 +00:00
|
|
|
// A few tests (of things like the environment) require these to be set.
|
all: merge NaCl branch (part 1)
See golang.org/s/go13nacl for design overview.
This CL is the mostly mechanical changes from rsc's Go 1.2 based NaCl branch, specifically 39cb35750369 to 500771b477cf from https://code.google.com/r/rsc-go13nacl. This CL does not include working NaCl support, there are probably two or three more large merges to come.
CL 15750044 is not included as it involves more invasive changes to the linker which will need to be merged separately.
The exact change lists included are
15050047: syscall: support for Native Client
15360044: syscall: unzip implementation for Native Client
15370044: syscall: Native Client SRPC implementation
15400047: cmd/dist, cmd/go, go/build, test: support for Native Client
15410048: runtime: support for Native Client
15410049: syscall: file descriptor table for Native Client
15410050: syscall: in-memory file system for Native Client
15440048: all: update +build lines for Native Client port
15540045: cmd/6g, cmd/8g, cmd/gc: support for Native Client
15570045: os: support for Native Client
15680044: crypto/..., hash/crc32, reflect, sync/atomic: support for amd64p32
15690044: net: support for Native Client
15690048: runtime: support for fake time like on Go Playground
15690051: build: disable various tests on Native Client
LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/68150047
2014-02-25 14:47:42 +00:00
|
|
|
if os.Getenv("GOOS") == "" {
|
|
|
|
os.Setenv("GOOS", runtime.GOOS)
|
|
|
|
}
|
|
|
|
if os.Getenv("GOARCH") == "" {
|
|
|
|
os.Setenv("GOARCH", runtime.GOARCH)
|
|
|
|
}
|
2012-03-07 07:22:08 +00:00
|
|
|
|
2020-03-24 20:18:02 +00:00
|
|
|
var (
|
|
|
|
runInDir = t.tempDir
|
|
|
|
tempDirIsGOPATH = false
|
|
|
|
)
|
2012-03-07 06:54:39 +00:00
|
|
|
runcmd := func(args ...string) ([]byte, error) {
|
|
|
|
cmd := exec.Command(args[0], args[1:]...)
|
|
|
|
var buf bytes.Buffer
|
|
|
|
cmd.Stdout = &buf
|
|
|
|
cmd.Stderr = &buf
|
2020-03-24 20:18:02 +00:00
|
|
|
cmd.Env = append(os.Environ(), "GOENV=off", "GOFLAGS=")
|
|
|
|
if runInDir != "" {
|
|
|
|
cmd.Dir = runInDir
|
|
|
|
// Set PWD to match Dir to speed up os.Getwd in the child process.
|
|
|
|
cmd.Env = append(cmd.Env, "PWD="+cmd.Dir)
|
2019-05-17 10:25:07 +00:00
|
|
|
}
|
2020-03-24 20:18:02 +00:00
|
|
|
if tempDirIsGOPATH {
|
|
|
|
cmd.Env = append(cmd.Env, "GOPATH="+t.tempDir)
|
2015-09-07 02:39:07 +00:00
|
|
|
}
|
2021-03-18 15:35:45 +00:00
|
|
|
cmd.Env = append(cmd.Env, runenv...)
|
2016-11-10 21:03:47 +00:00
|
|
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
if tim != 0 {
|
|
|
|
err = cmd.Start()
|
|
|
|
// This command-timeout code adapted from cmd/go/test.go
|
|
|
|
if err == nil {
|
|
|
|
tick := time.NewTimer(time.Duration(tim) * time.Second)
|
|
|
|
done := make(chan error)
|
|
|
|
go func() {
|
|
|
|
done <- cmd.Wait()
|
|
|
|
}()
|
|
|
|
select {
|
|
|
|
case err = <-done:
|
|
|
|
// ok
|
|
|
|
case <-tick.C:
|
2021-01-07 16:22:42 +00:00
|
|
|
cmd.Process.Signal(os.Interrupt)
|
|
|
|
time.Sleep(1 * time.Second)
|
2016-11-10 21:03:47 +00:00
|
|
|
cmd.Process.Kill()
|
2021-01-07 16:22:42 +00:00
|
|
|
<-done
|
|
|
|
err = errTimeout
|
2016-11-10 21:03:47 +00:00
|
|
|
}
|
|
|
|
tick.Stop()
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
err = cmd.Run()
|
|
|
|
}
|
2021-01-07 16:22:42 +00:00
|
|
|
if err != nil && err != errTimeout {
|
2012-10-06 07:23:31 +00:00
|
|
|
err = fmt.Errorf("%s\n%s", err, buf.Bytes())
|
|
|
|
}
|
2012-03-07 06:54:39 +00:00
|
|
|
return buf.Bytes(), err
|
2012-02-21 03:28:49 +00:00
|
|
|
}
|
|
|
|
|
2012-03-07 06:54:39 +00:00
|
|
|
long := filepath.Join(cwd, t.goFileName())
|
2012-03-08 19:03:40 +00:00
|
|
|
switch action {
|
2012-03-07 06:54:39 +00:00
|
|
|
default:
|
|
|
|
t.err = fmt.Errorf("unimplemented action %q", action)
|
2012-02-21 03:28:49 +00:00
|
|
|
|
2018-02-27 00:59:58 +00:00
|
|
|
case "asmcheck":
|
[dev.typeparams] test: fix and update run.go's generics testing
In a late change to golang.org/cl/320609, while going back and forth
on the meaning of the boolean result value for "checkFlags", I got one
of the cases wrong. As a result, rather than testing both default
flags and -G=3, we were (redundanly) testing default flags and -G=0.
I ran into this because in my local dev tree, I'm using types2 even
for -G=0, and evidently one of the recent types2 CLs changed the error
message in fixedbugs/issue10975.go. Fortunately, there haven't been
any other regressions despite lacking test coverage.
So this CL cleans things up a bit:
1. Fixes that test to use -lang=go1.17, so types2 reports the old
error message again.
2. Renames "checkFlags" to "validForGLevel" so the boolean result is
harder to get wrong.
3. Removes the blanket deny list of all -m tests, and instead adds the
specific tests that are still failing. This effectively extends -G=3
coverage to another 27 tests that were using -m but already passing,
so we can make sure they don't regress again.
4. Adds a -f flag to force running tests even if they're in the deny
list, to make it easier to test whether they're still failing without
having to edit run.go.
Change-Id: I058d9d90d81a92189e54c6f591d95fb617fede53
Reviewed-on: https://go-review.googlesource.com/c/go/+/322612
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-05-25 21:06:56 +00:00
|
|
|
if !validForGLevel(AsmCheck) {
|
2021-05-17 20:59:25 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-06-01 10:14:48 +00:00
|
|
|
// Compile Go file and match the generated assembly
|
|
|
|
// against a set of regexps in comments.
|
2018-04-15 17:00:27 +00:00
|
|
|
ops := t.wantedAsmOpcodes(long)
|
2019-05-16 04:12:34 +00:00
|
|
|
self := runtime.GOOS + "/" + runtime.GOARCH
|
2018-04-15 17:00:27 +00:00
|
|
|
for _, env := range ops.Envs() {
|
2019-05-16 04:12:34 +00:00
|
|
|
// Only run checks relevant to the current GOOS/GOARCH,
|
|
|
|
// to avoid triggering a cross-compile of the runtime.
|
|
|
|
if string(env) != self && !strings.HasPrefix(string(env), self+"/") && !*allCodegen {
|
|
|
|
continue
|
|
|
|
}
|
2018-12-07 18:00:36 +00:00
|
|
|
// -S=2 forces outermost line numbers when disassembling inlined code.
|
|
|
|
cmdline := []string{"build", "-gcflags", "-S=2"}
|
2020-03-10 17:45:19 +00:00
|
|
|
|
|
|
|
// Append flags, but don't override -gcflags=-S=2; add to it instead.
|
|
|
|
for i := 0; i < len(flags); i++ {
|
|
|
|
flag := flags[i]
|
|
|
|
switch {
|
|
|
|
case strings.HasPrefix(flag, "-gcflags="):
|
|
|
|
cmdline[2] += " " + strings.TrimPrefix(flag, "-gcflags=")
|
|
|
|
case strings.HasPrefix(flag, "--gcflags="):
|
|
|
|
cmdline[2] += " " + strings.TrimPrefix(flag, "--gcflags=")
|
|
|
|
case flag == "-gcflags", flag == "--gcflags":
|
|
|
|
i++
|
|
|
|
if i < len(flags) {
|
|
|
|
cmdline[2] += " " + flags[i]
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
cmdline = append(cmdline, flag)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-27 00:59:58 +00:00
|
|
|
cmdline = append(cmdline, long)
|
2018-03-29 16:52:12 +00:00
|
|
|
cmd := exec.Command(goTool(), cmdline...)
|
2018-04-15 17:00:27 +00:00
|
|
|
cmd.Env = append(os.Environ(), env.Environ()...)
|
2019-04-03 20:16:58 +00:00
|
|
|
if len(flags) > 0 && flags[0] == "-race" {
|
|
|
|
cmd.Env = append(cmd.Env, "CGO_ENABLED=1")
|
|
|
|
}
|
2018-03-29 16:52:12 +00:00
|
|
|
|
|
|
|
var buf bytes.Buffer
|
|
|
|
cmd.Stdout, cmd.Stderr = &buf, &buf
|
|
|
|
if err := cmd.Run(); err != nil {
|
2018-04-25 18:52:06 +00:00
|
|
|
fmt.Println(env, "\n", cmd.Stderr)
|
2018-02-27 00:59:58 +00:00
|
|
|
t.err = err
|
|
|
|
return
|
|
|
|
}
|
2018-03-29 16:52:12 +00:00
|
|
|
|
2018-04-15 17:00:27 +00:00
|
|
|
t.err = t.asmCheck(buf.String(), long, env, ops[env])
|
2018-02-27 00:59:58 +00:00
|
|
|
if t.err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
|
2012-03-07 06:54:39 +00:00
|
|
|
case "errorcheck":
|
[dev.typeparams] test: fix and update run.go's generics testing
In a late change to golang.org/cl/320609, while going back and forth
on the meaning of the boolean result value for "checkFlags", I got one
of the cases wrong. As a result, rather than testing both default
flags and -G=3, we were (redundanly) testing default flags and -G=0.
I ran into this because in my local dev tree, I'm using types2 even
for -G=0, and evidently one of the recent types2 CLs changed the error
message in fixedbugs/issue10975.go. Fortunately, there haven't been
any other regressions despite lacking test coverage.
So this CL cleans things up a bit:
1. Fixes that test to use -lang=go1.17, so types2 reports the old
error message again.
2. Renames "checkFlags" to "validForGLevel" so the boolean result is
harder to get wrong.
3. Removes the blanket deny list of all -m tests, and instead adds the
specific tests that are still failing. This effectively extends -G=3
coverage to another 27 tests that were using -m but already passing,
so we can make sure they don't regress again.
4. Adds a -f flag to force running tests even if they're in the deny
list, to make it easier to test whether they're still failing without
having to edit run.go.
Change-Id: I058d9d90d81a92189e54c6f591d95fb617fede53
Reviewed-on: https://go-review.googlesource.com/c/go/+/322612
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-05-25 21:06:56 +00:00
|
|
|
if !validForGLevel(Compile) {
|
2021-05-17 20:59:25 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-06-01 10:14:48 +00:00
|
|
|
// Compile Go file.
|
|
|
|
// Fail if wantError is true and compilation was successful and vice versa.
|
|
|
|
// Match errors produced by gc against errors in comments.
|
2017-03-08 22:26:23 +00:00
|
|
|
// TODO(gri) remove need for -C (disable printing of columns in error messages)
|
2021-03-04 15:31:43 +00:00
|
|
|
cmdline := []string{goTool(), "tool", "compile", "-d=panic", "-C", "-e", "-o", "a.o"}
|
2015-10-27 01:54:19 +00:00
|
|
|
// No need to add -dynlink even if linkshared if we're just checking for errors...
|
2012-09-23 17:16:14 +00:00
|
|
|
cmdline = append(cmdline, flags...)
|
|
|
|
cmdline = append(cmdline, long)
|
|
|
|
out, err := runcmd(cmdline...)
|
|
|
|
if wantError {
|
|
|
|
if err == nil {
|
|
|
|
t.err = fmt.Errorf("compilation succeeded unexpectedly\n%s", out)
|
|
|
|
return
|
|
|
|
}
|
2021-01-07 16:22:42 +00:00
|
|
|
if err == errTimeout {
|
|
|
|
t.err = fmt.Errorf("compilation timed out")
|
|
|
|
return
|
|
|
|
}
|
2012-09-23 17:16:14 +00:00
|
|
|
} else {
|
|
|
|
if err != nil {
|
2012-10-06 07:23:31 +00:00
|
|
|
t.err = err
|
2012-09-23 17:16:14 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2015-02-19 19:00:11 +00:00
|
|
|
if *updateErrors {
|
|
|
|
t.updateErrors(string(out), long)
|
|
|
|
}
|
2016-09-22 17:50:16 +00:00
|
|
|
t.err = t.errorCheck(string(out), wantAuto, long, t.gofile)
|
2020-12-01 05:38:49 +00:00
|
|
|
|
2021-05-17 20:59:25 +00:00
|
|
|
case "compile":
|
[dev.typeparams] test: fix and update run.go's generics testing
In a late change to golang.org/cl/320609, while going back and forth
on the meaning of the boolean result value for "checkFlags", I got one
of the cases wrong. As a result, rather than testing both default
flags and -G=3, we were (redundanly) testing default flags and -G=0.
I ran into this because in my local dev tree, I'm using types2 even
for -G=0, and evidently one of the recent types2 CLs changed the error
message in fixedbugs/issue10975.go. Fortunately, there haven't been
any other regressions despite lacking test coverage.
So this CL cleans things up a bit:
1. Fixes that test to use -lang=go1.17, so types2 reports the old
error message again.
2. Renames "checkFlags" to "validForGLevel" so the boolean result is
harder to get wrong.
3. Removes the blanket deny list of all -m tests, and instead adds the
specific tests that are still failing. This effectively extends -G=3
coverage to another 27 tests that were using -m but already passing,
so we can make sure they don't regress again.
4. Adds a -f flag to force running tests even if they're in the deny
list, to make it easier to test whether they're still failing without
having to edit run.go.
Change-Id: I058d9d90d81a92189e54c6f591d95fb617fede53
Reviewed-on: https://go-review.googlesource.com/c/go/+/322612
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-05-25 21:06:56 +00:00
|
|
|
if !validForGLevel(Compile) {
|
2021-05-17 20:59:25 +00:00
|
|
|
return
|
2020-12-01 05:38:49 +00:00
|
|
|
}
|
2012-03-08 19:03:40 +00:00
|
|
|
|
2018-06-01 10:14:48 +00:00
|
|
|
// Compile Go file.
|
2017-04-28 14:28:49 +00:00
|
|
|
_, t.err = compileFile(runcmd, long, flags)
|
2012-03-08 19:03:40 +00:00
|
|
|
|
2012-07-30 19:12:05 +00:00
|
|
|
case "compiledir":
|
[dev.typeparams] test: fix and update run.go's generics testing
In a late change to golang.org/cl/320609, while going back and forth
on the meaning of the boolean result value for "checkFlags", I got one
of the cases wrong. As a result, rather than testing both default
flags and -G=3, we were (redundanly) testing default flags and -G=0.
I ran into this because in my local dev tree, I'm using types2 even
for -G=0, and evidently one of the recent types2 CLs changed the error
message in fixedbugs/issue10975.go. Fortunately, there haven't been
any other regressions despite lacking test coverage.
So this CL cleans things up a bit:
1. Fixes that test to use -lang=go1.17, so types2 reports the old
error message again.
2. Renames "checkFlags" to "validForGLevel" so the boolean result is
harder to get wrong.
3. Removes the blanket deny list of all -m tests, and instead adds the
specific tests that are still failing. This effectively extends -G=3
coverage to another 27 tests that were using -m but already passing,
so we can make sure they don't regress again.
4. Adds a -f flag to force running tests even if they're in the deny
list, to make it easier to test whether they're still failing without
having to edit run.go.
Change-Id: I058d9d90d81a92189e54c6f591d95fb617fede53
Reviewed-on: https://go-review.googlesource.com/c/go/+/322612
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-05-25 21:06:56 +00:00
|
|
|
if !validForGLevel(Compile) {
|
2021-05-17 20:59:25 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-06-01 10:14:48 +00:00
|
|
|
// Compile all files in the directory as packages in lexicographic order.
|
2012-07-30 19:12:05 +00:00
|
|
|
longdir := filepath.Join(cwd, t.goDirName())
|
2016-06-21 22:33:04 +00:00
|
|
|
pkgs, err := goDirPackages(longdir, singlefilepkgs)
|
2012-10-06 07:23:31 +00:00
|
|
|
if err != nil {
|
|
|
|
t.err = err
|
2012-07-30 19:12:05 +00:00
|
|
|
return
|
|
|
|
}
|
2013-01-02 20:31:49 +00:00
|
|
|
for _, gofiles := range pkgs {
|
2018-05-30 16:46:59 +00:00
|
|
|
_, t.err = compileInDir(runcmd, longdir, flags, localImports, gofiles...)
|
2012-10-06 07:23:31 +00:00
|
|
|
if t.err != nil {
|
|
|
|
return
|
2012-08-06 04:56:39 +00:00
|
|
|
}
|
2012-10-06 07:23:31 +00:00
|
|
|
}
|
|
|
|
|
2016-03-11 05:10:52 +00:00
|
|
|
case "errorcheckdir", "errorcheckandrundir":
|
[dev.typeparams] test: fix and update run.go's generics testing
In a late change to golang.org/cl/320609, while going back and forth
on the meaning of the boolean result value for "checkFlags", I got one
of the cases wrong. As a result, rather than testing both default
flags and -G=3, we were (redundanly) testing default flags and -G=0.
I ran into this because in my local dev tree, I'm using types2 even
for -G=0, and evidently one of the recent types2 CLs changed the error
message in fixedbugs/issue10975.go. Fortunately, there haven't been
any other regressions despite lacking test coverage.
So this CL cleans things up a bit:
1. Fixes that test to use -lang=go1.17, so types2 reports the old
error message again.
2. Renames "checkFlags" to "validForGLevel" so the boolean result is
harder to get wrong.
3. Removes the blanket deny list of all -m tests, and instead adds the
specific tests that are still failing. This effectively extends -G=3
coverage to another 27 tests that were using -m but already passing,
so we can make sure they don't regress again.
4. Adds a -f flag to force running tests even if they're in the deny
list, to make it easier to test whether they're still failing without
having to edit run.go.
Change-Id: I058d9d90d81a92189e54c6f591d95fb617fede53
Reviewed-on: https://go-review.googlesource.com/c/go/+/322612
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-05-25 21:06:56 +00:00
|
|
|
if !validForGLevel(Compile) {
|
2021-05-17 20:59:25 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-03-04 15:31:43 +00:00
|
|
|
flags = append(flags, "-d=panic")
|
2018-06-01 10:14:48 +00:00
|
|
|
// Compile and errorCheck all files in the directory as packages in lexicographic order.
|
|
|
|
// If errorcheckdir and wantError, compilation of the last package must fail.
|
|
|
|
// If errorcheckandrundir and wantError, compilation of the package prior the last must fail.
|
2012-10-06 07:23:31 +00:00
|
|
|
longdir := filepath.Join(cwd, t.goDirName())
|
2016-06-21 22:33:04 +00:00
|
|
|
pkgs, err := goDirPackages(longdir, singlefilepkgs)
|
2012-10-06 07:23:31 +00:00
|
|
|
if err != nil {
|
|
|
|
t.err = err
|
|
|
|
return
|
|
|
|
}
|
2018-05-26 09:57:50 +00:00
|
|
|
errPkg := len(pkgs) - 1
|
|
|
|
if wantError && action == "errorcheckandrundir" {
|
|
|
|
// The last pkg should compiled successfully and will be run in next case.
|
|
|
|
// Preceding pkg must return an error from compileInDir.
|
|
|
|
errPkg--
|
|
|
|
}
|
2013-01-02 20:31:49 +00:00
|
|
|
for i, gofiles := range pkgs {
|
2018-05-30 16:46:59 +00:00
|
|
|
out, err := compileInDir(runcmd, longdir, flags, localImports, gofiles...)
|
2018-05-26 09:57:50 +00:00
|
|
|
if i == errPkg {
|
2012-10-06 07:23:31 +00:00
|
|
|
if wantError && err == nil {
|
|
|
|
t.err = fmt.Errorf("compilation succeeded unexpectedly\n%s", out)
|
|
|
|
return
|
|
|
|
} else if !wantError && err != nil {
|
|
|
|
t.err = err
|
|
|
|
return
|
|
|
|
}
|
|
|
|
} else if err != nil {
|
|
|
|
t.err = err
|
|
|
|
return
|
|
|
|
}
|
2013-01-02 20:31:49 +00:00
|
|
|
var fullshort []string
|
|
|
|
for _, name := range gofiles {
|
|
|
|
fullshort = append(fullshort, filepath.Join(longdir, name), name)
|
|
|
|
}
|
2016-09-22 17:50:16 +00:00
|
|
|
t.err = t.errorCheck(string(out), wantAuto, fullshort...)
|
2012-10-06 07:23:31 +00:00
|
|
|
if t.err != nil {
|
2012-07-30 19:12:05 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2016-03-11 05:10:52 +00:00
|
|
|
if action == "errorcheckdir" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
fallthrough
|
2012-07-30 19:12:05 +00:00
|
|
|
|
2012-10-06 07:23:31 +00:00
|
|
|
case "rundir":
|
[dev.typeparams] test: fix and update run.go's generics testing
In a late change to golang.org/cl/320609, while going back and forth
on the meaning of the boolean result value for "checkFlags", I got one
of the cases wrong. As a result, rather than testing both default
flags and -G=3, we were (redundanly) testing default flags and -G=0.
I ran into this because in my local dev tree, I'm using types2 even
for -G=0, and evidently one of the recent types2 CLs changed the error
message in fixedbugs/issue10975.go. Fortunately, there haven't been
any other regressions despite lacking test coverage.
So this CL cleans things up a bit:
1. Fixes that test to use -lang=go1.17, so types2 reports the old
error message again.
2. Renames "checkFlags" to "validForGLevel" so the boolean result is
harder to get wrong.
3. Removes the blanket deny list of all -m tests, and instead adds the
specific tests that are still failing. This effectively extends -G=3
coverage to another 27 tests that were using -m but already passing,
so we can make sure they don't regress again.
4. Adds a -f flag to force running tests even if they're in the deny
list, to make it easier to test whether they're still failing without
having to edit run.go.
Change-Id: I058d9d90d81a92189e54c6f591d95fb617fede53
Reviewed-on: https://go-review.googlesource.com/c/go/+/322612
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-05-25 21:06:56 +00:00
|
|
|
if !validForGLevel(Run) {
|
2021-05-17 20:59:25 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-06-01 10:14:48 +00:00
|
|
|
// Compile all files in the directory as packages in lexicographic order.
|
|
|
|
// In case of errorcheckandrundir, ignore failed compilation of the package before the last.
|
|
|
|
// Link as if the last file is the main package, run it.
|
|
|
|
// Verify the expected output.
|
2012-10-06 07:23:31 +00:00
|
|
|
longdir := filepath.Join(cwd, t.goDirName())
|
2016-06-21 22:33:04 +00:00
|
|
|
pkgs, err := goDirPackages(longdir, singlefilepkgs)
|
2012-10-06 07:23:31 +00:00
|
|
|
if err != nil {
|
|
|
|
t.err = err
|
|
|
|
return
|
|
|
|
}
|
2019-03-22 19:24:36 +00:00
|
|
|
// Split flags into gcflags and ldflags
|
|
|
|
ldflags := []string{}
|
|
|
|
for i, fl := range flags {
|
|
|
|
if fl == "-ldflags" {
|
|
|
|
ldflags = flags[i+1:]
|
|
|
|
flags = flags[0:i]
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-11 21:00:48 +00:00
|
|
|
for i, gofiles := range pkgs {
|
2019-03-22 19:24:36 +00:00
|
|
|
pflags := []string{}
|
|
|
|
pflags = append(pflags, flags...)
|
|
|
|
if setpkgpaths {
|
|
|
|
fp := filepath.Join(longdir, gofiles[0])
|
2020-02-09 06:40:45 +00:00
|
|
|
pkgname, err := getPackageNameFromSource(fp)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2019-03-22 19:24:36 +00:00
|
|
|
pflags = append(pflags, "-p", pkgname)
|
|
|
|
}
|
|
|
|
_, err := compileInDir(runcmd, longdir, pflags, localImports, gofiles...)
|
2018-05-26 09:57:50 +00:00
|
|
|
// Allow this package compilation fail based on conditions below;
|
|
|
|
// its errors were checked in previous case.
|
|
|
|
if err != nil && !(wantError && action == "errorcheckandrundir" && i == len(pkgs)-2) {
|
2012-10-06 07:23:31 +00:00
|
|
|
t.err = err
|
|
|
|
return
|
|
|
|
}
|
2013-01-11 21:00:48 +00:00
|
|
|
if i == len(pkgs)-1 {
|
2019-03-22 19:24:36 +00:00
|
|
|
err = linkFile(runcmd, gofiles[0], ldflags)
|
2013-01-11 21:00:48 +00:00
|
|
|
if err != nil {
|
|
|
|
t.err = err
|
|
|
|
return
|
|
|
|
}
|
all: merge NaCl branch (part 1)
See golang.org/s/go13nacl for design overview.
This CL is the mostly mechanical changes from rsc's Go 1.2 based NaCl branch, specifically 39cb35750369 to 500771b477cf from https://code.google.com/r/rsc-go13nacl. This CL does not include working NaCl support, there are probably two or three more large merges to come.
CL 15750044 is not included as it involves more invasive changes to the linker which will need to be merged separately.
The exact change lists included are
15050047: syscall: support for Native Client
15360044: syscall: unzip implementation for Native Client
15370044: syscall: Native Client SRPC implementation
15400047: cmd/dist, cmd/go, go/build, test: support for Native Client
15410048: runtime: support for Native Client
15410049: syscall: file descriptor table for Native Client
15410050: syscall: in-memory file system for Native Client
15440048: all: update +build lines for Native Client port
15540045: cmd/6g, cmd/8g, cmd/gc: support for Native Client
15570045: os: support for Native Client
15680044: crypto/..., hash/crc32, reflect, sync/atomic: support for amd64p32
15690044: net: support for Native Client
15690048: runtime: support for fake time like on Go Playground
15690051: build: disable various tests on Native Client
LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/68150047
2014-02-25 14:47:42 +00:00
|
|
|
var cmd []string
|
|
|
|
cmd = append(cmd, findExecCmd()...)
|
|
|
|
cmd = append(cmd, filepath.Join(t.tempDir, "a.exe"))
|
|
|
|
cmd = append(cmd, args...)
|
|
|
|
out, err := runcmd(cmd...)
|
2013-01-11 21:00:48 +00:00
|
|
|
if err != nil {
|
|
|
|
t.err = err
|
|
|
|
return
|
|
|
|
}
|
2021-01-04 19:05:17 +00:00
|
|
|
t.checkExpectedOutput(out)
|
2013-01-11 21:00:48 +00:00
|
|
|
}
|
2012-10-06 07:23:31 +00:00
|
|
|
}
|
|
|
|
|
2019-05-17 10:25:07 +00:00
|
|
|
case "runindir":
|
[dev.typeparams] test: fix and update run.go's generics testing
In a late change to golang.org/cl/320609, while going back and forth
on the meaning of the boolean result value for "checkFlags", I got one
of the cases wrong. As a result, rather than testing both default
flags and -G=3, we were (redundanly) testing default flags and -G=0.
I ran into this because in my local dev tree, I'm using types2 even
for -G=0, and evidently one of the recent types2 CLs changed the error
message in fixedbugs/issue10975.go. Fortunately, there haven't been
any other regressions despite lacking test coverage.
So this CL cleans things up a bit:
1. Fixes that test to use -lang=go1.17, so types2 reports the old
error message again.
2. Renames "checkFlags" to "validForGLevel" so the boolean result is
harder to get wrong.
3. Removes the blanket deny list of all -m tests, and instead adds the
specific tests that are still failing. This effectively extends -G=3
coverage to another 27 tests that were using -m but already passing,
so we can make sure they don't regress again.
4. Adds a -f flag to force running tests even if they're in the deny
list, to make it easier to test whether they're still failing without
having to edit run.go.
Change-Id: I058d9d90d81a92189e54c6f591d95fb617fede53
Reviewed-on: https://go-review.googlesource.com/c/go/+/322612
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-05-25 21:06:56 +00:00
|
|
|
if !validForGLevel(Run) {
|
2021-05-17 20:59:25 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-03-24 20:18:02 +00:00
|
|
|
// Make a shallow copy of t.goDirName() in its own module and GOPATH, and
|
|
|
|
// run "go run ." in it. The module path (and hence import path prefix) of
|
|
|
|
// the copy is equal to the basename of the source directory.
|
|
|
|
//
|
|
|
|
// It's used when test a requires a full 'go build' in order to compile
|
|
|
|
// the sources, such as when importing multiple packages (issue29612.dir)
|
|
|
|
// or compiling a package containing assembly files (see issue15609.dir),
|
|
|
|
// but still needs to be run to verify the expected output.
|
|
|
|
tempDirIsGOPATH = true
|
|
|
|
srcDir := t.goDirName()
|
|
|
|
modName := filepath.Base(srcDir)
|
|
|
|
gopathSrcDir := filepath.Join(t.tempDir, "src", modName)
|
|
|
|
runInDir = gopathSrcDir
|
|
|
|
|
|
|
|
if err := overlayDir(gopathSrcDir, srcDir); err != nil {
|
|
|
|
t.err = err
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
modFile := fmt.Sprintf("module %s\ngo 1.14\n", modName)
|
|
|
|
if err := ioutil.WriteFile(filepath.Join(gopathSrcDir, "go.mod"), []byte(modFile), 0666); err != nil {
|
|
|
|
t.err = err
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-05-17 20:59:25 +00:00
|
|
|
cmd := []string{goTool(), "run", t.goGcflags()}
|
2019-05-17 10:25:07 +00:00
|
|
|
if *linkshared {
|
|
|
|
cmd = append(cmd, "-linkshared")
|
|
|
|
}
|
2021-02-12 00:55:07 +00:00
|
|
|
cmd = append(cmd, flags...)
|
2019-05-17 10:25:07 +00:00
|
|
|
cmd = append(cmd, ".")
|
|
|
|
out, err := runcmd(cmd...)
|
|
|
|
if err != nil {
|
|
|
|
t.err = err
|
|
|
|
return
|
|
|
|
}
|
2021-01-04 19:05:17 +00:00
|
|
|
t.checkExpectedOutput(out)
|
2019-05-17 10:25:07 +00:00
|
|
|
|
2012-03-07 06:54:39 +00:00
|
|
|
case "build":
|
[dev.typeparams] test: fix and update run.go's generics testing
In a late change to golang.org/cl/320609, while going back and forth
on the meaning of the boolean result value for "checkFlags", I got one
of the cases wrong. As a result, rather than testing both default
flags and -G=3, we were (redundanly) testing default flags and -G=0.
I ran into this because in my local dev tree, I'm using types2 even
for -G=0, and evidently one of the recent types2 CLs changed the error
message in fixedbugs/issue10975.go. Fortunately, there haven't been
any other regressions despite lacking test coverage.
So this CL cleans things up a bit:
1. Fixes that test to use -lang=go1.17, so types2 reports the old
error message again.
2. Renames "checkFlags" to "validForGLevel" so the boolean result is
harder to get wrong.
3. Removes the blanket deny list of all -m tests, and instead adds the
specific tests that are still failing. This effectively extends -G=3
coverage to another 27 tests that were using -m but already passing,
so we can make sure they don't regress again.
4. Adds a -f flag to force running tests even if they're in the deny
list, to make it easier to test whether they're still failing without
having to edit run.go.
Change-Id: I058d9d90d81a92189e54c6f591d95fb617fede53
Reviewed-on: https://go-review.googlesource.com/c/go/+/322612
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-05-25 21:06:56 +00:00
|
|
|
if !validForGLevel(Build) {
|
2021-05-17 20:59:25 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-06-01 10:14:48 +00:00
|
|
|
// Build Go file.
|
2021-05-17 20:59:25 +00:00
|
|
|
_, err := runcmd(goTool(), "build", t.goGcflags(), "-o", "a.exe", long)
|
2012-03-07 06:54:39 +00:00
|
|
|
if err != nil {
|
2012-10-06 07:23:31 +00:00
|
|
|
t.err = err
|
2012-02-21 03:28:49 +00:00
|
|
|
}
|
2012-03-08 19:03:40 +00:00
|
|
|
|
2018-02-15 00:35:03 +00:00
|
|
|
case "builddir", "buildrundir":
|
[dev.typeparams] test: fix and update run.go's generics testing
In a late change to golang.org/cl/320609, while going back and forth
on the meaning of the boolean result value for "checkFlags", I got one
of the cases wrong. As a result, rather than testing both default
flags and -G=3, we were (redundanly) testing default flags and -G=0.
I ran into this because in my local dev tree, I'm using types2 even
for -G=0, and evidently one of the recent types2 CLs changed the error
message in fixedbugs/issue10975.go. Fortunately, there haven't been
any other regressions despite lacking test coverage.
So this CL cleans things up a bit:
1. Fixes that test to use -lang=go1.17, so types2 reports the old
error message again.
2. Renames "checkFlags" to "validForGLevel" so the boolean result is
harder to get wrong.
3. Removes the blanket deny list of all -m tests, and instead adds the
specific tests that are still failing. This effectively extends -G=3
coverage to another 27 tests that were using -m but already passing,
so we can make sure they don't regress again.
4. Adds a -f flag to force running tests even if they're in the deny
list, to make it easier to test whether they're still failing without
having to edit run.go.
Change-Id: I058d9d90d81a92189e54c6f591d95fb617fede53
Reviewed-on: https://go-review.googlesource.com/c/go/+/322612
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-05-25 21:06:56 +00:00
|
|
|
if !validForGLevel(Build) {
|
2021-05-17 20:59:25 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-06-14 18:36:36 +00:00
|
|
|
// Build an executable from all the .go and .s files in a subdirectory.
|
2018-06-01 10:14:48 +00:00
|
|
|
// Run it and verify its output in the buildrundir case.
|
2017-06-14 18:36:36 +00:00
|
|
|
longdir := filepath.Join(cwd, t.goDirName())
|
|
|
|
files, dirErr := ioutil.ReadDir(longdir)
|
|
|
|
if dirErr != nil {
|
|
|
|
t.err = dirErr
|
|
|
|
break
|
|
|
|
}
|
2018-11-02 02:04:02 +00:00
|
|
|
var gos []string
|
|
|
|
var asms []string
|
2017-06-14 18:36:36 +00:00
|
|
|
for _, file := range files {
|
|
|
|
switch filepath.Ext(file.Name()) {
|
|
|
|
case ".go":
|
2018-11-02 02:04:02 +00:00
|
|
|
gos = append(gos, filepath.Join(longdir, file.Name()))
|
2017-06-14 18:36:36 +00:00
|
|
|
case ".s":
|
2018-11-02 02:04:02 +00:00
|
|
|
asms = append(asms, filepath.Join(longdir, file.Name()))
|
2017-06-14 18:36:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2018-10-22 15:21:56 +00:00
|
|
|
if len(asms) > 0 {
|
2018-11-13 23:13:42 +00:00
|
|
|
emptyHdrFile := filepath.Join(t.tempDir, "go_asm.h")
|
|
|
|
if err := ioutil.WriteFile(emptyHdrFile, nil, 0666); err != nil {
|
2018-10-22 15:21:56 +00:00
|
|
|
t.err = fmt.Errorf("write empty go_asm.h: %s", err)
|
|
|
|
return
|
|
|
|
}
|
2018-11-15 20:23:48 +00:00
|
|
|
cmd := []string{goTool(), "tool", "asm", "-gensymabis", "-o", "symabis"}
|
2018-10-22 15:21:56 +00:00
|
|
|
cmd = append(cmd, asms...)
|
|
|
|
_, err = runcmd(cmd...)
|
|
|
|
if err != nil {
|
|
|
|
t.err = err
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2017-06-14 18:36:36 +00:00
|
|
|
var objs []string
|
2018-03-03 13:47:20 +00:00
|
|
|
cmd := []string{goTool(), "tool", "compile", "-e", "-D", ".", "-I", ".", "-o", "go.o"}
|
2017-11-29 19:58:03 +00:00
|
|
|
if len(asms) > 0 {
|
2018-10-22 15:21:56 +00:00
|
|
|
cmd = append(cmd, "-asmhdr", "go_asm.h", "-symabis", "symabis")
|
2017-11-29 19:58:03 +00:00
|
|
|
}
|
2018-11-02 02:04:02 +00:00
|
|
|
cmd = append(cmd, gos...)
|
2017-06-14 18:36:36 +00:00
|
|
|
_, err := runcmd(cmd...)
|
|
|
|
if err != nil {
|
|
|
|
t.err = err
|
|
|
|
break
|
|
|
|
}
|
|
|
|
objs = append(objs, "go.o")
|
|
|
|
if len(asms) > 0 {
|
2018-03-03 13:47:20 +00:00
|
|
|
cmd = []string{goTool(), "tool", "asm", "-e", "-I", ".", "-o", "asm.o"}
|
2018-11-02 02:04:02 +00:00
|
|
|
cmd = append(cmd, asms...)
|
2017-06-14 18:36:36 +00:00
|
|
|
_, err = runcmd(cmd...)
|
|
|
|
if err != nil {
|
|
|
|
t.err = err
|
|
|
|
break
|
|
|
|
}
|
|
|
|
objs = append(objs, "asm.o")
|
|
|
|
}
|
2018-03-03 13:47:20 +00:00
|
|
|
cmd = []string{goTool(), "tool", "pack", "c", "all.a"}
|
2017-06-14 18:36:36 +00:00
|
|
|
cmd = append(cmd, objs...)
|
|
|
|
_, err = runcmd(cmd...)
|
|
|
|
if err != nil {
|
|
|
|
t.err = err
|
|
|
|
break
|
|
|
|
}
|
2018-03-03 13:47:20 +00:00
|
|
|
cmd = []string{goTool(), "tool", "link", "-o", "a.exe", "all.a"}
|
2017-06-14 18:36:36 +00:00
|
|
|
_, err = runcmd(cmd...)
|
|
|
|
if err != nil {
|
|
|
|
t.err = err
|
|
|
|
break
|
|
|
|
}
|
2018-02-15 00:35:03 +00:00
|
|
|
if action == "buildrundir" {
|
|
|
|
cmd = append(findExecCmd(), filepath.Join(t.tempDir, "a.exe"))
|
|
|
|
out, err := runcmd(cmd...)
|
|
|
|
if err != nil {
|
|
|
|
t.err = err
|
|
|
|
break
|
|
|
|
}
|
2021-01-04 19:05:17 +00:00
|
|
|
t.checkExpectedOutput(out)
|
2018-02-15 00:35:03 +00:00
|
|
|
}
|
2017-06-14 18:36:36 +00:00
|
|
|
|
2018-06-01 10:14:48 +00:00
|
|
|
case "buildrun":
|
[dev.typeparams] test: fix and update run.go's generics testing
In a late change to golang.org/cl/320609, while going back and forth
on the meaning of the boolean result value for "checkFlags", I got one
of the cases wrong. As a result, rather than testing both default
flags and -G=3, we were (redundanly) testing default flags and -G=0.
I ran into this because in my local dev tree, I'm using types2 even
for -G=0, and evidently one of the recent types2 CLs changed the error
message in fixedbugs/issue10975.go. Fortunately, there haven't been
any other regressions despite lacking test coverage.
So this CL cleans things up a bit:
1. Fixes that test to use -lang=go1.17, so types2 reports the old
error message again.
2. Renames "checkFlags" to "validForGLevel" so the boolean result is
harder to get wrong.
3. Removes the blanket deny list of all -m tests, and instead adds the
specific tests that are still failing. This effectively extends -G=3
coverage to another 27 tests that were using -m but already passing,
so we can make sure they don't regress again.
4. Adds a -f flag to force running tests even if they're in the deny
list, to make it easier to test whether they're still failing without
having to edit run.go.
Change-Id: I058d9d90d81a92189e54c6f591d95fb617fede53
Reviewed-on: https://go-review.googlesource.com/c/go/+/322612
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-05-25 21:06:56 +00:00
|
|
|
if !validForGLevel(Build) {
|
2021-05-17 20:59:25 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-06-01 10:14:48 +00:00
|
|
|
// Build an executable from Go file, then run it, verify its output.
|
|
|
|
// Useful for timeout tests where failure mode is infinite loop.
|
2016-11-10 21:03:47 +00:00
|
|
|
// TODO: not supported on NaCl
|
2021-05-17 20:59:25 +00:00
|
|
|
cmd := []string{goTool(), "build", t.goGcflags(), "-o", "a.exe"}
|
2016-11-10 21:03:47 +00:00
|
|
|
if *linkshared {
|
|
|
|
cmd = append(cmd, "-linkshared")
|
|
|
|
}
|
|
|
|
longdirgofile := filepath.Join(filepath.Join(cwd, t.dir), t.gofile)
|
|
|
|
cmd = append(cmd, flags...)
|
|
|
|
cmd = append(cmd, longdirgofile)
|
2020-02-09 06:40:45 +00:00
|
|
|
_, err := runcmd(cmd...)
|
2016-11-10 21:03:47 +00:00
|
|
|
if err != nil {
|
|
|
|
t.err = err
|
|
|
|
return
|
|
|
|
}
|
|
|
|
cmd = []string{"./a.exe"}
|
2020-02-09 06:40:45 +00:00
|
|
|
out, err := runcmd(append(cmd, args...)...)
|
2016-11-10 21:03:47 +00:00
|
|
|
if err != nil {
|
|
|
|
t.err = err
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-01-04 19:05:17 +00:00
|
|
|
t.checkExpectedOutput(out)
|
2016-11-10 21:03:47 +00:00
|
|
|
|
2012-03-07 06:54:39 +00:00
|
|
|
case "run":
|
[dev.typeparams] test: fix and update run.go's generics testing
In a late change to golang.org/cl/320609, while going back and forth
on the meaning of the boolean result value for "checkFlags", I got one
of the cases wrong. As a result, rather than testing both default
flags and -G=3, we were (redundanly) testing default flags and -G=0.
I ran into this because in my local dev tree, I'm using types2 even
for -G=0, and evidently one of the recent types2 CLs changed the error
message in fixedbugs/issue10975.go. Fortunately, there haven't been
any other regressions despite lacking test coverage.
So this CL cleans things up a bit:
1. Fixes that test to use -lang=go1.17, so types2 reports the old
error message again.
2. Renames "checkFlags" to "validForGLevel" so the boolean result is
harder to get wrong.
3. Removes the blanket deny list of all -m tests, and instead adds the
specific tests that are still failing. This effectively extends -G=3
coverage to another 27 tests that were using -m but already passing,
so we can make sure they don't regress again.
4. Adds a -f flag to force running tests even if they're in the deny
list, to make it easier to test whether they're still failing without
having to edit run.go.
Change-Id: I058d9d90d81a92189e54c6f591d95fb617fede53
Reviewed-on: https://go-review.googlesource.com/c/go/+/322612
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-05-25 21:06:56 +00:00
|
|
|
if !validForGLevel(Run) {
|
2021-05-17 20:59:25 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-06-01 10:14:48 +00:00
|
|
|
// Run Go file if no special go command flags are provided;
|
|
|
|
// otherwise build an executable and run it.
|
|
|
|
// Verify the output.
|
2020-03-24 20:18:02 +00:00
|
|
|
runInDir = ""
|
2017-10-27 18:11:21 +00:00
|
|
|
var out []byte
|
|
|
|
var err error
|
2021-07-02 22:42:20 +00:00
|
|
|
if len(flags)+len(args) == 0 && t.goGcflagsIsEmpty() && !*linkshared && goarch == runtime.GOARCH && goos == runtime.GOOS && goexp == env.GOEXPERIMENT {
|
2017-10-27 18:11:21 +00:00
|
|
|
// If we're not using special go command flags,
|
|
|
|
// skip all the go command machinery.
|
|
|
|
// This avoids any time the go command would
|
|
|
|
// spend checking whether, for example, the installed
|
|
|
|
// package runtime is up to date.
|
|
|
|
// Because we run lots of trivial test programs,
|
|
|
|
// the time adds up.
|
|
|
|
pkg := filepath.Join(t.tempDir, "pkg.a")
|
2018-03-03 13:47:20 +00:00
|
|
|
if _, err := runcmd(goTool(), "tool", "compile", "-o", pkg, t.goFileName()); err != nil {
|
2017-10-27 18:11:21 +00:00
|
|
|
t.err = err
|
|
|
|
return
|
|
|
|
}
|
|
|
|
exe := filepath.Join(t.tempDir, "test.exe")
|
2018-03-03 13:47:20 +00:00
|
|
|
cmd := []string{goTool(), "tool", "link", "-s", "-w"}
|
2017-10-27 18:11:21 +00:00
|
|
|
cmd = append(cmd, "-o", exe, pkg)
|
|
|
|
if _, err := runcmd(cmd...); err != nil {
|
|
|
|
t.err = err
|
|
|
|
return
|
|
|
|
}
|
|
|
|
out, err = runcmd(append([]string{exe}, args...)...)
|
|
|
|
} else {
|
2021-05-17 20:59:25 +00:00
|
|
|
cmd := []string{goTool(), "run", t.goGcflags()}
|
2017-10-27 18:11:21 +00:00
|
|
|
if *linkshared {
|
|
|
|
cmd = append(cmd, "-linkshared")
|
|
|
|
}
|
|
|
|
cmd = append(cmd, flags...)
|
|
|
|
cmd = append(cmd, t.goFileName())
|
|
|
|
out, err = runcmd(append(cmd, args...)...)
|
2015-10-27 01:54:19 +00:00
|
|
|
}
|
2012-02-21 03:28:49 +00:00
|
|
|
if err != nil {
|
2012-10-06 07:23:31 +00:00
|
|
|
t.err = err
|
2014-09-11 19:47:17 +00:00
|
|
|
return
|
2012-02-21 03:28:49 +00:00
|
|
|
}
|
2021-01-04 19:05:17 +00:00
|
|
|
t.checkExpectedOutput(out)
|
2012-04-20 15:45:43 +00:00
|
|
|
|
|
|
|
case "runoutput":
|
[dev.typeparams] test: fix and update run.go's generics testing
In a late change to golang.org/cl/320609, while going back and forth
on the meaning of the boolean result value for "checkFlags", I got one
of the cases wrong. As a result, rather than testing both default
flags and -G=3, we were (redundanly) testing default flags and -G=0.
I ran into this because in my local dev tree, I'm using types2 even
for -G=0, and evidently one of the recent types2 CLs changed the error
message in fixedbugs/issue10975.go. Fortunately, there haven't been
any other regressions despite lacking test coverage.
So this CL cleans things up a bit:
1. Fixes that test to use -lang=go1.17, so types2 reports the old
error message again.
2. Renames "checkFlags" to "validForGLevel" so the boolean result is
harder to get wrong.
3. Removes the blanket deny list of all -m tests, and instead adds the
specific tests that are still failing. This effectively extends -G=3
coverage to another 27 tests that were using -m but already passing,
so we can make sure they don't regress again.
4. Adds a -f flag to force running tests even if they're in the deny
list, to make it easier to test whether they're still failing without
having to edit run.go.
Change-Id: I058d9d90d81a92189e54c6f591d95fb617fede53
Reviewed-on: https://go-review.googlesource.com/c/go/+/322612
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-05-25 21:06:56 +00:00
|
|
|
if !validForGLevel(Run) {
|
2021-05-17 20:59:25 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-06-01 10:14:48 +00:00
|
|
|
// Run Go file and write its output into temporary Go file.
|
|
|
|
// Run generated Go file and verify its output.
|
2013-01-12 06:52:52 +00:00
|
|
|
rungatec <- true
|
|
|
|
defer func() {
|
|
|
|
<-rungatec
|
|
|
|
}()
|
2020-03-24 20:18:02 +00:00
|
|
|
runInDir = ""
|
2021-05-17 20:59:25 +00:00
|
|
|
cmd := []string{goTool(), "run", t.goGcflags()}
|
2015-10-27 01:54:19 +00:00
|
|
|
if *linkshared {
|
|
|
|
cmd = append(cmd, "-linkshared")
|
|
|
|
}
|
|
|
|
cmd = append(cmd, t.goFileName())
|
|
|
|
out, err := runcmd(append(cmd, args...)...)
|
2012-04-20 15:45:43 +00:00
|
|
|
if err != nil {
|
2012-10-06 07:23:31 +00:00
|
|
|
t.err = err
|
2014-09-11 19:47:17 +00:00
|
|
|
return
|
2012-04-20 15:45:43 +00:00
|
|
|
}
|
|
|
|
tfile := filepath.Join(t.tempDir, "tmp__.go")
|
2013-01-12 06:52:52 +00:00
|
|
|
if err := ioutil.WriteFile(tfile, out, 0666); err != nil {
|
2012-04-20 15:45:43 +00:00
|
|
|
t.err = fmt.Errorf("write tempfile:%s", err)
|
|
|
|
return
|
|
|
|
}
|
2021-05-17 20:59:25 +00:00
|
|
|
cmd = []string{goTool(), "run", t.goGcflags()}
|
2015-10-27 01:54:19 +00:00
|
|
|
if *linkshared {
|
|
|
|
cmd = append(cmd, "-linkshared")
|
|
|
|
}
|
|
|
|
cmd = append(cmd, tfile)
|
|
|
|
out, err = runcmd(cmd...)
|
2012-04-20 15:45:43 +00:00
|
|
|
if err != nil {
|
2012-10-06 07:23:31 +00:00
|
|
|
t.err = err
|
2014-09-11 19:47:17 +00:00
|
|
|
return
|
2012-04-20 15:45:43 +00:00
|
|
|
}
|
2021-01-04 19:05:17 +00:00
|
|
|
t.checkExpectedOutput(out)
|
2012-11-07 20:33:54 +00:00
|
|
|
|
|
|
|
case "errorcheckoutput":
|
[dev.typeparams] test: fix and update run.go's generics testing
In a late change to golang.org/cl/320609, while going back and forth
on the meaning of the boolean result value for "checkFlags", I got one
of the cases wrong. As a result, rather than testing both default
flags and -G=3, we were (redundanly) testing default flags and -G=0.
I ran into this because in my local dev tree, I'm using types2 even
for -G=0, and evidently one of the recent types2 CLs changed the error
message in fixedbugs/issue10975.go. Fortunately, there haven't been
any other regressions despite lacking test coverage.
So this CL cleans things up a bit:
1. Fixes that test to use -lang=go1.17, so types2 reports the old
error message again.
2. Renames "checkFlags" to "validForGLevel" so the boolean result is
harder to get wrong.
3. Removes the blanket deny list of all -m tests, and instead adds the
specific tests that are still failing. This effectively extends -G=3
coverage to another 27 tests that were using -m but already passing,
so we can make sure they don't regress again.
4. Adds a -f flag to force running tests even if they're in the deny
list, to make it easier to test whether they're still failing without
having to edit run.go.
Change-Id: I058d9d90d81a92189e54c6f591d95fb617fede53
Reviewed-on: https://go-review.googlesource.com/c/go/+/322612
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-05-25 21:06:56 +00:00
|
|
|
if !validForGLevel(Compile) {
|
2021-05-17 20:59:25 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-06-01 10:14:48 +00:00
|
|
|
// Run Go file and write its output into temporary Go file.
|
|
|
|
// Compile and errorCheck generated Go file.
|
2020-03-24 20:18:02 +00:00
|
|
|
runInDir = ""
|
2021-05-17 20:59:25 +00:00
|
|
|
cmd := []string{goTool(), "run", t.goGcflags()}
|
2015-10-27 01:54:19 +00:00
|
|
|
if *linkshared {
|
|
|
|
cmd = append(cmd, "-linkshared")
|
|
|
|
}
|
|
|
|
cmd = append(cmd, t.goFileName())
|
|
|
|
out, err := runcmd(append(cmd, args...)...)
|
2012-11-07 20:33:54 +00:00
|
|
|
if err != nil {
|
|
|
|
t.err = err
|
2014-09-11 19:47:17 +00:00
|
|
|
return
|
2012-11-07 20:33:54 +00:00
|
|
|
}
|
|
|
|
tfile := filepath.Join(t.tempDir, "tmp__.go")
|
|
|
|
err = ioutil.WriteFile(tfile, out, 0666)
|
|
|
|
if err != nil {
|
|
|
|
t.err = fmt.Errorf("write tempfile:%s", err)
|
|
|
|
return
|
|
|
|
}
|
2021-03-04 15:31:43 +00:00
|
|
|
cmdline := []string{goTool(), "tool", "compile", "-d=panic", "-e", "-o", "a.o"}
|
2012-11-07 20:33:54 +00:00
|
|
|
cmdline = append(cmdline, flags...)
|
|
|
|
cmdline = append(cmdline, tfile)
|
|
|
|
out, err = runcmd(cmdline...)
|
|
|
|
if wantError {
|
|
|
|
if err == nil {
|
|
|
|
t.err = fmt.Errorf("compilation succeeded unexpectedly\n%s", out)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if err != nil {
|
|
|
|
t.err = err
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2016-09-22 17:50:16 +00:00
|
|
|
t.err = t.errorCheck(string(out), false, tfile, "tmp__.go")
|
2012-11-07 20:33:54 +00:00
|
|
|
return
|
2012-02-21 03:28:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
all: merge NaCl branch (part 1)
See golang.org/s/go13nacl for design overview.
This CL is the mostly mechanical changes from rsc's Go 1.2 based NaCl branch, specifically 39cb35750369 to 500771b477cf from https://code.google.com/r/rsc-go13nacl. This CL does not include working NaCl support, there are probably two or three more large merges to come.
CL 15750044 is not included as it involves more invasive changes to the linker which will need to be merged separately.
The exact change lists included are
15050047: syscall: support for Native Client
15360044: syscall: unzip implementation for Native Client
15370044: syscall: Native Client SRPC implementation
15400047: cmd/dist, cmd/go, go/build, test: support for Native Client
15410048: runtime: support for Native Client
15410049: syscall: file descriptor table for Native Client
15410050: syscall: in-memory file system for Native Client
15440048: all: update +build lines for Native Client port
15540045: cmd/6g, cmd/8g, cmd/gc: support for Native Client
15570045: os: support for Native Client
15680044: crypto/..., hash/crc32, reflect, sync/atomic: support for amd64p32
15690044: net: support for Native Client
15690048: runtime: support for fake time like on Go Playground
15690051: build: disable various tests on Native Client
LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/68150047
2014-02-25 14:47:42 +00:00
|
|
|
var execCmd []string
|
|
|
|
|
|
|
|
func findExecCmd() []string {
|
|
|
|
if execCmd != nil {
|
|
|
|
return execCmd
|
|
|
|
}
|
|
|
|
execCmd = []string{} // avoid work the second time
|
|
|
|
if goos == runtime.GOOS && goarch == runtime.GOARCH {
|
|
|
|
return execCmd
|
|
|
|
}
|
|
|
|
path, err := exec.LookPath(fmt.Sprintf("go_%s_%s_exec", goos, goarch))
|
|
|
|
if err == nil {
|
|
|
|
execCmd = []string{path}
|
|
|
|
}
|
|
|
|
return execCmd
|
2014-08-01 20:34:36 +00:00
|
|
|
}
|
all: merge NaCl branch (part 1)
See golang.org/s/go13nacl for design overview.
This CL is the mostly mechanical changes from rsc's Go 1.2 based NaCl branch, specifically 39cb35750369 to 500771b477cf from https://code.google.com/r/rsc-go13nacl. This CL does not include working NaCl support, there are probably two or three more large merges to come.
CL 15750044 is not included as it involves more invasive changes to the linker which will need to be merged separately.
The exact change lists included are
15050047: syscall: support for Native Client
15360044: syscall: unzip implementation for Native Client
15370044: syscall: Native Client SRPC implementation
15400047: cmd/dist, cmd/go, go/build, test: support for Native Client
15410048: runtime: support for Native Client
15410049: syscall: file descriptor table for Native Client
15410050: syscall: in-memory file system for Native Client
15440048: all: update +build lines for Native Client port
15540045: cmd/6g, cmd/8g, cmd/gc: support for Native Client
15570045: os: support for Native Client
15680044: crypto/..., hash/crc32, reflect, sync/atomic: support for amd64p32
15690044: net: support for Native Client
15690048: runtime: support for fake time like on Go Playground
15690051: build: disable various tests on Native Client
LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/68150047
2014-02-25 14:47:42 +00:00
|
|
|
|
2012-02-21 03:28:49 +00:00
|
|
|
func (t *test) String() string {
|
|
|
|
return filepath.Join(t.dir, t.gofile)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *test) makeTempDir() {
|
|
|
|
var err error
|
|
|
|
t.tempDir, err = ioutil.TempDir("", "")
|
2020-02-09 06:40:45 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2016-03-11 05:10:52 +00:00
|
|
|
if *keep {
|
|
|
|
log.Printf("Temporary directory is %s", t.tempDir)
|
|
|
|
}
|
2012-02-21 03:28:49 +00:00
|
|
|
}
|
|
|
|
|
2021-01-04 19:05:17 +00:00
|
|
|
// checkExpectedOutput compares the output from compiling and/or running with the contents
|
|
|
|
// of the corresponding reference output file, if any (replace ".go" with ".out").
|
|
|
|
// If they don't match, fail with an informative message.
|
|
|
|
func (t *test) checkExpectedOutput(gotBytes []byte) {
|
|
|
|
got := string(gotBytes)
|
2012-02-21 03:28:49 +00:00
|
|
|
filename := filepath.Join(t.dir, t.gofile)
|
|
|
|
filename = filename[:len(filename)-len(".go")]
|
|
|
|
filename += ".out"
|
2021-01-04 19:05:17 +00:00
|
|
|
b, err := ioutil.ReadFile(filename)
|
|
|
|
// File is allowed to be missing (err != nil) in which case output should be empty.
|
|
|
|
got = strings.Replace(got, "\r\n", "\n", -1)
|
|
|
|
if got != string(b) {
|
|
|
|
if err == nil {
|
|
|
|
t.err = fmt.Errorf("output does not match expected in %s. Instead saw\n%s", filename, got)
|
|
|
|
} else {
|
|
|
|
t.err = fmt.Errorf("output should be empty when (optional) expected-output file %s is not present. Instead saw\n%s", filename, got)
|
|
|
|
}
|
|
|
|
}
|
2012-02-21 03:28:49 +00:00
|
|
|
}
|
|
|
|
|
2016-09-22 17:50:16 +00:00
|
|
|
func splitOutput(out string, wantAuto bool) []string {
|
2015-06-23 23:50:12 +00:00
|
|
|
// gc error messages continue onto additional lines with leading tabs.
|
2012-02-21 03:28:49 +00:00
|
|
|
// Split the output at the beginning of each line that doesn't begin with a tab.
|
2015-06-16 22:28:01 +00:00
|
|
|
// <autogenerated> lines are impossible to match so those are filtered out.
|
2015-02-19 19:00:11 +00:00
|
|
|
var res []string
|
|
|
|
for _, line := range strings.Split(out, "\n") {
|
2012-09-23 17:16:14 +00:00
|
|
|
if strings.HasSuffix(line, "\r") { // remove '\r', output by compiler on windows
|
2012-08-16 06:46:59 +00:00
|
|
|
line = line[:len(line)-1]
|
|
|
|
}
|
2012-02-21 03:28:49 +00:00
|
|
|
if strings.HasPrefix(line, "\t") {
|
2015-02-19 19:00:11 +00:00
|
|
|
res[len(res)-1] += "\n" + line
|
2016-09-22 17:50:16 +00:00
|
|
|
} else if strings.HasPrefix(line, "go tool") || strings.HasPrefix(line, "#") || !wantAuto && strings.HasPrefix(line, "<autogenerated>") {
|
2012-10-08 14:36:45 +00:00
|
|
|
continue
|
|
|
|
} else if strings.TrimSpace(line) != "" {
|
2015-02-19 19:00:11 +00:00
|
|
|
res = append(res, line)
|
2012-02-21 03:28:49 +00:00
|
|
|
}
|
|
|
|
}
|
2015-02-19 19:00:11 +00:00
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
2018-06-01 10:14:48 +00:00
|
|
|
// errorCheck matches errors in outStr against comments in source files.
|
|
|
|
// For each line of the source files which should generate an error,
|
|
|
|
// there should be a comment of the form // ERROR "regexp".
|
|
|
|
// If outStr has an error for a line which has no such comment,
|
|
|
|
// this function will report an error.
|
|
|
|
// Likewise if outStr does not have an error for a line which has a comment,
|
|
|
|
// or if the error message does not match the <regexp>.
|
2018-10-08 01:19:51 +00:00
|
|
|
// The <regexp> syntax is Perl but it's best to stick to egrep.
|
2018-06-01 10:14:48 +00:00
|
|
|
//
|
|
|
|
// Sources files are supplied as fullshort slice.
|
2018-10-08 01:19:51 +00:00
|
|
|
// It consists of pairs: full path to source file and its base name.
|
2016-09-22 17:50:16 +00:00
|
|
|
func (t *test) errorCheck(outStr string, wantAuto bool, fullshort ...string) (err error) {
|
2015-02-19 19:00:11 +00:00
|
|
|
defer func() {
|
|
|
|
if *verbose && err != nil {
|
|
|
|
log.Printf("%s gc output:\n%s", t, outStr)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
var errs []error
|
2016-09-22 17:50:16 +00:00
|
|
|
out := splitOutput(outStr, wantAuto)
|
2012-02-21 03:28:49 +00:00
|
|
|
|
2012-03-07 06:54:39 +00:00
|
|
|
// Cut directory name.
|
|
|
|
for i := range out {
|
2013-01-02 20:31:49 +00:00
|
|
|
for j := 0; j < len(fullshort); j += 2 {
|
|
|
|
full, short := fullshort[j], fullshort[j+1]
|
|
|
|
out[i] = strings.Replace(out[i], full, short, -1)
|
|
|
|
}
|
|
|
|
}
|
2013-01-11 21:00:48 +00:00
|
|
|
|
2013-01-02 20:31:49 +00:00
|
|
|
var want []wantedError
|
|
|
|
for j := 0; j < len(fullshort); j += 2 {
|
|
|
|
full, short := fullshort[j], fullshort[j+1]
|
|
|
|
want = append(want, t.wantedErrors(full, short)...)
|
2012-03-07 06:54:39 +00:00
|
|
|
}
|
|
|
|
|
2013-01-02 20:31:49 +00:00
|
|
|
for _, we := range want {
|
2012-02-21 03:28:49 +00:00
|
|
|
var errmsgs []string
|
2016-09-22 17:50:16 +00:00
|
|
|
if we.auto {
|
|
|
|
errmsgs, out = partitionStrings("<autogenerated>", out)
|
|
|
|
} else {
|
|
|
|
errmsgs, out = partitionStrings(we.prefix, out)
|
|
|
|
}
|
2012-02-21 03:28:49 +00:00
|
|
|
if len(errmsgs) == 0 {
|
2012-03-07 06:54:39 +00:00
|
|
|
errs = append(errs, fmt.Errorf("%s:%d: missing error %q", we.file, we.lineNum, we.reStr))
|
2012-02-21 03:28:49 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
matched := false
|
2013-02-02 04:10:02 +00:00
|
|
|
n := len(out)
|
2012-02-21 03:28:49 +00:00
|
|
|
for _, errmsg := range errmsgs {
|
2016-10-18 04:34:57 +00:00
|
|
|
// Assume errmsg says "file:line: foo".
|
|
|
|
// Cut leading "file:line: " to avoid accidental matching of file name instead of message.
|
|
|
|
text := errmsg
|
|
|
|
if i := strings.Index(text, " "); i >= 0 {
|
|
|
|
text = text[i+1:]
|
|
|
|
}
|
|
|
|
if we.re.MatchString(text) {
|
2012-02-21 03:28:49 +00:00
|
|
|
matched = true
|
|
|
|
} else {
|
|
|
|
out = append(out, errmsg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !matched {
|
2013-02-02 04:10:02 +00:00
|
|
|
errs = append(errs, fmt.Errorf("%s:%d: no match for %#q in:\n\t%s", we.file, we.lineNum, we.reStr, strings.Join(out[n:], "\n\t")))
|
2012-02-21 03:28:49 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-08 14:36:45 +00:00
|
|
|
if len(out) > 0 {
|
|
|
|
errs = append(errs, fmt.Errorf("Unmatched Errors:"))
|
|
|
|
for _, errLine := range out {
|
|
|
|
errs = append(errs, fmt.Errorf("%s", errLine))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-21 03:28:49 +00:00
|
|
|
if len(errs) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if len(errs) == 1 {
|
|
|
|
return errs[0]
|
|
|
|
}
|
|
|
|
var buf bytes.Buffer
|
2012-03-07 06:54:39 +00:00
|
|
|
fmt.Fprintf(&buf, "\n")
|
2012-02-21 03:28:49 +00:00
|
|
|
for _, err := range errs {
|
|
|
|
fmt.Fprintf(&buf, "%s\n", err.Error())
|
|
|
|
}
|
|
|
|
return errors.New(buf.String())
|
2015-02-19 19:00:11 +00:00
|
|
|
}
|
2012-02-21 03:28:49 +00:00
|
|
|
|
2016-02-29 15:43:18 +00:00
|
|
|
func (t *test) updateErrors(out, file string) {
|
|
|
|
base := path.Base(file)
|
2015-02-19 19:00:11 +00:00
|
|
|
// Read in source file.
|
|
|
|
src, err := ioutil.ReadFile(file)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
lines := strings.Split(string(src), "\n")
|
|
|
|
// Remove old errors.
|
|
|
|
for i, ln := range lines {
|
|
|
|
pos := strings.Index(ln, " // ERROR ")
|
|
|
|
if pos >= 0 {
|
|
|
|
lines[i] = ln[:pos]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Parse new errors.
|
|
|
|
errors := make(map[int]map[string]bool)
|
|
|
|
tmpRe := regexp.MustCompile(`autotmp_[0-9]+`)
|
2016-09-22 17:50:16 +00:00
|
|
|
for _, errStr := range splitOutput(out, false) {
|
2015-02-19 19:00:11 +00:00
|
|
|
colon1 := strings.Index(errStr, ":")
|
2015-04-27 23:50:05 +00:00
|
|
|
if colon1 < 0 || errStr[:colon1] != file {
|
2015-02-19 19:00:11 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
colon2 := strings.Index(errStr[colon1+1:], ":")
|
|
|
|
if colon2 < 0 {
|
|
|
|
continue
|
|
|
|
}
|
2015-04-27 23:50:05 +00:00
|
|
|
colon2 += colon1 + 1
|
|
|
|
line, err := strconv.Atoi(errStr[colon1+1 : colon2])
|
2015-02-19 19:00:11 +00:00
|
|
|
line--
|
|
|
|
if err != nil || line < 0 || line >= len(lines) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
msg := errStr[colon2+2:]
|
2016-02-29 15:43:18 +00:00
|
|
|
msg = strings.Replace(msg, file, base, -1) // normalize file mentions in error itself
|
|
|
|
msg = strings.TrimLeft(msg, " \t")
|
2018-12-04 15:00:16 +00:00
|
|
|
for _, r := range []string{`\`, `*`, `+`, `?`, `[`, `]`, `(`, `)`} {
|
2015-04-27 23:50:05 +00:00
|
|
|
msg = strings.Replace(msg, r, `\`+r, -1)
|
2015-02-19 19:00:11 +00:00
|
|
|
}
|
|
|
|
msg = strings.Replace(msg, `"`, `.`, -1)
|
|
|
|
msg = tmpRe.ReplaceAllLiteralString(msg, `autotmp_[0-9]+`)
|
|
|
|
if errors[line] == nil {
|
|
|
|
errors[line] = make(map[string]bool)
|
|
|
|
}
|
|
|
|
errors[line][msg] = true
|
|
|
|
}
|
|
|
|
// Add new errors.
|
|
|
|
for line, errs := range errors {
|
|
|
|
var sorted []string
|
|
|
|
for e := range errs {
|
|
|
|
sorted = append(sorted, e)
|
|
|
|
}
|
|
|
|
sort.Strings(sorted)
|
|
|
|
lines[line] += " // ERROR"
|
|
|
|
for _, e := range sorted {
|
|
|
|
lines[line] += fmt.Sprintf(` "%s$"`, e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Write new file.
|
|
|
|
err = ioutil.WriteFile(file, []byte(strings.Join(lines, "\n")), 0640)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// Polish.
|
2018-03-03 13:47:20 +00:00
|
|
|
exec.Command(goTool(), "fmt", file).CombinedOutput()
|
2012-02-21 03:28:49 +00:00
|
|
|
}
|
|
|
|
|
2014-03-12 03:58:24 +00:00
|
|
|
// matchPrefix reports whether s is of the form ^(.*/)?prefix(:|[),
|
|
|
|
// That is, it needs the file name prefix followed by a : or a [,
|
|
|
|
// and possibly preceded by a directory name.
|
|
|
|
func matchPrefix(s, prefix string) bool {
|
|
|
|
i := strings.Index(s, ":")
|
|
|
|
if i < 0 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
j := strings.LastIndex(s[:i], "/")
|
|
|
|
s = s[j+1:]
|
|
|
|
if len(s) <= len(prefix) || s[:len(prefix)] != prefix {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
switch s[len(prefix)] {
|
|
|
|
case '[', ':':
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func partitionStrings(prefix string, strs []string) (matched, unmatched []string) {
|
2012-02-21 03:28:49 +00:00
|
|
|
for _, s := range strs {
|
2014-03-12 03:58:24 +00:00
|
|
|
if matchPrefix(s, prefix) {
|
2012-02-21 03:28:49 +00:00
|
|
|
matched = append(matched, s)
|
|
|
|
} else {
|
|
|
|
unmatched = append(unmatched, s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
type wantedError struct {
|
2014-08-01 20:34:36 +00:00
|
|
|
reStr string
|
|
|
|
re *regexp.Regexp
|
|
|
|
lineNum int
|
2016-09-22 17:50:16 +00:00
|
|
|
auto bool // match <autogenerated> line
|
2014-08-01 20:34:36 +00:00
|
|
|
file string
|
|
|
|
prefix string
|
2012-02-21 03:28:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
errRx = regexp.MustCompile(`// (?:GC_)?ERROR (.*)`)
|
2016-09-22 17:50:16 +00:00
|
|
|
errAutoRx = regexp.MustCompile(`// (?:GC_)?ERRORAUTO (.*)`)
|
2012-02-21 03:28:49 +00:00
|
|
|
errQuotesRx = regexp.MustCompile(`"([^"]*)"`)
|
|
|
|
lineRx = regexp.MustCompile(`LINE(([+-])([0-9]+))?`)
|
|
|
|
)
|
|
|
|
|
2012-10-06 07:23:31 +00:00
|
|
|
func (t *test) wantedErrors(file, short string) (errs []wantedError) {
|
2014-03-12 03:58:24 +00:00
|
|
|
cache := make(map[string]*regexp.Regexp)
|
|
|
|
|
2012-10-06 07:23:31 +00:00
|
|
|
src, _ := ioutil.ReadFile(file)
|
|
|
|
for i, line := range strings.Split(string(src), "\n") {
|
2012-02-21 03:28:49 +00:00
|
|
|
lineNum := i + 1
|
|
|
|
if strings.Contains(line, "////") {
|
|
|
|
// double comment disables ERROR
|
|
|
|
continue
|
|
|
|
}
|
2016-09-22 17:50:16 +00:00
|
|
|
var auto bool
|
|
|
|
m := errAutoRx.FindStringSubmatch(line)
|
|
|
|
if m != nil {
|
|
|
|
auto = true
|
|
|
|
} else {
|
|
|
|
m = errRx.FindStringSubmatch(line)
|
|
|
|
}
|
2012-02-21 03:28:49 +00:00
|
|
|
if m == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
all := m[1]
|
|
|
|
mm := errQuotesRx.FindAllStringSubmatch(all, -1)
|
|
|
|
if mm == nil {
|
2013-02-02 04:10:02 +00:00
|
|
|
log.Fatalf("%s:%d: invalid errchk line: %s", t.goFileName(), lineNum, line)
|
2012-02-21 03:28:49 +00:00
|
|
|
}
|
|
|
|
for _, m := range mm {
|
|
|
|
rx := lineRx.ReplaceAllStringFunc(m[1], func(m string) string {
|
|
|
|
n := lineNum
|
|
|
|
if strings.HasPrefix(m, "LINE+") {
|
|
|
|
delta, _ := strconv.Atoi(m[5:])
|
|
|
|
n += delta
|
|
|
|
} else if strings.HasPrefix(m, "LINE-") {
|
|
|
|
delta, _ := strconv.Atoi(m[5:])
|
|
|
|
n -= delta
|
|
|
|
}
|
2012-10-06 07:23:31 +00:00
|
|
|
return fmt.Sprintf("%s:%d", short, n)
|
2012-02-21 03:28:49 +00:00
|
|
|
})
|
2014-03-12 03:58:24 +00:00
|
|
|
re := cache[rx]
|
|
|
|
if re == nil {
|
|
|
|
var err error
|
|
|
|
re, err = regexp.Compile(rx)
|
|
|
|
if err != nil {
|
2015-02-19 19:00:11 +00:00
|
|
|
log.Fatalf("%s:%d: invalid regexp \"%s\" in ERROR line: %v", t.goFileName(), lineNum, rx, err)
|
2014-03-12 03:58:24 +00:00
|
|
|
}
|
|
|
|
cache[rx] = re
|
2013-02-02 04:10:02 +00:00
|
|
|
}
|
2014-03-12 03:58:24 +00:00
|
|
|
prefix := fmt.Sprintf("%s:%d", short, lineNum)
|
2012-02-21 03:28:49 +00:00
|
|
|
errs = append(errs, wantedError{
|
2014-08-01 20:34:36 +00:00
|
|
|
reStr: rx,
|
|
|
|
re: re,
|
|
|
|
prefix: prefix,
|
2016-09-22 17:50:16 +00:00
|
|
|
auto: auto,
|
2014-08-01 20:34:36 +00:00
|
|
|
lineNum: lineNum,
|
|
|
|
file: short,
|
2012-02-21 03:28:49 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
2012-09-23 17:16:14 +00:00
|
|
|
|
2018-03-01 00:39:01 +00:00
|
|
|
const (
|
|
|
|
// Regexp to match a single opcode check: optionally begin with "-" (to indicate
|
|
|
|
// a negative check), followed by a string literal enclosed in "" or ``. For "",
|
|
|
|
// backslashes must be handled.
|
|
|
|
reMatchCheck = `-?(?:\x60[^\x60]*\x60|"(?:[^"\\]|\\.)*")`
|
|
|
|
)
|
|
|
|
|
2018-02-27 00:59:58 +00:00
|
|
|
var (
|
2018-03-01 00:39:01 +00:00
|
|
|
// Regexp to split a line in code and comment, trimming spaces
|
2018-05-19 07:42:52 +00:00
|
|
|
rxAsmComment = regexp.MustCompile(`^\s*(.*?)\s*(?://\s*(.+)\s*)?$`)
|
2018-03-01 00:39:01 +00:00
|
|
|
|
2018-05-19 07:42:52 +00:00
|
|
|
// Regexp to extract an architecture check: architecture name (or triplet),
|
|
|
|
// followed by semi-colon, followed by a comma-separated list of opcode checks.
|
|
|
|
// Extraneous spaces are ignored.
|
|
|
|
rxAsmPlatform = regexp.MustCompile(`(\w+)(/\w+)?(/\w*)?\s*:\s*(` + reMatchCheck + `(?:\s*,\s*` + reMatchCheck + `)*)`)
|
2018-03-01 00:39:01 +00:00
|
|
|
|
|
|
|
// Regexp to extract a single opcoded check
|
|
|
|
rxAsmCheck = regexp.MustCompile(reMatchCheck)
|
2018-04-15 17:00:27 +00:00
|
|
|
|
|
|
|
// List of all architecture variants. Key is the GOARCH architecture,
|
2018-04-15 20:53:58 +00:00
|
|
|
// value[0] is the variant-changing environment variable, and values[1:]
|
2018-04-15 17:00:27 +00:00
|
|
|
// are the supported variants.
|
|
|
|
archVariants = map[string][]string{
|
2020-10-06 21:42:15 +00:00
|
|
|
"386": {"GO386", "sse2", "softfloat"},
|
2018-04-15 17:00:27 +00:00
|
|
|
"amd64": {},
|
|
|
|
"arm": {"GOARM", "5", "6", "7"},
|
|
|
|
"arm64": {},
|
|
|
|
"mips": {"GOMIPS", "hardfloat", "softfloat"},
|
2018-04-26 13:37:27 +00:00
|
|
|
"mips64": {"GOMIPS64", "hardfloat", "softfloat"},
|
2019-01-11 19:16:28 +00:00
|
|
|
"ppc64": {"GOPPC64", "power8", "power9"},
|
|
|
|
"ppc64le": {"GOPPC64", "power8", "power9"},
|
2018-04-15 17:00:27 +00:00
|
|
|
"s390x": {},
|
2019-03-05 00:56:17 +00:00
|
|
|
"wasm": {},
|
2021-06-22 11:20:03 +00:00
|
|
|
"riscv64": {},
|
2018-04-15 17:00:27 +00:00
|
|
|
}
|
2018-02-27 00:59:58 +00:00
|
|
|
)
|
|
|
|
|
2018-04-15 17:00:27 +00:00
|
|
|
// wantedAsmOpcode is a single asmcheck check
|
2018-02-27 00:59:58 +00:00
|
|
|
type wantedAsmOpcode struct {
|
2018-03-03 18:44:47 +00:00
|
|
|
fileline string // original source file/line (eg: "/path/foo.go:45")
|
|
|
|
line int // original source line
|
|
|
|
opcode *regexp.Regexp // opcode check to be performed on assembly output
|
|
|
|
negative bool // true if the check is supposed to fail rather than pass
|
|
|
|
found bool // true if the opcode check matched at least one in the output
|
2018-02-27 00:59:58 +00:00
|
|
|
}
|
|
|
|
|
2020-10-06 21:42:15 +00:00
|
|
|
// A build environment triplet separated by slashes (eg: linux/386/sse2).
|
2018-04-15 20:53:58 +00:00
|
|
|
// The third field can be empty if the arch does not support variants (eg: "plan9/amd64/")
|
2018-04-15 17:00:27 +00:00
|
|
|
type buildEnv string
|
|
|
|
|
|
|
|
// Environ returns the environment it represents in cmd.Environ() "key=val" format
|
2020-10-06 21:42:15 +00:00
|
|
|
// For instance, "linux/386/sse2".Environ() returns {"GOOS=linux", "GOARCH=386", "GO386=sse2"}
|
2018-04-15 17:00:27 +00:00
|
|
|
func (b buildEnv) Environ() []string {
|
|
|
|
fields := strings.Split(string(b), "/")
|
2018-04-15 20:53:58 +00:00
|
|
|
if len(fields) != 3 {
|
2018-04-15 17:00:27 +00:00
|
|
|
panic("invalid buildEnv string: " + string(b))
|
|
|
|
}
|
|
|
|
env := []string{"GOOS=" + fields[0], "GOARCH=" + fields[1]}
|
2018-04-15 20:53:58 +00:00
|
|
|
if fields[2] != "" {
|
2018-04-15 17:00:27 +00:00
|
|
|
env = append(env, archVariants[fields[1]][0]+"="+fields[2])
|
|
|
|
}
|
|
|
|
return env
|
|
|
|
}
|
|
|
|
|
|
|
|
// asmChecks represents all the asmcheck checks present in a test file
|
|
|
|
// The outer map key is the build triplet in which the checks must be performed.
|
|
|
|
// The inner map key represent the source file line ("filename.go:1234") at which the
|
|
|
|
// checks must be performed.
|
|
|
|
type asmChecks map[buildEnv]map[string][]wantedAsmOpcode
|
|
|
|
|
|
|
|
// Envs returns all the buildEnv in which at least one check is present
|
|
|
|
func (a asmChecks) Envs() []buildEnv {
|
|
|
|
var envs []buildEnv
|
|
|
|
for e := range a {
|
|
|
|
envs = append(envs, e)
|
|
|
|
}
|
|
|
|
sort.Slice(envs, func(i, j int) bool {
|
|
|
|
return string(envs[i]) < string(envs[j])
|
|
|
|
})
|
|
|
|
return envs
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *test) wantedAsmOpcodes(fn string) asmChecks {
|
|
|
|
ops := make(asmChecks)
|
2018-02-27 00:59:58 +00:00
|
|
|
|
2018-03-01 00:39:01 +00:00
|
|
|
comment := ""
|
2018-02-27 00:59:58 +00:00
|
|
|
src, _ := ioutil.ReadFile(fn)
|
|
|
|
for i, line := range strings.Split(string(src), "\n") {
|
2018-03-01 00:39:01 +00:00
|
|
|
matches := rxAsmComment.FindStringSubmatch(line)
|
|
|
|
code, cmt := matches[1], matches[2]
|
|
|
|
|
|
|
|
// Keep comments pending in the comment variable until
|
|
|
|
// we find a line that contains some code.
|
|
|
|
comment += " " + cmt
|
|
|
|
if code == "" {
|
2018-02-27 00:59:58 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2018-03-01 00:39:01 +00:00
|
|
|
// Parse and extract any architecture check from comments,
|
|
|
|
// made by one architecture name and multiple checks.
|
2018-02-27 00:59:58 +00:00
|
|
|
lnum := fn + ":" + strconv.Itoa(i+1)
|
2018-03-01 00:39:01 +00:00
|
|
|
for _, ac := range rxAsmPlatform.FindAllStringSubmatch(comment, -1) {
|
2018-04-15 17:00:27 +00:00
|
|
|
archspec, allchecks := ac[1:4], ac[4]
|
|
|
|
|
|
|
|
var arch, subarch, os string
|
|
|
|
switch {
|
2020-10-06 21:42:15 +00:00
|
|
|
case archspec[2] != "": // 3 components: "linux/386/sse2"
|
2018-04-15 17:00:27 +00:00
|
|
|
os, arch, subarch = archspec[0], archspec[1][1:], archspec[2][1:]
|
2020-10-06 21:42:15 +00:00
|
|
|
case archspec[1] != "": // 2 components: "386/sse2"
|
2018-04-15 17:00:27 +00:00
|
|
|
os, arch, subarch = "linux", archspec[0], archspec[1][1:]
|
2020-10-06 21:42:15 +00:00
|
|
|
default: // 1 component: "386"
|
2018-04-15 17:00:27 +00:00
|
|
|
os, arch, subarch = "linux", archspec[0], ""
|
2019-03-05 00:56:17 +00:00
|
|
|
if arch == "wasm" {
|
|
|
|
os = "js"
|
|
|
|
}
|
2018-04-15 17:00:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if _, ok := archVariants[arch]; !ok {
|
|
|
|
log.Fatalf("%s:%d: unsupported architecture: %v", t.goFileName(), i+1, arch)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the build environments corresponding the above specifiers
|
|
|
|
envs := make([]buildEnv, 0, 4)
|
|
|
|
if subarch != "" {
|
|
|
|
envs = append(envs, buildEnv(os+"/"+arch+"/"+subarch))
|
|
|
|
} else {
|
|
|
|
subarchs := archVariants[arch]
|
|
|
|
if len(subarchs) == 0 {
|
2018-04-15 20:53:58 +00:00
|
|
|
envs = append(envs, buildEnv(os+"/"+arch+"/"))
|
2018-04-15 17:00:27 +00:00
|
|
|
} else {
|
|
|
|
for _, sa := range archVariants[arch][1:] {
|
|
|
|
envs = append(envs, buildEnv(os+"/"+arch+"/"+sa))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-03-01 00:39:01 +00:00
|
|
|
|
|
|
|
for _, m := range rxAsmCheck.FindAllString(allchecks, -1) {
|
|
|
|
negative := false
|
|
|
|
if m[0] == '-' {
|
|
|
|
negative = true
|
|
|
|
m = m[1:]
|
|
|
|
}
|
|
|
|
|
|
|
|
rxsrc, err := strconv.Unquote(m)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("%s:%d: error unquoting string: %v", t.goFileName(), i+1, err)
|
|
|
|
}
|
2018-03-01 00:55:33 +00:00
|
|
|
|
|
|
|
// Compile the checks as regular expressions. Notice that we
|
|
|
|
// consider checks as matching from the beginning of the actual
|
|
|
|
// assembler source (that is, what is left on each line of the
|
|
|
|
// compile -S output after we strip file/line info) to avoid
|
|
|
|
// trivial bugs such as "ADD" matching "FADD". This
|
|
|
|
// doesn't remove genericity: it's still possible to write
|
|
|
|
// something like "F?ADD", but we make common cases simpler
|
|
|
|
// to get right.
|
|
|
|
oprx, err := regexp.Compile("^" + rxsrc)
|
2018-03-01 00:39:01 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("%s:%d: %v", t.goFileName(), i+1, err)
|
|
|
|
}
|
2018-04-15 17:00:27 +00:00
|
|
|
|
|
|
|
for _, env := range envs {
|
|
|
|
if ops[env] == nil {
|
|
|
|
ops[env] = make(map[string][]wantedAsmOpcode)
|
|
|
|
}
|
|
|
|
ops[env][lnum] = append(ops[env][lnum], wantedAsmOpcode{
|
|
|
|
negative: negative,
|
|
|
|
fileline: lnum,
|
|
|
|
line: i + 1,
|
|
|
|
opcode: oprx,
|
|
|
|
})
|
2018-03-01 00:39:01 +00:00
|
|
|
}
|
2018-02-27 00:59:58 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-01 00:39:01 +00:00
|
|
|
comment = ""
|
2018-02-27 00:59:58 +00:00
|
|
|
}
|
|
|
|
|
2018-04-15 17:00:27 +00:00
|
|
|
return ops
|
2018-02-27 00:59:58 +00:00
|
|
|
}
|
|
|
|
|
2018-04-15 17:00:27 +00:00
|
|
|
func (t *test) asmCheck(outStr string, fn string, env buildEnv, fullops map[string][]wantedAsmOpcode) (err error) {
|
2018-03-03 18:44:47 +00:00
|
|
|
// The assembly output contains the concatenated dump of multiple functions.
|
|
|
|
// the first line of each function begins at column 0, while the rest is
|
|
|
|
// indented by a tabulation. These data structures help us index the
|
|
|
|
// output by function.
|
|
|
|
functionMarkers := make([]int, 1)
|
|
|
|
lineFuncMap := make(map[string]int)
|
|
|
|
|
|
|
|
lines := strings.Split(outStr, "\n")
|
2018-02-27 00:59:58 +00:00
|
|
|
rxLine := regexp.MustCompile(fmt.Sprintf(`\((%s:\d+)\)\s+(.*)`, regexp.QuoteMeta(fn)))
|
|
|
|
|
2018-03-03 18:44:47 +00:00
|
|
|
for nl, line := range lines {
|
|
|
|
// Check if this line begins a function
|
|
|
|
if len(line) > 0 && line[0] != '\t' {
|
|
|
|
functionMarkers = append(functionMarkers, nl)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Search if this line contains a assembly opcode (which is prefixed by the
|
|
|
|
// original source file/line in parenthesis)
|
2018-02-27 00:59:58 +00:00
|
|
|
matches := rxLine.FindStringSubmatch(line)
|
|
|
|
if len(matches) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
2018-03-03 18:44:47 +00:00
|
|
|
srcFileLine, asm := matches[1], matches[2]
|
|
|
|
|
|
|
|
// Associate the original file/line information to the current
|
|
|
|
// function in the output; it will be useful to dump it in case
|
|
|
|
// of error.
|
|
|
|
lineFuncMap[srcFileLine] = len(functionMarkers) - 1
|
2018-02-27 00:59:58 +00:00
|
|
|
|
2018-03-03 18:44:47 +00:00
|
|
|
// If there are opcode checks associated to this source file/line,
|
|
|
|
// run the checks.
|
|
|
|
if ops, found := fullops[srcFileLine]; found {
|
|
|
|
for i := range ops {
|
|
|
|
if !ops[i].found && ops[i].opcode.FindString(asm) != "" {
|
|
|
|
ops[i].found = true
|
|
|
|
}
|
2018-02-27 00:59:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-03-03 18:44:47 +00:00
|
|
|
functionMarkers = append(functionMarkers, len(lines))
|
2018-02-27 00:59:58 +00:00
|
|
|
|
2018-03-01 00:56:07 +00:00
|
|
|
var failed []wantedAsmOpcode
|
2018-02-27 00:59:58 +00:00
|
|
|
for _, ops := range fullops {
|
|
|
|
for _, o := range ops {
|
2018-03-01 00:56:07 +00:00
|
|
|
// There's a failure if a negative match was found,
|
|
|
|
// or a positive match was not found.
|
|
|
|
if o.negative == o.found {
|
|
|
|
failed = append(failed, o)
|
2018-02-27 00:59:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-03-01 00:56:07 +00:00
|
|
|
if len(failed) == 0 {
|
2018-02-27 00:59:58 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// At least one asmcheck failed; report them
|
2018-03-01 00:56:07 +00:00
|
|
|
sort.Slice(failed, func(i, j int) bool {
|
|
|
|
return failed[i].line < failed[j].line
|
2018-02-27 00:59:58 +00:00
|
|
|
})
|
|
|
|
|
2018-03-03 18:44:47 +00:00
|
|
|
lastFunction := -1
|
2018-02-27 00:59:58 +00:00
|
|
|
var errbuf bytes.Buffer
|
|
|
|
fmt.Fprintln(&errbuf)
|
2018-03-01 00:56:07 +00:00
|
|
|
for _, o := range failed {
|
2018-03-03 18:44:47 +00:00
|
|
|
// Dump the function in which this opcode check was supposed to
|
|
|
|
// pass but failed.
|
|
|
|
funcIdx := lineFuncMap[o.fileline]
|
|
|
|
if funcIdx != 0 && funcIdx != lastFunction {
|
|
|
|
funcLines := lines[functionMarkers[funcIdx]:functionMarkers[funcIdx+1]]
|
|
|
|
log.Println(strings.Join(funcLines, "\n"))
|
|
|
|
lastFunction = funcIdx // avoid printing same function twice
|
|
|
|
}
|
|
|
|
|
2018-03-01 00:56:07 +00:00
|
|
|
if o.negative {
|
2018-04-15 17:00:27 +00:00
|
|
|
fmt.Fprintf(&errbuf, "%s:%d: %s: wrong opcode found: %q\n", t.goFileName(), o.line, env, o.opcode.String())
|
2018-03-01 00:56:07 +00:00
|
|
|
} else {
|
2018-04-15 17:00:27 +00:00
|
|
|
fmt.Fprintf(&errbuf, "%s:%d: %s: opcode not found: %q\n", t.goFileName(), o.line, env, o.opcode.String())
|
2018-03-01 00:56:07 +00:00
|
|
|
}
|
2018-02-27 00:59:58 +00:00
|
|
|
}
|
|
|
|
err = errors.New(errbuf.String())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2013-01-12 06:52:52 +00:00
|
|
|
// defaultRunOutputLimit returns the number of runoutput tests that
|
|
|
|
// can be executed in parallel.
|
|
|
|
func defaultRunOutputLimit() int {
|
|
|
|
const maxArmCPU = 2
|
|
|
|
|
|
|
|
cpu := runtime.NumCPU()
|
|
|
|
if runtime.GOARCH == "arm" && cpu > maxArmCPU {
|
|
|
|
cpu = maxArmCPU
|
|
|
|
}
|
|
|
|
return cpu
|
|
|
|
}
|
2013-01-28 20:29:45 +00:00
|
|
|
|
2013-08-13 16:25:41 +00:00
|
|
|
// checkShouldTest runs sanity checks on the shouldTest function.
|
2013-01-28 20:29:45 +00:00
|
|
|
func checkShouldTest() {
|
|
|
|
assert := func(ok bool, _ string) {
|
|
|
|
if !ok {
|
|
|
|
panic("fail")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assertNot := func(ok bool, _ string) { assert(!ok, "") }
|
2013-08-13 16:25:41 +00:00
|
|
|
|
|
|
|
// Simple tests.
|
2013-01-28 20:29:45 +00:00
|
|
|
assert(shouldTest("// +build linux", "linux", "arm"))
|
|
|
|
assert(shouldTest("// +build !windows", "linux", "arm"))
|
|
|
|
assertNot(shouldTest("// +build !windows", "windows", "amd64"))
|
2013-08-13 16:25:41 +00:00
|
|
|
|
|
|
|
// A file with no build tags will always be tested.
|
2013-01-28 20:29:45 +00:00
|
|
|
assert(shouldTest("// This is a test.", "os", "arch"))
|
2013-08-13 16:25:41 +00:00
|
|
|
|
|
|
|
// Build tags separated by a space are OR-ed together.
|
|
|
|
assertNot(shouldTest("// +build arm 386", "linux", "amd64"))
|
|
|
|
|
2013-12-27 16:59:02 +00:00
|
|
|
// Build tags separated by a comma are AND-ed together.
|
2013-08-13 16:25:41 +00:00
|
|
|
assertNot(shouldTest("// +build !windows,!plan9", "windows", "amd64"))
|
|
|
|
assertNot(shouldTest("// +build !windows,!plan9", "plan9", "386"))
|
|
|
|
|
|
|
|
// Build tags on multiple lines are AND-ed together.
|
|
|
|
assert(shouldTest("// +build !windows\n// +build amd64", "linux", "amd64"))
|
|
|
|
assertNot(shouldTest("// +build !windows\n// +build amd64", "windows", "amd64"))
|
|
|
|
|
|
|
|
// Test that (!a OR !b) matches anything.
|
|
|
|
assert(shouldTest("// +build !windows !plan9", "windows", "amd64"))
|
2013-01-28 20:29:45 +00:00
|
|
|
}
|
2013-02-14 19:21:26 +00:00
|
|
|
|
2014-07-24 21:18:54 +00:00
|
|
|
func getenv(key, def string) string {
|
|
|
|
value := os.Getenv(key)
|
|
|
|
if value != "" {
|
|
|
|
return value
|
|
|
|
}
|
|
|
|
return def
|
|
|
|
}
|
2020-03-24 20:18:02 +00:00
|
|
|
|
|
|
|
// overlayDir makes a minimal-overhead copy of srcRoot in which new files may be added.
|
|
|
|
func overlayDir(dstRoot, srcRoot string) error {
|
|
|
|
dstRoot = filepath.Clean(dstRoot)
|
|
|
|
if err := os.MkdirAll(dstRoot, 0777); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
srcRoot, err := filepath.Abs(srcRoot)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-11-04 23:20:17 +00:00
|
|
|
return filepath.WalkDir(srcRoot, func(srcPath string, d fs.DirEntry, err error) error {
|
2020-03-24 20:18:02 +00:00
|
|
|
if err != nil || srcPath == srcRoot {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
suffix := strings.TrimPrefix(srcPath, srcRoot)
|
|
|
|
for len(suffix) > 0 && suffix[0] == filepath.Separator {
|
|
|
|
suffix = suffix[1:]
|
|
|
|
}
|
|
|
|
dstPath := filepath.Join(dstRoot, suffix)
|
|
|
|
|
2020-11-04 23:20:17 +00:00
|
|
|
var info fs.FileInfo
|
|
|
|
if d.Type()&os.ModeSymlink != 0 {
|
2020-03-24 20:18:02 +00:00
|
|
|
info, err = os.Stat(srcPath)
|
2020-11-04 23:20:17 +00:00
|
|
|
} else {
|
|
|
|
info, err = d.Info()
|
2020-03-24 20:18:02 +00:00
|
|
|
}
|
2020-11-04 23:20:17 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
perm := info.Mode() & os.ModePerm
|
2020-03-24 20:18:02 +00:00
|
|
|
|
|
|
|
// Always copy directories (don't symlink them).
|
|
|
|
// If we add a file in the overlay, we don't want to add it in the original.
|
|
|
|
if info.IsDir() {
|
|
|
|
return os.MkdirAll(dstPath, perm|0200)
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the OS supports symlinks, use them instead of copying bytes.
|
|
|
|
if err := os.Symlink(srcPath, dstPath); err == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, copy the bytes.
|
|
|
|
src, err := os.Open(srcPath)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer src.Close()
|
|
|
|
|
|
|
|
dst, err := os.OpenFile(dstPath, os.O_WRONLY|os.O_CREATE|os.O_EXCL, perm)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = io.Copy(dst, src)
|
|
|
|
if closeErr := dst.Close(); err == nil {
|
|
|
|
err = closeErr
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
})
|
|
|
|
}
|
2020-12-03 19:11:05 +00:00
|
|
|
|
2021-05-17 20:59:25 +00:00
|
|
|
// The following is temporary scaffolding to get types2 typechecker
|
|
|
|
// up and running against the existing test cases. The explicitly
|
|
|
|
// listed files don't pass yet, usually because the error messages
|
|
|
|
// are slightly different (this list is not complete). Any errorcheck
|
|
|
|
// tests that require output from analysis phases past initial type-
|
|
|
|
// checking are also excluded since these phases are not running yet.
|
|
|
|
// We can get rid of this code once types2 is fully plugged in.
|
|
|
|
|
2020-12-03 19:11:05 +00:00
|
|
|
// List of files that the compiler cannot errorcheck with the new typechecker (compiler -G option).
|
|
|
|
// Temporary scaffolding until we pass all the tests at which point this map can be removed.
|
2021-07-02 20:18:03 +00:00
|
|
|
var types2Failures = setOf(
|
|
|
|
"directive.go", // misplaced compiler directive checks
|
|
|
|
"float_lit3.go", // types2 reports extra errors
|
|
|
|
"import1.go", // types2 reports extra errors
|
|
|
|
"import6.go", // issue #43109
|
|
|
|
"initializerr.go", // types2 reports extra errors
|
|
|
|
"linkname2.go", // error reported by noder (not running for types2 errorcheck test)
|
|
|
|
"notinheap.go", // types2 doesn't report errors about conversions that are invalid due to //go:notinheap
|
|
|
|
"shift1.go", // issue #42989
|
|
|
|
"typecheck.go", // invalid function is not causing errors when called
|
|
|
|
|
|
|
|
"interface/private.go", // types2 phrases errors differently (doesn't use non-spec "private" term)
|
|
|
|
|
|
|
|
"fixedbugs/bug176.go", // types2 reports all errors (pref: types2)
|
|
|
|
"fixedbugs/bug195.go", // types2 reports slightly different (but correct) bugs
|
|
|
|
"fixedbugs/bug228.go", // types2 doesn't run when there are syntax errors
|
|
|
|
"fixedbugs/bug231.go", // types2 bug? (same error reported twice)
|
|
|
|
"fixedbugs/bug255.go", // types2 reports extra errors
|
|
|
|
"fixedbugs/bug374.go", // types2 reports extra errors
|
|
|
|
"fixedbugs/bug388.go", // types2 not run due to syntax errors
|
|
|
|
"fixedbugs/bug412.go", // types2 produces a follow-on error
|
|
|
|
|
|
|
|
"fixedbugs/issue10700.go", // types2 reports ok hint, but does not match regexp
|
|
|
|
"fixedbugs/issue11590.go", // types2 doesn't report a follow-on error (pref: types2)
|
|
|
|
"fixedbugs/issue11610.go", // types2 not run after syntax errors
|
|
|
|
"fixedbugs/issue11614.go", // types2 reports an extra error
|
|
|
|
"fixedbugs/issue14520.go", // missing import path error by types2
|
|
|
|
"fixedbugs/issue16428.go", // types2 reports two instead of one error
|
|
|
|
"fixedbugs/issue17038.go", // types2 doesn't report a follow-on error (pref: types2)
|
|
|
|
"fixedbugs/issue17645.go", // multiple errors on same line
|
|
|
|
"fixedbugs/issue18331.go", // missing error about misuse of //go:noescape (irgen needs code from noder)
|
|
|
|
"fixedbugs/issue18419.go", // types2 reports
|
|
|
|
"fixedbugs/issue19012.go", // multiple errors on same line
|
|
|
|
"fixedbugs/issue20233.go", // types2 reports two instead of one error (pref: compiler)
|
|
|
|
"fixedbugs/issue20245.go", // types2 reports two instead of one error (pref: compiler)
|
|
|
|
"fixedbugs/issue21979.go", // types2 doesn't report a follow-on error (pref: types2)
|
|
|
|
"fixedbugs/issue23732.go", // types2 reports different (but ok) line numbers
|
|
|
|
"fixedbugs/issue25958.go", // types2 doesn't report a follow-on error (pref: types2)
|
|
|
|
"fixedbugs/issue28079b.go", // types2 reports follow-on errors
|
|
|
|
"fixedbugs/issue28268.go", // types2 reports follow-on errors
|
|
|
|
"fixedbugs/issue31053.go", // types2 reports "unknown field" instead of "cannot refer to unexported field"
|
|
|
|
"fixedbugs/issue33460.go", // types2 reports alternative positions in separate error
|
|
|
|
"fixedbugs/issue42058a.go", // types2 doesn't report "channel element type too large"
|
|
|
|
"fixedbugs/issue42058b.go", // types2 doesn't report "channel element type too large"
|
|
|
|
"fixedbugs/issue4232.go", // types2 reports (correct) extra errors
|
|
|
|
"fixedbugs/issue4452.go", // types2 reports (correct) extra errors
|
|
|
|
"fixedbugs/issue4510.go", // types2 reports different (but ok) line numbers
|
2021-07-20 19:46:13 +00:00
|
|
|
"fixedbugs/issue47201.go", // types2 spells the error message differently
|
2021-07-02 20:18:03 +00:00
|
|
|
"fixedbugs/issue5609.go", // types2 needs a better error message
|
|
|
|
"fixedbugs/issue7525b.go", // types2 reports init cycle error on different line - ok otherwise
|
|
|
|
"fixedbugs/issue7525c.go", // types2 reports init cycle error on different line - ok otherwise
|
|
|
|
"fixedbugs/issue7525d.go", // types2 reports init cycle error on different line - ok otherwise
|
|
|
|
"fixedbugs/issue7525e.go", // types2 reports init cycle error on different line - ok otherwise
|
|
|
|
"fixedbugs/issue7525.go", // types2 reports init cycle error on different line - ok otherwise
|
|
|
|
)
|
|
|
|
|
|
|
|
var types2Failures32Bit = setOf(
|
|
|
|
"printbig.go", // large untyped int passed to print (32-bit)
|
|
|
|
"fixedbugs/bug114.go", // large untyped int passed to println (32-bit)
|
|
|
|
"fixedbugs/issue23305.go", // large untyped int passed to println (32-bit)
|
|
|
|
"fixedbugs/bug385_32.go", // types2 doesn't produce missing error "type .* too large" (32-bit specific)
|
|
|
|
)
|
|
|
|
|
|
|
|
var g3Failures = setOf(
|
2021-07-11 20:06:54 +00:00
|
|
|
"writebarrier.go", // correct diagnostics, but different lines (probably irgen's fault)
|
2021-07-02 20:18:03 +00:00
|
|
|
|
|
|
|
"typeparam/nested.go", // -G=3 doesn't support function-local types with generics
|
2021-06-08 18:57:11 +00:00
|
|
|
|
2021-09-09 18:17:39 +00:00
|
|
|
"typeparam/issue46461b.go", // -G=3 fails when type parameters refer back to the parameterized type itself
|
|
|
|
|
2021-08-22 20:34:22 +00:00
|
|
|
"typeparam/mdempsky/4.go", // -G=3 can't export functions with labeled breaks in loops
|
2021-07-02 20:18:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var unifiedFailures = setOf(
|
|
|
|
"closure3.go", // unified IR numbers closures differently than -d=inlfuncswithclosures
|
|
|
|
"escape4.go", // unified IR can inline f5 and f6; test doesn't expect this
|
|
|
|
"inline.go", // unified IR reports function literal diagnostics on different lines than -d=inlfuncswithclosures
|
|
|
|
|
|
|
|
"fixedbugs/issue42284.go", // prints "T(0) does not escape", but test expects "a.I(a.T(0)) does not escape"
|
|
|
|
"fixedbugs/issue7921.go", // prints "… escapes to heap", but test expects "string(…) escapes to heap"
|
|
|
|
)
|
|
|
|
|
|
|
|
func setOf(keys ...string) map[string]bool {
|
|
|
|
m := make(map[string]bool, len(keys))
|
|
|
|
for _, key := range keys {
|
|
|
|
m[key] = true
|
|
|
|
}
|
|
|
|
return m
|
2020-12-03 19:11:05 +00:00
|
|
|
}
|
2021-06-11 16:54:40 +00:00
|
|
|
|
|
|
|
// splitQuoted splits the string s around each instance of one or more consecutive
|
|
|
|
// white space characters while taking into account quotes and escaping, and
|
|
|
|
// returns an array of substrings of s or an empty list if s contains only white space.
|
|
|
|
// Single quotes and double quotes are recognized to prevent splitting within the
|
|
|
|
// quoted region, and are removed from the resulting substrings. If a quote in s
|
|
|
|
// isn't closed err will be set and r will have the unclosed argument as the
|
|
|
|
// last element. The backslash is used for escaping.
|
|
|
|
//
|
|
|
|
// For example, the following string:
|
|
|
|
//
|
|
|
|
// a b:"c d" 'e''f' "g\""
|
|
|
|
//
|
|
|
|
// Would be parsed as:
|
|
|
|
//
|
|
|
|
// []string{"a", "b:c d", "ef", `g"`}
|
|
|
|
//
|
|
|
|
// [copied from src/go/build/build.go]
|
|
|
|
func splitQuoted(s string) (r []string, err error) {
|
|
|
|
var args []string
|
|
|
|
arg := make([]rune, len(s))
|
|
|
|
escaped := false
|
|
|
|
quoted := false
|
|
|
|
quote := '\x00'
|
|
|
|
i := 0
|
|
|
|
for _, rune := range s {
|
|
|
|
switch {
|
|
|
|
case escaped:
|
|
|
|
escaped = false
|
|
|
|
case rune == '\\':
|
|
|
|
escaped = true
|
|
|
|
continue
|
|
|
|
case quote != '\x00':
|
|
|
|
if rune == quote {
|
|
|
|
quote = '\x00'
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
case rune == '"' || rune == '\'':
|
|
|
|
quoted = true
|
|
|
|
quote = rune
|
|
|
|
continue
|
|
|
|
case unicode.IsSpace(rune):
|
|
|
|
if quoted || i > 0 {
|
|
|
|
quoted = false
|
|
|
|
args = append(args, string(arg[:i]))
|
|
|
|
i = 0
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
arg[i] = rune
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
if quoted || i > 0 {
|
|
|
|
args = append(args, string(arg[:i]))
|
|
|
|
}
|
|
|
|
if quote != 0 {
|
|
|
|
err = errors.New("unclosed quote")
|
|
|
|
} else if escaped {
|
|
|
|
err = errors.New("unfinished escaping")
|
|
|
|
}
|
|
|
|
return args, err
|
|
|
|
}
|