diff options
| author | Veronica Radu <veronicaradu@google.com> | 2019-09-10 11:39:54 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2019-09-23 15:35:26 +0200 |
| commit | 1e9788a0d9bd8fca36978810fd3fc50b6c4f060b (patch) | |
| tree | a74f499ed8ffbb4b92121c34f4fd58a6dfb895f8 | |
| parent | 8491e03fb279f9bf4f3f8678318b4e602355fa84 (diff) | |
prog: add insertionPoint param in generateCall func
| -rw-r--r-- | prog/generation.go | 2 | ||||
| -rw-r--r-- | prog/mutation.go | 2 | ||||
| -rw-r--r-- | prog/rand.go | 7 |
3 files changed, 6 insertions, 5 deletions
diff --git a/prog/generation.go b/prog/generation.go index dcb8dc2ac..85d1bbb02 100644 --- a/prog/generation.go +++ b/prog/generation.go @@ -16,7 +16,7 @@ func (target *Target) Generate(rs rand.Source, ncalls int, ct *ChoiceTable) *Pro r := newRand(target, rs) s := newState(target, ct, nil) for len(p.Calls) < ncalls { - calls := r.generateCall(s, p) + calls := r.generateCall(s, p, len(p.Calls)) for _, c := range calls { s.analyze(c) p.Calls = append(p.Calls, c) diff --git a/prog/mutation.go b/prog/mutation.go index b0702ebba..f19813148 100644 --- a/prog/mutation.go +++ b/prog/mutation.go @@ -134,7 +134,7 @@ func (ctx *mutator) insertCall() bool { c = p.Calls[idx] } s := analyze(ctx.ct, ctx.corpus, p, c) - calls := r.generateCall(s, p) + calls := r.generateCall(s, p, idx) // TODO: the program might have more than ncalls p.insertBefore(c, calls) return true diff --git a/prog/rand.go b/prog/rand.go index 3306ced66..f8c640161 100644 --- a/prog/rand.go +++ b/prog/rand.go @@ -490,14 +490,15 @@ func (r *randGen) nOutOf(n, outOf int) bool { return v < n } -func (r *randGen) generateCall(s *state, p *Prog) []*Call { +func (r *randGen) generateCall(s *state, p *Prog, insertionPoint int) []*Call { idx := 0 - if s.ct == nil { + if s.ct == nil || insertionPoint <= 0 { idx = r.Intn(len(r.target.Syscalls)) } else { call := -1 if len(p.Calls) != 0 { - call = p.Calls[r.Intn(len(p.Calls))].Meta.ID + // Choosing the base call is based on the insertion point of the new calls sequence. + call = p.Calls[r.Intn(insertionPoint)].Meta.ID } idx = s.ct.Choose(r.Rand, call) } |
