History

Use single global for flags

Gregory Petrosyan committed 6 years ago

Commit e5424da1 parent 8f0b7cb5 files · +38 −23Browse files

Showing the changes to engine.go (1 of 5 files). Show all

Unified · Split

engine.go+28−13
@@ -31,14 +31,7 @@ const ( · 30 unmodified lines
31)31)
32 32
33var (33var (
34 checks = flag.Int("rapid.checks", 100, "rapid: number of checks to perform")34 flags cmdline
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")
42 35
43 emptyStructType = reflect.TypeOf(struct{}{})36 emptyStructType = reflect.TypeOf(struct{}{})
44 emptyStructValue = reflect.ValueOf(struct{}{})37 emptyStructValue = reflect.ValueOf(struct{}{})
@@ -49,6 +42,28 @@ var ( · 4 unmodified lines
49 }42 }
50)43)
51 44
45type 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
56func 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
52func assert(ok bool) {67func assert(ok bool) {
53 if !ok {68 if !ok {
54 panic("assertion failed")69 panic("assertion failed")
@@ -104,7 +119,7 @@ func checkTB(tb tb, prop func(*T)) { · 49 unmodified lines
104 dt := time.Since(start)119 dt := time.Since(start)
105 120
106 if err1 == nil && err2 == nil {121 if err1 == nil && err2 == nil {
107 if valid == *checks {122 if valid == flags.checks {
108 tb.Logf("[rapid] OK, passed %v tests (%v)", valid, dt)123 tb.Logf("[rapid] OK, passed %v tests (%v)", valid, dt)
109 } else {124 } else {
110 tb.Errorf("[rapid] only generated %v valid tests from %v total (%v)", valid, valid+invalid, dt)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 s := newRandomBitStream(seed, true)157 s := newRandomBitStream(seed, true)
143 t := newT(tb, s, *verbose, nil)158 t := newT(tb, s, flags.verbose, nil)
144 t.Logf("[rapid] trying to reproduce the failure")159 t.Logf("[rapid] trying to reproduce the failure")
145 err2 := checkOnce(t, prop)160 err2 := checkOnce(t, prop)
146 if !sameError(err1, err2) {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 var (174 var (
160 r = newRandomBitStream(0, false)175 r = newRandomBitStream(0, false)
161 t = newT(tb, r, *verbose, nil)176 t = newT(tb, r, flags.verbose, nil)
162 valid = 0177 valid = 0
163 invalid = 0178 invalid = 0
164 )179 )
165 180
166 for valid < *checks && invalid < *checks*invalidChecksMult {181 for valid < flags.checks && invalid < flags.checks*invalidChecksMult {
167 seed += uint64(valid) + uint64(invalid)182 seed += uint64(valid) + uint64(invalid)
168 r.init(seed)183 r.init(seed)
169 var start time.Time184 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 refDraws: refDraws,334 refDraws: refDraws,
320 }335 }
321 336
322 if rawLog == nil && *rapidLog {337 if rawLog == nil && flags.rapidLog {
323 testName := "rapid test"338 testName := "rapid test"
324 if tb != nil {339 if tb != nil {
325 testName = tb.Name()340 testName = tb.Name()

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t