From fc3e01bb5b62d080f629b8deffeb4a26b903e9c1 Mon Sep 17 00:00:00 2001 From: aarzilli Date: Thu, 23 Jan 2020 17:55:08 +0100 Subject: [PATCH] tests: add benchmark for conditional breakpoints --- _fixtures/issue1549.go | 16 ++++++++++++++++ pkg/proc/proc_test.go | 18 +++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 _fixtures/issue1549.go diff --git a/_fixtures/issue1549.go b/_fixtures/issue1549.go new file mode 100644 index 00000000..43a9592e --- /dev/null +++ b/_fixtures/issue1549.go @@ -0,0 +1,16 @@ +package main + +import ( + "fmt" + "time" +) + +func main() { + sum := int64(0) + start := time.Now() + for value := int64(0); value < 10000; value++ { + sum += value + } + elapsed := time.Since(start) + fmt.Printf("Sum: %d\nTook %s\n", sum, elapsed) +} diff --git a/pkg/proc/proc_test.go b/pkg/proc/proc_test.go index 05acdde2..7edc0b89 100644 --- a/pkg/proc/proc_test.go +++ b/pkg/proc/proc_test.go @@ -190,7 +190,7 @@ func setFunctionBreakpoint(p *proc.Target, t testing.TB, fname string) *proc.Bre return bp } -func setFileBreakpoint(p *proc.Target, t *testing.T, path string, lineno int) *proc.Breakpoint { +func setFileBreakpoint(p *proc.Target, t testing.TB, path string, lineno int) *proc.Breakpoint { _, f, l, _ := runtime.Caller(1) f = filepath.Base(f) @@ -4557,3 +4557,19 @@ func TestIssue1795(t *testing.T) { } }) } + +func BenchmarkConditionalBreakpoints(b *testing.B) { + b.N = 1 + withTestProcess("issue1549", b, func(p *proc.Target, fixture protest.Fixture) { + bp := setFileBreakpoint(p, b, fixture.Source, 12) + bp.Cond = &ast.BinaryExpr{ + Op: token.EQL, + X: &ast.Ident{Name: "value"}, + Y: &ast.BasicLit{Kind: token.INT, Value: "-1"}, + } + err := proc.Continue(p) + if _, exited := err.(proc.ErrProcessExited); !exited { + b.Fatalf("Unexpected error on Continue(): %v", err) + } + }) +}