forked from bufbuild/protoc-gen-validate
/
executor.go
60 lines (48 loc) · 870 Bytes
/
executor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"log"
"os"
"runtime"
"sync"
"sync/atomic"
"testing"
"time"
)
func main() {
start := time.Now()
log.SetFlags(0)
successes, failures := uint64(0), uint64(0)
wg := new(sync.WaitGroup)
wg.Add(runtime.NumCPU())
in := make(chan TestCase)
out := make(chan bool)
done := make(chan struct{})
for i := 0; i < runtime.NumCPU(); i++ {
go Work(wg, in, out)
}
go func() {
for success := range out {
if success {
atomic.AddUint64(&successes, 1)
} else {
atomic.AddUint64(&failures, 1)
}
}
close(done)
}()
log.Println("loading test cases")
for _, test := range TestCases {
in <- test
}
close(in)
wg.Wait()
close(out)
<-done
log.Printf("Successes: %d | Failures: %d (%v)", successes, failures, time.Since(start))
if failures > 0 {
os.Exit(1)
}
}
func TestEverything(test *testing.T) {
main()
}