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
3131 )
3232
3333 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
4235
4336 emptyStructType = reflect.TypeOf(struct{}{})
4437 emptyStructValue = reflect.ValueOf(struct{}{})
@@ -49,6 +42,28 @@ var ( · 4 unmodified lines
4942 }
5043 )
5144
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+
5267 func assert(ok bool) {
5368 if !ok {
5469 panic("assertion failed")
@@ -104,7 +119,7 @@ func checkTB(tb tb, prop func(*T)) { · 49 unmodified lines
104119 dt := time.Since(start)
105120
106121 if err1 == nil && err2 == nil {
107− if valid == *checks {
122+ if valid == flags.checks {
108123 tb.Logf("[rapid] OK, passed %v tests (%v)", valid, dt)
109124 } else {
110125 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
140155 }
141156
142157 s := newRandomBitStream(seed, true)
143− t := newT(tb, s, *verbose, nil)
158+ t := newT(tb, s, flags.verbose, nil)
144159 t.Logf("[rapid] trying to reproduce the failure")
145160 err2 := checkOnce(t, prop)
146161 if !sameError(err1, err2) {
@@ -158,12 +173,12 @@ func findBug(tb tb, seed uint64, prop func(*T)) (uint64, int, int, *testError) { · 11 unmodified lines
158173
159174 var (
160175 r = newRandomBitStream(0, false)
161− t = newT(tb, r, *verbose, nil)
176+ t = newT(tb, r, flags.verbose, nil)
162177 valid = 0
163178 invalid = 0
164179 )
165180
166− for valid < *checks && invalid < *checks*invalidChecksMult {
181+ for valid < flags.checks && invalid < flags.checks*invalidChecksMult {
167182 seed += uint64(valid) + uint64(invalid)
168183 r.init(seed)
169184 var start time.Time
@@ -319,7 +334,7 @@ func newT(tb tb, s bitStream, tbLog bool, rawLog *log.Logger, refDraws ...value) · 149 unmodified lines
319334 refDraws: refDraws,
320335 }
321336
322− if rawLog == nil && *rapidLog {
337+ if rawLog == nil && flags.rapidLog {
323338 testName := "rapid test"
324339 if tb != nil {
325340 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