Skip to content

Commit 19a43c2

Browse files
committed
Introduce SpecExt to allow wrapping tests with handlers
1 parent 47b70fe commit 19a43c2

6 files changed

+48
-5
lines changed

lib/STM.ml

+13
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,19 @@ sig
108108
Note: [s] is in this case the model's state prior to command execution. *)
109109
end
110110

111+
module type SpecExt =
112+
sig
113+
include Spec
114+
115+
val wrap : (unit -> 'a) -> 'a
116+
end
117+
118+
module SpecDefaults =
119+
struct
120+
let cleanup = ignore
121+
let precond _ _ = true
122+
let wrap th = th ()
123+
end
111124

112125
module Internal =
113126
struct

lib/STM.mli

+12
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@ sig
126126
This is helpful to model, e.g., a [remove] [cmd] that returns the removed element. *)
127127
end
128128

129+
module type SpecExt =
130+
sig
131+
include Spec
132+
133+
val wrap : (unit -> 'a) -> 'a
134+
end
135+
136+
module SpecDefaults : sig
137+
val cleanup : 'sut -> unit
138+
val precond : 'cmd -> 'state -> bool
139+
val wrap : (unit -> 'a) -> 'a
140+
end
129141

130142
module Internal : sig
131143
open QCheck

lib/STM_domain.ml

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
open STM
22

3-
module Make (Spec: Spec) = struct
3+
module MakeExt (Spec: SpecExt) = struct
44

55
open Util
66
open QCheck
@@ -24,9 +24,9 @@ module Make (Spec: Spec) = struct
2424

2525
let run_par seq_pref cmds1 cmds2 =
2626
let sut = Spec.init_sut () in
27-
let pref_obs = interp_sut_res sut seq_pref in
27+
let pref_obs = Spec.wrap @@ fun () -> interp_sut_res sut seq_pref in
2828
let barrier = Atomic.make 2 in
29-
let main cmds () =
29+
let main cmds () = Spec.wrap @@ fun () ->
3030
Atomic.decr barrier;
3131
while Atomic.get barrier <> 0 do Domain.cpu_relax() done;
3232
try Ok (interp_sut_res sut cmds) with exn -> Error exn
@@ -125,3 +125,9 @@ module Make (Spec: Spec) = struct
125125
assume (all_interleavings_ok triple);
126126
repeat rep_count agree_prop_par_asym triple) (* 25 times each, then 25 * 10 times when shrinking *)
127127
end
128+
129+
module Make (Spec: Spec) =
130+
MakeExt (struct
131+
include SpecDefaults
132+
include Spec
133+
end)

lib/STM_domain.mli

+3
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,6 @@ module Make : functor (Spec : STM.Spec) ->
9696
interleaving search like {!agree_test_par} and {!neg_agree_test_par}. *)
9797

9898
end
99+
100+
module MakeExt : functor (Spec : STM.SpecExt) ->
101+
module type of Make (Spec)

lib/STM_sequential.ml

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
open STM
22

3-
module Make (Spec: Spec) = struct
3+
module MakeExt (Spec: SpecExt) = struct
44

55
open QCheck
66
open Internal.Make(Spec)
@@ -18,7 +18,7 @@ module Make (Spec: Spec) = struct
1818
let agree_prop cs =
1919
assume (cmds_ok Spec.init_state cs);
2020
let sut = Spec.init_sut () in (* reset system's state *)
21-
let res = try Ok (check_disagree Spec.init_state sut cs) with exn -> Error exn in
21+
let res = try Ok (Spec.wrap @@ fun () -> check_disagree Spec.init_state sut cs) with exn -> Error exn in
2222
let () = Spec.cleanup sut in
2323
let res = match res with Ok res -> res | Error exn -> raise exn in
2424
match res with
@@ -34,3 +34,9 @@ module Make (Spec: Spec) = struct
3434
Test.make_neg ~name ~count (arb_cmds Spec.init_state) agree_prop
3535

3636
end
37+
38+
module Make (Spec : Spec) =
39+
MakeExt (struct
40+
include SpecDefaults
41+
include Spec
42+
end)

lib/STM_sequential.mli

+3
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ module Make : functor (Spec : STM.Spec) ->
2525
(** A negative agreement test (for convenience). Accepts two labeled parameters:
2626
[count] is the test count and [name] is the printed test name. *)
2727
end
28+
29+
module MakeExt : functor (Spec : STM.SpecExt) ->
30+
module type of Make (Spec)

0 commit comments

Comments
 (0)