Commit 0ae57c3b authored by Michael Hudson-Doyle's avatar Michael Hudson-Doyle Committed by Russ Cox

test: add ability to run tests with dynamic linking

This is a bit ugly but it's a useful test. Run go install -buildmode=shared std
and then go run run.go -linkshared (it passes on linux/amd64).

Change-Id: I5684c79cd03817fa1fc399788b7320f8535c08da
Reviewed-on: https://go-review.googlesource.com/16343Reviewed-by: default avatarRuss Cox <rsc@golang.org>
parent 0e771c72
...@@ -37,6 +37,7 @@ var ( ...@@ -37,6 +37,7 @@ var (
numParallel = flag.Int("n", runtime.NumCPU(), "number of parallel tests to run") numParallel = flag.Int("n", runtime.NumCPU(), "number of parallel tests to run")
summary = flag.Bool("summary", false, "show summary of results") summary = flag.Bool("summary", false, "show summary of results")
showSkips = flag.Bool("show_skips", false, "show skipped tests") showSkips = flag.Bool("show_skips", false, "show skipped tests")
linkshared = flag.Bool("linkshared", false, "")
updateErrors = flag.Bool("update_errors", false, "update error messages in test file based on compiler output") updateErrors = flag.Bool("update_errors", false, "update error messages in test file based on compiler output")
runoutputLimit = flag.Int("l", defaultRunOutputLimit(), "number of parallel runoutput tests to run") runoutputLimit = flag.Int("l", defaultRunOutputLimit(), "number of parallel runoutput tests to run")
...@@ -191,11 +192,19 @@ func goFiles(dir string) []string { ...@@ -191,11 +192,19 @@ func goFiles(dir string) []string {
type runCmd func(...string) ([]byte, error) type runCmd func(...string) ([]byte, error)
func compileFile(runcmd runCmd, longname string) (out []byte, err error) { func compileFile(runcmd runCmd, longname string) (out []byte, err error) {
return runcmd("go", "tool", "compile", "-e", longname) cmd := []string{"go", "tool", "compile", "-e"}
if *linkshared {
cmd = append(cmd, "-dynlink", "-installsuffix=dynlink")
}
cmd = append(cmd, longname)
return runcmd(cmd...)
} }
func compileInDir(runcmd runCmd, dir string, names ...string) (out []byte, err error) { func compileInDir(runcmd runCmd, dir string, names ...string) (out []byte, err error) {
cmd := []string{"go", "tool", "compile", "-e", "-D", ".", "-I", "."} cmd := []string{"go", "tool", "compile", "-e", "-D", ".", "-I", "."}
if *linkshared {
cmd = append(cmd, "-dynlink", "-installsuffix=dynlink")
}
for _, name := range names { for _, name := range names {
cmd = append(cmd, filepath.Join(dir, name)) cmd = append(cmd, filepath.Join(dir, name))
} }
...@@ -204,7 +213,12 @@ func compileInDir(runcmd runCmd, dir string, names ...string) (out []byte, err e ...@@ -204,7 +213,12 @@ func compileInDir(runcmd runCmd, dir string, names ...string) (out []byte, err e
func linkFile(runcmd runCmd, goname string) (err error) { func linkFile(runcmd runCmd, goname string) (err error) {
pfile := strings.Replace(goname, ".go", ".o", -1) pfile := strings.Replace(goname, ".go", ".o", -1)
_, err = runcmd("go", "tool", "link", "-w", "-o", "a.exe", "-L", ".", pfile) cmd := []string{"go", "tool", "link", "-w", "-o", "a.exe", "-L", "."}
if *linkshared {
cmd = append(cmd, "-linkshared", "-installsuffix=dynlink")
}
cmd = append(cmd, pfile)
_, err = runcmd(cmd...)
return return
} }
...@@ -513,6 +527,7 @@ func (t *test) run() { ...@@ -513,6 +527,7 @@ func (t *test) run() {
case "errorcheck": case "errorcheck":
cmdline := []string{"go", "tool", "compile", "-e", "-o", "a.o"} cmdline := []string{"go", "tool", "compile", "-e", "-o", "a.o"}
// No need to add -dynlink even if linkshared if we're just checking for errors...
cmdline = append(cmdline, flags...) cmdline = append(cmdline, flags...)
cmdline = append(cmdline, long) cmdline = append(cmdline, long)
out, err := runcmd(cmdline...) out, err := runcmd(cmdline...)
...@@ -628,7 +643,12 @@ func (t *test) run() { ...@@ -628,7 +643,12 @@ func (t *test) run() {
case "run": case "run":
useTmp = false useTmp = false
out, err := runcmd(append([]string{"go", "run", t.goFileName()}, args...)...) cmd := []string{"go", "run"}
if *linkshared {
cmd = append(cmd, "-linkshared")
}
cmd = append(cmd, t.goFileName())
out, err := runcmd(append(cmd, args...)...)
if err != nil { if err != nil {
t.err = err t.err = err
return return
...@@ -643,7 +663,12 @@ func (t *test) run() { ...@@ -643,7 +663,12 @@ func (t *test) run() {
<-rungatec <-rungatec
}() }()
useTmp = false useTmp = false
out, err := runcmd(append([]string{"go", "run", t.goFileName()}, args...)...) cmd := []string{"go", "run"}
if *linkshared {
cmd = append(cmd, "-linkshared")
}
cmd = append(cmd, t.goFileName())
out, err := runcmd(append(cmd, args...)...)
if err != nil { if err != nil {
t.err = err t.err = err
return return
...@@ -653,7 +678,12 @@ func (t *test) run() { ...@@ -653,7 +678,12 @@ func (t *test) run() {
t.err = fmt.Errorf("write tempfile:%s", err) t.err = fmt.Errorf("write tempfile:%s", err)
return return
} }
out, err = runcmd("go", "run", tfile) cmd = []string{"go", "run"}
if *linkshared {
cmd = append(cmd, "-linkshared")
}
cmd = append(cmd, tfile)
out, err = runcmd(cmd...)
if err != nil { if err != nil {
t.err = err t.err = err
return return
...@@ -664,7 +694,12 @@ func (t *test) run() { ...@@ -664,7 +694,12 @@ func (t *test) run() {
case "errorcheckoutput": case "errorcheckoutput":
useTmp = false useTmp = false
out, err := runcmd(append([]string{"go", "run", t.goFileName()}, args...)...) cmd := []string{"go", "run"}
if *linkshared {
cmd = append(cmd, "-linkshared")
}
cmd = append(cmd, t.goFileName())
out, err := runcmd(append(cmd, args...)...)
if err != nil { if err != nil {
t.err = err t.err = err
return return
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment