1// Copyright 2015 syzkaller project authors. All rights reserved. 2// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4package prog 5 6import ( 7 "math/rand" 8) 9 10// Generate generates a random program of length ~ncalls. 11// calls is a set of allowed syscalls, if nil all syscalls are used. 12func (target *Target) Generate(rs rand.Source, ncalls int, ct *ChoiceTable) *Prog { 13 p := &Prog{ 14 Target: target, 15 } 16 r := newRand(target, rs) 17 s := newState(target, ct) 18 for len(p.Calls) < ncalls { 19 calls := r.generateCall(s, p) 20 for _, c := range calls { 21 s.analyze(c) 22 p.Calls = append(p.Calls, c) 23 } 24 } 25 p.debugValidate() 26 return p 27} 28