Skip to content

Commit fc06cf7

Browse files
authored
Merge pull request #443 from ocaml-multicore/lin-stress-mode
Add Lin_domain.stress_test
2 parents 7a22943 + 72c3025 commit fc06cf7

File tree

18 files changed

+173
-11
lines changed

18 files changed

+173
-11
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
- #415: Remove `--verbose` in internal `mutable_set_v5` expect test to avoid
66
a test failure on a slow machine
7+
- #443: Add `Lin_domain.stress_test` as a lighter stress test, not
8+
requiring an interleaving search.
79

810
## 0.3
911

lib/lin_domain.ml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ module Make_internal (Spec : Internal.CmdSpec [@alert "-internal"]) = struct
1010
let res_arr = Array.map (fun c -> Domain.cpu_relax(); Spec.run c sut) cs_arr in
1111
List.combine cs (Array.to_list res_arr)
1212

13-
(* Linearization property based on [Domain] and an Atomic flag *)
14-
let lin_prop (seq_pref,cmds1,cmds2) =
13+
let run_parallel (seq_pref,cmds1,cmds2) =
1514
let sut = Spec.init () in
1615
let pref_obs = interp sut seq_pref in
1716
let wait = Atomic.make true in
@@ -22,18 +21,31 @@ module Make_internal (Spec : Internal.CmdSpec [@alert "-internal"]) = struct
2221
Spec.cleanup sut ;
2322
let obs1 = match obs1 with Ok v -> v | Error exn -> raise exn in
2423
let obs2 = match obs2 with Ok v -> v | Error exn -> raise exn in
24+
(pref_obs,obs1,obs2)
25+
26+
(* Linearization property based on [Domain] and an Atomic flag *)
27+
let lin_prop (seq_pref,cmds1,cmds2) =
28+
let pref_obs,obs1,obs2 = run_parallel (seq_pref,cmds1,cmds2) in
2529
let seq_sut = Spec.init () in
2630
check_seq_cons pref_obs obs1 obs2 seq_sut []
2731
|| QCheck.Test.fail_reportf " Results incompatible with sequential execution\n\n%s"
2832
@@ Util.print_triple_vertical ~fig_indent:5 ~res_width:35
2933
(fun (c,r) -> Printf.sprintf "%s : %s" (Spec.show_cmd c) (Spec.show_res r))
3034
(pref_obs,obs1,obs2)
3135

36+
(* "Don't crash under parallel usage" property *)
37+
let stress_prop (seq_pref,cmds1,cmds2) =
38+
let _ = run_parallel (seq_pref,cmds1,cmds2) in
39+
true
40+
3241
let lin_test ~count ~name =
33-
lin_test ~rep_count:50 ~count ~retries:3 ~name ~lin_prop:lin_prop
42+
M.lin_test ~rep_count:50 ~count ~retries:3 ~name ~lin_prop:lin_prop
3443

3544
let neg_lin_test ~count ~name =
3645
neg_lin_test ~rep_count:50 ~count ~retries:3 ~name ~lin_prop:lin_prop
46+
47+
let stress_test ~count ~name =
48+
M.lin_test ~rep_count:25 ~count ~retries:5 ~name ~lin_prop:stress_prop
3749
end
3850

3951
module Make (Spec : Spec) = Make_internal(MakeCmd(Spec))

lib/lin_domain.mli

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ open Lin
44
module Make_internal (Spec : Internal.CmdSpec [@alert "-internal"]) : sig
55
val arb_cmds_triple : int -> int -> (Spec.cmd list * Spec.cmd list * Spec.cmd list) QCheck.arbitrary
66
val lin_prop : (Spec.cmd list * Spec.cmd list * Spec.cmd list) -> bool
7+
val stress_prop : (Spec.cmd list * Spec.cmd list * Spec.cmd list) -> bool
78
val lin_test : count:int -> name:string -> QCheck.Test.t
89
val neg_lin_test : count:int -> name:string -> QCheck.Test.t
10+
val stress_test : count:int -> name:string -> QCheck.Test.t
911
end
1012
[@@alert internal "This module is exposed for internal uses only, its API may change at any time"]
1113

@@ -24,4 +26,10 @@ module Make (Spec : Spec) : sig
2426
found, and succeeds if a counter example is indeed found, and prints it
2527
afterwards.
2628
*)
29+
30+
val stress_test : count:int -> name:string -> QCheck.Test.t
31+
(** [stress_test ~count:c ~name:n] builds a parallel test with the name
32+
[n] that iterates [c] times. The test fails if an unexpected exception is
33+
raised underway. It is intended as a stress test and does not perform an
34+
interleaving search like {!lin_test} and {!neg_lin_test}. *)
2735
end

src/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Tests utilizing the parallel STM.ml capability:
4545

4646

4747

48-
Tests utilizing the linearization tests of Lin.ml:
48+
Tests utilizing `Lin`:
4949

5050
- [array/lin_internal_tests.ml](array/lin_internal_tests.ml) and [array/lin_tests.ml](array/lin_tests.ml)
5151
contain experimental `Lin.Internal` and `Lin`-tests of `Array`
@@ -61,6 +61,8 @@ Tests utilizing the linearization tests of Lin.ml:
6161

6262
- [dynlink/lin_tests.ml](dynlink/lin_tests.ml) contains experimental `Lin`-tests of `Dynlink`
6363

64+
- [ephemeron/lin_tests.ml](ephemeron/lin_tests.ml) contains experimental `Lin`-stress tests of `Ephemeron`
65+
6466
- [floatarray/lin_tests.ml](floatarray/lin_tests.ml) contains experimental `Lin`-tests of `Float.Array`
6567

6668
- [hashtbl/lin_internal_tests.ml](hashtbl/lin_internal_tests.ml) and [hashtbl/lin_tests.ml](hashtbl/lin_tests.ml)
@@ -80,6 +82,10 @@ Tests utilizing the linearization tests of Lin.ml:
8082
- [stack/lin_internal_tests.ml](stack/lin_internal_tests.ml) and [stack/lin_tests.ml](stack/lin_tests.ml)
8183
contain experimental `Lin.Internal` and `Lin`-tests of `Stack`
8284

85+
- [weak/lin_tests.ml](weak/lin_tests.ml) and
86+
[weak/lin_tests_hashset.ml](weak/lin_tests_hashset.ml) contains experimental
87+
`Lin`-stress tests of the `Weak` module
88+
8389

8490

8591
Tests of the underlying spawn/async functionality of `Domain` and

src/array/lin_tests.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ module AT_domain = Lin_domain.Make(AConf)
3030
;;
3131
QCheck_base_runner.run_tests_main [
3232
AT_domain.neg_lin_test ~count:1000 ~name:"Lin Array test with Domain";
33+
AT_domain.stress_test ~count:1000 ~name:"Lin Array stress test with Domain";
3334
]

src/bigarray/lin_tests.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ module BA1T = Lin_domain.Make(BA1Conf)
3030
let _ =
3131
QCheck_base_runner.run_tests_main [
3232
BA1T.neg_lin_test ~count:5000 ~name:"Lin Bigarray.Array1 (of ints) test with Domain";
33+
BA1T.stress_test ~count:1000 ~name:"Lin Bigarray.Array1 stress test with Domain";
3334
]

src/dynlink/lin_tests.ml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ end
3131
module DynT = Lin_domain.Make(DynConf)
3232

3333
let _ =
34-
if Sys.win32 then
35-
Printf.printf "negative Lin Dynlink test with Domain disabled under Windows\n\n%!"
36-
else
37-
QCheck_base_runner.run_tests_main [
38-
DynT.neg_lin_test ~count:100 ~name:"negative Lin Dynlink test with Domain";
39-
]
34+
let ts = [DynT.stress_test ~count:1000 ~name:"Lin Dynlink stress test with Domain"] in
35+
let ts =
36+
if Sys.win32 then
37+
(Printf.printf "negative Lin Dynlink test with Domain disabled under Windows\n\n%!"; ts)
38+
else
39+
(DynT.neg_lin_test ~count:100 ~name:"negative Lin Dynlink test with Domain")::ts in
40+
QCheck_base_runner.run_tests_main ts

src/ephemeron/dune

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,11 @@
77
(libraries qcheck-stm.sequential qcheck-stm.domain)
88
(action (run %{test} --verbose))
99
)
10+
11+
(test
12+
(name lin_tests)
13+
(modules lin_tests)
14+
(package multicoretests)
15+
(libraries qcheck-lin.domain)
16+
(action (run %{test} --verbose))
17+
)

src/ephemeron/lin_tests.ml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
(* ************************************************************ *)
2+
(* Lin tests of [Ephemeron] *)
3+
(* ************************************************************ *)
4+
5+
module EConf =
6+
struct
7+
module E = Ephemeron.K1.Make(struct
8+
type t = Int.t
9+
let equal = Int.equal
10+
let hash = Fun.id
11+
end)
12+
13+
type t = string E.t
14+
let init () = E.create 42
15+
let cleanup _ = ()
16+
17+
open Lin
18+
let int,string = nat_small, string_small_printable
19+
let api =
20+
[ val_ "Ephemeron.clear" E.clear (t @-> returning unit);
21+
val_ "Ephemeron.add" E.add (t @-> int @-> string @-> returning unit);
22+
val_ "Ephemeron.remove" E.remove (t @-> int @-> returning unit);
23+
val_ "Ephemeron.find" E.find (t @-> int @-> returning_or_exc string);
24+
val_ "Ephemeron.find_opt" E.find_opt (t @-> int @-> returning (option string));
25+
val_ "Ephemeron.find_all" E.find_all (t @-> int @-> returning (list string));
26+
val_ "Ephemeron.replace" E.replace (t @-> int @-> string @-> returning unit);
27+
val_ "Ephemeron.mem" E.mem (t @-> int @-> returning bool);
28+
val_ "Ephemeron.length" E.length (t @-> returning int);
29+
val_ "Ephemeron.clean" E.clean (t @-> returning unit);
30+
]
31+
end
32+
33+
module ET_domain = Lin_domain.Make(EConf)
34+
;;
35+
QCheck_base_runner.run_tests_main [
36+
ET_domain.stress_test ~count:1000 ~name:"Lin Ephemeron stress test with Domain";
37+
]

src/floatarray/lin_tests.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ module FAT = Lin_domain.Make(FAConf)
3838
let _ =
3939
QCheck_base_runner.run_tests_main [
4040
FAT.neg_lin_test ~count:1000 ~name:"Lin Float.Array test with Domain";
41+
FAT.stress_test ~count:1000 ~name:"Lin Float.Array stress test with Domain";
4142
]

0 commit comments

Comments
 (0)