diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2020-05-21 13:37:18 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2020-05-21 13:56:29 +0200 |
| commit | 4053862c2605da2c3cfdf9f866f8588cf5716ebd (patch) | |
| tree | 338eb9212062a6d256d67e257a1e0cdd8a5c3ffa /prog/prio_test.go | |
| parent | d06aafeef69b6ffb906d7015fe5b24432766a579 (diff) | |
prog: fix determinism in choice table
Floats bite.
We interated over uses map non-deterministically,
which would be fine overall except that it may
break floats due to rounding.
Diffstat (limited to 'prog/prio_test.go')
| -rw-r--r-- | prog/prio_test.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/prog/prio_test.go b/prog/prio_test.go index 4497233b4..dede67e5f 100644 --- a/prog/prio_test.go +++ b/prog/prio_test.go @@ -7,6 +7,8 @@ import ( "math/rand" "reflect" "testing" + + "github.com/google/go-cmp/cmp" ) func TestNormalizePrio(t *testing.T) { @@ -67,3 +69,25 @@ func TestStaticPriorities(t *testing.T) { } } } + +func TestPrioDeterminism(t *testing.T) { + target, rs, iters := initTest(t) + ct := target.DefaultChoiceTable() + var corpus []*Prog + for i := 0; i < 100; i++ { + corpus = append(corpus, target.Generate(rs, 10, ct)) + } + ct0 := target.BuildChoiceTable(corpus, nil) + ct1 := target.BuildChoiceTable(corpus, nil) + if diff := cmp.Diff(ct0.runs, ct1.runs); diff != "" { + t.Fatal(diff) + } + for i := 0; i < iters; i++ { + seed := rs.Int63() + call0 := ct0.choose(rand.New(rand.NewSource(seed)), -1) + call1 := ct1.choose(rand.New(rand.NewSource(seed)), -1) + if call0 != call1 { + t.Fatalf("seed=%v iter=%v call=%v/%v", seed, i, call0, call1) + } + } +} |
