-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
126 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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#19a43c238fee7fd56fac32519a53240b52a00303" ] | ||
[ "qcheck-multicoretests-util.dev" "git+https://github.com/ocaml-multicore/multicoretests#19a43c238fee7fd56fac32519a53240b52a00303" ] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
open QCheck | ||
open STM | ||
module Rwlock = Picos_std_sync.Rwlock | ||
|
||
module Spec = struct | ||
include SpecDefaults | ||
|
||
type cmd = Push of int | Pop_opt | Top_opt | Length | ||
|
||
let show_cmd = function | ||
| Push x -> "Push " ^ string_of_int x | ||
| Pop_opt -> "Pop_opt" | ||
| Top_opt -> "Top_opt" | ||
| Length -> "Length" | ||
|
||
module State = struct | ||
type t = int list | ||
|
||
let push x xs = x :: xs | ||
let pop_opt = function _ :: xs -> xs | [] -> [] | ||
let top_opt = function x :: _ -> Some x | [] -> None | ||
let length = List.length | ||
end | ||
|
||
type state = State.t | ||
type sut = { stack : int Stack.t; rwlock : Rwlock.t } | ||
|
||
let arb_cmd _s = | ||
[ | ||
Gen.int_range 1 1000 |> Gen.map (fun x -> Push x); | ||
Gen.return Pop_opt; | ||
Gen.return Top_opt; | ||
Gen.return Length; | ||
] | ||
|> Gen.oneof |> make ~print:show_cmd | ||
|
||
let init_state = [] | ||
let init_sut () = { stack = Stack.create (); rwlock = Rwlock.create () } | ||
let cleanup _ = () | ||
|
||
let next_state c s = | ||
match c with | ||
| Push x -> State.push x s | ||
| Pop_opt -> State.pop_opt s | ||
| Top_opt -> s | ||
| Length -> s | ||
|
||
let run c d = | ||
match c with | ||
| Push x -> | ||
Rwlock.wrlock d.rwlock; | ||
Stack.push x d.stack; | ||
Rwlock.unlock d.rwlock; | ||
Res (unit, ()) | ||
| Pop_opt -> | ||
Rwlock.wrlock d.rwlock; | ||
let result = Stack.pop_opt d.stack in | ||
Rwlock.unlock d.rwlock; | ||
Res (option int, result) | ||
| Top_opt -> | ||
Rwlock.rdlock d.rwlock; | ||
let result = Stack.top_opt d.stack in | ||
Rwlock.unlock d.rwlock; | ||
Res (option int, result) | ||
| Length -> | ||
Rwlock.rdlock d.rwlock; | ||
let result = Stack.length d.stack in | ||
Rwlock.unlock d.rwlock; | ||
Res (int, result) | ||
|
||
let postcond c (s : state) res = | ||
match (c, res) with | ||
| Push _x, Res ((Unit, _), ()) -> true | ||
| Pop_opt, Res ((Option Int, _), res) -> res = State.top_opt s | ||
| Top_opt, Res ((Option Int, _), res) -> res = State.top_opt s | ||
| Length, Res ((Int, _), res) -> res = State.length s | ||
| _, _ -> false | ||
|
||
let wrap 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 } | ||
end | ||
|
||
let () = Stm_run.run ~name:"Rwlock" (module Spec) |> exit |