diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2021-10-01 14:43:02 +0000 |
|---|---|---|
| committer | Aleksandr Nogikh <wp32pw@gmail.com> | 2021-10-01 17:45:20 +0200 |
| commit | db0f57870523a9bff1629dad1a340ba8aac79d82 (patch) | |
| tree | 33b82e919cef96856bf952c78c76190885877fdd /prog | |
| parent | cc80db955d0551c2456692da6176530dd27e08ed (diff) | |
pkg/csource: remove calls instead of skipping them
Currently csource skips calls at the very last moment, which has an
unpleasant consequence - if we make choice of enabled defines depend on
the individual calls or call properties, we may end up with defined yet
unused functions.
The perfect solution would be to untie
syz_emit_ethernet/syz_extract_tcp_res and NetInjection, and also to
untie VhciInjection and syz_emit_vhci.
For the time being, move these checks to the very beginning of csource
processing, so that these calls could be removed before we construct our
defines.
Adjust pkg/csource/csource_test.go to better cover fault injection
generation problems.
Diffstat (limited to 'prog')
| -rw-r--r-- | prog/generation.go | 2 | ||||
| -rw-r--r-- | prog/minimization.go | 2 | ||||
| -rw-r--r-- | prog/mutation.go | 8 | ||||
| -rw-r--r-- | prog/prog.go | 2 | ||||
| -rw-r--r-- | prog/rand.go | 4 |
5 files changed, 9 insertions, 9 deletions
diff --git a/prog/generation.go b/prog/generation.go index 037801b75..09240e858 100644 --- a/prog/generation.go +++ b/prog/generation.go @@ -27,7 +27,7 @@ func (target *Target) Generate(rs rand.Source, ncalls int, ct *ChoiceTable) *Pro // The resources in the last call will be replaced with the default values, // which is exactly what we want. for len(p.Calls) > ncalls { - p.removeCall(ncalls - 1) + p.RemoveCall(ncalls - 1) } p.sanitizeFix() p.debugValidate() diff --git a/prog/minimization.go b/prog/minimization.go index 71320d92e..60a715b66 100644 --- a/prog/minimization.go +++ b/prog/minimization.go @@ -68,7 +68,7 @@ func removeCalls(p0 *Prog, callIndex0 int, crash bool, pred func(*Prog, int) boo callIndex-- } p := p0.Clone() - p.removeCall(i) + p.RemoveCall(i) if !pred(p, callIndex) { continue } diff --git a/prog/mutation.go b/prog/mutation.go index 9d6dc2118..0181aaa43 100644 --- a/prog/mutation.go +++ b/prog/mutation.go @@ -79,7 +79,7 @@ func (ctx *mutator) splice() bool { idx := r.Intn(len(p.Calls)) p.Calls = append(p.Calls[:idx], append(p0c.Calls, p.Calls[idx:]...)...) for i := len(p.Calls) - 1; i >= ctx.ncalls; i-- { - p.removeCall(i) + p.RemoveCall(i) } return true } @@ -141,7 +141,7 @@ func (ctx *mutator) insertCall() bool { calls := r.generateCall(s, p, idx) p.insertBefore(c, calls) for len(p.Calls) > ctx.ncalls { - p.removeCall(idx) + p.RemoveCall(idx) } return true } @@ -153,7 +153,7 @@ func (ctx *mutator) removeCall() bool { return false } idx := r.Intn(len(p.Calls)) - p.removeCall(idx) + p.RemoveCall(idx) return true } @@ -188,7 +188,7 @@ func (ctx *mutator) mutateArg() bool { idx += len(calls) for len(p.Calls) > ctx.ncalls { idx-- - p.removeCall(idx) + p.RemoveCall(idx) } if idx < 0 || idx >= len(p.Calls) || p.Calls[idx] != c { panic(fmt.Sprintf("wrong call index: idx=%v calls=%v p.Calls=%v ncalls=%v", diff --git a/prog/prog.go b/prog/prog.go index 068198ffe..d41117a2f 100644 --- a/prog/prog.go +++ b/prog/prog.go @@ -404,7 +404,7 @@ func removeArg(arg0 Arg) { } // removeCall removes call idx from p. -func (p *Prog) removeCall(idx int) { +func (p *Prog) RemoveCall(idx int) { c := p.Calls[idx] for _, arg := range c.Args { removeArg(arg) diff --git a/prog/rand.go b/prog/rand.go index f36cb0822..7a7de9b4a 100644 --- a/prog/rand.go +++ b/prog/rand.go @@ -881,7 +881,7 @@ func (r *randGen) resourceCentric(s *state, t *ResourceType, dir Dir) (arg Arg, } }) if !includeCall { - p.removeCall(idx) + p.RemoveCall(idx) } else { for _, res := range newResources { relatedRes[res] = true @@ -895,7 +895,7 @@ func (r *randGen) resourceCentric(s *state, t *ResourceType, dir Dir) (arg Arg, // Removes the references that are not used anymore. for i := biasedLen; i < len(calls); i++ { - p.removeCall(i) + p.RemoveCall(i) } return MakeResultArg(t, dir, resource, 0), p.Calls |
