1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // Incomplete source tree on Android.
11 // This file runs the pointer analysis on all packages and tests beneath
12 // $GOROOT. It provides a "smoke test" that the analysis doesn't crash
13 // on a large input, and a benchmark for performance measurement.
15 // Because it is relatively slow, the --stdlib flag must be enabled for
17 // % go test -v golang.org/x/tools/go/pointer --stdlib
26 "golang.org/x/tools/go/buildutil"
27 "golang.org/x/tools/go/loader"
28 "golang.org/x/tools/go/ssa"
29 "golang.org/x/tools/go/ssa/ssautil"
32 var runStdlibTest = flag.Bool("stdlib", false, "Run the (slow) stdlib test")
34 func TestStdlib(t *testing.T) {
36 t.Skip("skipping (slow) stdlib test (use --stdlib)")
39 // Load, parse and type-check the program.
40 ctxt := build.Default // copy
41 ctxt.GOPATH = "" // disable GOPATH
42 conf := loader.Config{Build: &ctxt}
43 if _, err := conf.FromArgs(buildutil.AllPackages(conf.Build), true); err != nil {
44 t.Errorf("FromArgs failed: %v", err)
48 iprog, err := conf.Load()
50 t.Fatalf("Load failed: %v", err)
53 // Create SSA packages.
54 prog := ssautil.CreateProgram(iprog, 0)
57 numPkgs := len(prog.AllPackages())
58 if want := 240; numPkgs < want {
59 t.Errorf("Loaded only %d packages, want at least %d", numPkgs, want)
62 // Determine the set of packages/tests to analyze.
63 var mains []*ssa.Package
64 for _, info := range iprog.InitialPackages() {
65 ssapkg := prog.Package(info.Pkg)
66 if main := prog.CreateTestMainPackage(ssapkg); main != nil {
67 mains = append(mains, main)
71 t.Fatal("no tests found in analysis scope")
76 Reflection: false, // TODO(adonovan): fix remaining bug in rVCallConstraint, then enable.
80 // TODO(adonovan): add some query values (affects track bits).
84 result, err := Analyze(config)
86 t.Fatal(err) // internal error in pointer analysis
88 _ = result // TODO(adonovan): measure something
92 // Dump some statistics.
93 allFuncs := ssautil.AllFunctions(prog)
95 for fn := range allFuncs {
96 for _, b := range fn.Blocks {
97 numInstrs += len(b.Instrs)
101 // determine line count
103 prog.Fset.Iterate(func(f *token.File) bool {
104 lineCount += f.LineCount()
108 t.Log("#Source lines: ", lineCount)
109 t.Log("#Instructions: ", numInstrs)
110 t.Log("Pointer analysis: ", t1.Sub(t0))