From 1e9788a0d9bd8fca36978810fd3fc50b6c4f060b Mon Sep 17 00:00:00 2001 From: Veronica Radu Date: Tue, 10 Sep 2019 11:39:54 +0200 Subject: prog: add insertionPoint param in generateCall func --- prog/generation.go | 2 +- prog/mutation.go | 2 +- 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) } -- cgit mrf-deployment