forked from ocaml-multicore/multicoretests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlin_tests.ml
93 lines (77 loc) · 2.78 KB
/
lin_tests.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
open QCheck
(** ********************************************************************** *)
(** Tests of the Atomic module *)
(** ********************************************************************** *)
module AConf =
struct
type t = int Atomic.t
type cmd =
| Get
| Set of int'
| Exchange of int'
| Compare_and_set of int' * int'
| Fetch_and_add of int'
| Incr
| Decr [@@deriving qcheck, show { with_path = false }]
and int' = int [@gen Gen.nat]
let shrink_cmd = Shrink.nil
type res =
| RGet of int
| RSet
| RExchange of int
| RFetch_and_add of int
| RCompare_and_set of bool
| RIncr
| RDecr [@@deriving show { with_path = false }, eq]
let init () = Atomic.make 0
let run c r = match c with
| Get -> RGet (Atomic.get r)
| Set i -> (Atomic.set r i; RSet)
| Exchange i -> RExchange (Atomic.exchange r i)
| Fetch_and_add i -> RFetch_and_add (Atomic.fetch_and_add r i)
| Compare_and_set (seen,v) -> RCompare_and_set (Atomic.compare_and_set r seen v)
| Incr -> (Atomic.incr r; RIncr)
| Decr -> (Atomic.decr r; RDecr)
let cleanup _ = ()
end
module AT_domain = Lin_domain.Make_internal(AConf)
(** A variant of the above with 3 Atomics *)
module A3Conf =
struct
type t = int Atomic.t array
type cmd =
| Get of var
| Set of var * int'
| Exchange of var * int'
| Compare_and_set of var * int' * int'
| Fetch_and_add of var * int'
| Incr of var
| Decr of var [@@deriving qcheck, show { with_path = false }]
and int' = int [@gen Gen.nat]
and var = int [@gen Gen.int_bound 2]
let shrink_cmd = Shrink.nil
type res =
| RGet of int
| RSet
| RExchange of int
| RFetch_and_add of int
| RCompare_and_set of bool
| RIncr
| RDecr [@@deriving show { with_path = false }, eq]
let init () = [| Atomic.make 0; Atomic.make 0; Atomic.make 0 |]
let run c env = match c with
| Get v -> RGet (Atomic.get env.(v))
| Set (v,i) -> (Atomic.set env.(v) i; RSet)
| Exchange (v,i) -> RExchange (Atomic.exchange env.(v) i)
| Fetch_and_add (v,i) -> RFetch_and_add (Atomic.fetch_and_add env.(v) i)
| Compare_and_set (v,seen,nval) -> RCompare_and_set (Atomic.compare_and_set env.(v) seen nval)
| Incr v -> (Atomic.incr env.(v); RIncr)
| Decr v -> (Atomic.decr env.(v); RDecr)
let cleanup _ = ()
end
module A3T_domain = Lin_domain.Make_internal(A3Conf)
;;
QCheck_base_runner.run_tests_main [
AT_domain.lin_test ~count:1000 ~name:"Lin Atomic test with Domain";
A3T_domain.lin_test ~count:1000 ~name:"Lin Atomic3 test with Domain";
]