mirror of
https://github.com/golang/go
synced 2024-11-20 06:54:42 -07:00
cmd/objdump: speed up tests
Rebuild cmd/objdump once instead of twice. Speeds up standalone 'go test cmd/objdump' on my machine from ~1.4s to ~1s. Updates #17751 Change-Id: I15fd79cf18c310f892bc28a9e9ca47ee010c989a Reviewed-on: https://go-review.googlesource.com/32673 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
3797446150
commit
6e26925626
@ -6,6 +6,7 @@ package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"go/build"
|
||||
"internal/testenv"
|
||||
"io/ioutil"
|
||||
@ -17,21 +18,43 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func buildObjdump(t *testing.T) (tmp, exe string) {
|
||||
testenv.MustHaveGoBuild(t)
|
||||
var tmp, exe string // populated by buildObjdump
|
||||
|
||||
tmp, err := ioutil.TempDir("", "TestObjDump")
|
||||
func TestMain(m *testing.M) {
|
||||
flag.Parse()
|
||||
if !testenv.HasGoBuild() {
|
||||
return
|
||||
}
|
||||
var exitcode int
|
||||
if err := buildObjdump(); err == nil {
|
||||
exitcode = m.Run()
|
||||
} else {
|
||||
fmt.Println(err)
|
||||
exitcode = 1
|
||||
}
|
||||
os.RemoveAll(tmp)
|
||||
os.Exit(exitcode)
|
||||
}
|
||||
|
||||
func buildObjdump() error {
|
||||
var err error
|
||||
tmp, err = ioutil.TempDir("", "TestObjDump")
|
||||
if err != nil {
|
||||
t.Fatal("TempDir failed: ", err)
|
||||
return fmt.Errorf("TempDir failed: %v", err)
|
||||
}
|
||||
|
||||
exe = filepath.Join(tmp, "testobjdump.exe")
|
||||
out, err := exec.Command(testenv.GoToolPath(t), "build", "-o", exe, "cmd/objdump").CombinedOutput()
|
||||
gotool, err := testenv.GoTool()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
out, err := exec.Command(gotool, "build", "-o", exe, "cmd/objdump").CombinedOutput()
|
||||
if err != nil {
|
||||
os.RemoveAll(tmp)
|
||||
t.Fatalf("go build -o %v cmd/objdump: %v\n%s", exe, err, string(out))
|
||||
return fmt.Errorf("go build -o %v cmd/objdump: %v\n%s", exe, err, string(out))
|
||||
}
|
||||
return
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var x86Need = []string{
|
||||
@ -70,9 +93,6 @@ var target = flag.String("target", "", "test disassembly of `goos/goarch` binary
|
||||
// can handle that one.
|
||||
|
||||
func testDisasm(t *testing.T, flags ...string) {
|
||||
tmp, exe := buildObjdump(t)
|
||||
defer os.RemoveAll(tmp)
|
||||
|
||||
goarch := runtime.GOARCH
|
||||
if *target != "" {
|
||||
f := strings.Split(*target, "/")
|
||||
|
Loading…
Reference in New Issue
Block a user