Skip to content

Commit b0e1b30

Browse files
authored
Merge pull request #472 from ocaml-multicore/stm-cmd-list-dist
Reduce `STM.cmds_gen` list size
2 parents 4ad6543 + a661f27 commit b0e1b30

File tree

6 files changed

+30
-18
lines changed

6 files changed

+30
-18
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
requiring an interleaving search.
99
- #462: Add `STM_domain.stress_test_par`, similar to `Lin_domain.stress_test`
1010
for STM models.
11+
- #472: Switch `arb_cmds` to use an exponential distribution with a
12+
mean of 10, avoiding lists of up to 10000 cmds in `STM_sequential`
13+
(reported by @nikolaushuber).
1114

1215
## 0.3
1316

lib/STM.ml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,19 @@ struct
157157
| None -> () (* no elem. shrinker provided *)
158158
| Some shrink -> Shrink.list_elems shrink l yield
159159

160+
let gen_cmds_size gen s size_gen = Gen.sized_size size_gen (gen_cmds gen s)
161+
162+
let exp_dist_gen mean =
163+
let unit_gen = Gen.float_bound_inclusive 1.0 in
164+
Gen.map (fun p -> -. mean *. (log p)) unit_gen
165+
166+
let cmd_list_size_dist mean =
167+
let skew = 0.75 in (* to avoid too many empty cmd lists *)
168+
Gen.map (fun p -> int_of_float (p +. skew)) (exp_dist_gen mean)
169+
160170
let arb_cmds s =
161-
let cmds_gen = Gen.sized (gen_cmds Spec.arb_cmd s) in
171+
let mean = 10. in (* generate on average ~10 cmds, ignoring skew *)
172+
let cmds_gen = gen_cmds_size Spec.arb_cmd s (cmd_list_size_dist mean) in
162173
let shrinker = shrink_list ?shrink:(Spec.arb_cmd s).shrink in (* pass opt. elem. shrinker *)
163174
let ac = QCheck.make ~shrink:(Shrink.filter (cmds_ok Spec.init_state) shrinker) cmds_gen in
164175
(match (Spec.arb_cmd s).print with
@@ -237,8 +248,6 @@ struct
237248
(let b2 = Spec.postcond c2 s res2 in
238249
b2 && check_obs pref cs1 cs2' (Spec.next_state c2 s))
239250

240-
let gen_cmds_size gen s size_gen = Gen.sized_size size_gen (gen_cmds gen s)
241-
242251
(* Shrinks a single cmd, starting in the given state *)
243252
let shrink_cmd arb cmd state =
244253
Option.value (arb state).shrink ~default:Shrink.nil @@ cmd

test/mutable_set_v4.expected.32

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
--- Failure --------------------------------------------------------------------
44

5-
Test STM sequential tests failed (13 shrink steps):
5+
Test STM sequential tests failed (9 shrink steps):
66

7-
Add (-605797133)
8-
Remove (-605797133)
7+
Add (-923247292)
8+
Remove (-923247292)
99
Cardinal
1010

1111

@@ -15,8 +15,8 @@ Messages for test STM sequential tests:
1515

1616
Results incompatible with model
1717

18-
Add (-605797133) : ()
19-
Remove (-605797133) : Some (-605797133)
18+
Add (-923247292) : ()
19+
Remove (-923247292) : Some (-923247292)
2020
Cardinal : 1
2121
================================================================================
2222
failure (1 tests failed, 0 tests errored, ran 1 tests)

test/mutable_set_v4.expected.64

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
--- Failure --------------------------------------------------------------------
44

5-
Test STM sequential tests failed (13 shrink steps):
5+
Test STM sequential tests failed (11 shrink steps):
66

77
Add (-3576245632788335623)
88
Remove (-3576245632788335623)

test/mutable_set_v5.expected.32

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
Test STM sequential tests failed (2 shrink steps):
66

7-
Add (-942638288)
8-
Remove (-942638288)
7+
Add (-286715106)
8+
Remove (-286715106)
99
Cardinal
1010

1111

@@ -15,8 +15,8 @@ Messages for test STM sequential tests:
1515

1616
Results incompatible with model
1717

18-
Add (-942638288) : ()
19-
Remove (-942638288) : Some (-942638288)
18+
Add (-286715106) : ()
19+
Remove (-286715106) : Some (-286715106)
2020
Cardinal : 1
2121
================================================================================
2222
failure (1 tests failed, 0 tests errored, ran 1 tests)

test/mutable_set_v5.expected.64

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
--- Failure --------------------------------------------------------------------
44

5-
Test STM sequential tests failed (15 shrink steps):
5+
Test STM sequential tests failed (6 shrink steps):
66

7-
Add (-3922091896265746428)
8-
Remove (-3922091896265746428)
7+
Add 3036269937054427589
8+
Remove 3036269937054427589
99
Cardinal
1010

1111

@@ -15,8 +15,8 @@ Messages for test STM sequential tests:
1515

1616
Results incompatible with model
1717

18-
Add (-3922091896265746428) : ()
19-
Remove (-3922091896265746428) : Some (-3922091896265746428)
18+
Add 3036269937054427589 : ()
19+
Remove 3036269937054427589 : Some (3036269937054427589)
2020
Cardinal : 1
2121
================================================================================
2222
failure (1 tests failed, 0 tests errored, ran 1 tests)

0 commit comments

Comments
 (0)