diff options
author | Josh Bleecher Snyder <josharian@gmail.com> | 2017-08-20 10:17:02 -0700 |
---|---|---|
committer | Josh Bleecher Snyder <josharian@gmail.com> | 2017-08-22 23:07:40 +0000 |
commit | f6944c780f5104114a7a5e404115478f8deb739b (patch) | |
tree | 4483508233dc75bad79ee6a9993bc2e53651c727 /src/runtime/runtime_test.go | |
parent | 6cbe5c8ac342ad3d8f907caf105feaa55cb0404b (diff) | |
download | go-f6944c780f5104114a7a5e404115478f8deb739b.tar.gz go-f6944c780f5104114a7a5e404115478f8deb739b.zip |
runtime: add TestIntendedInlining
The intent is to allow more aggressive refactoring
in the runtime without silent performance changes.
The test would be useful for many functions.
I've seeded it with the runtime functions tophash and add;
it will grow organically (or wither!) from here.
Updates #21536 and #17566
Change-Id: Ib26d9cfd395e7a8844150224da0856add7bedc42
Reviewed-on: https://go-review.googlesource.com/57410
Reviewed-by: Martin Möhrmann <moehrmann@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/runtime/runtime_test.go')
-rw-r--r-- | src/runtime/runtime_test.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/runtime/runtime_test.go b/src/runtime/runtime_test.go index 922cd830bc..25dfe921fe 100644 --- a/src/runtime/runtime_test.go +++ b/src/runtime/runtime_test.go @@ -5,7 +5,10 @@ package runtime_test import ( + "bytes" + "internal/testenv" "io" + "os/exec" . "runtime" "runtime/debug" "strings" @@ -354,3 +357,42 @@ func TestVersion(t *testing.T) { t.Fatalf("cr/nl in version: %q", vers) } } + +// TestIntendedInlining tests that specific runtime functions are inlined. +// This allows refactoring for code clarity and re-use without fear that +// changes to the compiler will cause silent performance regressions. +func TestIntendedInlining(t *testing.T) { + if testing.Short() { + t.Skip("skipping in short mode") + } + testenv.MustHaveGoRun(t) + t.Parallel() + + // want is the list of function names that should be inlined. + want := []string{"tophash", "add"} + + m := make(map[string]bool, len(want)) + for _, s := range want { + m[s] = true + } + + cmd := testEnv(exec.Command(testenv.GoToolPath(t), "build", "-gcflags=-m", "runtime")) + out, err := cmd.CombinedOutput() + if err != nil { + t.Logf("%s", out) + t.Fatal(err) + } + lines := bytes.Split(out, []byte{'\n'}) + for _, x := range lines { + f := bytes.Split(x, []byte(": can inline ")) + if len(f) < 2 { + continue + } + fn := bytes.TrimSpace(f[1]) + delete(m, string(fn)) + } + + for s := range m { + t.Errorf("function %s not inlined", s) + } +} |