Skip to content

Commit

Permalink
CP-50448: move quickcheck tests into internal libraries
Browse files Browse the repository at this point in the history
We want to run these from 'quicktest', so make them available as libraries,
and add a _run.ml that would run them separately, just as before.
(running separately in the CI is better, because it can be parallelize)

No functional change.

Signed-off-by: Edwin Török <[email protected]>
  • Loading branch information
edwintorok committed Jul 29, 2024
1 parent afe5fec commit eb58c7d
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 20 deletions.
16 changes: 10 additions & 6 deletions ocaml/libs/clock/dune
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,23 @@
)
)

(tests
(names test_date test_timer)
(library
(name test_timer)
(package clock)
(modules test_date test_timer)
(modules test_timer)
(libraries
alcotest
clock
fmt
mtime
mtime.clock.os
ptime
qcheck-alcotest
qcheck-core
qcheck-core.runner
)
)

(tests
(names test_date test_timer_run)
(package clock)
(modules test_date test_timer_run)
(libraries alcotest clock fmt mtime mtime.clock.os ptime qcheck-core qcheck-alcotest test_timer)
)
4 changes: 1 addition & 3 deletions ocaml/libs/clock/test_timer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ let test_timer_remaining =
Mtime.Span.pp duration Timer.pp timer ;
true

let tests_timer = List.map QCheck_alcotest.to_alcotest [test_timer_remaining]

let combinations =
let pair x y = (x, y) in
let rec loop acc = function
Expand Down Expand Up @@ -154,4 +152,4 @@ let test_conversion_from_s =
let tests_span =
List.concat [test_conversion_to_s; test_conversion_from_s; test_span_compare]

let () = Alcotest.run "Timer" [("Timer", tests_timer); ("Span", tests_span)]
let tests = [test_timer_remaining]
3 changes: 3 additions & 0 deletions ocaml/libs/clock/test_timer.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
val tests_span : unit Alcotest.V1.test_case list

val tests : QCheck2.Test.t list
4 changes: 4 additions & 0 deletions ocaml/libs/clock/test_timer_run.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let tests_timer = List.map QCheck_alcotest.to_alcotest Test_timer.tests

let () =
Alcotest.run "Timer" [("Timer", tests_timer); ("Span", Test_timer.tests_span)]
Empty file.
4 changes: 3 additions & 1 deletion ocaml/libs/http-lib/bufio_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ let test_buf_io =
in
true

let tests = [test_buf_io]

let () =
(* avoid SIGPIPE *)
let (_ : Sys.signal_behavior) = Sys.signal Sys.sigpipe Sys.Signal_ignore in
QCheck_base_runner.run_tests_main [test_buf_io]
()
1 change: 1 addition & 0 deletions ocaml/libs/http-lib/bufio_test.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
val tests : QCheck2.Test.t list
1 change: 1 addition & 0 deletions ocaml/libs/http-lib/bufio_test_run.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let () = QCheck_base_runner.run_tests_main Bufio_test.tests
Empty file.
19 changes: 14 additions & 5 deletions ocaml/libs/http-lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
(public_name http-lib)
(modes best)
(wrapped false)
(modules (:standard \ http_svr http_proxy server_io http_test radix_tree_test test_client test_server bufio_test))
(modules (:standard \ http_svr http_proxy server_io http_test radix_tree_test test_client test_server bufio_test bufio_test_run))
(preprocess (per_module ((pps ppx_deriving_rpc) Http)))
(libraries
astring
Expand Down Expand Up @@ -67,9 +67,21 @@
)

(test
(name bufio_test)
(name bufio_test_run)
(package http-lib)
(modes (best exe))
(modules bufio_test_run)
(libraries
qcheck-core.runner
bufio_test
)
; use fixed seed to avoid causing random failures in CI and package builds
(action (run %{test} -v -bt --seed 42))
)

(library
(name bufio_test)
(modes best)
(modules bufio_test)
(libraries
fmt
Expand All @@ -79,11 +91,8 @@
rresult
http_lib
qcheck-core
qcheck-core.runner
xapi_fd_test
)
; use fixed seed to avoid causing random failures in CI and package builds
(action (run %{test} -v -bt --seed 42))
)

(rule
Expand Down
12 changes: 9 additions & 3 deletions ocaml/libs/xapi-stdext/lib/xapi-stdext-unix/test/dune
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
(test
(library
(name unixext_test)
(package xapi-stdext-unix)
(modules unixext_test)
(libraries xapi_stdext_unix qcheck-core mtime.clock.os qcheck-core.runner fmt xapi_fd_test mtime threads.posix rresult)
(libraries xapi_stdext_unix qcheck-core mtime.clock.os fmt xapi_fd_test mtime threads.posix rresult)
)

(test
(name unixext_test_run)
(package xapi-stdext-unix)
(modules unixext_test_run)
(libraries unixext_test qcheck-core.runner)
; use fixed seed to avoid causing random failures in CI and package builds
(action (run %{test} -v -bt --seed 42))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,4 @@ let tests = [test_proxy; test_time_limited_write; test_time_limited_read]
let () =
(* avoid SIGPIPE *)
let (_ : Sys.signal_behavior) = Sys.signal Sys.sigpipe Sys.Signal_ignore in
Xapi_stdext_unix.Unixext.test_open 1024 ;
QCheck_base_runner.run_tests_main tests
Xapi_stdext_unix.Unixext.test_open 1024
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
val tests : QCheck2.Test.t list
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let () = QCheck_base_runner.run_tests_main Unixext_test.tests
Empty file.

0 comments on commit eb58c7d

Please sign in to comment.