Skip to content

Commit

Permalink
cmd/objdump: speed up tests
Browse files Browse the repository at this point in the history
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 <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Brad Fitzpatrick <[email protected]>
  • Loading branch information
josharian committed Nov 4, 2016
1 parent 3797446 commit 6e26925
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions src/cmd/objdump/objdump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main

import (
"flag"
"fmt"
"go/build"
"internal/testenv"
"io/ioutil"
Expand All @@ -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{
Expand Down Expand Up @@ -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, "/")
Expand Down

0 comments on commit 6e26925

Please sign in to comment.