tools/stress: minor improvements

This commit is contained in:
Dmitry Vyukov 2015-12-11 14:25:43 +01:00
parent c4b809f85f
commit 48d0a3662e

View File

@ -13,6 +13,7 @@ import (
"os"
"regexp"
"runtime"
"sync/atomic"
"time"
"github.com/google/syzkaller/ipc"
@ -24,18 +25,23 @@ var (
flagExecutor = flag.String("executor", "", "path to executor binary")
flagOutput = flag.Bool("output", false, "print executor output to console")
flagDebug = flag.Bool("debug", false, "executor debug output")
flagProcs = flag.Int("procs", runtime.NumCPU(), "number of parallel processes")
flagProcs = flag.Int("procs", 2*runtime.NumCPU(), "number of parallel processes")
flagThreaded = flag.Bool("threaded", true, "use threaded mode in executor")
flagCollide = flag.Bool("collide", true, "collide syscalls to provoke data races")
flagNobody = flag.Bool("nobody", false, "impersonate into nobody")
flagTimeout = flag.Duration("timeout", 5*time.Second, "executor timeout")
flagNobody = flag.Bool("nobody", true, "impersonate into nobody")
flagTimeout = flag.Duration("timeout", 10*time.Second, "executor timeout")
failedRe = regexp.MustCompile("runtime error: |panic: |Panic: ")
statExec uint64
)
const programLength = 30
func main() {
flag.Parse()
corpus := readCorpus()
log.Printf("parsed %v programs", len(corpus))
var flags uint64
if *flagThreaded {
flags |= ipc.FlagThreaded
@ -51,35 +57,41 @@ func main() {
}
for p := 0; p < *flagProcs; p++ {
p := p
go func() {
env, err := ipc.MakeEnv(*flagExecutor, 10*time.Second, flags)
env, err := ipc.MakeEnv(*flagExecutor, *flagTimeout, flags)
if err != nil {
failf("failed to create execution environment: %v", err)
}
rs := rand.NewSource(time.Now().UnixNano())
rs := rand.NewSource(time.Now().UnixNano() + int64(p)*1e12)
rnd := rand.New(rs)
for i := 0; ; i++ {
var p *prog.Prog
if len(corpus) == 0 || i%10 != 0 {
p = prog.Generate(rs, 50, nil)
if len(corpus) == 0 || i%2 != 0 {
p = prog.Generate(rs, programLength, nil)
execute(env, p)
p.Mutate(rs, 50, nil)
p.Mutate(rs, programLength, nil)
execute(env, p)
} else {
p = corpus[rnd.Intn(len(corpus))].Clone()
p.Mutate(rs, 50, nil)
p.Mutate(rs, programLength, nil)
execute(env, p)
p.Mutate(rs, programLength, nil)
execute(env, p)
}
}
}()
}
select {}
for range time.NewTicker(5 * time.Second).C {
log.Printf("executed %v programs", atomic.LoadUint64(&statExec))
}
}
func execute(env *ipc.Env, p *prog.Prog) {
if *flagExecutor == "" {
return
}
atomic.AddUint64(&statExec, 1)
output, _, _, _, _, err := env.Exec(p)
if err != nil {
fmt.Printf("failed to execute executor: %v\n", err)