diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2017-08-09 12:57:23 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2017-08-09 15:41:52 +0200 |
| commit | 8b78527436f4171d1fbd1c44b1954b7807ec5ef4 (patch) | |
| tree | 62df7be0fbdad79d8d3889527277a278f2147a7a /pkg/csource/csource.go | |
| parent | 98dd5f9922717291e20498f5b3ee48694a568a0a (diff) | |
pkg/csource, pkg/repro: filter out invalid options combinations
We currently have 2 invalid options combinations:
- collide without threads
- procs>1 without repeat
They are invalid in the sense that result of csource.Write
is the same for them. Filter out these combinations.
This cuts csource testing time in half and reduces repro minimization time.
Diffstat (limited to 'pkg/csource/csource.go')
| -rw-r--r-- | pkg/csource/csource.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/pkg/csource/csource.go b/pkg/csource/csource.go index 32415e982..e351a2e1d 100644 --- a/pkg/csource/csource.go +++ b/pkg/csource/csource.go @@ -9,6 +9,7 @@ package csource import ( "bytes" + "errors" "fmt" "io" "io/ioutil" @@ -45,7 +46,23 @@ type Options struct { Repro bool } +// Check checks if the opts combination is valid or not. +// For example, Collide without Threaded is not valid. +// Invalid combinations must not be passed to Write. +func (opts Options) Check() error { + if !opts.Threaded && opts.Collide { + return errors.New("Collide without Threaded") + } + if !opts.Repeat && opts.Procs > 1 { + return errors.New("Procs>1 without Repeat") + } + return nil +} + func Write(p *prog.Prog, opts Options) ([]byte, error) { + if err := opts.Check(); err != nil { + return nil, fmt.Errorf("csource: invalid opts: %v", err) + } exec := make([]byte, prog.ExecBufferSize) if err := p.SerializeForExec(exec, 0); err != nil { return nil, fmt.Errorf("failed to serialize program: %v", err) |
