-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Make
Accumulator
grow automatically
- Loading branch information
Showing
12 changed files
with
153 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
open Kcas_data | ||
|
||
module Spec = struct | ||
type cmd = Incr | Decr | Get | Set of int | ||
|
||
let show_cmd = function | ||
| Incr -> "Incr" | ||
| Decr -> "Decr" | ||
| Get -> "Get" | ||
| Set v -> "Set " ^ string_of_int v | ||
|
||
type state = int | ||
type sut = Accumulator.t | ||
|
||
let arb_cmd _s = | ||
QCheck.( | ||
[ | ||
Gen.return Incr; | ||
Gen.return Decr; | ||
Gen.return Get; | ||
Gen.map (fun i -> Set i) Gen.nat; | ||
] | ||
|> Gen.oneof |> make ~print:show_cmd) | ||
|
||
let init_state = 0 | ||
let init_sut () = Accumulator.make 0 | ||
let cleanup _ = () | ||
|
||
let next_state c s = | ||
match c with Incr -> s + 1 | Decr -> s - 1 | Get -> s | Set v -> v | ||
|
||
let precond _ _ = true | ||
|
||
let run c d = | ||
let open STM in | ||
match c with | ||
| Incr -> Res (unit, Accumulator.incr d) | ||
| Decr -> Res (unit, Accumulator.decr d) | ||
| Get -> Res (int, Accumulator.get d) | ||
| Set v -> Res (unit, Accumulator.set d v) | ||
|
||
let postcond c (s : state) res = | ||
let open STM in | ||
match (c, res) with | ||
| Incr, Res ((Unit, _), ()) -> true | ||
| Decr, Res ((Unit, _), ()) -> true | ||
| Set _, Res ((Unit, _), ()) -> true | ||
| Get, Res ((Int, _), res) -> res = s | ||
| _, _ -> false | ||
end | ||
|
||
let () = | ||
Stm_run.run ~count:1000 ~verbose:true ~name:"Accumulator" (module Spec) | ||
|> exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
(tests | ||
(names | ||
accumulator_test | ||
dllist_test | ||
hashtbl_test | ||
lru_cache_example | ||
mvar_test | ||
queue_test | ||
stack_test | ||
xt_test) | ||
(libraries alcotest kcas kcas_data domain_shims) | ||
(libraries | ||
alcotest | ||
kcas | ||
kcas_data | ||
domain_shims | ||
stm_run | ||
qcheck-core | ||
qcheck-stm.stm) | ||
(package kcas_data)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
(library | ||
(name stm_run) | ||
(libraries | ||
qcheck-stm.sequential | ||
(select | ||
stm_run.ml | ||
from | ||
(qcheck-core | ||
qcheck-core.runner | ||
qcheck-stm.stm | ||
qcheck-stm.thread | ||
qcheck-stm.domain | ||
-> | ||
stm_run.ocaml5.ml) | ||
(qcheck-core | ||
qcheck-core.runner | ||
qcheck-stm.stm | ||
qcheck-stm.thread | ||
-> | ||
stm_run.ocaml4.ml) | ||
(-> stm_run.ignore.ml))) | ||
(package kcas_data)) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
let run ~verbose ~count ~name (module Spec : STM.Spec) = | ||
let module Seq = STM_sequential.Make (Spec) in | ||
let module Con = STM_thread.Make (Spec) [@alert "-experimental"] in | ||
QCheck_base_runner.run_tests ~verbose | ||
[ | ||
Seq.agree_test ~count ~name:(name ^ " sequential"); | ||
Con.agree_test_conc ~count ~name:(name ^ " concurrent"); | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
let run ~verbose ~count ~name (module Spec : STM.Spec) = | ||
let module Seq = STM_sequential.Make (Spec) in | ||
let module Dom = STM_domain.Make (Spec) in | ||
QCheck_base_runner.run_tests ~verbose | ||
[ | ||
Seq.agree_test ~count ~name:(name ^ " sequential"); | ||
Dom.agree_test_par ~count ~name:(name ^ " parallel"); | ||
] |