aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/testutil
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2022-11-22 12:03:55 +0100
committerDmitry Vyukov <dvyukov@google.com>2022-11-23 09:09:39 +0100
commitcaddc6cbcef9933a4539a06714df006e0c5ac7b2 (patch)
treea1c058c702d31527eb9a183f8115f73d6945776b /pkg/testutil
parent75740b3f90c81d4c226b0e30eec947df4fbd6832 (diff)
pkg/testutil: add RandSource helper
The code to send rand source is dublicated in several packages. Move it to testutil package.
Diffstat (limited to 'pkg/testutil')
-rw-r--r--pkg/testutil/testutil.go24
1 files changed, 24 insertions, 0 deletions
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)
+}