diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2018-08-01 19:45:15 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2018-08-02 16:57:31 +0200 |
| commit | 1da82ae0f070bbed7300a8e9462abeeb0cf3c344 (patch) | |
| tree | e42ef3d6c468255729aadb06e27fb0c024054525 /prog | |
| parent | c8643744fe4be55e516f7ba494777016abc1055e (diff) | |
prog: introduce debugValidate
Move debug validation into a separate function.
Update #538
Diffstat (limited to 'prog')
| -rw-r--r-- | prog/clone.go | 6 | ||||
| -rw-r--r-- | prog/encoding.go | 6 | ||||
| -rw-r--r-- | prog/encodingexec.go | 6 | ||||
| -rw-r--r-- | prog/generation.go | 6 | ||||
| -rw-r--r-- | prog/hints.go | 6 | ||||
| -rw-r--r-- | prog/minimization.go | 6 | ||||
| -rw-r--r-- | prog/mutation.go | 6 | ||||
| -rw-r--r-- | prog/validation.go | 8 |
8 files changed, 15 insertions, 35 deletions
diff --git a/prog/clone.go b/prog/clone.go index 3b6ba0fbc..5ad82c358 100644 --- a/prog/clone.go +++ b/prog/clone.go @@ -21,11 +21,7 @@ func (p *Prog) Clone() *Prog { } p1.Calls[ci] = c1 } - if debug { - if err := p1.validate(); err != nil { - panic(err) - } - } + p1.debugValidate() return p1 } diff --git a/prog/encoding.go b/prog/encoding.go index 1bdff4c6d..bdb00c7cc 100644 --- a/prog/encoding.go +++ b/prog/encoding.go @@ -25,11 +25,7 @@ func (p *Prog) String() string { } func (p *Prog) Serialize() []byte { - if debug { - if err := p.validate(); err != nil { - panic("serializing invalid program") - } - } + p.debugValidate() ctx := &serializer{ target: p.Target, buf: new(bytes.Buffer), diff --git a/prog/encodingexec.go b/prog/encodingexec.go index e67373923..659f4be3f 100644 --- a/prog/encodingexec.go +++ b/prog/encodingexec.go @@ -55,11 +55,7 @@ const ( // Returns number of bytes written to the buffer. // If the provided buffer is too small for the program an error is returned. func (p *Prog) SerializeForExec(buffer []byte) (int, error) { - if debug { - if err := p.validate(); err != nil { - panic(fmt.Errorf("serializing invalid program: %v", err)) - } - } + p.debugValidate() w := &execContext{ target: p.Target, buf: buffer, diff --git a/prog/generation.go b/prog/generation.go index 860924031..df31f0271 100644 --- a/prog/generation.go +++ b/prog/generation.go @@ -22,10 +22,6 @@ func (target *Target) Generate(rs rand.Source, ncalls int, ct *ChoiceTable) *Pro p.Calls = append(p.Calls, c) } } - if debug { - if err := p.validate(); err != nil { - panic(err) - } - } + p.debugValidate() return p } diff --git a/prog/hints.go b/prog/hints.go index 5250476e4..63199439c 100644 --- a/prog/hints.go +++ b/prog/hints.go @@ -68,11 +68,7 @@ func (p *Prog) MutateWithHints(callIndex int, comps CompMap, exec func(p *Prog)) c := p.Calls[callIndex] execValidate := func() { p.Target.SanitizeCall(c) - if debug { - if err := p.validate(); err != nil { - panic(fmt.Sprintf("invalid hints candidate: %v", err)) - } - } + p.debugValidate() exec(p) } ForeachArg(c, func(arg Arg, _ *ArgCtx) { diff --git a/prog/minimization.go b/prog/minimization.go index 021d8e2ea..35cff7976 100644 --- a/prog/minimization.go +++ b/prog/minimization.go @@ -16,11 +16,7 @@ func Minimize(p0 *Prog, callIndex0 int, crash bool, pred0 func(*Prog, int) bool) for _, call := range p.Calls { p.Target.SanitizeCall(call) } - if debug { - if err := p.validate(); err != nil { - panic(err) - } - } + p.debugValidate() return pred0(p, callIndex) } name0 := "" diff --git a/prog/mutation.go b/prog/mutation.go index fd5ef8f89..9dd06a4ba 100644 --- a/prog/mutation.go +++ b/prog/mutation.go @@ -134,11 +134,7 @@ outer: for _, c := range p.Calls { p.Target.SanitizeCall(c) } - if debug { - if err := p.validate(); err != nil { - panic(err) - } - } + p.debugValidate() } func (target *Target) mutateArg(r *randGen, s *state, arg Arg, ctx ArgCtx, updateSizes *bool) ([]*Call, bool) { diff --git a/prog/validation.go b/prog/validation.go index af27d4187..3274fca9e 100644 --- a/prog/validation.go +++ b/prog/validation.go @@ -10,6 +10,14 @@ import ( var debug = false // enabled in tests +func (p *Prog) debugValidate() { + if debug { + if err := p.validate(); err != nil { + panic(err) + } + } +} + type validCtx struct { target *Target args map[Arg]bool |
