Skip to content

Commit

Permalink
Use stm_run private lib (from Picos) with time based deadline
Browse files Browse the repository at this point in the history
Some of the tests just take too much time on some of the OCaml CI machines.
  • Loading branch information
polytypic committed Aug 29, 2024
1 parent 780e50e commit bcb4e12
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 30 deletions.
15 changes: 1 addition & 14 deletions test/kcas_data/dune
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
(rule
(enabled_if %{lib-available:qcheck-stm.domain})
(action
(copy stm_run.ocaml5.ml stm_run.ml)))

(rule
(enabled_if
(not %{lib-available:qcheck-stm.domain}))
(action
(copy stm_run.ocaml4.ml stm_run.ml)))

(tests
(names
accumulator_test_stm
Expand All @@ -30,10 +19,8 @@
kcas_data
domain_shims
qcheck-core
qcheck-core.runner
qcheck-stm.stm
qcheck-stm.sequential
qcheck-stm.thread
stm_run
(select
empty.ml
from
Expand Down
8 changes: 0 additions & 8 deletions test/kcas_data/stm_run.ocaml4.ml

This file was deleted.

8 changes: 0 additions & 8 deletions test/kcas_data/stm_run.ocaml5.ml

This file was deleted.

26 changes: 26 additions & 0 deletions test/kcas_data/stm_run/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
(rule
(enabled_if %{lib-available:qcheck-stm.domain})
(action
(copy stm_run.ocaml5.ml stm_run.ml)))

(rule
(enabled_if
(not %{lib-available:qcheck-stm.domain}))
(action
(copy stm_run.ocaml4.ml stm_run.ml)))

(library
(name stm_run)
(package kcas_data)
(libraries
qcheck-core
qcheck-core.runner
qcheck-stm.stm
qcheck-stm.sequential
qcheck-stm.thread
unix
(select
empty.ml
from
(qcheck-stm.domain -> empty.ocaml5.ml)
(-> empty.ocaml4.ml))))
Empty file.
Empty file.
45 changes: 45 additions & 0 deletions test/kcas_data/stm_run/intf.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module type STM_domain = sig
module Spec : STM.Spec

val check_obs :
(Spec.cmd * STM.res) list ->
(Spec.cmd * STM.res) list ->
(Spec.cmd * STM.res) list ->
Spec.state ->
bool

val all_interleavings_ok :
Spec.cmd list * Spec.cmd list * Spec.cmd list -> bool

val arb_cmds_triple :
int ->
int ->
(Spec.cmd list * Spec.cmd list * Spec.cmd list) QCheck.arbitrary

val arb_triple :
int ->
int ->
(Spec.state -> Spec.cmd QCheck.arbitrary) ->
(Spec.state -> Spec.cmd QCheck.arbitrary) ->
(Spec.state -> Spec.cmd QCheck.arbitrary) ->
(Spec.cmd list * Spec.cmd list * Spec.cmd list) QCheck.arbitrary

val arb_triple_asym :
int ->
int ->
(Spec.state -> Spec.cmd QCheck.arbitrary) ->
(Spec.state -> Spec.cmd QCheck.arbitrary) ->
(Spec.state -> Spec.cmd QCheck.arbitrary) ->
(Spec.cmd list * Spec.cmd list * Spec.cmd list) QCheck.arbitrary

val interp_sut_res : Spec.sut -> Spec.cmd list -> (Spec.cmd * STM.res) list
val agree_prop_par : Spec.cmd list * Spec.cmd list * Spec.cmd list -> bool

val agree_prop_par_asym :
Spec.cmd list * Spec.cmd list * Spec.cmd list -> bool

val agree_test_par : count:int -> name:string -> QCheck.Test.t
val neg_agree_test_par : count:int -> name:string -> QCheck.Test.t
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
19 changes: 19 additions & 0 deletions test/kcas_data/stm_run/stm_run.ocaml4.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
include Intf

let count =
let factor b = if b then 10 else 1 in
factor (64 <= Sys.word_size) * factor (Sys.backend_type = Native) * 10

let run ?(verbose = true) ?(count = count) ?(budgetf = 60.0) ~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
| None -> [ Con.agree_test_conc ~count ~name:(name ^ " concurrent") ]
| Some _ -> []);
]
|> List.concat
|> QCheck_base_runner.run_tests ~verbose
33 changes: 33 additions & 0 deletions test/kcas_data/stm_run/stm_run.ocaml5.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
include Intf

let count =
let factor b = if b then 10 else 1 in
factor (64 <= Sys.word_size)
* factor (Sys.backend_type = Native)
* factor (1 < Domain.recommended_domain_count ())

let run (type cmd state sut) ?(verbose = true) ?(count = count)
?(budgetf = 60.0) ~name ?make_domain
(module Spec : STM.Spec
with type cmd = cmd
and type state = state
and type sut = sut) =
let module Seq = STM_sequential.Make (Spec) in
let module Dom = struct
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
| None -> [ Dom.agree_test_par ~count ~name:(name ^ " parallel") ]
| Some make_domain ->
make_domain ~count ~name
(module Dom : STM_domain
with type Spec.cmd = cmd
and type Spec.state = state
and type Spec.sut = sut));
]
|> List.concat
|> QCheck_base_runner.run_tests ~verbose
23 changes: 23 additions & 0 deletions test/kcas_data/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

0 comments on commit bcb4e12

Please sign in to comment.