Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add time limit for stm tests. #152

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions test/michael_scott_queue/dune
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,4 @@
(package saturn_lockfree)
(name stm_michael_scott_queue)
(modules stm_michael_scott_queue)
(libraries ms_queues saturn_lockfree qcheck-core qcheck-stm.stm stm_run)
(enabled_if
(= %{arch_sixtyfour} true)))
(libraries ms_queues saturn_lockfree qcheck-core qcheck-stm.stm stm_run))
5 changes: 1 addition & 4 deletions test/michael_scott_queue/stm_michael_scott_queue.ml
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ module STM_ms_queue (Queue : Ms_queues.MS_queue_tests) = struct
| _, _ -> false
end

let run () =
Stm_run.run ~count:500 ~verbose:true
~name:("Saturn_lockfree." ^ Queue.name)
(module Spec)
let run () = Stm_run.run ~name:("Saturn_lockfree." ^ Queue.name) (module Spec)
end

let () =
Expand Down
4 changes: 1 addition & 3 deletions test/mpsc_queue/dune
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,4 @@
qcheck-core
qcheck-multicoretests-util
qcheck-stm.stm
stm_run)
(enabled_if
(= %{arch_sixtyfour} true)))
stm_run))
4 changes: 1 addition & 3 deletions test/mpsc_queue/stm_mpsc_queue.ml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,5 @@ let () =
Dom.neg_agree_test_par ~count ~name:(name ^ " parallel, negative");
]
in
Stm_run.run ~count:1000 ~name:"Saturn_lockfree.Mpsc_queue" ~verbose:true
~make_domain
(module Spec)
Stm_run.run ~name:"Saturn_lockfree.Mpsc_queue" ~make_domain (module Spec)
|> exit
4 changes: 1 addition & 3 deletions test/skiplist/stm_skiplist.ml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,4 @@ module Spec = struct
| _, _ -> false
end

let () =
Stm_run.run ~count:1000 ~verbose:true ~name:"Lockfree.Skiplist" (module Spec)
|> exit
let () = Stm_run.run ~name:"Lockfree.Skiplist" (module Spec) |> exit
4 changes: 1 addition & 3 deletions test/spsc_queue/dune
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,4 @@
qcheck-core
qcheck-multicoretests-util
qcheck-stm.stm
stm_run)
(enabled_if
(= %{arch_sixtyfour} true)))
stm_run))
4 changes: 2 additions & 2 deletions test/spsc_queue/stm_spsc_queue.ml
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ module STM_spsc (Spsc_queue : Spsc_queues.SPSC_tests) = struct
Dom.neg_agree_test_par ~count ~name:(name ^ " parallel, negative");
]
in
Stm_run.run ~count:1000
Stm_run.run
~name:("Saturn_lockfree." ^ Spsc_queue.name)
~verbose:true ~make_domain
~make_domain
(module Spec)
end

Expand Down
1 change: 1 addition & 0 deletions test/stm_run/dune
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
qcheck-stm.stm
qcheck-stm.sequential
qcheck-stm.thread
unix
(select
empty.ml
from
Expand Down
3 changes: 3 additions & 0 deletions test/stm_run/intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ module type STM_domain = sig
val agree_test_par_asym : count:int -> name:string -> QCheck.Test.t
val neg_agree_test_par_asym : count:int -> name:string -> QCheck.Test.t
end

let default_count = 1_000
let default_budgetf = 60.0
4 changes: 3 additions & 1 deletion test/stm_run/stm_run.ocaml4.ml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
include Intf

let run ~verbose ~count ~name ?make_domain (module Spec : STM.Spec) =
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
Util.run_with_budget ~budgetf ~count @@ fun count ->
[
[ Seq.agree_test ~count ~name:(name ^ " sequential") ];
(match make_domain with
Expand Down
4 changes: 3 additions & 1 deletion test/stm_run/stm_run.ocaml5.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
include Intf

let run (type cmd state sut) ~verbose ~count ~name ?make_domain
let run (type cmd state sut) ?(verbose = true) ?(count = default_count)
?(budgetf = default_budgetf) ~name ?make_domain
(module Spec : STM.Spec
with type cmd = cmd
and type state = state
Expand All @@ -10,6 +11,7 @@ let run (type cmd state sut) ~verbose ~count ~name ?make_domain
module Spec = Spec
include STM_domain.Make (Spec)
end in
Util.run_with_budget ~budgetf ~count @@ fun count ->
[
[ Seq.agree_test ~count ~name:(name ^ " sequential") ];
(match make_domain with
Expand Down
23 changes: 23 additions & 0 deletions test/stm_run/util.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
let run_with_budget ~budgetf ~count run =
let state = Random.State.make_self_init () in
let start = Unix.gettimeofday () in
let rec loop ~total n =
let current = Unix.gettimeofday () in
if current -. start <= budgetf && total < count then begin
let count =
if total = 0 then n
else
let per_test = (current -. start) /. Float.of_int total in
let max_count =
Float.to_int ((start +. budgetf -. current) /. per_test)
in
Int.min (Int.min n (count - total)) max_count |> Int.max 32
in
let seed = Random.State.full_int state Int.max_int in
QCheck_base_runner.set_seed seed;
let error_code = run count in
if error_code = 0 then loop ~total:(total + count) (n * 2) else error_code
end
else 0
in
loop ~total:0 32
4 changes: 1 addition & 3 deletions test/treiber_stack/dune
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,4 @@
(package saturn_lockfree)
(name stm_treiber_stack)
(modules stm_treiber_stack)
(libraries saturn_lockfree qcheck-core qcheck-stm.stm stm_run)
(enabled_if
(= %{arch_sixtyfour} true)))
(libraries saturn_lockfree qcheck-core qcheck-stm.stm stm_run))
5 changes: 1 addition & 4 deletions test/treiber_stack/stm_treiber_stack.ml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,4 @@ module Spec = struct
| _, _ -> false
end

let () =
Stm_run.run ~count:500 ~verbose:true ~name:"Saturn_lockfree.Treiber_stack"
(module Spec)
|> exit
let () = Stm_run.run ~name:"Saturn_lockfree.Treiber_stack" (module Spec) |> exit
4 changes: 1 addition & 3 deletions test/ws_deque/dune
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,4 @@
qcheck-core
qcheck-multicoretests-util
qcheck-stm.stm
stm_run)
(enabled_if
(= %{arch_sixtyfour} true)))
stm_run))
4 changes: 1 addition & 3 deletions test/ws_deque/stm_ws_deque.ml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,5 @@ let () =
Dom.neg_agree_test_par ~count ~name:(name ^ " parallel, negative");
]
in
Stm_run.run ~count:1000 ~name:"Saturn_lockfree.Ws_deque" ~verbose:true
~make_domain
(module Spec)
Stm_run.run ~name:"Saturn_lockfree.Ws_deque" ~make_domain (module Spec)
|> exit
Loading