aboutsummaryrefslogtreecommitdiffstats
path: root/fuzzer
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2015-12-16 17:10:52 +0100
committerDmitry Vyukov <dvyukov@google.com>2015-12-17 14:38:46 +0100
commitd665e11e9df6cd99160817aad775bacdbbd2e26f (patch)
tree0d9092bced32d534e4023de269d7a281d0990abc /fuzzer
parentce0bb4c05d45db0bba56c5ab11d2b1d7c17e002a (diff)
move Gate type to ipc package and use it in stress tool
This allows to print what programs stress executes.
Diffstat (limited to 'fuzzer')
-rw-r--r--fuzzer/fuzzer.go57
1 files changed, 10 insertions, 47 deletions
diff --git a/fuzzer/fuzzer.go b/fuzzer/fuzzer.go
index f85a59a64..34d99499f 100644
--- a/fuzzer/fuzzer.go
+++ b/fuzzer/fuzzer.go
@@ -76,7 +76,7 @@ var (
triage []Input
candidates []*prog.Prog
- gate *Gate
+ gate *ipc.Gate
statExecGen uint64
statExecFuzz uint64
@@ -136,7 +136,7 @@ func main() {
*flagProcs = 1
}
- gate = newGate(2 * *flagProcs)
+ gate = ipc.NewGate(2 * *flagProcs)
envs := make([]*ipc.Env, *flagProcs)
for pid := 0; pid < *flagProcs; pid++ {
env, err := ipc.MakeEnv(*flagExecutor, 10*time.Second, flags)
@@ -418,8 +418,15 @@ func execute1(pid int, env *ipc.Env, p *prog.Prog, stat *uint64) []cover.Cover {
triageMu.Unlock()
}
+ // Limit concurrency window and do leak checking once in a while.
idx := gate.Enter()
- defer gate.Leave(idx)
+ defer gate.Leave(idx, func() {
+ if idx == 0 && *flagLeak && atomic.LoadUint32(&allTriaged) != 0 {
+ // Scan for leaks once in a while (it is damn slow).
+ kmemleakScan(true)
+ }
+ })
+
if *flagSaveProg {
f, err := os.Create(fmt.Sprintf("%v-%v.prog", *flagName, pid))
if err == nil {
@@ -471,50 +478,6 @@ func logf(v int, msg string, args ...interface{}) {
}
}
-type Gate struct {
- cv *sync.Cond
- busy []bool
- pos int
-}
-
-func newGate(c int) *Gate {
- return &Gate{
- cv: sync.NewCond(new(sync.Mutex)),
- busy: make([]bool, c),
- }
-}
-
-func (g *Gate) Enter() int {
- g.cv.L.Lock()
- for g.busy[g.pos] {
- g.cv.Wait()
- }
- idx := g.pos
- g.pos++
- if g.pos >= len(g.busy) {
- g.pos = 0
- }
- g.busy[idx] = true
- g.cv.L.Unlock()
- return idx
-}
-
-func (g *Gate) Leave(idx int) {
- g.cv.L.Lock()
- if !g.busy[idx] {
- panic("broken gate")
- }
- if idx == 0 && *flagLeak && atomic.LoadUint32(&allTriaged) != 0 {
- // Scan for leaks once in a while (it is damn slow).
- kmemleakScan(true)
- }
- g.busy[idx] = false
- if idx == g.pos {
- g.cv.Broadcast()
- }
- g.cv.L.Unlock()
-}
-
func kmemleakInit() {
fd, err := syscall.Open("/sys/kernel/debug/kmemleak", syscall.O_RDWR, 0)
if err != nil {