t.Fatalf("error writing go.mod: %v", err)
}
+ // Run the test without PGO to ensure that the test assertions are
+ // correct even in the non-optimized version.
+ cmd := testenv.CleanCmdEnv(testenv.Command(t, testenv.GoToolPath(t), "test", "."))
+ cmd.Dir = dir
+ b, err := cmd.CombinedOutput()
+ t.Logf("Test without PGO:\n%s", b)
+ if err != nil {
+ t.Fatalf("Test failed without PGO: %v", err)
+ }
+
// Build the test with the profile.
pprof := filepath.Join(dir, "devirt.pprof")
gcflag := fmt.Sprintf("-gcflags=-m=2 -pgoprofile=%s -d=pgodebug=3", pprof)
out := filepath.Join(dir, "test.exe")
- cmd := testenv.CleanCmdEnv(testenv.Command(t, testenv.GoToolPath(t), "build", "-o", out, gcflag, "."))
+ cmd = testenv.CleanCmdEnv(testenv.Command(t, testenv.GoToolPath(t), "test", "-o", out, gcflag, "."))
cmd.Dir = dir
pr, pw, err := os.Pipe()
}
want := []devirtualization{
+ // ExerciseIface
{
- pos: "./devirt.go:66:21",
+ pos: "./devirt.go:101:20",
callee: "mult.Mult.Multiply",
},
{
- pos: "./devirt.go:66:31",
+ pos: "./devirt.go:101:39",
callee: "Add.Add",
},
+ // ExerciseFuncConcrete
+ {
+ pos: "./devirt.go:178:18",
+ callee: "AddFn",
+ },
+ // TODO(prattmic): Export data lookup for function value callees not implemented.
+ //{
+ // pos: "./devirt.go:179:15",
+ // callee: "mult.MultFn",
+ //},
+ // ExerciseFuncField
+ {
+ pos: "./devirt.go:218:13",
+ callee: "AddFn",
+ },
+ // TODO(prattmic): Export data lookup for function value callees not implemented.
+ //{
+ // pos: "./devirt.go:219:19",
+ // callee: "mult.MultFn",
+ //},
+ // ExerciseFuncClosure
+ // TODO(prattmic): Closure callees not implemented.
+ //{
+ // pos: "./devirt.go:266:9",
+ // callee: "AddClosure.func1",
+ //},
+ //{
+ // pos: "./devirt.go:267:15",
+ // callee: "mult.MultClosure.func1",
+ //},
}
got := make(map[devirtualization]struct{})
- devirtualizedLine := regexp.MustCompile(`(.*): PGO devirtualizing .* to (.*)`)
+ devirtualizedLine := regexp.MustCompile(`(.*): PGO devirtualizing \w+ call .* to (.*)`)
scanner := bufio.NewScanner(pr)
for scanner.Scan() {
}
t.Errorf("devirtualization %v missing; got %v", w, got)
}
+
+ // Run test with PGO to ensure the assertions are still true.
+ cmd = testenv.CleanCmdEnv(testenv.Command(t, out))
+ cmd.Dir = dir
+ b, err = cmd.CombinedOutput()
+ t.Logf("Test with PGO:\n%s", b)
+ if err != nil {
+ t.Fatalf("Test failed without PGO: %v", err)
+ }
}
// TestPGODevirtualize tests that specific functions are devirtualized when PGO