| @@ -31,14 +31,7 @@ const ( · 30 unmodified lines |
| 31 | 31 | ) |
| 32 | 32 | |
| 33 | 33 | var ( |
| 34 | | − checks = flag.Int("rapid.checks", 100, "rapid: number of checks to perform") |
| 35 | | − steps = flag.Int("rapid.steps", 100, "rapid: number of state machine steps to perform") |
| 36 | | − startSeed = flag.Uint64("rapid.seed", 0, "rapid: PRNG seed to start with (0 to use a random one)") |
| 37 | | − rapidLog = flag.Bool("rapid.log", false, "rapid: eager verbose output to stdout (to aid with unrecoverable test failures)") |
| 38 | | − verbose = flag.Bool("rapid.v", false, "rapid: verbose output") |
| 39 | | − debug = flag.Bool("rapid.debug", false, "rapid: debugging output") |
| 40 | | − debugvis = flag.Bool("rapid.debugvis", false, "rapid: debugging visualization") |
| 41 | | − shrinkTime = flag.Duration("rapid.shrinktime", 30*time.Second, "rapid: maximum time to spend on test case minimization") |
| 34 | + flags cmdline |
| 42 | 35 | |
| 43 | 36 | emptyStructType = reflect.TypeOf(struct{}{}) |
| 44 | 37 | emptyStructValue = reflect.ValueOf(struct{}{}) |
| @@ -49,6 +42,28 @@ var ( · 4 unmodified lines |
| 49 | 42 | } |
| 50 | 43 | ) |
| 51 | 44 | |
| 45 | +type cmdline struct { |
| 46 | + checks int |
| 47 | + steps int |
| 48 | + startSeed uint64 |
| 49 | + rapidLog bool |
| 50 | + verbose bool |
| 51 | + debug bool |
| 52 | + debugvis bool |
| 53 | + shrinkTime time.Duration |
| 54 | +} |
| 55 | + |
| 56 | +func init() { |
| 57 | + flag.IntVar(&flags.checks, "rapid.checks", 100, "rapid: number of checks to perform") |
| 58 | + flag.IntVar(&flags.steps, "rapid.steps", 100, "rapid: number of state machine steps to perform") |
| 59 | + flag.Uint64Var(&flags.startSeed, "rapid.seed", 0, "rapid: PRNG seed to start with (0 to use a random one)") |
| 60 | + flag.BoolVar(&flags.rapidLog, "rapid.log", false, "rapid: eager verbose output to stdout (to aid with unrecoverable test failures)") |
| 61 | + flag.BoolVar(&flags.verbose, "rapid.v", false, "rapid: verbose output") |
| 62 | + flag.BoolVar(&flags.debug, "rapid.debug", false, "rapid: debugging output") |
| 63 | + flag.BoolVar(&flags.debugvis, "rapid.debugvis", false, "rapid: debugging visualization") |
| 64 | + flag.DurationVar(&flags.shrinkTime, "rapid.shrinktime", 30*time.Second, "rapid: maximum time to spend on test case minimization") |
| 65 | +} |
| 66 | + |
| 52 | 67 | func assert(ok bool) { |
| 53 | 68 | if !ok { |
| 54 | 69 | panic("assertion failed") |
| @@ -104,7 +119,7 @@ func checkTB(tb tb, prop func(*T)) { · 49 unmodified lines |
| 104 | 119 | dt := time.Since(start) |
| 105 | 120 | |
| 106 | 121 | if err1 == nil && err2 == nil { |
| 107 | | − if valid == *checks { |
| 122 | + if valid == flags.checks { |
| 108 | 123 | tb.Logf("[rapid] OK, passed %v tests (%v)", valid, dt) |
| 109 | 124 | } else { |
| 110 | 125 | tb.Errorf("[rapid] only generated %v valid tests from %v total (%v)", valid, valid+invalid, dt) |
| @@ -140,7 +155,7 @@ func doCheck(tb tb, prop func(*T)) (int, int, uint64, []uint64, *testError, *tes · 29 unmodified lines |
| 140 | 155 | } |
| 141 | 156 | |
| 142 | 157 | s := newRandomBitStream(seed, true) |
| 143 | | − t := newT(tb, s, *verbose, nil) |
| 158 | + t := newT(tb, s, flags.verbose, nil) |
| 144 | 159 | t.Logf("[rapid] trying to reproduce the failure") |
| 145 | 160 | err2 := checkOnce(t, prop) |
| 146 | 161 | if !sameError(err1, err2) { |
| @@ -158,12 +173,12 @@ func findBug(tb tb, seed uint64, prop func(*T)) (uint64, int, int, *testError) { · 11 unmodified lines |
| 158 | 173 | |
| 159 | 174 | var ( |
| 160 | 175 | r = newRandomBitStream(0, false) |
| 161 | | − t = newT(tb, r, *verbose, nil) |
| 176 | + t = newT(tb, r, flags.verbose, nil) |
| 162 | 177 | valid = 0 |
| 163 | 178 | invalid = 0 |
| 164 | 179 | ) |
| 165 | 180 | |
| 166 | | − for valid < *checks && invalid < *checks*invalidChecksMult { |
| 181 | + for valid < flags.checks && invalid < flags.checks*invalidChecksMult { |
| 167 | 182 | seed += uint64(valid) + uint64(invalid) |
| 168 | 183 | r.init(seed) |
| 169 | 184 | var start time.Time |
| @@ -319,7 +334,7 @@ func newT(tb tb, s bitStream, tbLog bool, rawLog *log.Logger, refDraws ...value) · 149 unmodified lines |
| 319 | 334 | refDraws: refDraws, |
| 320 | 335 | } |
| 321 | 336 | |
| 322 | | − if rawLog == nil && *rapidLog { |
| 337 | + if rawLog == nil && flags.rapidLog { |
| 323 | 338 | testName := "rapid test" |
| 324 | 339 | if tb != nil { |
| 325 | 340 | testName = tb.Name() |