aboutsummaryrefslogtreecommitdiffstats
path: root/prog/generation.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2015-10-12 10:16:57 +0200
committerDmitry Vyukov <dvyukov@google.com>2015-10-12 10:16:57 +0200
commit874c5754bb22dbf77d6b600ff91f0f4f1fc5073a (patch)
tree0075fbd088046ad5c86e6e972235701d68b3ce7c /prog/generation.go
initial commit
Diffstat (limited to 'prog/generation.go')
-rw-r--r--prog/generation.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/prog/generation.go b/prog/generation.go
new file mode 100644
index 000000000..43e527aa0
--- /dev/null
+++ b/prog/generation.go
@@ -0,0 +1,29 @@
+// Copyright 2015 syzkaller project authors. All rights reserved.
+// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
+
+package prog
+
+import (
+ "math/rand"
+
+ "github.com/google/syzkaller/sys"
+)
+
+// Generate generates a random program of length ~ncalls.
+// calls is a set of allowed syscalls, if nil all syscalls are used.
+func Generate(rs rand.Source, ncalls int, enabledCalls []*sys.Call) *Prog {
+ p := new(Prog)
+ r := newRand(rs)
+ s := newState(enabledCalls)
+ for len(p.Calls) < ncalls {
+ calls := r.generateCall(s)
+ for _, c := range calls {
+ s.analyze(c)
+ p.Calls = append(p.Calls, c)
+ }
+ }
+ if err := p.validate(); err != nil {
+ panic(err)
+ }
+ return p
+}