diff options
| author | Andrey Konovalov <andreyknvl@gmail.com> | 2017-06-12 19:59:33 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-06-12 19:59:33 +0200 |
| commit | 75fc393514b64e2416c5a2d5a29997981ec12dc4 (patch) | |
| tree | 4d3d74d2854ca2b69ab4cd930f4984c9a064d0f7 /csource/csource_test.go | |
| parent | 4ca73f9c87f1098a69deb761a8d23f040d8e89db (diff) | |
| parent | ebcd9ade3f2d3098f069dcc0a0f093ca7b3ed6b1 (diff) | |
Merge pull request #195 from xairy/up-simplify-csource
Simplify generated C reproducers
Diffstat (limited to 'csource/csource_test.go')
| -rw-r--r-- | csource/csource_test.go | 94 |
1 files changed, 62 insertions, 32 deletions
diff --git a/csource/csource_test.go b/csource/csource_test.go index abff96f72..7db490444 100644 --- a/csource/csource_test.go +++ b/csource/csource_test.go @@ -7,6 +7,7 @@ import ( "fmt" "math/rand" "os" + "reflect" "testing" "time" @@ -16,47 +17,66 @@ import ( func initTest(t *testing.T) (rand.Source, int) { t.Parallel() - iters := 10 - if testing.Short() { - iters = 1 - } + iters := 1 seed := int64(time.Now().UnixNano()) rs := rand.NewSource(seed) t.Logf("seed=%v", seed) return rs, iters } +func enumerateField(opt Options, field int) []Options { + var opts []Options + s := reflect.ValueOf(&opt).Elem() + fldName := s.Type().Field(field).Name + fld := s.Field(field) + if fldName == "Sandbox" { + for _, sandbox := range []string{"", "none", "setuid", "namespace"} { + fld.SetString(sandbox) + opts = append(opts, opt) + } + } else if fldName == "Procs" { + for _, procs := range []int64{1, 4} { + fld.SetInt(procs) + opts = append(opts, opt) + } + } else if fldName == "FaultCall" { + opts = append(opts, opt) + } else if fldName == "FaultNth" { + opts = append(opts, opt) + } else if fld.Kind() == reflect.Bool { + for _, v := range []bool{false, true} { + fld.SetBool(v) + opts = append(opts, opt) + } + } else { + panic(fmt.Sprintf("field '%v' is not boolean", fldName)) + } + return opts +} + +func allOptionsSingle() []Options { + var opts []Options + fields := reflect.TypeOf(Options{}).NumField() + for i := 0; i < fields; i++ { + opts = append(opts, enumerateField(Options{}, i)...) + } + return opts +} + func allOptionsPermutations() []Options { - var options []Options - var opt Options - for _, opt.Threaded = range []bool{false, true} { - for _, opt.Collide = range []bool{false, true} { - for _, opt.Repeat = range []bool{false, true} { - for _, opt.Repro = range []bool{false, true} { - for _, opt.Procs = range []int{1, 4} { - for _, opt.Sandbox = range []string{"none", "setuid", "namespace"} { - for _, opt.Fault = range []bool{false, true} { - if opt.Collide && !opt.Threaded { - continue - } - if !opt.Repeat && opt.Procs != 1 { - continue - } - if testing.Short() && opt.Procs != 1 { - continue - } - options = append(options, opt) - } - } - } - } - } + opts := []Options{ Options{} } + fields := reflect.TypeOf(Options{}).NumField() + for i := 0; i < fields; i++ { + var newOpts []Options + for _, opt := range opts { + newOpts = append(newOpts, enumerateField(opt, i)...) } + opts = newOpts } - return options + return opts } -func TestSyz(t *testing.T) { +func TestOne(t *testing.T) { rs, _ := initTest(t) opts := Options{ Threaded: true, @@ -70,11 +90,21 @@ func TestSyz(t *testing.T) { testOne(t, p, opts) } -func Test(t *testing.T) { +func TestOptions(t *testing.T) { rs, _ := initTest(t) syzProg := prog.GenerateAllSyzProg(rs) t.Logf("syz program:\n%s\n", syzProg.Serialize()) - for i, opts := range allOptionsPermutations() { + permutations := allOptionsSingle() + allPermutations := allOptionsPermutations() + if testing.Short() { + r := rand.New(rs) + for i := 0; i < 32; i++ { + permutations = append(permutations, allPermutations[r.Intn(len(allPermutations))]) + } + } else { + permutations = append(permutations, allPermutations...) + } + for i, opts := range permutations { t.Run(fmt.Sprintf("%v", i), func(t *testing.T) { rs, iters := initTest(t) t.Logf("opts: %+v", opts) |
