Skip to content

Commit ab18eaa

Browse files
committedAug 29, 2024·
Use stm_run private lib (from Picos) with time based deadline
Some of the tests just take too much time on some of the OCaml CI machines.
1 parent 780e50e commit ab18eaa

12 files changed

+156
-30
lines changed
 

‎dune-project

+8
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@
4848
(and
4949
(>= 1.8.0)
5050
:with-test))
51+
(qcheck-core
52+
(and
53+
(>= 0.21.2)
54+
:with-test))
55+
(qcheck-stm
56+
(and
57+
(>= 0.3)
58+
:with-test))
5159
(mdx
5260
(and
5361
(>= 2.4.1)

‎kcas.opam

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ depends: [
2424
"multicore-magic" {>= "2.3.0"}
2525
"domain_shims" {>= "0.1.0" & with-test}
2626
"alcotest" {>= "1.8.0" & with-test}
27+
"qcheck-core" {>= "0.21.2" & with-test}
28+
"qcheck-stm" {>= "0.3" & with-test}
2729
"mdx" {>= "2.4.1" & with-test}
2830
"sherlodoc" {>= "0.2" & with-doc}
2931
"odoc" {>= "2.4.2" & with-doc}

‎test/kcas_data/dune

+1-14
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
(rule
2-
(enabled_if %{lib-available:qcheck-stm.domain})
3-
(action
4-
(copy stm_run.ocaml5.ml stm_run.ml)))
5-
6-
(rule
7-
(enabled_if
8-
(not %{lib-available:qcheck-stm.domain}))
9-
(action
10-
(copy stm_run.ocaml4.ml stm_run.ml)))
11-
121
(tests
132
(names
143
accumulator_test_stm
@@ -30,10 +19,8 @@
3019
kcas_data
3120
domain_shims
3221
qcheck-core
33-
qcheck-core.runner
3422
qcheck-stm.stm
35-
qcheck-stm.sequential
36-
qcheck-stm.thread
23+
stm_run
3724
(select
3825
empty.ml
3926
from

‎test/kcas_data/stm_run.ocaml4.ml

-8
This file was deleted.

‎test/kcas_data/stm_run.ocaml5.ml

-8
This file was deleted.

‎test/kcas_data/stm_run/dune

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
(rule
2+
(enabled_if %{lib-available:qcheck-stm.domain})
3+
(action
4+
(copy stm_run.ocaml5.ml stm_run.ml)))
5+
6+
(rule
7+
(enabled_if
8+
(not %{lib-available:qcheck-stm.domain}))
9+
(action
10+
(copy stm_run.ocaml4.ml stm_run.ml)))
11+
12+
(library
13+
(name stm_run)
14+
(libraries
15+
qcheck-core
16+
qcheck-core.runner
17+
qcheck-stm.stm
18+
qcheck-stm.sequential
19+
qcheck-stm.thread
20+
unix
21+
(select
22+
empty.ml
23+
from
24+
(qcheck-stm.domain -> empty.ocaml5.ml)
25+
(-> empty.ocaml4.ml))))

‎test/kcas_data/stm_run/empty.ocaml4.ml

Whitespace-only changes.

‎test/kcas_data/stm_run/empty.ocaml5.ml

Whitespace-only changes.

‎test/kcas_data/stm_run/intf.ml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
module type STM_domain = sig
2+
module Spec : STM.Spec
3+
4+
val check_obs :
5+
(Spec.cmd * STM.res) list ->
6+
(Spec.cmd * STM.res) list ->
7+
(Spec.cmd * STM.res) list ->
8+
Spec.state ->
9+
bool
10+
11+
val all_interleavings_ok :
12+
Spec.cmd list * Spec.cmd list * Spec.cmd list -> bool
13+
14+
val arb_cmds_triple :
15+
int ->
16+
int ->
17+
(Spec.cmd list * Spec.cmd list * Spec.cmd list) QCheck.arbitrary
18+
19+
val arb_triple :
20+
int ->
21+
int ->
22+
(Spec.state -> Spec.cmd QCheck.arbitrary) ->
23+
(Spec.state -> Spec.cmd QCheck.arbitrary) ->
24+
(Spec.state -> Spec.cmd QCheck.arbitrary) ->
25+
(Spec.cmd list * Spec.cmd list * Spec.cmd list) QCheck.arbitrary
26+
27+
val arb_triple_asym :
28+
int ->
29+
int ->
30+
(Spec.state -> Spec.cmd QCheck.arbitrary) ->
31+
(Spec.state -> Spec.cmd QCheck.arbitrary) ->
32+
(Spec.state -> Spec.cmd QCheck.arbitrary) ->
33+
(Spec.cmd list * Spec.cmd list * Spec.cmd list) QCheck.arbitrary
34+
35+
val interp_sut_res : Spec.sut -> Spec.cmd list -> (Spec.cmd * STM.res) list
36+
val agree_prop_par : Spec.cmd list * Spec.cmd list * Spec.cmd list -> bool
37+
38+
val agree_prop_par_asym :
39+
Spec.cmd list * Spec.cmd list * Spec.cmd list -> bool
40+
41+
val agree_test_par : count:int -> name:string -> QCheck.Test.t
42+
val neg_agree_test_par : count:int -> name:string -> QCheck.Test.t
43+
val agree_test_par_asym : count:int -> name:string -> QCheck.Test.t
44+
val neg_agree_test_par_asym : count:int -> name:string -> QCheck.Test.t
45+
end
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
include Intf
2+
3+
let count =
4+
let factor b = if b then 10 else 1 in
5+
factor (64 <= Sys.word_size) * factor (Sys.backend_type = Native) * 10
6+
7+
let run ?(verbose = true) ?(count = count) ?(budgetf = 60.0) ~name ?make_domain
8+
(module Spec : STM.Spec) =
9+
let module Seq = STM_sequential.Make (Spec) in
10+
let module Con = STM_thread.Make (Spec) [@alert "-experimental"] in
11+
Util.run_with_budget ~budgetf ~count @@ fun count ->
12+
[
13+
[ Seq.agree_test ~count ~name:(name ^ " sequential") ];
14+
(match make_domain with
15+
| None -> [ Con.agree_test_conc ~count ~name:(name ^ " concurrent") ]
16+
| Some _ -> []);
17+
]
18+
|> List.concat
19+
|> QCheck_base_runner.run_tests ~verbose
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
include Intf
2+
3+
let count =
4+
let factor b = if b then 10 else 1 in
5+
factor (64 <= Sys.word_size)
6+
* factor (Sys.backend_type = Native)
7+
* factor (1 < Domain.recommended_domain_count ())
8+
9+
let run (type cmd state sut) ?(verbose = true) ?(count = count)
10+
?(budgetf = 60.0) ~name ?make_domain
11+
(module Spec : STM.Spec
12+
with type cmd = cmd
13+
and type state = state
14+
and type sut = sut) =
15+
let module Seq = STM_sequential.Make (Spec) in
16+
let module Dom = struct
17+
module Spec = Spec
18+
include STM_domain.Make (Spec)
19+
end in
20+
Util.run_with_budget ~budgetf ~count @@ fun count ->
21+
[
22+
[ Seq.agree_test ~count ~name:(name ^ " sequential") ];
23+
(match make_domain with
24+
| None -> [ Dom.agree_test_par ~count ~name:(name ^ " parallel") ]
25+
| Some make_domain ->
26+
make_domain ~count ~name
27+
(module Dom : STM_domain
28+
with type Spec.cmd = cmd
29+
and type Spec.state = state
30+
and type Spec.sut = sut));
31+
]
32+
|> List.concat
33+
|> QCheck_base_runner.run_tests ~verbose

‎test/kcas_data/stm_run/util.ml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
let run_with_budget ~budgetf ~count run =
2+
let state = Random.State.make_self_init () in
3+
let start = Unix.gettimeofday () in
4+
let rec loop ~total n =
5+
let current = Unix.gettimeofday () in
6+
if current -. start <= budgetf && total < count then begin
7+
let count =
8+
if total = 0 then n
9+
else
10+
let per_test = (current -. start) /. Float.of_int total in
11+
let max_count =
12+
Float.to_int ((start +. budgetf -. current) /. per_test)
13+
in
14+
Int.min (Int.min n (count - total)) max_count |> Int.max 32
15+
in
16+
let seed = Random.State.full_int state Int.max_int in
17+
QCheck_base_runner.set_seed seed;
18+
let error_code = run count in
19+
if error_code = 0 then loop ~total:(total + count) (n * 2) else error_code
20+
end
21+
else 0
22+
in
23+
loop ~total:0 32

0 commit comments

Comments
 (0)