diff options
| author | Veronica Radu <veronicaradu@google.com> | 2019-09-11 18:20:17 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2019-09-23 15:33:19 +0200 |
| commit | bf7e28925b8894ca13f803f66d16cf2b0ae12430 (patch) | |
| tree | 5e25e384f1b97ff2f3fda580dd2ac2fe6fb43d91 /prog/mutation_test.go | |
| parent | d96e88f3207d7ac7ad65e13b896f702ad04c46f7 (diff) | |
prog: use type size when generating/mutating ints
Update #1381
Diffstat (limited to 'prog/mutation_test.go')
| -rw-r--r-- | prog/mutation_test.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/prog/mutation_test.go b/prog/mutation_test.go index 9ae807e0a..6d19300b4 100644 --- a/prog/mutation_test.go +++ b/prog/mutation_test.go @@ -152,6 +152,37 @@ func TestMutateArgument(t *testing.T) { } } +func TestSizeMutateArg(t *testing.T) { + target, rs, iters := initRandomTargetTest(t, "test", "64") + r := newRand(target, rs) + ct := target.BuildChoiceTable(nil, nil) + for i := 0; i < 100; i++ { + p := target.Generate(rs, 10, nil) + for it := 0; it < iters; it++ { + p1 := p.Clone() + ctx := &mutator{ + p: p1, + r: r, + ncalls: 10, + ct: ct, + corpus: nil, + } + ctx.mutateArg() + ForeachArg(p.Calls[0], func(arg Arg, ctx *ArgCtx) { + if _, ok := arg.Type().(*IntType); !ok { + return + } + bits := arg.Type().TypeBitSize() + limit := uint64(1<<bits - 1) + val := arg.(*ConstArg).Val + if val > limit { + t.Fatalf("Invalid argument value: %d. (arg size: %d; max value: %d)", val, arg.Size(), limit) + } + }) + } + } +} + func TestRandomChoice(t *testing.T) { t.Parallel() target, err := GetTarget("test", "64") |
