Skip to content

Commit

Permalink
Merge pull request #463 from OlivierNicole/dynarray-tests
Browse files Browse the repository at this point in the history
Dynarray tests
  • Loading branch information
jmid authored Dec 20, 2024
2 parents b3097cb + 861596f commit 2ef4b84
Show file tree
Hide file tree
Showing 4 changed files with 731 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Tests utilizing the parallel STM.ml capability:
- [domain/stm_tests_dls.ml](domain/stm_tests_dls.ml) contains sequential and
parallel tests of the `Domain.DLS` module

- [dynarray/stm_tests.ml](dynarray/stm_tests.ml) contains sequential and
parallel tests of the `Dynarray` module

- [ephemeron/stm_tests.ml](ephemeron/stm_tests.ml) contains sequential and
parallel tests of the `Ephemeron` module

Expand Down Expand Up @@ -59,6 +62,8 @@ Tests utilizing `Lin`:

- [domain/lin_tests_dls.ml](domain/lin_tests_dls.ml) contains experimental `Lin`-tests of `Domain.DLS`

- [dynarray/lin_tests.ml](dynarray/lin_tests.ml) contains experimental `Lin`-tests of `Dynarray`

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

- [ephemeron/lin_tests.ml](ephemeron/lin_tests.ml) contains experimental `Lin`-stress tests of `Ephemeron`
Expand Down
19 changes: 19 additions & 0 deletions src/dynarray/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
;; Tests of the Dynarray library - added in 5.2

(test
(name lin_tests)
(modules lin_tests)
(package multicoretests)
(libraries qcheck-lin.domain)
(action (run %{test} --verbose))
(enabled_if (>= %{ocaml_version} 5.2))
)

(test
(name stm_tests)
(modules stm_tests)
(package multicoretests)
(libraries qcheck-stm.sequential qcheck-stm.domain)
(action (run %{test} --verbose))
(enabled_if (>= %{ocaml_version} 5.2))
)
41 changes: 41 additions & 0 deletions src/dynarray/lin_tests.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module Dynarray_api = struct
type t = int Dynarray.t
let init () = Dynarray.make 1024 0xcafe
let cleanup _ = ()

open Lin
type elem = int [@@warning "-34"]
let elem = nat_small
let int = nat_small

let get_check a i =
let v = Dynarray.get a i in
if not (Obj.is_int (Obj.repr v)) then (Printf.eprintf "dummy found!\n%!"; exit 1) else v

let api =
(*let int_not_too_big = int_bound 2048 in*)
[ val_ "get_check" get_check (t @-> int @-> returning_or_exc elem);
val_ "set" Dynarray.set (t @-> int @-> elem @-> returning_or_exc unit);
val_ "length" Dynarray.length (t @-> returning int);
val_freq 3 "add_last" Dynarray.add_last (t @-> elem @-> returning_or_exc unit);
val_ "append_seq" Dynarray.append_seq (t @-> seq elem @-> returning_or_exc unit);
val_ "get_last" Dynarray.get_last (t @-> returning_or_exc elem);
val_ "pop_last" Dynarray.pop_last (t @-> returning_or_exc elem);
val_freq 2 "remove_last" Dynarray.remove_last (t @-> returning_or_exc unit);
val_ "clear" Dynarray.clear (t @-> returning_or_exc unit);
val_ "truncate" Dynarray.truncate (t @-> int @-> returning_or_exc unit);
val_ "ensure_capacity" Dynarray.ensure_capacity (t @-> int @-> returning_or_exc unit);
val_ "fit_capacity" Dynarray.fit_capacity (t @-> returning_or_exc unit);
(*val_ "blit" Dynarray.blit (t @-> int_not_too_big @-> t @-> int_not_too_big @-> int_not_too_big @-> returning_or_exc unit);*)
val_freq 2 "set_capacity" Dynarray.set_capacity (t @-> int @-> returning_or_exc unit);
val_ "reset" Dynarray.reset (t @-> returning_or_exc unit);
]
end

module DAT = Lin_domain.Make (Dynarray_api)

let () =
QCheck_base_runner.run_tests_main
[ DAT.neg_lin_test ~count:1000 ~name:"Lin Dynarray test with Domain";
DAT.stress_test ~count:1000 ~name:"Lin Dynarray stress test with Domain";
]
Loading

0 comments on commit 2ef4b84

Please sign in to comment.