From 4053862c2605da2c3cfdf9f866f8588cf5716ebd Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Thu, 21 May 2020 13:37:18 +0200 Subject: 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. --- prog/prio_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'prog/prio_test.go') 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) + } + } +} -- cgit mrf-deployment