1+ open Lin_base
2+
13(* * Definitions for Effect interpretation *)
24
35(* Scheduler adapted from https://kcsrk.info/slides/retro_effects_simcorp.pdf *)
@@ -31,11 +33,13 @@ let start_sched main =
3133let fork f = perform (Fork f)
3234let yield () = perform Yield
3335
36+ module Make_internal (Spec : Lin_internal.CmdSpec ) = struct
3437
3538
3639 (* * A refined [CmdSpec] specification with generator-controlled [Yield] effects *)
3740 module EffSpec
3841 = struct
42+ open QCheck
3943
4044 type t = Spec .t
4145 let init = Spec. init
@@ -75,10 +79,16 @@ let yield () = perform Yield
7579 UserRes res
7680 end
7781
78- module EffTest = MakeDomThr (EffSpec )
82+ module EffTest = Lin_internal. Make (EffSpec )
7983
8084 let filter_res rs = List. filter (fun (c ,_ ) -> c <> EffSpec. SchedYield ) rs
8185
86+ let rec interp sut cs = match cs with
87+ | [] -> []
88+ | c ::cs ->
89+ let res = EffSpec. run c sut in
90+ (c,res)::interp sut cs
91+
8292 (* Parallel agreement property based on effect-handler scheduler *)
8393 let lin_prop_effect =
8494 (fun (seq_pref ,cmds1 ,cmds2 ) ->
@@ -87,29 +97,30 @@ let yield () = perform Yield
8797 let pref_obs = EffTest. interp_plain sut (List. filter (fun c -> c <> EffSpec. SchedYield ) seq_pref) in
8898 let obs1,obs2 = ref [] , ref [] in
8999 let main () =
90- (* For now, we reuse [interp_thread] which performs useless [Thread.yield] on single-domain/fibered program *)
91- fork (fun () -> let tmp1 = EffTest. interp_thread sut cmds1 in obs1 := tmp1);
92- fork (fun () -> let tmp2 = EffTest. interp_thread sut cmds2 in obs2 := tmp2); in
100+ fork (fun () -> let tmp1 = interp sut cmds1 in obs1 := tmp1);
101+ fork (fun () -> let tmp2 = interp sut cmds2 in obs2 := tmp2); in
93102 let () = start_sched main in
94103 let () = Spec. cleanup sut in
95104 let seq_sut = Spec. init () in
96105 (* exclude [Yield]s from sequential executions when searching for an interleaving *)
97106 EffTest. check_seq_cons (filter_res pref_obs) (filter_res ! obs1) (filter_res ! obs2) seq_sut []
98- || Test. fail_reportf " Results incompatible with linearized model\n\n %s"
107+ || QCheck. Test. fail_reportf " Results incompatible with linearized model\n\n %s"
99108 @@ Util. print_triple_vertical ~fig_indent: 5 ~res_width: 35
100109 (fun (c ,r ) -> Printf. sprintf " %s : %s" (EffSpec. show_cmd c) (EffSpec. show_res r))
101110 (pref_obs,! obs1,! obs2))
102111
103- | `Effect ->
104- (* this generator is over [EffSpec.cmd] including [SchedYield], not [Spec.cmd] like the above two *)
105- let arb_cmd_triple = EffTest. arb_cmds_par seq_len par_len in
106- let rep_count = 1 in
107- Test. make ~count ~retries: 10 ~name
108- arb_cmd_triple (repeat rep_count lin_prop_effect)
109-
110- | `Effect ->
111- (* this generator is over [EffSpec.cmd] including [SchedYield], not [Spec.cmd] like the above two *)
112- let arb_cmd_triple = EffTest. arb_cmds_par seq_len par_len in
113- let rep_count = 1 in
114- Test. make_neg ~count ~retries: 10 ~name
115- arb_cmd_triple (repeat rep_count lin_prop_effect)
112+ let lin_test ~count ~name =
113+ let arb_cmd_triple = EffTest. arb_cmds_par 20 12 in
114+ let rep_count = 1 in
115+ QCheck.Test. make ~count ~retries: 10 ~name
116+ arb_cmd_triple (Util. repeat rep_count lin_prop_effect)
117+
118+ let neg_lin_test ~count ~name =
119+ let arb_cmd_triple = EffTest. arb_cmds_par 20 12 in
120+ let rep_count = 1 in
121+ QCheck.Test. make_neg ~count ~retries: 10 ~name
122+ arb_cmd_triple (Util. repeat rep_count lin_prop_effect)
123+ end
124+
125+ module Make (Spec : Lin_common.ApiSpec ) =
126+ Make_internal (Lin_common. MakeCmd (Spec ))
0 commit comments