diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2018-01-26 12:34:02 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2018-01-27 17:08:43 +0100 |
| commit | e8b49705479678b38c0068e84f1f599af8829184 (patch) | |
| tree | 4010754d8153c508159c24fe6ac2caeddaf4f284 /prog/mutation_test.go | |
| parent | 1d18b11287c0248782efe867659c17dbdf76e3d5 (diff) | |
pkg/compiler: allow unions with only 1 field
Unions with only 1 field are not actually unions,
and can always be replaced with the option type.
However, they are still useful when there will be
more options in future but currently only 1 is described.
Alternatives are:
- not using union (but then all existing programs will be
broken when union is finally introduced)
- adding a fake field (ugly and reduces fuzzer efficiency)
Allow unions with only 1 field.
Diffstat (limited to 'prog/mutation_test.go')
| -rw-r--r-- | prog/mutation_test.go | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/prog/mutation_test.go b/prog/mutation_test.go index 97490a078..144b48d11 100644 --- a/prog/mutation_test.go +++ b/prog/mutation_test.go @@ -24,32 +24,33 @@ func TestClone(t *testing.T) { } func TestMutateRandom(t *testing.T) { - target, rs, iters := initTest(t) -next: - for i := 0; i < iters; i++ { - p := target.Generate(rs, 10, nil) - data0 := p.Serialize() - p1 := p.Clone() - // There is a chance that mutation will produce the same program. - // So we check that at least 1 out of 10 mutations actually change the program. - for try := 0; try < 10; try++ { - p1.Mutate(rs, 10, nil, nil) - data := p.Serialize() - if !bytes.Equal(data0, data) { - t.Fatalf("program changed after clone/mutate\noriginal:\n%s\n\nnew:\n%s\n", - data0, data) - } - data1 := p1.Serialize() - if bytes.Equal(data, data1) { - continue - } - if _, err := target.Deserialize(data1); err != nil { - t.Fatalf("Deserialize failed after Mutate: %v\n%s", err, data1) + testEachTargetRandom(t, func(t *testing.T, target *Target, rs rand.Source, iters int) { + next: + for i := 0; i < iters; i++ { + p := target.Generate(rs, 10, nil) + data0 := p.Serialize() + p1 := p.Clone() + // There is a chance that mutation will produce the same program. + // So we check that at least 1 out of 10 mutations actually change the program. + for try := 0; try < 10; try++ { + p1.Mutate(rs, 10, nil, nil) + data := p.Serialize() + if !bytes.Equal(data0, data) { + t.Fatalf("program changed after mutate\noriginal:\n%s\n\nnew:\n%s\n", + data0, data) + } + data1 := p1.Serialize() + if bytes.Equal(data, data1) { + continue + } + if _, err := target.Deserialize(data1); err != nil { + t.Fatalf("Deserialize failed after Mutate: %v\n%s", err, data1) + } + continue next } - continue next + t.Fatalf("mutation does not change program:\n%s", data0) } - t.Fatalf("mutation does not change program:\n%s", data0) - } + }) } func TestMutateCorpus(t *testing.T) { |
