From 36929569281488286389e3b8f539ee0395449b52 Mon Sep 17 00:00:00 2001 From: Pau Ruiz Safont Date: Fri, 26 Jul 2024 09:16:34 +0100 Subject: [PATCH] clock: use external qcheck-alcotest Signed-off-by: Pau Ruiz Safont --- clock.opam | 2 + dune-project | 6 ++- ocaml/libs/clock/dune | 12 +++++- ocaml/libs/clock/test_timer.ml | 76 ---------------------------------- 4 files changed, 17 insertions(+), 79 deletions(-) diff --git a/clock.opam b/clock.opam index 52cc8d0ef09..45b4fd162c2 100644 --- a/clock.opam +++ b/clock.opam @@ -13,6 +13,8 @@ depends: [ "astring" "mtime" "ptime" + "qcheck-core" {with-test} + "qcheck-alcotest" {with-test} "odoc" {with-doc} ] build: [ diff --git a/dune-project b/dune-project index 3c6620b2c6c..53e8bf39981 100644 --- a/dune-project +++ b/dune-project @@ -29,6 +29,8 @@ astring mtime ptime + (qcheck-core :with-test) + (qcheck-alcotest :with-test) ) ) @@ -67,7 +69,7 @@ (synopsis "Xen-API client library for remotely-controlling a xapi host") (authors "David Scott" "Anil Madhavapeddy" "Jerome Maloberti" "John Else" "Jon Ludlam" "Thomas Sanders" "Mike McClurg") (depends - + (alcotest :with-test) astring (cohttp (>= "0.22.0")) @@ -188,7 +190,7 @@ (description "This daemon monitors 'datasources' i.e. time-varying values such as performance counters and records the samples in RRD archives. These archives can be used to examine historical performance trends.") (depends (ocaml (>= "4.02.0")) - + (alcotest :with-test) astring (gzip (= :version)) diff --git a/ocaml/libs/clock/dune b/ocaml/libs/clock/dune index 3c2ab5c67d6..ebc174c9f2e 100644 --- a/ocaml/libs/clock/dune +++ b/ocaml/libs/clock/dune @@ -15,5 +15,15 @@ (names test_date test_timer) (package clock) (modules test_date test_timer) - (libraries alcotest clock fmt mtime mtime.clock.os ptime qcheck-core qcheck-core.runner) + (libraries + alcotest + clock + fmt + mtime + mtime.clock.os + ptime + qcheck-alcotest + qcheck-core + qcheck-core.runner + ) ) diff --git a/ocaml/libs/clock/test_timer.ml b/ocaml/libs/clock/test_timer.ml index 2d5e20d7d8a..fca152ee96d 100644 --- a/ocaml/libs/clock/test_timer.ml +++ b/ocaml/libs/clock/test_timer.ml @@ -2,82 +2,6 @@ module Timer = Clock.Timer module Gen = QCheck2.Gen module Test = QCheck2.Test -module QCheck_alcotest = struct - (* SPDX: BSD-2-Clause - From github.com/c-cube/qcheck - *) - - module Q = QCheck2 - module T = QCheck2.Test - module Raw = QCheck_base_runner.Raw - - let seed_ = - lazy - (let s = - try int_of_string @@ Sys.getenv "QCHECK_SEED" - with _ -> Random.self_init () ; Random.int 1_000_000_000 - in - Printf.printf "qcheck random seed: %d\n%!" s ; - s - ) - - let default_rand () = - (* random seed, for repeatability of tests *) - Random.State.make [|Lazy.force seed_|] - - let verbose_ = - lazy - ( match Sys.getenv "QCHECK_VERBOSE" with - | "1" | "true" -> - true - | _ -> - false - | exception Not_found -> - false - ) - - let long_ = - lazy - ( match Sys.getenv "QCHECK_LONG" with - | "1" | "true" -> - true - | _ -> - false - | exception Not_found -> - false - ) - - let to_alcotest ?(colors = false) ?(verbose = Lazy.force verbose_) - ?(long = Lazy.force long_) ?(debug_shrink = None) ?debug_shrink_list - ?(rand = default_rand ()) (t : T.t) = - let (T.Test cell) = t in - let handler name cell r = - match (r, debug_shrink) with - | QCheck2.Test.Shrunk (step, x), Some out -> - let go = - match debug_shrink_list with - | None -> - true - | Some test_list -> - List.mem name test_list - in - if not go then - () - else - QCheck_base_runner.debug_shrinking_choices ~colors ~out ~name cell - ~step x - | _ -> - () - in - let print = Raw.print_std in - let name = T.get_name cell in - let run () = - let call = Raw.callback ~colors ~verbose ~print_res:true ~print in - T.check_cell_exn ~long ~call ~handler ~rand cell - in - ((name, `Slow, run) : unit Alcotest.test_case) -end - let spans = Gen.oneofa ([|1; 100; 300|] |> Array.map (fun v -> Mtime.Span.(v * ms)))