mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-09 13:33:39 +00:00
testing: support -test.count
This makes running benchmarks repeatedly easier.
This commit is contained in:
+23
-17
@@ -27,6 +27,7 @@ var (
|
||||
matchBenchmarks *string
|
||||
benchmarkMemory *bool
|
||||
benchTime = benchTimeFlag{d: 1 * time.Second} // changed during test of testing package
|
||||
testCount *int
|
||||
)
|
||||
|
||||
type benchTimeFlag struct {
|
||||
@@ -213,11 +214,14 @@ func (b *B) doBench() BenchmarkResult {
|
||||
// of benchmark iterations until the benchmark runs for the requested benchtime.
|
||||
// run1 must have been called on b.
|
||||
func (b *B) launch() {
|
||||
runtime.GC()
|
||||
// Run the benchmark for at least the specified amount of time.
|
||||
if b.benchTime.n > 0 {
|
||||
b.runN(b.benchTime.n)
|
||||
} else {
|
||||
d := b.benchTime.d
|
||||
b.failed = false
|
||||
b.duration = 0
|
||||
for n := int64(1); !b.failed && b.duration < d && n < 1e9; {
|
||||
last := n
|
||||
// Predict required iterations.
|
||||
@@ -394,24 +398,26 @@ func runBenchmarks(matchString func(pat, str string) (bool, error), benchmarks [
|
||||
func (b *B) processBench(ctx *benchContext) {
|
||||
benchName := b.name
|
||||
|
||||
if ctx != nil {
|
||||
fmt.Printf("%-*s\t", ctx.maxLen, benchName)
|
||||
}
|
||||
r := b.doBench()
|
||||
if b.failed {
|
||||
// The output could be very long here, but probably isn't.
|
||||
// We print it all, regardless, because we don't want to trim the reason
|
||||
// the benchmark failed.
|
||||
fmt.Printf("--- FAIL: %s\n%s", benchName, "") // b.output)
|
||||
return
|
||||
}
|
||||
if ctx != nil {
|
||||
results := r.String()
|
||||
|
||||
if *benchmarkMemory || b.showAllocResult {
|
||||
results += "\t" + r.MemString()
|
||||
for i := 0; i < flagCount; i++ {
|
||||
if ctx != nil {
|
||||
fmt.Printf("%-*s\t", ctx.maxLen, benchName)
|
||||
}
|
||||
r := b.doBench()
|
||||
if b.failed {
|
||||
// The output could be very long here, but probably isn't.
|
||||
// We print it all, regardless, because we don't want to trim the reason
|
||||
// the benchmark failed.
|
||||
fmt.Printf("--- FAIL: %s\n%s", benchName, "") // b.output)
|
||||
return
|
||||
}
|
||||
if ctx != nil {
|
||||
results := r.String()
|
||||
|
||||
if *benchmarkMemory || b.showAllocResult {
|
||||
results += "\t" + r.MemString()
|
||||
}
|
||||
fmt.Println(results)
|
||||
}
|
||||
fmt.Println(results)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-6
@@ -26,6 +26,7 @@ var (
|
||||
flagVerbose bool
|
||||
flagShort bool
|
||||
flagRunRegexp string
|
||||
flagCount int
|
||||
)
|
||||
|
||||
var initRan bool
|
||||
@@ -40,6 +41,7 @@ func Init() {
|
||||
flag.BoolVar(&flagVerbose, "test.v", false, "verbose: print additional output")
|
||||
flag.BoolVar(&flagShort, "test.short", false, "short: run smaller test suite to save time")
|
||||
flag.StringVar(&flagRunRegexp, "test.run", "", "run: regexp of tests to run")
|
||||
flag.IntVar(&flagCount, "test.count", 1, "run each test or benchmark `count` times")
|
||||
|
||||
initBenchmarkFlags()
|
||||
}
|
||||
@@ -485,12 +487,14 @@ func runTests(matchString func(pat, str string) (bool, error), tests []InternalT
|
||||
context: ctx,
|
||||
}
|
||||
|
||||
tRunner(t, func(t *T) {
|
||||
for _, test := range tests {
|
||||
t.Run(test.Name, test.F)
|
||||
ok = ok && !t.Failed()
|
||||
}
|
||||
})
|
||||
for i := 0; i < flagCount; i++ {
|
||||
tRunner(t, func(t *T) {
|
||||
for _, test := range tests {
|
||||
t.Run(test.Name, test.F)
|
||||
ok = ok && !t.Failed()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return t.ran, ok
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user