diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2022-11-22 12:03:55 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2022-11-23 09:09:39 +0100 |
| commit | caddc6cbcef9933a4539a06714df006e0c5ac7b2 (patch) | |
| tree | a1c058c702d31527eb9a183f8115f73d6945776b /prog/export_test.go | |
| parent | 75740b3f90c81d4c226b0e30eec947df4fbd6832 (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 'prog/export_test.go')
| -rw-r--r-- | prog/export_test.go | 19 |
1 files changed, 2 insertions, 17 deletions
diff --git a/prog/export_test.go b/prog/export_test.go index 4a116dc49..e544103c1 100644 --- a/prog/export_test.go +++ b/prog/export_test.go @@ -6,10 +6,7 @@ package prog import ( "fmt" "math/rand" - "os" - "strconv" "testing" - "time" "github.com/google/syzkaller/pkg/testutil" ) @@ -26,18 +23,6 @@ var ( initTargetTest = InitTargetTest ) -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) -} - func iterCount() int { iters := 1000 if testing.Short() { @@ -51,7 +36,7 @@ func iterCount() int { func initRandomTargetTest(t *testing.T, os, arch string) (*Target, rand.Source, int) { target := initTargetTest(t, os, arch) - return target, randSource(t), iterCount() + return target, testutil.RandSource(t), iterCount() } func initTest(t *testing.T) (*Target, rand.Source, int) { @@ -78,7 +63,7 @@ func testEachTargetRandom(t *testing.T, fn func(t *testing.T, target *Target, rs if iters < 3 { iters = 3 } - rs0 := randSource(t) + rs0 := testutil.RandSource(t) for _, target := range targets { target := target rs := rand.NewSource(rs0.Int63()) |
