From 7013cb0d7d7b78bb0160c45d13a8d7d472835513 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Wed, 7 Aug 2024 15:16:35 +0200 Subject: prog: replace MinimizeParams with MinimizeMode All callers shouldn't control lots of internal details of minimization (if we have more params, that's just more variations to test, and we don't have more, params is just a more convoluted way to say if we minimize for corpus or a crash). 2 bools also allow to express 4 options, but only 3 make sense. Also when I see MinimizeParams{} in the code, it's unclear what it means. Replace params with mode. And potentially "crash" minimization is not "light", it's just different. E.g. we can simplify int arguments for reproducers (esp in snapshot mode), but we don't need that for corpus. --- prog/minimization_test.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'prog/minimization_test.go') diff --git a/prog/minimization_test.go b/prog/minimization_test.go index e0736206a..7862bcc01 100644 --- a/prog/minimization_test.go +++ b/prog/minimization_test.go @@ -251,7 +251,7 @@ func TestMinimize(t *testing.T) { if err != nil { t.Fatalf("failed to deserialize original program #%v: %v", ti, err) } - p1, ci := Minimize(p, test.callIndex, MinimizeParams{}, test.pred) + p1, ci := Minimize(p, test.callIndex, MinimizeCorpus, test.pred) res := p1.Serialize() if string(res) != test.result { t.Fatalf("minimization produced wrong result #%v\norig:\n%v\nexpect:\n%v\ngot:\n%v", @@ -270,10 +270,10 @@ func TestMinimizeRandom(t *testing.T) { ct := target.DefaultChoiceTable() r := rand.New(rs) for i := 0; i < iters; i++ { - for _, crash := range []bool{false, true} { + for _, mode := range []MinimizeMode{MinimizeCorpus, MinimizeCrash} { p := target.Generate(rs, 5, ct) copyP := p.Clone() - minP, _ := Minimize(p, len(p.Calls)-1, MinimizeParams{Light: crash}, func(p1 *Prog, callIndex int) bool { + minP, _ := Minimize(p, len(p.Calls)-1, mode, func(p1 *Prog, callIndex int) bool { if r.Intn(2) == 0 { return false } @@ -296,7 +296,11 @@ func TestMinimizeCallIndex(t *testing.T) { for i := 0; i < iters; i++ { p := target.Generate(rs, 5, ct) ci := r.Intn(len(p.Calls)) - p1, ci1 := Minimize(p, ci, MinimizeParams{Light: r.Intn(2) == 0}, func(p1 *Prog, callIndex int) bool { + mode := MinimizeCorpus + if r.Intn(2) == 0 { + mode = MinimizeCrash + } + p1, ci1 := Minimize(p, ci, mode, func(p1 *Prog, callIndex int) bool { return r.Intn(2) == 0 }) if ci1 < 0 || ci1 >= len(p1.Calls) || p.Calls[ci].Meta.Name != p1.Calls[ci1].Meta.Name { -- cgit mrf-deployment