From caddc6cbcef9933a4539a06714df006e0c5ac7b2 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Tue, 22 Nov 2022 12:03:55 +0100 Subject: pkg/testutil: add RandSource helper The code to send rand source is dublicated in several packages. Move it to testutil package. --- pkg/testutil/testutil.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 pkg/testutil/testutil.go (limited to 'pkg/testutil') diff --git a/pkg/testutil/testutil.go b/pkg/testutil/testutil.go new file mode 100644 index 000000000..9a8de26bd --- /dev/null +++ b/pkg/testutil/testutil.go @@ -0,0 +1,24 @@ +// Copyright 2022 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +package testutil + +import ( + "math/rand" + "os" + "strconv" + "testing" + "time" +) + +func RandSource(t *testing.T) rand.Source { + seed := time.Now().UnixNano() + if fixed := os.Getenv("SYZ_SEED"); fixed != "" { + seed, _ = strconv.ParseInt(fixed, 0, 64) + } + if os.Getenv("CI") != "" { + seed = 0 // required for deterministic coverage reports + } + t.Logf("seed=%v", seed) + return rand.NewSource(seed) +} -- cgit mrf-deployment