Skip to content

Commit

Permalink
Upgrade QCheck STM to version with wrap_cmd_seq support
Browse files Browse the repository at this point in the history
Also reorganize code under `test/` such that libraries are under `test/lib/`.

Co-authored-by: Jan Midtgaard <[email protected]>
  • Loading branch information
polytypic and jmid committed Jan 18, 2025
1 parent fc7ca3e commit 7bebb77
Show file tree
Hide file tree
Showing 21 changed files with 94 additions and 43 deletions.
4 changes: 4 additions & 0 deletions picos_meta.opam
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ build: [
]
]
dev-repo: "git+https://github.com/ocaml-multicore/picos.git"
pin-depends: [
[ "qcheck-stm.dev" "git+https://github.com/ocaml-multicore/multicoretests#59296ec5491475b191cac6babf8f290c9ced47a4" ]
[ "qcheck-multicoretests-util.dev" "git+https://github.com/ocaml-multicore/multicoretests#59296ec5491475b191cac6babf8f290c9ced47a4" ]
]
4 changes: 4 additions & 0 deletions picos_meta.opam.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pin-depends: [
[ "qcheck-stm.dev" "git+https://github.com/ocaml-multicore/multicoretests#59296ec5491475b191cac6babf8f290c9ced47a4" ]
[ "qcheck-multicoretests-util.dev" "git+https://github.com/ocaml-multicore/multicoretests#59296ec5491475b191cac6babf8f290c9ced47a4" ]
]
26 changes: 0 additions & 26 deletions test/dune
Original file line number Diff line number Diff line change
@@ -1,29 +1,3 @@
(library
(package picos_meta)
(name test_scheduler)
(modules test_scheduler)
(libraries
(re_export picos)
picos_io.select
(select
test_scheduler.ml
from
(picos.thread
picos_lwt.unix
picos_mux.random
picos_mux.fifo
picos_mux.multififo
->
test_scheduler.ocaml5.ml)
(picos_mux.thread lwt.unix -> test_scheduler.ocaml4.ml))))

(library
(package picos_meta)
(name test_util)
(modules test_util))

;;

(test
(package picos_meta)
(name test_picos)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
include Intf

let run ?(verbose = true) ?(count = default_count) ?(budgetf = default_budgetf)
~name ?make_domain (module Spec : STM.Spec) =
let module Seq = STM_sequential.Make (Spec) in
let module Con = STM_thread.Make (Spec) [@alert "-experimental"] in
~name ?make_domain (module Spec : STM.SpecExt) =
let module Seq = STM_sequential.MakeExt (Spec) in
let module Con = STM_thread.MakeExt (Spec) [@alert "-experimental"] in
Util.run_with_budget ~budgetf ~count @@ fun count ->
[
[ Seq.agree_test ~count ~name:(name ^ " sequential") ];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ include Intf

let run (type cmd state sut) ?(verbose = true) ?(count = default_count)
?(budgetf = default_budgetf) ~name ?make_domain
(module Spec : STM.Spec
(module Spec : STM.SpecExt
with type cmd = cmd
and type state = state
and type sut = sut) =
let module Seq = STM_sequential.Make (Spec) in
let module Seq = STM_sequential.MakeExt (Spec) in
let module Dom = struct
module Spec = Spec
include STM_domain.Make (Spec)
include STM_domain.MakeExt (Spec)
end in
Util.run_with_budget ~budgetf ~count @@ fun count ->
[
Expand Down
File renamed without changes.
11 changes: 11 additions & 0 deletions test/lib/stm_wrap/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(library
(package picos_meta)
(name stm_wrap)
(modules stm_wrap)
(libraries
picos
(select
stm_wrap.ml
from
(picos_mux.fifo -> stm_wrap.ocaml5.ml)
(threads.posix -> stm_wrap.ocaml4.ml))))
25 changes: 25 additions & 0 deletions test/lib/stm_wrap/stm_wrap.ocaml4.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
open Picos

let[@inline never] error entry _ = failwith entry

let handler =
let current fiber = fiber
and spawn _ _ = error "spawn"
and yield = error "yield"
and cancel_after _ _ ~seconds:_ _ = error "cancel_after"
and await _ t =
while not (Trigger.is_signaled t) do
Thread.yield ()
done;
None
in
Handler.{ current; spawn; yield; cancel_after; await }

let wrap_cmd_seq th =
let result = ref (Error Exit) in
Handler.using handler
(Fiber.create ~forbid:false (Computation.create ()))
(fun _fiber ->
result :=
match th () with value -> Ok value | exception exn -> Error exn);
match !result with Ok value -> value | Error exn -> raise exn
15 changes: 15 additions & 0 deletions test/lib/stm_wrap/stm_wrap.ocaml5.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
let wrap_cmd_seq th =
let open Picos in
let effc (type a) (e : a Effect.t) :
((a, _) Effect.Deep.continuation -> _) option =
match e with
| Trigger.Await t ->
Some
(fun k ->
while not (Trigger.is_signaled t) do
Domain.cpu_relax ()
done;
Effect.Deep.continue k None)
| _ -> None
in
Effect.Deep.match_with th () { effc; exnc = raise; retc = Fun.id }
18 changes: 18 additions & 0 deletions test/lib/test_scheduler/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(library
(package picos_meta)
(name test_scheduler)
(modules test_scheduler)
(libraries
(re_export picos)
picos_io.select
(select
test_scheduler.ml
from
(picos.thread
picos_lwt.unix
picos_mux.random
picos_mux.fifo
picos_mux.multififo
->
test_scheduler.ocaml5.ml)
(picos_mux.thread lwt.unix -> test_scheduler.ocaml4.ml))))
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions test/lib/test_util/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(library
(package picos_meta)
(name test_util)
(modules test_util))
File renamed without changes.
5 changes: 2 additions & 3 deletions test/test_htbl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ module Int = struct
end

module Spec = struct
include SpecDefaults

type cmd =
| Try_add of int
| Mem of int
Expand Down Expand Up @@ -61,7 +63,6 @@ module Spec = struct

let init_state = State.empty
let init_sut () = Htbl.create ~hashed_type:(module Int) ()
let cleanup _ = ()

let next_state c s =
match c with
Expand All @@ -72,8 +73,6 @@ module Spec = struct
| To_keys -> s
| Remove_all -> State.empty

let precond _ _ = true

let run c d =
match c with
| Try_add x -> Res (bool, Htbl.try_add d x x)
Expand Down
5 changes: 2 additions & 3 deletions test/test_mpmcq.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ let () =
match Queue.pop_exn q with _ -> assert false | exception Queue.Empty -> ()

module Spec = struct
include SpecDefaults

type cmd = Push of int | Push_head of int | Pop_opt | Length

let show_cmd = function
Expand Down Expand Up @@ -48,7 +50,6 @@ module Spec = struct

let init_state = ([], [])
let init_sut () = Queue.create ~padded:true ()
let cleanup _ = ()

let next_state c s =
match c with
Expand All @@ -57,8 +58,6 @@ module Spec = struct
| Pop_opt -> State.drop s
| Length -> s

let precond _ _ = true

let run c d =
match c with
| Push x -> Res (unit, Queue.push d x)
Expand Down
8 changes: 3 additions & 5 deletions test/test_mpscq.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
open STM
module Queue = Picos_aux_mpscq

module Spec = struct
include SpecDefaults

type cmd = Push of int | Push_head of int | Pop | Pop_all

let show_cmd c =
Expand Down Expand Up @@ -35,7 +38,6 @@ module Spec = struct

let init_state = []
let init_sut () = Queue.create ()
let cleanup _ = ()

let next_state c s =
match c with
Expand All @@ -44,10 +46,7 @@ module Spec = struct
| Pop -> ( match s with _ :: s -> s | [] -> [])
| Pop_all -> []

let precond _ _ = true

let run c d =
let open STM in
match c with
| Push i -> Res (unit, Queue.push d i)
| Push_head i -> Res (unit, Queue.push_head d i)
Expand All @@ -60,7 +59,6 @@ module Spec = struct
| Pop_all -> Res (list int, Queue.pop_all d |> List.of_seq)

let postcond c (s : state) res =
let open STM in
match (c, res) with
| Push _, Res ((Unit, _), ()) -> true
| Push_head _, Res ((Unit, _), ()) -> true
Expand Down

0 comments on commit 7bebb77

Please sign in to comment.