X-Git-Url: https://git.josue.xyz/?a=blobdiff_plain;f=.config%2Fcoc%2Fextensions%2Fcoc-go-data%2Ftools%2Fpkg%2Fmod%2Fgolang.org%2Fx%2Ftools%40v0.1.0%2Fgo%2Fpointer%2Fstdlib_test.go;fp=.config%2Fcoc%2Fextensions%2Fcoc-go-data%2Ftools%2Fpkg%2Fmod%2Fgolang.org%2Fx%2Ftools%40v0.1.0%2Fgo%2Fpointer%2Fstdlib_test.go;h=d3ba7216b4d20bbd262cd022ec75c3a7c82d93f2;hb=3c06164f15bd10aed7d66b6314764a2961a14762;hp=0000000000000000000000000000000000000000;hpb=0e9c3ceb40901f4d44981c1376cb9e23a248e006;p=dotfiles%2F.git diff --git a/.config/coc/extensions/coc-go-data/tools/pkg/mod/golang.org/x/tools@v0.1.0/go/pointer/stdlib_test.go b/.config/coc/extensions/coc-go-data/tools/pkg/mod/golang.org/x/tools@v0.1.0/go/pointer/stdlib_test.go new file mode 100644 index 00000000..d3ba7216 --- /dev/null +++ b/.config/coc/extensions/coc-go-data/tools/pkg/mod/golang.org/x/tools@v0.1.0/go/pointer/stdlib_test.go @@ -0,0 +1,111 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Incomplete source tree on Android. + +// +build !android + +package pointer + +// This file runs the pointer analysis on all packages and tests beneath +// $GOROOT. It provides a "smoke test" that the analysis doesn't crash +// on a large input, and a benchmark for performance measurement. +// +// Because it is relatively slow, the --stdlib flag must be enabled for +// this test to run: +// % go test -v golang.org/x/tools/go/pointer --stdlib + +import ( + "flag" + "go/build" + "go/token" + "testing" + "time" + + "golang.org/x/tools/go/buildutil" + "golang.org/x/tools/go/loader" + "golang.org/x/tools/go/ssa" + "golang.org/x/tools/go/ssa/ssautil" +) + +var runStdlibTest = flag.Bool("stdlib", false, "Run the (slow) stdlib test") + +func TestStdlib(t *testing.T) { + if !*runStdlibTest { + t.Skip("skipping (slow) stdlib test (use --stdlib)") + } + + // Load, parse and type-check the program. + ctxt := build.Default // copy + ctxt.GOPATH = "" // disable GOPATH + conf := loader.Config{Build: &ctxt} + if _, err := conf.FromArgs(buildutil.AllPackages(conf.Build), true); err != nil { + t.Errorf("FromArgs failed: %v", err) + return + } + + iprog, err := conf.Load() + if err != nil { + t.Fatalf("Load failed: %v", err) + } + + // Create SSA packages. + prog := ssautil.CreateProgram(iprog, 0) + prog.Build() + + numPkgs := len(prog.AllPackages()) + if want := 240; numPkgs < want { + t.Errorf("Loaded only %d packages, want at least %d", numPkgs, want) + } + + // Determine the set of packages/tests to analyze. + var mains []*ssa.Package + for _, info := range iprog.InitialPackages() { + ssapkg := prog.Package(info.Pkg) + if main := prog.CreateTestMainPackage(ssapkg); main != nil { + mains = append(mains, main) + } + } + if mains == nil { + t.Fatal("no tests found in analysis scope") + } + + // Run the analysis. + config := &Config{ + Reflection: false, // TODO(adonovan): fix remaining bug in rVCallConstraint, then enable. + BuildCallGraph: true, + Mains: mains, + } + // TODO(adonovan): add some query values (affects track bits). + + t0 := time.Now() + + result, err := Analyze(config) + if err != nil { + t.Fatal(err) // internal error in pointer analysis + } + _ = result // TODO(adonovan): measure something + + t1 := time.Now() + + // Dump some statistics. + allFuncs := ssautil.AllFunctions(prog) + var numInstrs int + for fn := range allFuncs { + for _, b := range fn.Blocks { + numInstrs += len(b.Instrs) + } + } + + // determine line count + var lineCount int + prog.Fset.Iterate(func(f *token.File) bool { + lineCount += f.LineCount() + return true + }) + + t.Log("#Source lines: ", lineCount) + t.Log("#Instructions: ", numInstrs) + t.Log("Pointer analysis: ", t1.Sub(t0)) +}