From f1dc999904149046a60a2b32656aa5bbe3af267a Mon Sep 17 00:00:00 2001 From: Pietro Abate Date: Tue, 11 Apr 2023 11:16:27 +0200 Subject: [PATCH 1/6] lib_test: move module Raw_Tree to lib_context/test --- manifest/main.ml | 1 - opam/tezos-context.opam | 1 - src/lib_context/test/dune | 1 - src/lib_context/test/test_context.ml | 27 +++++++++++++++++++++++++-- src/lib_test/assert_lib.ml | 20 -------------------- src/lib_test/assert_lib.mli | 15 --------------- 6 files changed, 25 insertions(+), 40 deletions(-) diff --git a/manifest/main.ml b/manifest/main.ml index 6b274623c96b..9a054993d1f3 100644 --- a/manifest/main.ml +++ b/manifest/main.ml @@ -2632,7 +2632,6 @@ let _octez_context_tests = octez_context_encoding; octez_stdlib_unix |> open_; octez_test_helpers |> open_; - octez_test_helpers_extra; qcheck_alcotest; alcotezt; ] diff --git a/opam/tezos-context.opam b/opam/tezos-context.opam index 678eef65643f..25f2b75cf6c5 100644 --- a/opam/tezos-context.opam +++ b/opam/tezos-context.opam @@ -21,7 +21,6 @@ depends: [ "tezt" { with-test & >= "3.0.0" } "octez-alcotezt" {with-test} "tezos-test-helpers" {with-test} - "tezos-test-helpers-extra" {with-test} "qcheck-alcotest" { with-test & >= "0.20" } ] build: [ diff --git a/src/lib_context/test/dune b/src/lib_context/test/dune index 798e505d1bcf..5cd9113d2e64 100644 --- a/src/lib_context/test/dune +++ b/src/lib_context/test/dune @@ -14,7 +14,6 @@ tezos-context.encoding tezos-stdlib-unix tezos-test-helpers - tezos-test-helpers-extra qcheck-alcotest octez-alcotezt) (library_flags (:standard -linkall)) diff --git a/src/lib_context/test/test_context.ml b/src/lib_context/test/test_context.ml index 4ef7923cae96..d4d021e376da 100644 --- a/src/lib_context/test/test_context.ml +++ b/src/lib_context/test/test_context.ml @@ -30,7 +30,30 @@ Subject: On context features. *) -module Assert_lib = Lib_test_extra.Assert_lib +(** Module concerning assertions about raw trees i.e. values of type + [[< `Tree of 'a Tezos_base.TzPervasives.String.Map.t | `Value of bytes] as 'a] *) +module Raw_Tree = struct + (** [equal loc msg rt0 rt1] checks that the raw tree [rt0] and [rt1] are equal. + Will fail with the message [msg] displaying the location [loc] otherwise *) + let equal ?loc ?msg r1 r2 = + let rec aux r1 r2 = + match (r1, r2) with + | `Value v1, `Value v2 -> + Assert.Bytes.equal ?loc ?msg v1 v2 ; + true + | `Tree t1, `Tree t2 -> + if not (Tezos_base.TzPervasives.String.Map.equal aux t1 t2) then + Assert.String.fail "" "" ?msg ?loc + else true + | `Tree _, `Value v -> + Assert.String.fail ?loc ?msg "" (Bytes.to_string v) + | `Value v, `Tree _ -> + Assert.String.fail ?loc ?msg (Bytes.to_string v) "" + in + let _b : bool = aux r1 r2 in + () +end + module Assert = Assert let equal_context_hash ?loc ?msg l1 l2 = @@ -460,7 +483,7 @@ struct let c = String.Map.add "bar" (`Tree b) a in let d = String.Map.singleton "foo" (`Tree c) in let e = `Tree d in - Assert_lib.Raw_Tree.equal ~loc:__LOC__ e raw ; + Raw_Tree.equal ~loc:__LOC__ e raw ; Lwt.return () let string n = String.make n 'a' diff --git a/src/lib_test/assert_lib.ml b/src/lib_test/assert_lib.ml index e6fefc7a00ff..09a0b7739038 100644 --- a/src/lib_test/assert_lib.ml +++ b/src/lib_test/assert_lib.ml @@ -94,23 +94,3 @@ module Crypto = struct in Assert.equal ?loc ?msg ~pp ~eq bd1 bd2 end - -module Raw_Tree = struct - let equal ?loc ?msg r1 r2 = - let rec aux r1 r2 = - match (r1, r2) with - | `Value v1, `Value v2 -> - Assert.Bytes.equal ?loc ?msg v1 v2 ; - true - | `Tree t1, `Tree t2 -> - if not (Tezos_base.TzPervasives.String.Map.equal aux t1 t2) then - Assert.String.fail "" "" ?msg ?loc - else true - | `Tree _, `Value v -> - Assert.String.fail ?loc ?msg "" (Bytes.to_string v) - | `Value v, `Tree _ -> - Assert.String.fail ?loc ?msg (Bytes.to_string v) "" - in - let _b : bool = aux r1 r2 in - () -end diff --git a/src/lib_test/assert_lib.mli b/src/lib_test/assert_lib.mli index 703486ac1770..0d7e756370eb 100644 --- a/src/lib_test/assert_lib.mli +++ b/src/lib_test/assert_lib.mli @@ -56,18 +56,3 @@ module Crypto : sig val equal_block_descriptor : (int32 * Tezos_crypto.Hashed.Block_hash.t) Tezos_test_helpers.Assert.check2 end - -(** Module concerning assertions about raw trees i.e. values of type - [[< `Tree of 'a Tezos_base.TzPervasives.String.Map.t | `Value of bytes] as 'a] *) -module Raw_Tree : sig - (** [equal loc msg rt0 rt1] checks that the raw tree [rt0] and [rt1] are equal. - Will fail with the message [msg] displaying the location [loc] otherwise *) - val equal : - ?loc:string -> - ?msg:string -> - ([< `Tree of 'a Tezos_base.TzPervasives.String.Map.t | `Value of bytes] - as - 'a) -> - 'a -> - unit -end -- GitLab From c77a684a0f30ade45099bab1f280915a91bf9c72 Mon Sep 17 00:00:00 2001 From: Pietro Abate Date: Tue, 11 Apr 2023 13:46:50 +0200 Subject: [PATCH 2/6] manifest: move octez_test_helpers_extra to lib_store/unix/test --- .gitlab/ci/jobs/packaging/opam_package.yml | 9 +------- dune-project | 1 - manifest/main.ml | 19 ++-------------- opam/tezos-store.opam | 1 - opam/tezos-test-helpers-extra.opam | 22 ------------------- .../unix/test}/assert_lib.ml | 0 .../unix/test}/assert_lib.mli | 0 src/lib_store/unix/test/dune | 7 +++--- src/lib_store/unix/test/test_block_store.ml | 1 - .../unix/test/test_cemented_store.ml | 9 +++++++- src/lib_store/unix/test/test_reconstruct.ml | 9 +++++++- src/lib_store/unix/test/test_snapshots.ml | 9 +++++++- src/lib_store/unix/test/test_utils.ml | 1 - src/lib_test/dune | 12 ---------- 14 files changed, 31 insertions(+), 69 deletions(-) delete mode 100644 opam/tezos-test-helpers-extra.opam rename src/{lib_test => lib_store/unix/test}/assert_lib.ml (100%) rename src/{lib_test => lib_store/unix/test}/assert_lib.mli (100%) diff --git a/.gitlab/ci/jobs/packaging/opam_package.yml b/.gitlab/ci/jobs/packaging/opam_package.yml index c092da6c1531..d49aff55af93 100644 --- a/.gitlab/ci/jobs/packaging/opam_package.yml +++ b/.gitlab/ci/jobs/packaging/opam_package.yml @@ -519,7 +519,7 @@ opam:tezos-base-test-helpers: opam:tezos-clic: extends: - .opam_template - - .rules_template__trigger_opam_batch_7 + - .rules_template__trigger_opam_batch_6 variables: package: tezos-clic @@ -1607,13 +1607,6 @@ opam:tezos-test-helpers: variables: package: tezos-test-helpers -opam:tezos-test-helpers-extra: - extends: - - .opam_template - - .rules_template__trigger_opam_batch_6 - variables: - package: tezos-test-helpers-extra - # Ignoring unreleased package tezos-tooling. # Ignoring unreleased package tezos-tps-evaluation. diff --git a/dune-project b/dune-project index e8afa8e5c4e3..064c16b951b1 100644 --- a/dune-project +++ b/dune-project @@ -247,7 +247,6 @@ (package (name tezos-stdlib-unix)) (package (name tezos-store)) (package (name tezos-test-helpers)) -(package (name tezos-test-helpers-extra)) (package (name tezos-tooling)) (package (name tezos-tps-evaluation)) (package (name tezos-tree-encoding)) diff --git a/manifest/main.ml b/manifest/main.ml index 9a054993d1f3..e153ad63b5aa 100644 --- a/manifest/main.ml +++ b/manifest/main.ml @@ -2164,22 +2164,6 @@ let octez_shell_services = ~linkall:true ~js_compatible:true -let octez_test_helpers_extra = - public_lib - "tezos-test-helpers-extra" - ~path:"src/lib_test" - ~internal_name:"lib_test_extra" - ~synopsis:"Test helpers dependent on tezos-base" - ~deps:[octez_base; octez_crypto; octez_test_helpers] - ~dune: - Dune. - [ - (* This rule is necessary for `make lint-tests-pkg`, without it dune - complains that the alias is empty. *) - alias_rule "runtest_js_base" ~action:(S "progn"); - ] - ~modules:["assert_lib"] - let _octez_shell_services_tests = tezt ["test_block_services"] @@ -6495,6 +6479,8 @@ let _octez_store_tests = "test_protocol_store"; "test_store"; "test_testchain"; + "test_utils"; + "assert_lib"; ] ~path:"src/lib_store/unix/test" ~with_macos_security_framework:true @@ -6519,7 +6505,6 @@ let _octez_store_tests = Protocol.(plugin_exn alpha) |> open_; alcotest_lwt; octez_test_helpers |> open_; - octez_test_helpers_extra; ] ~alias:"" ~dune: diff --git a/opam/tezos-store.opam b/opam/tezos-store.opam index a318b60e6e5b..bad8787bbfdc 100644 --- a/opam/tezos-store.opam +++ b/opam/tezos-store.opam @@ -39,7 +39,6 @@ depends: [ "tezos-protocol-plugin-alpha" {with-test} "alcotest-lwt" { with-test & >= "1.5.0" } "tezos-test-helpers" {with-test} - "tezos-test-helpers-extra" {with-test} ] build: [ ["rm" "-r" "vendors"] diff --git a/opam/tezos-test-helpers-extra.opam b/opam/tezos-test-helpers-extra.opam deleted file mode 100644 index db9da3c8a400..000000000000 --- a/opam/tezos-test-helpers-extra.opam +++ /dev/null @@ -1,22 +0,0 @@ -# This file was automatically generated, do not edit. -# Edit file manifest/main.ml instead. -opam-version: "2.0" -maintainer: "contact@tezos.com" -authors: ["Tezos devteam"] -homepage: "https://www.tezos.com/" -bug-reports: "https://gitlab.com/tezos/tezos/issues" -dev-repo: "git+https://gitlab.com/tezos/tezos.git" -license: "MIT" -depends: [ - "dune" { >= "3.0" } - "ocaml" { >= "4.14" } - "tezos-base" - "tezos-crypto" - "tezos-test-helpers" -] -build: [ - ["rm" "-r" "vendors"] - ["dune" "build" "-p" name "-j" jobs] - ["dune" "runtest" "-p" name "-j" jobs] {with-test} -] -synopsis: "Test helpers dependent on tezos-base" diff --git a/src/lib_test/assert_lib.ml b/src/lib_store/unix/test/assert_lib.ml similarity index 100% rename from src/lib_test/assert_lib.ml rename to src/lib_store/unix/test/assert_lib.ml diff --git a/src/lib_test/assert_lib.mli b/src/lib_store/unix/test/assert_lib.mli similarity index 100% rename from src/lib_test/assert_lib.mli rename to src/lib_store/unix/test/assert_lib.mli diff --git a/src/lib_store/unix/test/dune b/src/lib_store/unix/test/dune index 86954a391156..e7ec9a51e1d0 100644 --- a/src/lib_store/unix/test/dune +++ b/src/lib_store/unix/test/dune @@ -10,7 +10,9 @@ test_block_store test_protocol_store test_store - test_testchain) + test_testchain + test_utils + assert_lib) (libraries tezos-base tezos-crypto @@ -29,8 +31,7 @@ tezos-protocol-alpha.parameters tezos-protocol-plugin-alpha alcotest-lwt - tezos-test-helpers - tezos-test-helpers-extra) + tezos-test-helpers) (link_flags (:standard) (:include %{workspace_root}/macos-link-flags.sexp)) diff --git a/src/lib_store/unix/test/test_block_store.ml b/src/lib_store/unix/test/test_block_store.ml index 7ff0d9910a2a..2f38af6b50dc 100644 --- a/src/lib_store/unix/test/test_block_store.ml +++ b/src/lib_store/unix/test/test_block_store.ml @@ -24,7 +24,6 @@ (*****************************************************************************) module Assert = Assert -module Assert_lib = Lib_test_extra.Assert_lib open Test_utils open Block_store diff --git a/src/lib_store/unix/test/test_cemented_store.ml b/src/lib_store/unix/test/test_cemented_store.ml index c7b0daf17bc8..05b190da26db 100644 --- a/src/lib_store/unix/test/test_cemented_store.ml +++ b/src/lib_store/unix/test/test_cemented_store.ml @@ -23,7 +23,14 @@ (* *) (*****************************************************************************) -module Assert_lib = Lib_test_extra.Assert_lib +(** Testing + _______ + + Component: Store + Invocation: dune exec src/lib_store/unix/test/main.exe + Subject: Store tests ( block cementing ) +*) + open Test_utils let assert_presence_in_cemented_store ?(with_metadata = true) cemented_store diff --git a/src/lib_store/unix/test/test_reconstruct.ml b/src/lib_store/unix/test/test_reconstruct.ml index 0c7fc452c962..78b2c2df735e 100644 --- a/src/lib_store/unix/test/test_reconstruct.ml +++ b/src/lib_store/unix/test/test_reconstruct.ml @@ -24,7 +24,14 @@ (* *) (*****************************************************************************) -module Assert_lib = Lib_test_extra.Assert_lib +(** Testing + _______ + + Component: Store + Invocation: dune exec src/lib_store/unix/test/main.exe + Subject: Store tests ( reconstruct ) +*) + open Test_utils (* Export mode used to export snapshot. Tar is seleceted by diff --git a/src/lib_store/unix/test/test_snapshots.ml b/src/lib_store/unix/test/test_snapshots.ml index bfce21c214da..8b5411647ce0 100644 --- a/src/lib_store/unix/test/test_snapshots.ml +++ b/src/lib_store/unix/test/test_snapshots.ml @@ -25,7 +25,14 @@ (* *) (*****************************************************************************) -module Assert_lib = Lib_test_extra.Assert_lib +(** Testing + _______ + + Component: Store + Invocation: dune exec src/lib_store/unix/test/main.exe + Subject: Store tests ( snapshots ) +*) + open Test_utils let check_import_invariants ~test_descr ~rolling diff --git a/src/lib_store/unix/test/test_utils.ml b/src/lib_store/unix/test/test_utils.ml index f1d877b1f3c6..1ab584b33ce3 100644 --- a/src/lib_store/unix/test/test_utils.ml +++ b/src/lib_store/unix/test/test_utils.ml @@ -24,7 +24,6 @@ (*****************************************************************************) module Assert = Assert -module Assert_lib = Lib_test_extra.Assert_lib open Alcotest_lwt open Filename.Infix diff --git a/src/lib_test/dune b/src/lib_test/dune index 3e9eb9068d17..2b36f26c20fc 100644 --- a/src/lib_test/dune +++ b/src/lib_test/dune @@ -26,15 +26,3 @@ testable)) (rule (alias runtest_js) (action progn)) - -(library - (name lib_test_extra) - (public_name tezos-test-helpers-extra) - (instrumentation (backend bisect_ppx)) - (libraries - tezos-base - tezos-crypto - tezos-test-helpers) - (modules assert_lib)) - -(rule (alias runtest_js_base) (action progn)) -- GitLab From 947c552b87e7d0c9862a1c97bf6b649327fe8313 Mon Sep 17 00:00:00 2001 From: Pietro Abate Date: Thu, 13 Apr 2023 13:16:51 +0200 Subject: [PATCH 3/6] manifest: make tezt return the private tezt lib --- manifest/main.ml | 35 +++++++++++++++------------- manifest/manifest.ml | 48 ++++++++++++++++++++------------------- manifest/manifest.mli | 8 +++++-- src/lib_sapling/test/dune | 34 +++++++++++++-------------- 4 files changed, 67 insertions(+), 58 deletions(-) diff --git a/manifest/main.ml b/manifest/main.ml index e153ad63b5aa..171a7850ee24 100644 --- a/manifest/main.ml +++ b/manifest/main.ml @@ -4905,22 +4905,25 @@ end = struct can be run either with [dune build @runtezt], with [dune exec src/proto_alpha/lib_protocol/test/regression/main.exe], or with [dune exec tezt/tests/main.exe -- -f test_logging.ml]. *) - tezt - ["test_logging"] - ~path:(path // "lib_protocol/test/regression") - ~with_macos_security_framework:true - ~opam:(sf "tezos-protocol-%s-tests" name_dash) - ~deps: - [ - octez_base |> open_ ~m:"TzPervasives"; - tezt_tezos |> open_; - main |> open_; - client |> if_some |> open_; - plugin |> if_some |> open_; - test_helpers |> if_some |> open_; - octez_micheline |> open_; - ] - ~dep_globs:["contracts/*.tz"; "expected/test_logging.ml/*.out"] + let _ = + tezt + ["test_logging"] + ~path:(path // "lib_protocol/test/regression") + ~with_macos_security_framework:true + ~opam:(sf "tezos-protocol-%s-tests" name_dash) + ~deps: + [ + octez_base |> open_ ~m:"TzPervasives"; + tezt_tezos |> open_; + main |> open_; + client |> if_some |> open_; + plugin |> if_some |> open_; + test_helpers |> if_some |> open_; + octez_micheline |> open_; + ] + ~dep_globs:["contracts/*.tz"; "expected/test_logging.ml/*.out"] + in + () in () diff --git a/manifest/manifest.ml b/manifest/manifest.ml index 38b8180e65ea..bbb2cce6c3ad 100644 --- a/manifest/manifest.ml +++ b/manifest/manifest.ml @@ -1804,6 +1804,7 @@ type tezt_target = { opam_with_test : with_test option; with_macos_security_framework : bool; dune : Dune.s_expr; + tezt_local_test_lib : target; } let tezt_targets_by_path : tezt_target String_map.t ref = ref String_map.empty @@ -1815,6 +1816,23 @@ let tezt ~opam ~path ?js_compatible ?modes ?(lib_deps = []) ?(exe_deps = []) if String_map.mem path !tezt_targets_by_path then invalid_arg ("cannot call Manifest.tezt twice for the same directory: " ^ path) ; + let path_with_underscores = + String.map (function '-' | '/' -> '_' | c -> c) path + in + (* [linkall] is used to ensure that the test executable is linked with [module_name] and [tezt]. *) + let tezt_local_test_lib_name = path_with_underscores ^ "_tezt_lib" in + let tezt_local_test_lib = + Target.( + private_lib + ~path + ~opam:"" + ?js_compatible + ~deps:lib_deps + ~modules + ~linkall:true + ~dune + tezt_local_test_lib_name) + in let tezt_target = { opam; @@ -1831,46 +1849,30 @@ let tezt ~opam ~path ?js_compatible ?modes ?(lib_deps = []) ?(exe_deps = []) opam_with_test; with_macos_security_framework; dune; + tezt_local_test_lib; } in - tezt_targets_by_path := String_map.add path tezt_target !tezt_targets_by_path + tezt_targets_by_path := String_map.add path tezt_target !tezt_targets_by_path ; + tezt_local_test_lib let register_tezt_targets ~make_tezt_exe = let tezt_test_libs = ref [] in let register_path path { opam; - lib_deps; exe_deps; js_deps; dep_globs; dep_globs_rec; dep_files; - modules; - js_compatible; modes; synopsis; opam_with_test; with_macos_security_framework; - dune; + tezt_local_test_lib; + _; } = - let path_with_underscores = - String.map (function '-' | '/' -> '_' | c -> c) path - in - let lib = - (* [linkall] is used to ensure that the test executable is linked with - [module_name] and [tezt]. *) - Target.private_lib - (path_with_underscores ^ "_tezt_lib") - ~path - ~opam:"" - ?js_compatible - ~deps:lib_deps - ~modules - ~linkall:true - ~dune - in - tezt_test_libs := lib :: !tezt_test_libs ; + tezt_test_libs := tezt_local_test_lib :: !tezt_test_libs ; let declare_exe ?js_compatible exe_name modes deps main = let (_ : Target.t option) = Target.test @@ -1885,7 +1887,7 @@ let register_tezt_targets ~make_tezt_exe = (* Instrument with sigterm handler, to ensure that coverage from Tezt worker processes are collected. *) ~bisect_ppx:With_sigterm - ~deps:(lib :: deps) + ~deps:(tezt_local_test_lib :: deps) ~dep_globs ~dep_globs_rec ~dep_files diff --git a/manifest/manifest.mli b/manifest/manifest.mli index de561cf350a5..c31ae7c784b2 100644 --- a/manifest/manifest.mli +++ b/manifest/manifest.mli @@ -939,7 +939,11 @@ val tests : The flag [with_macos_security_framework] has a default [false]. When set to [true], the [-ccopt "-framework Security"]flag is added at link time for - macOS system. *) + macOS system. + + The function returns a target that is the local library created by tezt + to register all tests. This can be reused locally in the same module + to share code with other targets. *) val tezt : opam:string -> path:string -> @@ -956,7 +960,7 @@ val tezt : ?with_macos_security_framework:bool -> ?dune:Dune.s_expr -> string list -> - unit + target (** Make an external vendored library, for use in internal target dependencies. diff --git a/src/lib_sapling/test/dune b/src/lib_sapling/test/dune index 663f006e4302..f4bbc29bdb52 100644 --- a/src/lib_sapling/test/dune +++ b/src/lib_sapling/test/dune @@ -3,23 +3,6 @@ (env (_ (env-vars (NODE_PRELOAD hacl-wasm,ocaml-bls12-381,secp256k1-wasm)))) -(executable - (name test_js) - (modes js) - (libraries - tezos-sapling - tezos-hacl) - (js_of_ocaml) - (link_flags - (:standard) - (-linkall)) - (modules test_js)) - -(rule - (alias runtest_js) - (package tezos-sapling) - (action (run node %{dep:./test_js.bc.js}))) - (library (name src_lib_sapling_test_tezt_lib) (instrumentation (backend bisect_ppx)) @@ -54,6 +37,23 @@ keys example)) +(executable + (name test_js) + (modes js) + (libraries + tezos-sapling + tezos-hacl) + (js_of_ocaml) + (link_flags + (:standard) + (-linkall)) + (modules test_js)) + +(rule + (alias runtest_js) + (package tezos-sapling) + (action (run node %{dep:./test_js.bc.js}))) + (executable (name main) (instrumentation (backend bisect_ppx --bisect-sigterm)) -- GitLab From 758a5cc47e27054afd508b39d509e386ae9e8cd6 Mon Sep 17 00:00:00 2001 From: Arvid Jakobsson Date: Thu, 20 Apr 2023 09:42:02 +0200 Subject: [PATCH 4/6] Alcotezt: add [slow] tag for tests that are not [`Quick] --- tezt/lib_alcotezt/alcotest.ml | 2 +- tezt/lib_alcotezt/alcotest_lwt.ml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tezt/lib_alcotezt/alcotest.ml b/tezt/lib_alcotezt/alcotest.ml index 8c095565955b..c424fa932ee5 100644 --- a/tezt/lib_alcotezt/alcotest.ml +++ b/tezt/lib_alcotezt/alcotest.ml @@ -45,7 +45,7 @@ let run ~__FILE__ library_name tests = |> List.iter @@ fun (test_case_name, speed_level, body) -> let tags = "alcotezt" - :: (match speed_level with `Quick -> ["quick"] | `Slow -> []) + :: (match speed_level with `Quick -> ["quick"] | `Slow -> ["slow"]) @ proto_tags in Test.register diff --git a/tezt/lib_alcotezt/alcotest_lwt.ml b/tezt/lib_alcotezt/alcotest_lwt.ml index 5aeaab5c2c32..82893716c737 100644 --- a/tezt/lib_alcotezt/alcotest_lwt.ml +++ b/tezt/lib_alcotezt/alcotest_lwt.ml @@ -55,7 +55,7 @@ let run ~__FILE__ library_name tests = |> List.iter @@ fun (test_case_name, speed_level, body) -> let tags = "alcotezt" - :: (match speed_level with `Quick -> ["quick"] | `Slow -> []) + :: (match speed_level with `Quick -> ["quick"] | `Slow -> ["slow"]) @ proto_tags in Test.register -- GitLab From 977ff663176dfff7a5ee42c9ca99c8a279304caf Mon Sep 17 00:00:00 2001 From: Arvid Jakobsson Date: Thu, 20 Apr 2023 09:42:36 +0200 Subject: [PATCH 5/6] Alcotezt: refactor [title] formatting --- tezt/lib_alcotezt/alcotest.ml | 8 +++----- tezt/lib_alcotezt/alcotest_lwt.ml | 7 ++----- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/tezt/lib_alcotezt/alcotest.ml b/tezt/lib_alcotezt/alcotest.ml index c424fa932ee5..b4ffc81f6223 100644 --- a/tezt/lib_alcotezt/alcotest.ml +++ b/tezt/lib_alcotezt/alcotest.ml @@ -24,6 +24,7 @@ (*****************************************************************************) open Tezt_core +open Tezt_core.Base type return = unit @@ -48,11 +49,8 @@ let run ~__FILE__ library_name tests = :: (match speed_level with `Quick -> ["quick"] | `Slow -> ["slow"]) @ proto_tags in - Test.register - ~__FILE__ - ~title:(library_name ^ ": " ^ test_name ^ " (" ^ test_case_name ^ ")") - ~tags - @@ fun () -> + let title = sf "%s: %s (%s)" library_name test_name test_case_name in + Test.register ~__FILE__ ~title ~tags @@ fun () -> body () ; Base.unit diff --git a/tezt/lib_alcotezt/alcotest_lwt.ml b/tezt/lib_alcotezt/alcotest_lwt.ml index 82893716c737..ce66d3e2e04b 100644 --- a/tezt/lib_alcotezt/alcotest_lwt.ml +++ b/tezt/lib_alcotezt/alcotest_lwt.ml @@ -58,9 +58,6 @@ let run ~__FILE__ library_name tests = :: (match speed_level with `Quick -> ["quick"] | `Slow -> ["slow"]) @ proto_tags in - Test.register - ~__FILE__ - ~title:(library_name ^ ": " ^ test_name ^ " (" ^ test_case_name ^ ")") - ~tags - @@ fun () -> body ()) ; + let title = sf "%s: %s (%s)" library_name test_name test_case_name in + Test.register ~__FILE__ ~title ~tags @@ fun () -> body ()) ; unit -- GitLab From d5ccc0d2b525abf5ae7a63a6c6316abd2188dce4 Mon Sep 17 00:00:00 2001 From: Arvid Jakobsson Date: Thu, 20 Apr 2023 09:43:02 +0200 Subject: [PATCH 6/6] lib_store: port tests to alcotezt --- Makefile | 12 +- manifest/main.ml | 91 ++++++++------- opam/tezos-store.opam | 4 +- src/lib_store/unix/test/bench/bench.ml | 104 ++++++++++++++++++ src/lib_store/unix/test/bench/dune | 16 +++ src/lib_store/unix/test/dune | 95 +++++++--------- src/lib_store/unix/test/slow/dune | 17 +++ src/lib_store/unix/test/slow/test_slow.ml | 48 ++++++++ src/lib_store/unix/test/test.ml | 24 ++-- src/lib_store/unix/test/test_block_store.ml | 11 +- .../unix/test/test_cemented_store.ml | 4 +- src/lib_store/unix/test/test_consistency.ml | 10 ++ .../unix/test/test_history_mode_switch.ml | 66 ++++++----- src/lib_store/unix/test/test_locator.ml | 86 +-------------- .../unix/test/test_protocol_store.ml | 11 +- src/lib_store/unix/test/test_reconstruct.ml | 4 +- src/lib_store/unix/test/test_snapshots.ml | 21 ++-- src/lib_store/unix/test/test_store.ml | 11 +- src/lib_store/unix/test/test_testchain.ml | 9 +- src/lib_store/unix/test/test_utils.ml | 2 + tezt/tests/dune | 1 + 21 files changed, 402 insertions(+), 245 deletions(-) create mode 100644 src/lib_store/unix/test/bench/bench.ml create mode 100644 src/lib_store/unix/test/bench/dune create mode 100644 src/lib_store/unix/test/slow/dune create mode 100644 src/lib_store/unix/test/slow/test_slow.ml diff --git a/Makefile b/Makefile index d834c355f51c..f838b26687c5 100644 --- a/Makefile +++ b/Makefile @@ -239,7 +239,17 @@ test-proto-unit: scripts/test_wrapper.sh test-proto-unit \ $(addprefix @, $(addsuffix /runtest,$(PROTO_DIRS))) +.PHONY: test-lib-store-slow +test-lib-store-slow: + DUNE_PROFILE=$(PROFILE) \ + COVERAGE_OPTIONS="$(COVERAGE_OPTIONS)" \ + dune exec src/lib_store/unix/test/slow/test_slow.exe -- --file test_slow.ml --info +.PHONY: test-lib-store-bench +test-lib-store-bench: + DUNE_PROFILE=$(PROFILE) \ + COVERAGE_OPTIONS="$(COVERAGE_OPTIONS)" \ + dune exec src/lib_store/unix/test/bench/bench.exe -- --file bench.ml --info .PHONY: test-nonproto-unit test-nonproto-unit: @@ -253,7 +263,7 @@ test-lib-store-unit: DUNE_PROFILE=$(PROFILE) \ COVERAGE_OPTIONS="$(COVERAGE_OPTIONS)" \ scripts/test_wrapper.sh test-lib-store-unit \ - @$(LIBSTORE_UNIX_DIR)/runtest + @$(LIBSTORE_UNIX_DIR)/runtezt .PHONY: test-unit test-unit: test-nonproto-unit test-proto-unit diff --git a/manifest/main.ml b/manifest/main.ml index 171a7850ee24..6155bcc32f77 100644 --- a/manifest/main.ml +++ b/manifest/main.ml @@ -6472,9 +6472,13 @@ let _octez_micheline_rewriting_tests = ] let _octez_store_tests = - tests + tezt [ "test"; + "test_snapshots"; + "test_reconstruct"; + "test_history_mode_switch"; + "alpha_utils"; "test_consistency"; "test_locator"; "test_cemented_store"; @@ -6506,55 +6510,46 @@ let _octez_store_tests = Protocol.(embedded alpha); Protocol.(parameters_exn alpha |> open_); Protocol.(plugin_exn alpha) |> open_; - alcotest_lwt; + alcotezt; octez_test_helpers |> open_; ] - ~alias:"" - ~dune: - (* [test_slow_manual] is a very long test, running a huge - combination of tests that are useful for local testing for a - given test suite. In addition to that, there is a memory leak - is the tests (that could be in alcotest) which makes the test - to consumes like > 10Gb of ram. For these reasons, we do not - run these tests in the CI. *) - Dune. - [ - alias_rule - "runtest" - ~package:"tezos-store" - ~action:(run_exe "test_cemented_store" []); - alias_rule - "runtest" - ~package:"tezos-store" - ~action:(run_exe "test_consistency" []); - alias_rule - "runtest" - ~package:"tezos-store" - ~action:(run_exe "test_block_store" []); - alias_rule - "runtest" - ~package:"tezos-store" - ~action:(run_exe "test_protocol_store" []); - alias_rule - "runtest" - ~package:"tezos-store" - ~action:(run_exe "test_store" []); - alias_rule - "runtest" - ~package:"tezos-store" - ~action:(run_exe "test_testchain" []); - alias_rule - "runtest" - ~package:"tezos-store" - ~action:(setenv "SLOW_TEST" "false" @@ run_exe "test" []); - alias_rule - "test_slow_manual" - ~action:(setenv "SLOW_TEST" "true" @@ run_exe "test" []); - alias_rule - "runtest_locator_bench" - ~package:"tezos-store" - ~action:(run_exe "test_locator" ["--bench"]); - ] + +(* [_octez_bench_store_lib_tests_exe] is a bench for the store locator, + We do not run these tests in the CI. *) +let _octez_bench_store_lib_tests_exe = + private_exe + "bench" + ~path:"src/lib_store/unix/test/bench" + ~synopsis:"Bench store lib tests" + ~opam:"" + ~deps: + [ + octez_base |> open_ ~m:"TzPervasives"; + tezt_lib; + alcotezt; + _octez_store_tests |> open_; + ] + +(* [_octez_slow_store_lib_tests_exe] is a very long test, running a huge + combination of tests that are useful for local testing for a + given test suite. In addition to that, there is a memory leak + is the tests (that could be in alcotest) which makes the test + to consumes like > 10Gb of ram. For these reasons, we do not + run these tests in the CI. *) +let _octez_slow_store_lib_tests_exe = + private_exe + "test_slow" + ~path:"src/lib_store/unix/test/slow" + ~synopsis:"Slow store lib tests" + ~modules:["test_slow"] + ~opam:"" + ~deps: + [ + octez_base |> open_ ~m:"TzPervasives"; + tezt_lib; + alcotezt; + _octez_store_tests |> open_; + ] let _octez_shell_tests = tezt diff --git a/opam/tezos-store.opam b/opam/tezos-store.opam index bad8787bbfdc..f867f699a954 100644 --- a/opam/tezos-store.opam +++ b/opam/tezos-store.opam @@ -32,18 +32,20 @@ depends: [ "tar-unix" { >= "2.0.1" & < "3.0.0" } "prometheus" { >= "1.2" } "tezos-rpc" + "tezt" { with-test & >= "3.0.0" } "tezos-embedded-protocol-demo-noops" {with-test} "tezos-embedded-protocol-genesis" {with-test} "tezos-embedded-protocol-alpha" {with-test} "tezos-protocol-alpha" {with-test} "tezos-protocol-plugin-alpha" {with-test} - "alcotest-lwt" { with-test & >= "1.5.0" } + "octez-alcotezt" {with-test} "tezos-test-helpers" {with-test} ] build: [ ["rm" "-r" "vendors"] ["dune" "build" "-p" name "-j" jobs] ["dune" "runtest" "-p" name "-j" jobs] {with-test} + ["dune" "build" "@runtezt" "-p" name "-j" jobs] {with-test} ] synopsis: "Tezos: store for `octez-node`" description: "This library provides abstraction for storing and iterating over blocks. diff --git a/src/lib_store/unix/test/bench/bench.ml b/src/lib_store/unix/test/bench/bench.ml new file mode 100644 index 000000000000..20643e1abec1 --- /dev/null +++ b/src/lib_store/unix/test/bench/bench.ml @@ -0,0 +1,104 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2020 Nomadic Labs, *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +(** Testing + _______ + + Invocation: dune exec src/lib_store/unix/test/bench.exe --file bench.ml + Subject: Store locator bench. These tests are not run in the CI +*) + +module Store = Tezos_store_unix.Store + +(** Test if the linear and exponential locator are the same and outputs + their timing. + Run the test with: + $ dune build @runtest_locator + Copy the output to a file timing.dat and plot it with: + $ generate_locator_plot.sh timing.dat +*) +let bench_locator base_dir = + let open Test_locator in + let open Lwt_result_syntax in + let size_chain = 80000 in + (* timing locators with average over [runs] times *) + let runs = 10 in + let _ = Printf.printf "#runs %i\n" runs in + (* limit after which exp should go linear *) + let exp_limit = Test_locator.compute_size_chain 120 in + let _ = Printf.printf "#exp_limit %i\n" exp_limit in + (* size after which locator always reaches genesis *) + let locator_limit = compute_size_locator size_chain in + let _ = Printf.printf "#locator_limit %i\n" locator_limit in + let*! store = init_chain base_dir in + let chain_store = Store.main_chain_store store in + time1 (fun () -> make_empty_chain chain_store size_chain) + |> fun (res, t_chain) -> + let _ = + Printf.printf + "#size_chain %i built in %f sec\n# size exp lins\n" + size_chain + t_chain + in + let*! head = res in + let check_locator max_size : unit tzresult Lwt.t = + let*! caboose, _ = Store.Chain.caboose chain_store in + let* block = Store.Block.read_block chain_store head in + time ~runs (fun () -> + Store.Chain.compute_locator chain_store ~max_size block seed) + |> fun (l_exp, t_exp) -> + time ~runs (fun () -> + compute_linear_locator chain_store ~caboose ~max_size block) + |> fun (l_lin, t_lin) -> + let*! {Block_locator.history = l_exp; _} = l_exp in + let*! {Block_locator.history = l_lin; _} = l_lin in + let _ = Printf.printf "%10i %f %f\n" max_size t_exp t_lin in + Lwt.return + @@ List.iter2 + ~when_different_lengths:(TzTrace.make @@ Exn (Failure __LOC__)) + (fun hn ho -> + if not (Block_hash.equal hn ho) then + Assert.fail_msg "Invalid locator %i" max_size) + l_exp + l_lin + in + let stop = locator_limit + 20 in + let rec loop size = + if size < stop then + let* _ = check_locator size in + loop (size + 5) + else return_unit + in + loop 1 + +let bench = [Test_locator.wrap "bench locator" bench_locator] + +let () = + let open Lwt_syntax in + Lwt_main.run + (let* () = Tezos_base_unix.Internal_event_unix.init () in + Alcotest_lwt.run ~__FILE__ "tezos-store-bench" [("locator bench", bench)]) + +let () = Tezt.Test.run () diff --git a/src/lib_store/unix/test/bench/dune b/src/lib_store/unix/test/bench/dune new file mode 100644 index 000000000000..fe4fe776392c --- /dev/null +++ b/src/lib_store/unix/test/bench/dune @@ -0,0 +1,16 @@ +; This file was automatically generated, do not edit. +; Edit file manifest/main.ml instead. + +(executable + (name bench) + (instrumentation (backend bisect_ppx)) + (libraries + tezos-base + tezt + octez-alcotezt + src_lib_store_unix_test_tezt_lib) + (flags + (:standard) + -open Tezos_base.TzPervasives + -open Octez_alcotezt + -open Src_lib_store_unix_test_tezt_lib)) diff --git a/src/lib_store/unix/test/dune b/src/lib_store/unix/test/dune index e7ec9a51e1d0..98d0d1ee061b 100644 --- a/src/lib_store/unix/test/dune +++ b/src/lib_store/unix/test/dune @@ -1,19 +1,11 @@ ; This file was automatically generated, do not edit. ; Edit file manifest/main.ml instead. -(executables - (names - test - test_consistency - test_locator - test_cemented_store - test_block_store - test_protocol_store - test_store - test_testchain - test_utils - assert_lib) +(library + (name src_lib_store_unix_test_tezt_lib) + (instrumentation (backend bisect_ppx)) (libraries + tezt.core tezos-base tezos-crypto tezos-context-ops @@ -30,13 +22,13 @@ tezos-embedded-protocol-alpha tezos-protocol-alpha.parameters tezos-protocol-plugin-alpha - alcotest-lwt + octez-alcotezt tezos-test-helpers) - (link_flags - (:standard) - (:include %{workspace_root}/macos-link-flags.sexp)) + (library_flags (:standard -linkall)) (flags (:standard) + -open Tezt_core + -open Tezt_core.Base -open Tezos_base.TzPervasives -open Tezos_crypto -open Tezos_context_ops @@ -50,48 +42,37 @@ -open Tezos_protocol_updater -open Tezos_protocol_alpha_parameters -open Tezos_protocol_plugin_alpha - -open Tezos_test_helpers)) - -(rule - (alias runtest) - (package tezos-store) - (action (run %{exe:test_cemented_store.exe}))) - -(rule - (alias runtest) - (package tezos-store) - (action (run %{exe:test_consistency.exe}))) - -(rule - (alias runtest) - (package tezos-store) - (action (run %{exe:test_block_store.exe}))) - -(rule - (alias runtest) - (package tezos-store) - (action (run %{exe:test_protocol_store.exe}))) - -(rule - (alias runtest) - (package tezos-store) - (action (run %{exe:test_store.exe}))) - -(rule - (alias runtest) - (package tezos-store) - (action (run %{exe:test_testchain.exe}))) + -open Octez_alcotezt + -open Tezos_test_helpers) + (modules + test + test_snapshots + test_reconstruct + test_history_mode_switch + alpha_utils + test_consistency + test_locator + test_cemented_store + test_block_store + test_protocol_store + test_store + test_testchain + test_utils + assert_lib)) -(rule - (alias runtest) - (package tezos-store) - (action (setenv SLOW_TEST false (run %{exe:test.exe})))) +(executable + (name main) + (instrumentation (backend bisect_ppx --bisect-sigterm)) + (libraries + src_lib_store_unix_test_tezt_lib + tezt) + (link_flags + (:standard) + (:include %{workspace_root}/macos-link-flags.sexp)) + (modules main)) -(rule - (alias test_slow_manual) - (action (setenv SLOW_TEST true (run %{exe:test.exe})))) +(rule (alias runtezt) (package tezos-store) (action (run %{dep:./main.exe}))) (rule - (alias runtest_locator_bench) - (package tezos-store) - (action (run %{exe:test_locator.exe} --bench))) + (targets main.ml) + (action (with-stdout-to %{targets} (echo "let () = Tezt.Test.run ()")))) diff --git a/src/lib_store/unix/test/slow/dune b/src/lib_store/unix/test/slow/dune new file mode 100644 index 000000000000..00a64ea6fa91 --- /dev/null +++ b/src/lib_store/unix/test/slow/dune @@ -0,0 +1,17 @@ +; This file was automatically generated, do not edit. +; Edit file manifest/main.ml instead. + +(executable + (name test_slow) + (instrumentation (backend bisect_ppx)) + (libraries + tezos-base + tezt + octez-alcotezt + src_lib_store_unix_test_tezt_lib) + (flags + (:standard) + -open Tezos_base.TzPervasives + -open Octez_alcotezt + -open Src_lib_store_unix_test_tezt_lib) + (modules test_slow)) diff --git a/src/lib_store/unix/test/slow/test_slow.ml b/src/lib_store/unix/test/slow/test_slow.ml new file mode 100644 index 000000000000..5b5b3677f310 --- /dev/null +++ b/src/lib_store/unix/test/slow/test_slow.ml @@ -0,0 +1,48 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2020 Nomadic Labs, *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +(** Testing + _______ + + Invocation: dune exec src/lib_store/unix/test/slow/test_slow.exe \ + -- --file test_slow.ml + Subject: Store slow tests. Same tests as test.ml, but run on the + side and not in the CI +*) + +let () = + let open Lwt_syntax in + Lwt_main.run + (let* () = Tezos_base_unix.Internal_event_unix.init () in + Alcotest_lwt.run + ~__FILE__ + "tezos-store-slow" + [ + Test_snapshots.tests `Slow; + Test_reconstruct.tests `Slow; + Test_history_mode_switch.tests `Slow; + ]) + +let () = Tezt.Test.run () diff --git a/src/lib_store/unix/test/test.ml b/src/lib_store/unix/test/test.ml index 34705c983fe0..fd269c2d9ea9 100644 --- a/src/lib_store/unix/test/test.ml +++ b/src/lib_store/unix/test/test.ml @@ -23,25 +23,23 @@ (* *) (*****************************************************************************) -(* Several of the tests take the additional [SLOW_TEST] environment variable. - We group those tests in this here executable for simplicity. *) +(** Testing + _______ + + Component: Store + Invocation: dune exec src/lib_store/unix/test/main.exe --file test.ml + Subject: Store tests ( snapshots, reconstruct, history_mode_switch ) +*) let () = - let speed = - try - let s = Sys.getenv "SLOW_TEST" in - match String.(trim (uncapitalize_ascii s)) with - | "true" | "1" | "yes" -> `Slow - | _ -> `Quick - with Not_found -> `Quick - in let open Lwt_syntax in Lwt_main.run (let* () = Tezos_base_unix.Internal_event_unix.init () in Alcotest_lwt.run + ~__FILE__ "tezos-store" [ - Test_snapshots.tests speed; - Test_reconstruct.tests speed; - Test_history_mode_switch.tests speed; + Test_snapshots.tests `Quick; + Test_reconstruct.tests `Quick; + Test_history_mode_switch.tests `Quick; ]) diff --git a/src/lib_store/unix/test/test_block_store.ml b/src/lib_store/unix/test/test_block_store.ml index 2f38af6b50dc..31f4bf7f56f7 100644 --- a/src/lib_store/unix/test/test_block_store.ml +++ b/src/lib_store/unix/test/test_block_store.ml @@ -23,6 +23,15 @@ (* *) (*****************************************************************************) +(** Testing + _______ + + Component: Store + Invocation: dune exec src/lib_store/unix/test/main.exe \ + -- --file test_block_store.ml + Subject: Store tests ( block storing and access ) +*) + module Assert = Assert open Test_utils open Block_store @@ -756,4 +765,4 @@ let () = let open Lwt_syntax in Lwt_main.run (let* () = Tezos_base_unix.Internal_event_unix.init () in - Alcotest_lwt.run "tezos-store" [tests]) + Alcotest_lwt.run ~__FILE__ "tezos-store" [tests]) diff --git a/src/lib_store/unix/test/test_cemented_store.ml b/src/lib_store/unix/test/test_cemented_store.ml index 05b190da26db..49ef637a4fe5 100644 --- a/src/lib_store/unix/test/test_cemented_store.ml +++ b/src/lib_store/unix/test/test_cemented_store.ml @@ -27,7 +27,7 @@ _______ Component: Store - Invocation: dune exec src/lib_store/unix/test/main.exe + Invocation: dune exec src/lib_store/unix/test/main.exe -- --file test_cemented_store.ml Subject: Store tests ( block cementing ) *) @@ -151,4 +151,4 @@ let () = let open Lwt_syntax in Lwt_main.run (let* () = Tezos_base_unix.Internal_event_unix.init () in - Alcotest_lwt.run "tezos-store" [tests]) + Alcotest_lwt.run ~__FILE__ "tezos-store" [tests]) diff --git a/src/lib_store/unix/test/test_consistency.ml b/src/lib_store/unix/test/test_consistency.ml index 72b62d241b92..36e269c435e9 100644 --- a/src/lib_store/unix/test/test_consistency.ml +++ b/src/lib_store/unix/test/test_consistency.ml @@ -23,6 +23,15 @@ (* *) (*****************************************************************************) +(** Testing + _______ + + Component: Store + Invocation: dune exec src/lib_store/unix/test/main.exe \ + -- --file test_consistency.ml + Subject: Store consistency tests +*) + open Test_utils let nb_protocols = 5 @@ -302,6 +311,7 @@ let make_tests = let () = Lwt_main.run @@ Alcotest_lwt.run + ~__FILE__ "tezos-store" [ ( "consistency", diff --git a/src/lib_store/unix/test/test_history_mode_switch.ml b/src/lib_store/unix/test/test_history_mode_switch.ml index 8db19853a55a..87e3781ce8ca 100644 --- a/src/lib_store/unix/test/test_history_mode_switch.ml +++ b/src/lib_store/unix/test/test_history_mode_switch.ml @@ -24,6 +24,14 @@ (* *) (*****************************************************************************) +(** Testing + _______ + + Component: Store + Invocation: dune exec src/lib_store/unix/test/main.exe -- --match history_mode_switch + Subject: Store tests ( history_mode_switch ) +*) + open Test_utils open History_mode @@ -377,32 +385,34 @@ let make_tests speed parameters = ~json:(Default_parameters.json_of_parameters parameters) in let history_modes = - match speed with - | `Slow -> - [ - Archive; - Full (Some {offset = 0}); - Full (Some {offset = 3}); - default_full; - Full (Some {offset = 7}); - Full (Some {offset = 10}); - Rolling (Some {offset = 0}); - Rolling (Some {offset = 3}); - default_rolling; - Rolling (Some {offset = 7}); - Rolling (Some {offset = 10}); - default; - ] - | `Quick -> - [ - Archive; - Full (Some {offset = 0}); - default_full; - Rolling (Some {offset = 0}); - default_rolling; - Full (Some {offset = 5}); - Rolling (Some {offset = 5}); - ] + List.sort_uniq + compare + (match speed with + | `Slow -> + [ + Archive; + Full (Some {offset = 0}); + Full (Some {offset = 3}); + default_full; + Full (Some {offset = 7}); + Full (Some {offset = 10}); + Rolling (Some {offset = 0}); + Rolling (Some {offset = 3}); + default_rolling; + Rolling (Some {offset = 7}); + Rolling (Some {offset = 10}); + default; + ] + | `Quick -> + [ + Archive; + Full (Some {offset = 0}); + default_full; + Rolling (Some {offset = 0}); + default_rolling; + Full (Some {offset = 5}); + Rolling (Some {offset = 5}); + ]) in let blocks_per_cycle = parameters.constants.blocks_per_cycle in let nb_blocks_to_bake = [9 * Int32.to_int blocks_per_cycle] in @@ -424,6 +434,7 @@ let make_tests speed parameters = in Some (wrap_simple_store_init_test + ~speed ~with_gc:true ~keep_dir:false ~history_mode:from_hm @@ -440,7 +451,7 @@ let make_tests speed parameters = store ))) permutations -let make_test_drag _speed parameters = +let make_test_drag speed parameters = let patch_context ctxt = Alpha_utils.patch_context ctxt @@ -451,6 +462,7 @@ let make_test_drag _speed parameters = let test_descr = "Check savepoint drag with cycles bigger that max_op_ttl" in let from_hm = default_full in wrap_simple_store_init_test + ~speed ~with_gc:true ~keep_dir:false ~history_mode:from_hm diff --git a/src/lib_store/unix/test/test_locator.ml b/src/lib_store/unix/test/test_locator.ml index ccde7c2ff3e1..3cca2f2f60ba 100644 --- a/src/lib_store/unix/test/test_locator.ml +++ b/src/lib_store/unix/test/test_locator.ml @@ -25,13 +25,12 @@ (** Testing ------- - Component: Shell - Invocation: dune exec src/lib_shell/test/test_locator.exe + Component: Store + Invocation: dune exec src/lib_shell/test/main.exe \ + -- --file test_locator.ml Subject: Checks operations on locators. *) -(** Basic blocks *) - module Assert = Assert (** Basic blocks *) @@ -374,66 +373,6 @@ let compute_size_chain size_locator = chain 2 months 86k covered by locator 120 *) -(** Test if the linear and exponential locator are the same and outputs - their timing. - Run the test with: - $ dune build @runtest_locator - Copy the output to a file timing.dat and plot it with: - $ generate_locator_plot.sh timing.dat -*) -let bench_locator base_dir = - let open Lwt_result_syntax in - let size_chain = 80000 in - (* timing locators with average over [runs] times *) - let runs = 10 in - let _ = Printf.printf "#runs %i\n" runs in - (* limit after which exp should go linear *) - let exp_limit = compute_size_chain 120 in - let _ = Printf.printf "#exp_limit %i\n" exp_limit in - (* size after which locator always reaches genesis *) - let locator_limit = compute_size_locator size_chain in - let _ = Printf.printf "#locator_limit %i\n" locator_limit in - let*! store = init_chain base_dir in - let chain_store = Store.main_chain_store store in - time1 (fun () -> make_empty_chain chain_store size_chain) - |> fun (res, t_chain) -> - let _ = - Printf.printf - "#size_chain %i built in %f sec\n# size exp lins\n" - size_chain - t_chain - in - let*! head = res in - let check_locator max_size : unit tzresult Lwt.t = - let*! caboose, _ = Store.Chain.caboose chain_store in - let* block = Store.Block.read_block chain_store head in - time ~runs (fun () -> - Store.Chain.compute_locator chain_store ~max_size block seed) - |> fun (l_exp, t_exp) -> - time ~runs (fun () -> - compute_linear_locator chain_store ~caboose ~max_size block) - |> fun (l_lin, t_lin) -> - let*! {Block_locator.history = l_exp; _} = l_exp in - let*! {Block_locator.history = l_lin; _} = l_lin in - let _ = Printf.printf "%10i %f %f\n" max_size t_exp t_lin in - Lwt.return - @@ List.iter2 - ~when_different_lengths:(TzTrace.make @@ Exn (Failure __LOC__)) - (fun hn ho -> - if not (Block_hash.equal hn ho) then - Assert.fail_msg "Invalid locator %i" max_size) - l_exp - l_lin - in - let stop = locator_limit + 20 in - let rec loop size = - if size < stop then - let* _ = check_locator size in - loop (size + 5) - else return_unit - in - loop 1 - let test_protocol_locator base_dir = let open Lwt_result_syntax in let*! store = init_chain base_dir in @@ -619,22 +558,5 @@ let tests = wrap "test protocol locator" test_protocol_locator; ] -let bench = [wrap "bench locator" bench_locator] - -let tests = - tests - @ - if Array.length Sys.argv > 1 then - match Sys.argv.(1) with "--bench" -> bench | _ -> [] - else [] - -let tests = - tests - @ - if Array.length Sys.argv > 1 then - match Sys.argv.(1) with "--bench" -> bench | _ -> [] - else [] - let () = - Alcotest_lwt.run ~argv:[|""|] "tezos-store" [("locator", tests)] - |> Lwt_main.run + Alcotest_lwt.run ~__FILE__ "tezos-store" [("locator", tests)] |> Lwt_main.run diff --git a/src/lib_store/unix/test/test_protocol_store.ml b/src/lib_store/unix/test/test_protocol_store.ml index bae252a0d16e..1e6189bd904a 100644 --- a/src/lib_store/unix/test/test_protocol_store.ml +++ b/src/lib_store/unix/test/test_protocol_store.ml @@ -23,6 +23,15 @@ (* *) (*****************************************************************************) +(** Testing + _______ + + Component: Store + Invocation: dune exec src/lib_store/unix/test/main.exe \ + -- --file test_protocol_store.ml + Subject: Store tests ( protocol ) +*) + open Test_utils let test_protocol_store _ store = @@ -74,4 +83,4 @@ let () = let open Lwt_syntax in Lwt_main.run (let* () = Tezos_base_unix.Internal_event_unix.init () in - Alcotest_lwt.run "tezos-store" [tests]) + Alcotest_lwt.run ~__FILE__ "tezos-store" [tests]) diff --git a/src/lib_store/unix/test/test_reconstruct.ml b/src/lib_store/unix/test/test_reconstruct.ml index 78b2c2df735e..fff158336a36 100644 --- a/src/lib_store/unix/test/test_reconstruct.ml +++ b/src/lib_store/unix/test/test_reconstruct.ml @@ -28,7 +28,7 @@ _______ Component: Store - Invocation: dune exec src/lib_store/unix/test/main.exe + Invocation: dune exec src/lib_store/unix/test/main.exe -- --match construct Subject: Store tests ( reconstruct ) *) @@ -174,6 +174,7 @@ let make_tests_bootstrapped speed patch_context = nb_blocks_to_bake in wrap_simple_store_init_test + ~speed ~patch_context ~history_mode ~keep_dir:false @@ -325,6 +326,7 @@ let make_tests_snapshoted speed patch_context = nb_blocks_to_bake in wrap_simple_store_init_test + ~speed ~patch_context ~history_mode ~keep_dir:false diff --git a/src/lib_store/unix/test/test_snapshots.ml b/src/lib_store/unix/test/test_snapshots.ml index 8b5411647ce0..5084c6fb27d6 100644 --- a/src/lib_store/unix/test/test_snapshots.ml +++ b/src/lib_store/unix/test/test_snapshots.ml @@ -29,7 +29,7 @@ _______ Component: Store - Invocation: dune exec src/lib_store/unix/test/main.exe + Invocation: dune exec src/lib_store/unix/test/main.exe -- --match "tezos-store: snapshots" Subject: Store tests ( snapshots ) *) @@ -476,6 +476,7 @@ let make_tests speed genesis_parameters = | None | Some _ -> Some (wrap_test + ~speed ~with_gc:true ~keep_dir:false ~history_mode @@ -493,7 +494,7 @@ let make_tests speed genesis_parameters = store )))) permutations -let test_rolling export_mode = +let test_rolling speed export_mode = let patch_context ctxt = Alpha_utils.default_patch_context ctxt in let test (store_dir, context_dir) store = let open Lwt_result_syntax in @@ -568,6 +569,7 @@ let test_rolling export_mode = return_unit in wrap_test + ~speed ~keep_dir:false ~with_gc:true ~history_mode:History_mode.default @@ -580,9 +582,9 @@ let test_rolling export_mode = export_mode, test ) -let make_tests_rolling = +let make_tests_rolling speed = let export_mode = Snapshots.[Tar; Raw] in - List.map test_rolling export_mode + List.map (test_rolling speed) export_mode (* This test aims to check that the caboose and savepoint are well dragged when the first merge occurs, after a rolling snapshot @@ -593,7 +595,7 @@ let make_tests_rolling = In this test, we need to increase the number of blocks per cycle to avoid the max_op_ttl to hide this potential issue. The exported block must be outside the max_op_ttl of the next checkpoint. *) -let test_drag_after_import export_mode = +let test_drag_after_import speed export_mode = let open Lwt_result_syntax in let constants = Default_parameters. @@ -722,6 +724,7 @@ let test_drag_after_import export_mode = return_unit in wrap_test + ~speed ~keep_dir:false ~with_gc:true ~history_mode:History_mode.default @@ -734,9 +737,9 @@ let test_drag_after_import export_mode = export_mode, test ) -let make_tests_drag_after_import = +let make_tests_drag_after_import speed = let export_mode = Snapshots.[Tar; Raw] in - List.map test_drag_after_import export_mode + List.map (test_drag_after_import speed) export_mode (* TODO: export => import => export => import from full & rolling @@ -752,8 +755,8 @@ let tests speed = parameters_of_constants {constants_sandbox with consensus_threshold = 0}) in - let tests_rolling = make_tests_rolling in - let tests_drag_after_import = make_tests_drag_after_import in + let tests_rolling = make_tests_rolling speed in + let tests_drag_after_import = make_tests_drag_after_import speed in tests_rolling @ tests_drag_after_import @ generated_tests in ("snapshots", test_cases) diff --git a/src/lib_store/unix/test/test_store.ml b/src/lib_store/unix/test/test_store.ml index 6b783fe0bc19..f95d4ad6ab42 100644 --- a/src/lib_store/unix/test/test_store.ml +++ b/src/lib_store/unix/test/test_store.ml @@ -24,6 +24,15 @@ (* *) (*****************************************************************************) +(** Testing + _______ + + Component: Store + Invocation: dune exec src/lib_store/unix/test/main.exe \ + -- --file test_store.ml + Subject: Store tests +*) + open Test_utils let test_cycles store = @@ -752,4 +761,4 @@ let () = let open Lwt_syntax in Lwt_main.run (let* () = Tezos_base_unix.Internal_event_unix.init () in - Alcotest_lwt.run "tezos-store" [tests]) + Alcotest_lwt.run ~__FILE__ "tezos-store" [tests]) diff --git a/src/lib_store/unix/test/test_testchain.ml b/src/lib_store/unix/test/test_testchain.ml index 63767080b50d..aea9163e7ce5 100644 --- a/src/lib_store/unix/test/test_testchain.ml +++ b/src/lib_store/unix/test/test_testchain.ml @@ -22,6 +22,13 @@ (* DEALINGS IN THE SOFTWARE. *) (* *) (*****************************************************************************) +(** Testing + _______ + + Component: Store + Invocation: dune exec src/lib_store/unix/test/main.exe -- --file test_testchain.ml + Subject: Store tests ( testchain ) +*) open Test_utils @@ -155,4 +162,4 @@ let () = let open Lwt_syntax in Lwt_main.run (let* () = Tezos_base_unix.Internal_event_unix.init () in - Alcotest_lwt.run "tezos-store" [tests]) + Alcotest_lwt.run ~__FILE__ "tezos-store" [tests]) diff --git a/src/lib_store/unix/test/test_utils.ml b/src/lib_store/unix/test/test_utils.ml index 1ab584b33ce3..270b65cb274c 100644 --- a/src/lib_store/unix/test/test_utils.ml +++ b/src/lib_store/unix/test/test_utils.ml @@ -833,3 +833,5 @@ module Example_tree = struct in wrap_test ?keep_dir ?history_mode ?with_gc (name, f) end + +let speed_to_string = function `Slow -> "slow" | `Quick -> "quick" diff --git a/tezt/tests/dune b/tezt/tests/dune index bcdd6e53ce15..acc73cbf9324 100644 --- a/tezt/tests/dune +++ b/tezt/tests/dune @@ -65,6 +65,7 @@ src_lib_webassembly_tests_tezt_lib src_lib_version_test_tezt_lib src_lib_tree_encoding_test_tezt_lib + src_lib_store_unix_test_tezt_lib src_lib_stdlib_unix_test__tezt_lib src_lib_stdlib_test_unix_tezt_lib src_lib_stdlib_test_tezt_lib -- GitLab