-
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
8 changed files
with
126 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,63 @@ | ||
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.( | ||
make ~print:show_cmd | ||
(Gen.oneof | ||
[ | ||
Gen.return Incr; | ||
Gen.return Decr; | ||
Gen.return Get; | ||
Gen.map (fun i -> Set i) Gen.nat; | ||
])) | ||
|
||
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 | ||
|
||
module Seq = STM_sequential.Make (Spec) | ||
module Dom = STM_domain.Make (Spec) | ||
|
||
let () = | ||
let count = 1000 in | ||
QCheck_base_runner.run_tests ~verbose:true | ||
[ | ||
Seq.agree_test ~count ~name:"STM Accumulator_test test sequential"; | ||
Dom.agree_test_par ~count ~name:"STM Accumulator_test test parallel"; | ||
] | ||
|> 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,21 @@ | ||
(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 | ||
qcheck-core | ||
qcheck-core.runner | ||
qcheck-stm.stm | ||
qcheck-stm.sequential | ||
qcheck-stm.domain) | ||
(package kcas_data)) |