X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fcmd%2Fcompile%2Finternal%2Ftest%2Fpgo_devirtualize_test.go;h=3e264a3f41cb6752d9b363ed27f7b5ac2e943d26;hb=fb6ff1e4caaece9be61c45518ffb51081e892a73;hp=fbee8dedfdbe345d786d2d3f425a651951b86c8d;hpb=0c66ae5c27706d4fe5c43fc71f92b52052b24497;p=gostls13.git diff --git a/src/cmd/compile/internal/test/pgo_devirtualize_test.go b/src/cmd/compile/internal/test/pgo_devirtualize_test.go index fbee8dedfd..3e264a3f41 100644 --- a/src/cmd/compile/internal/test/pgo_devirtualize_test.go +++ b/src/cmd/compile/internal/test/pgo_devirtualize_test.go @@ -29,11 +29,21 @@ go 1.19 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() @@ -56,19 +66,50 @@ go 1.19 } 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() { @@ -102,6 +143,15 @@ go 1.19 } 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