mirror of
https://github.com/reactos/syzkaller.git
synced 2025-02-15 09:07:43 +00:00
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.
This commit is contained in:
parent
98dd5f9922
commit
8b78527436
@ -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)
|
||||
|
@ -51,7 +51,13 @@ func enumerateField(opt Options, field int) []Options {
|
||||
} else {
|
||||
panic(fmt.Sprintf("field '%v' is not boolean", fldName))
|
||||
}
|
||||
return opts
|
||||
var checked []Options
|
||||
for _, opt := range opts {
|
||||
if err := opt.Check(); err == nil {
|
||||
checked = append(checked, opt)
|
||||
}
|
||||
}
|
||||
return checked
|
||||
}
|
||||
|
||||
func allOptionsSingle() []Options {
|
||||
@ -102,7 +108,7 @@ func TestOptions(t *testing.T) {
|
||||
permutations = append(permutations, allPermutations[r.Intn(len(allPermutations))])
|
||||
}
|
||||
} else {
|
||||
permutations = append(permutations, allPermutations...)
|
||||
permutations = allPermutations
|
||||
}
|
||||
for i, opts := range permutations {
|
||||
t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {
|
||||
|
@ -757,6 +757,7 @@ var progSimplifies = []Simplify{
|
||||
return false
|
||||
}
|
||||
opts.Repeat = false
|
||||
opts.Procs = 1
|
||||
return true
|
||||
},
|
||||
func(opts *csource.Options) bool {
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/syzkaller/pkg/csource"
|
||||
"github.com/google/syzkaller/prog"
|
||||
)
|
||||
|
||||
@ -63,3 +64,27 @@ func TestBisect(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSimplifies(t *testing.T) {
|
||||
opts := csource.Options{
|
||||
Threaded: true,
|
||||
Collide: true,
|
||||
Repeat: true,
|
||||
Procs: 10,
|
||||
Sandbox: "namespace",
|
||||
EnableTun: true,
|
||||
UseTmpDir: true,
|
||||
HandleSegv: true,
|
||||
WaitRepeat: true,
|
||||
Repro: true,
|
||||
}
|
||||
if err := opts.Check(); err != nil {
|
||||
t.Fatalf("initial opts are invalid: %v", err)
|
||||
}
|
||||
for i, fn := range cSimplifies {
|
||||
fn(&opts)
|
||||
if err := opts.Check(); err != nil {
|
||||
t.Fatalf("opts %v are invalid: %v", i, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user