tests: add benchmark for conditional breakpoints

This commit is contained in:
aarzilli 2020-01-23 17:55:08 +01:00 committed by Derek Parker
parent 279c29a37c
commit fc3e01bb5b
2 changed files with 33 additions and 1 deletions

16
_fixtures/issue1549.go Normal file

@ -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)
}

@ -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)
}
})
}