blob: 67dee7ddfea379c0f42d876549b3be953b0778a2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
// 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 IterCount() int {
iters := 1000
if testing.Short() {
iters /= 10
}
if RaceEnabled {
iters /= 10
}
return iters
}
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 RandMountImage(r *rand.Rand) []byte {
const maxLen = 1 << 20 // 1 MB.
len := r.Intn(maxLen)
slice := make([]byte, len)
r.Read(slice)
return slice
}
|