diff --git a/.github/workflows/setup-xapi-environment/action.yml b/.github/workflows/setup-xapi-environment/action.yml index d46ae3a5b96..a7890222498 100644 --- a/.github/workflows/setup-xapi-environment/action.yml +++ b/.github/workflows/setup-xapi-environment/action.yml @@ -50,7 +50,6 @@ runs: ocaml-compiler: ${{ steps.dotenv.outputs.ocaml_version_full }} opam-repositories: | xs-opam: ${{ steps.dotenv.outputs.repository }} - opam-pin: false dune-cache: true env: DUNE_CACHE_STORAGE_MODE: copy diff --git a/dune-project b/dune-project index 3078c5af641..a6e20690815 100644 --- a/dune-project +++ b/dune-project @@ -23,6 +23,19 @@ (name xml-light2) ) +(package + (name xapi-sdk) + (license "BSD-2-Clause") + (synopsis "Xen API SDK generation code") + (depends + (alcotest :with-test) + astring + mustache + (xapi-datamodel (= :version)) + (xapi-stdext-unix (and (= :version) :with-test)) + ) + (allow_empty) +) (package (name xen-api-client-lwt) ) @@ -34,6 +47,23 @@ (package (name xen-api-client) + (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 + dune-build-info + (alcotest :with-test) + astring + (cohttp (>= "0.22.0")) + re + rpclib + uri + (uuid (= :version)) + (xapi-client (= :version)) + (xapi-idl (= :version)) + (xapi-rrd (= :version)) + (xapi-types (= :version)) + xmlm + ) ) (package @@ -142,6 +172,7 @@ (depends (ocaml (>= "4.02.0")) dune-build-info + (alcotest :with-test) astring (gzip (= :version)) (http-lib (= :version)) @@ -229,6 +260,19 @@ (package (name wsproxy) + (synopsis "Websockets proxy for VNC traffic") + (authors "Jon Ludlam" "Marcello Seri") + (license "LGPL-2.0-only WITH OCaml-LGPL-linking-exception") + (depends + (alcotest :with-test) + (base64 (>= "3.1.0")) + fmt + logs + (lwt (>= "3.0.0")) + re + uuid + (qcheck-core :with-test) + ) ) (package @@ -241,6 +285,29 @@ (package (name vhd-format-lwt) + (synopsis "Lwt interface to read/write VHD format data") + (description "A pure OCaml library to read and write +[vhd](http://en.wikipedia.org/wiki/VHD_(file_format)) format data, plus a +simple command-line tool which allows vhd files to be interrogated, +manipulated, format-converted and streamed to and from files and remote +servers. + +This package provides an Lwt compatible interface to the library.") + (authors "Jon Ludlam" "Dave Scott") + (maintainers "Dave Scott ") + (tags ("org:mirage" "org:xapi-project")) + (homepage "https://github.com/mirage/ocaml-vhd") + (source (github mirage/ocaml-vhd)) + (depends + (ocaml (and (>= "4.02.3") (< "5.0.0"))) + (alcotest :with-test) + (alcotest-lwt :with-test) + (cstruct (< "6.1.0")) + (lwt (>= "3.2.0")) + (mirage-block (>= "2.0.1")) + (vhd-format (= :version)) + (io-page (and :with-test (>= "2.4.0"))) + ) ) (package @@ -277,6 +344,19 @@ (package (name rrd-transport) + (synopsis "Shared-memory protocols for exposing system metrics") + (description "VMs running on a Xen host can use this library to expose performance counters which can be sampled by xapi's metric daemon.") + (authors "John Else") + (depends + (alcotest :with-test) + astring + cstruct + crc + yojson + (xapi-idl (= :version)) + (xapi-rrd (= :version)) + (odoc :with-doc) + ) ) (package @@ -322,6 +402,27 @@ (package (name http-lib) + (synopsis "An HTTP required used by xapi") + (description "This library allows xapi to perform varios activities related to the HTTP protocol.") + (depends + (alcotest :with-test) + astring + (base64 (>= "3.1.0")) + rpclib + (safe-resources(= :version)) + sha + (stunnel (= :version)) + (uuid (= :version)) + xapi-backtrace + (xapi-idl (= :version)) + (xapi-log (= :version)) + (xapi-stdext-date (= :version)) + (xapi-stdext-pervasives (= :version)) + (xapi-stdext-threads (= :version)) + (xapi-tracing (= :version)) + (xml-light2 (= :version)) + (odoc :with-doc) + ) ) (package diff --git a/http-lib.opam b/http-lib.opam index cbea47b7d2f..77965984777 100644 --- a/http-lib.opam +++ b/http-lib.opam @@ -1,42 +1,45 @@ # This file is generated by dune, edit dune-project instead -license: "LGPL-2.1-only WITH OCaml-LGPL-linking-exception" opam-version: "2.0" -maintainer: "xen-api@lists.xen.org" -authors: "xen-api@lists.xen.org" +synopsis: "An HTTP required used by xapi" +description: + "This library allows xapi to perform varios activities related to the HTTP protocol." +maintainer: ["Xapi project maintainers"] +authors: ["xen-api@lists.xen.org"] +license: "LGPL-2.1-only WITH OCaml-LGPL-linking-exception" homepage: "https://xapi-project.github.io/" -bug-reports: "https://github.com/xapi-project/xen-api.git" -dev-repo: "git+https://github.com/xapi-project/xen-api.git" -build: [ - ["dune" "build" "-p" name "-j" jobs] - ["dune" "runtest" "-p" name "-j" jobs] {with-test} -] -available: [ os = "linux" | os = "macos" ] +bug-reports: "https://github.com/xapi-project/xen-api/issues" depends: [ - "ocaml" - "dune" + "dune" {>= "3.0"} + "alcotest" {with-test} "astring" "base64" {>= "3.1.0"} "rpclib" - "safe-resources" + "safe-resources" {= version} "sha" - "stunnel" - "uuid" + "stunnel" {= version} + "uuid" {= version} "xapi-backtrace" - "xapi-idl" - "xapi-log" - "xapi-stdext-date" - "xapi-stdext-pervasives" - "xapi-stdext-threads" - "xapi-stdext-unix" - "xapi-tracing" - "xml-light2" - "ounit2" {with-test & >= "2.0.0"} + "xapi-idl" {= version} + "xapi-log" {= version} + "xapi-stdext-date" {= version} + "xapi-stdext-pervasives" {= version} + "xapi-stdext-threads" {= version} + "xapi-tracing" {= version} + "xml-light2" {= version} + "odoc" {with-doc} +] +build: [ + ["dune" "subst"] {dev} + [ + "dune" + "build" + "-p" + name + "-j" + jobs + "@install" + "@runtest" {with-test} + "@doc" {with-doc} + ] ] -synopsis: "Library required by xapi" -description: """ -These libraries are provided for backwards compatibility only. -No new code should use these libraries.""" -url { - src: - "https://github.com/xapi-project/xen-api/archive/master.tar.gz" -} +dev-repo: "git+https://github.com/xapi-project/xen-api.git" diff --git a/http-lib.opam.template b/http-lib.opam.template deleted file mode 100644 index 7a09878b4a1..00000000000 --- a/http-lib.opam.template +++ /dev/null @@ -1,40 +0,0 @@ -opam-version: "2.0" -maintainer: "xen-api@lists.xen.org" -authors: "xen-api@lists.xen.org" -homepage: "https://xapi-project.github.io/" -bug-reports: "https://github.com/xapi-project/xen-api.git" -dev-repo: "git+https://github.com/xapi-project/xen-api.git" -build: [ - ["dune" "build" "-p" name "-j" jobs] - ["dune" "runtest" "-p" name "-j" jobs] {with-test} -] -available: [ os = "linux" | os = "macos" ] -depends: [ - "ocaml" - "dune" - "astring" - "base64" {>= "3.1.0"} - "rpclib" - "safe-resources" - "sha" - "stunnel" - "uuid" - "xapi-backtrace" - "xapi-idl" - "xapi-log" - "xapi-stdext-date" - "xapi-stdext-pervasives" - "xapi-stdext-threads" - "xapi-stdext-unix" - "xapi-tracing" - "xml-light2" - "ounit2" {with-test & >= "2.0.0"} -] -synopsis: "Library required by xapi" -description: """ -These libraries are provided for backwards compatibility only. -No new code should use these libraries.""" -url { - src: - "https://github.com/xapi-project/xen-api/archive/master.tar.gz" -} diff --git a/ocaml/libs/http-lib/dune b/ocaml/libs/http-lib/dune index efa34f0bddd..1bd9932703d 100644 --- a/ocaml/libs/http-lib/dune +++ b/ocaml/libs/http-lib/dune @@ -68,7 +68,6 @@ (libraries dune-build-info http_lib - ounit2 safe-resources stunnel threads.posix @@ -85,7 +84,6 @@ dune-build-info http_lib httpsvr - ounit2 safe-resources threads.posix xapi-stdext-threads diff --git a/ocaml/libs/vhd/vhd_format_lwt_test/dune b/ocaml/libs/vhd/vhd_format_lwt_test/dune index 57b8d72dece..c8ff604d921 100644 --- a/ocaml/libs/vhd/vhd_format_lwt_test/dune +++ b/ocaml/libs/vhd/vhd_format_lwt_test/dune @@ -1,5 +1,5 @@ (test (name parse_test) (package vhd-format-lwt) - (libraries cstruct disk io-page lwt lwt.unix ounit2 vhd-format + (libraries alcotest alcotest-lwt cstruct disk io-page lwt lwt.unix vhd-format vhd_format_lwt)) diff --git a/ocaml/libs/vhd/vhd_format_lwt_test/patterns_lwt.ml b/ocaml/libs/vhd/vhd_format_lwt_test/lib.ml similarity index 92% rename from ocaml/libs/vhd/vhd_format_lwt_test/patterns_lwt.ml rename to ocaml/libs/vhd/vhd_format_lwt_test/lib.ml index beb1482c3ab..3073ba88bca 100644 --- a/ocaml/libs/vhd/vhd_format_lwt_test/patterns_lwt.ml +++ b/ocaml/libs/vhd/vhd_format_lwt_test/lib.ml @@ -11,7 +11,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. *) -open OUnit open Lwt module IO = Vhd_format_lwt.IO module Impl = Vhd_format.F.From_file (IO) @@ -19,6 +18,18 @@ module F = Vhd_format.F module Field = F.Vhd.Field open Impl +let header = + Alcotest.testable (Fmt.of_to_string F.Header.to_string) F.Header.equal + +let footer = Alcotest.testable (Fmt.of_to_string F.Footer.to_string) ( = ) + +let bat = Alcotest.testable (Fmt.of_to_string F.BAT.to_string) F.BAT.equal + +let cstruct_to_string c = String.escaped (Cstruct.to_string c) + +let cstruct = + Alcotest.testable (Fmt.of_to_string cstruct_to_string) F.cstruct_equal + module Memory = struct let alloc bytes = if bytes = 0 then @@ -76,8 +87,6 @@ let _absolute_sector_of vhd _position {Vhd_format.Patterns.block; sector} = (of_int relative_sector) ) -let cstruct_to_string c = String.escaped (Cstruct.to_string c) - (* Verify that vhd [t] contains the sectors [expected] *) let check_written_sectors t expected = let y = Memory.alloc 512 in @@ -90,7 +99,7 @@ let check_written_sectors t expected = | false -> fail (Failure "read empty sector, expected data") | true -> - assert_equal ~printer:cstruct_to_string ~cmp:F.cstruct_equal data y ; + Alcotest.check cstruct __LOC__ data y ; return () ) >>= fun () -> loop xs @@ -130,12 +139,10 @@ let check_raw_stream_contents t expected = let actual = Cstruct.sub data (i * 512) 512 in ( if not (List.mem_assoc sector expected) then - assert_equal ~printer:cstruct_to_string ~cmp:F.cstruct_equal - empty_sector actual + Alcotest.check cstruct __LOC__ empty_sector actual else let expected = List.assoc sector expected in - assert_equal ~printer:cstruct_to_string ~cmp:F.cstruct_equal - expected actual + Alcotest.check cstruct __LOC__ expected actual ) ; check (i + 1) in @@ -156,8 +163,7 @@ let check_raw_stream_contents t expected = else let expected = List.assoc offset expected in let actual = Cstruct.sub remaining 0 F.sector_size in - assert_equal ~printer:cstruct_to_string ~cmp:F.cstruct_equal - expected actual ; + Alcotest.check cstruct __LOC__ expected actual ; loop Int64.(add offset 1L) (Cstruct.shift remaining F.sector_size) in loop offset data diff --git a/ocaml/libs/vhd/vhd_format_lwt_test/patterns_lwt.mli b/ocaml/libs/vhd/vhd_format_lwt_test/lib.mli similarity index 81% rename from ocaml/libs/vhd/vhd_format_lwt_test/patterns_lwt.mli rename to ocaml/libs/vhd/vhd_format_lwt_test/lib.mli index cd5c186039d..7e06e2959d3 100644 --- a/ocaml/libs/vhd/vhd_format_lwt_test/patterns_lwt.mli +++ b/ocaml/libs/vhd/vhd_format_lwt_test/lib.mli @@ -12,6 +12,14 @@ * GNU Lesser General Public License for more details. *) +val header : Vhd_format.F.Header.t Alcotest.testable + +val footer : Vhd_format.F.Footer.t Alcotest.testable + +val bat : Vhd_format.F.BAT.t Alcotest.testable + +val cstruct : Cstruct.t Alcotest.testable + val verify : Vhd_format_lwt.IO.fd Vhd_format.F.Vhd.t -> (int64 * Cstruct.t) list diff --git a/ocaml/libs/vhd/vhd_format_lwt_test/parse_test.ml b/ocaml/libs/vhd/vhd_format_lwt_test/parse_test.ml index 9f94653f466..02d9b32d456 100644 --- a/ocaml/libs/vhd/vhd_format_lwt_test/parse_test.ml +++ b/ocaml/libs/vhd/vhd_format_lwt_test/parse_test.ml @@ -11,19 +11,15 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. *) -open OUnit open Vhd_format.Patterns module Impl = Vhd_format.F.From_file (Vhd_format_lwt.IO) open Impl open Vhd_format.F open Vhd_format_lwt.IO -open Patterns_lwt -let cstruct_to_string c = String.escaped (Cstruct.to_string c) - -let create () = +let create _ () = let _ = Create_vhd.disk in - () + Lwt.return () let tmp_file_dir = Filename.get_temp_dir_name () @@ -55,10 +51,9 @@ let check_empty_disk size = let filename = make_new_filename () in Vhd_IO.create_dynamic ~filename ~size () >>= fun vhd -> Vhd_IO.openchain filename false >>= fun vhd' -> - assert_equal ~printer:Header.to_string ~cmp:Header.equal vhd.Vhd.header - vhd'.Vhd.header ; - assert_equal ~printer:Footer.to_string vhd.Vhd.footer vhd'.Vhd.footer ; - assert_equal ~printer:BAT.to_string ~cmp:BAT.equal vhd.Vhd.bat vhd'.Vhd.bat ; + Alcotest.check Lib.header __LOC__ vhd.Vhd.header vhd'.Vhd.header ; + Alcotest.check Lib.footer __LOC__ vhd.Vhd.footer vhd'.Vhd.footer ; + Alcotest.check Lib.bat __LOC__ vhd.Vhd.bat vhd'.Vhd.bat ; Vhd_IO.close vhd' >>= fun () -> Vhd_IO.close vhd (* Create a disk, resize it, check headers *) @@ -69,8 +64,7 @@ let check_resize size = let vhd = Vhd.resize vhd newsize in Vhd_IO.close vhd >>= fun () -> Vhd_IO.openchain filename false >>= fun vhd' -> - assert_equal ~printer:Int64.to_string newsize - vhd.Vhd.footer.Footer.current_size ; + Alcotest.(check int64) __LOC__ newsize vhd.Vhd.footer.Footer.current_size ; Vhd_IO.close vhd' (* Create a snapshot, check headers *) @@ -80,10 +74,9 @@ let check_empty_snapshot size = let filename = make_new_filename () in Vhd_IO.create_difference ~filename ~parent:vhd () >>= fun vhd' -> Vhd_IO.openchain filename false >>= fun vhd'' -> - assert_equal ~printer:Header.to_string ~cmp:Header.equal vhd'.Vhd.header - vhd''.Vhd.header ; - assert_equal ~printer:Footer.to_string vhd'.Vhd.footer vhd''.Vhd.footer ; - assert_equal ~printer:BAT.to_string ~cmp:BAT.equal vhd'.Vhd.bat vhd''.Vhd.bat ; + Alcotest.check Lib.header __LOC__ vhd'.Vhd.header vhd''.Vhd.header ; + Alcotest.check Lib.footer __LOC__ vhd'.Vhd.footer vhd''.Vhd.footer ; + Alcotest.check Lib.bat __LOC__ vhd'.Vhd.bat vhd''.Vhd.bat ; Vhd_IO.close vhd'' >>= fun () -> Vhd_IO.close vhd' >>= fun () -> Vhd_IO.close vhd @@ -105,10 +98,9 @@ let check_reparent () = let l = make_new_filename () in Vhd_IO.openchain p1 false >>= fun vhd -> Vhd_IO.create_difference ~filename:l ~parent:vhd () >>= fun vhd' -> - (* Verify block 0 has '1' *) let sector = fill_sector_with "0" in Vhd_IO.read_sector vhd' 0L sector >>= fun _ -> - assert_equal ~printer:cstruct_to_string ~cmp:cstruct_equal all_ones sector ; + Alcotest.check Lib.cstruct "Block 0 has '1'" all_ones sector ; Vhd_IO.close vhd' >>= fun () -> Vhd_IO.close vhd >>= fun () -> (* Flip the parent locator *) @@ -117,10 +109,9 @@ let check_reparent () = let vhd' = {vhd' with Vhd.header} in Vhd_IO.close vhd' >>= fun () -> Vhd_IO.openchain l false >>= fun vhd -> - (* Verify block 0 has '2' *) let sector = fill_sector_with "0" in Vhd_IO.read_sector vhd 0L sector >>= fun _ -> - assert_equal ~printer:cstruct_to_string ~cmp:cstruct_equal all_twos sector ; + Alcotest.check Lib.cstruct "Block 0 has '2'" all_twos sector ; Vhd_IO.close vhd (* Check ../ works in parent locator *) @@ -239,7 +230,11 @@ let execute state = function ) let verify state = - match state.child with None -> return () | Some t -> verify t state.contents + match state.child with + | None -> + return () + | Some t -> + Lib.verify t state.contents module In = From_input (Input) open In @@ -290,25 +285,28 @@ let run program = ) >>= fun () -> cleanup final_state +let test = Alcotest_lwt.test_case + let all_program_tests = List.map - (fun p -> string_of_program p >:: fun () -> Lwt_main.run (run p)) + (fun p -> test (string_of_program p) `Slow (fun _ () -> run p)) programs -let _ = +let () = let check_empty_disk size = - Printf.sprintf "check_empty_disk_%Ld" size >:: fun () -> - Lwt_main.run (check_empty_disk size) + test (Printf.sprintf "size %Ld" size) `Quick (fun _ () -> + check_empty_disk size + ) in let check_resize size = - Printf.sprintf "check_resize_%Ld" size >:: fun () -> - Lwt_main.run (check_resize size) + test (Printf.sprintf "size %Ld" size) `Quick (fun _ () -> check_resize size) in let check_empty_snapshot size = - Printf.sprintf "check_empty_snapshot_%Ld" size >:: fun () -> - Lwt_main.run (check_empty_snapshot size) + test (Printf.sprintf "size %Ld" size) `Quick (fun _ () -> + check_empty_snapshot size + ) in (* Switch to the 'nobody' user so we can test file permissions *) @@ -322,18 +320,19 @@ let _ = (Printexc.to_string e) ) ; let suite = - "vhd" - >::: [ - "create" >:: create - ; ( "check_parent_parent_dir" >:: fun () -> - Lwt_main.run (check_parent_parent_dir ()) - ) - ; ("check_readonly" >:: fun () -> Lwt_main.run (check_readonly ())) - ; ("check_reparent" >:: fun () -> Lwt_main.run (check_reparent ())) - ] - @ List.map check_empty_disk sizes - @ List.map check_resize sizes - @ List.map check_empty_snapshot sizes - @ all_program_tests + [ + ( "Simple" + , [ + test "create" `Quick create + ; test "parent_parent_dir" `Quick (fun _ -> check_parent_parent_dir) + ; test "readonly" `Quick (fun _ () -> check_readonly ()) + ; test "reparent" `Quick (fun _ () -> check_reparent ()) + ] + ) + ; ("Empty disk", List.map check_empty_disk sizes) + ; ("Resize", List.map check_resize sizes) + ; ("Empty snapshots", List.map check_empty_snapshot sizes) + ; ("All program test", all_program_tests) + ] in - run_test_tt_main suite + Lwt_main.run @@ Alcotest_lwt.run "vhd_format_lwt" suite diff --git a/ocaml/sdk-gen/go/dune b/ocaml/sdk-gen/go/dune index 311ff35f4fd..75c98f0d0b6 100644 --- a/ocaml/sdk-gen/go/dune +++ b/ocaml/sdk-gen/go/dune @@ -32,6 +32,7 @@ (test (name test_gen_go) + (package xapi-sdk) (modules test_gen_go) (libraries alcotest xapi-test-utils gen_go_helper) (deps diff --git a/ocaml/wsproxy/test/dune b/ocaml/wsproxy/test/dune index 3b57c6e4518..fafcac25646 100644 --- a/ocaml/wsproxy/test/dune +++ b/ocaml/wsproxy/test/dune @@ -2,5 +2,5 @@ (name wsproxy_tests) (modes exe) (package wsproxy) - (libraries ounit2 qcheck-core wslib) + (libraries alcotest qcheck-core wslib) ) diff --git a/ocaml/wsproxy/test/test_helpers.ml b/ocaml/wsproxy/test/test_helpers.ml index 01d4c4f4526..74ba5c69360 100644 --- a/ocaml/wsproxy/test/test_helpers.ml +++ b/ocaml/wsproxy/test/test_helpers.ml @@ -12,79 +12,98 @@ * GNU Lesser General Public License for more details. *) -open OUnit open Wslib let gen_nums n generator = QCheck.Gen.generate ~n generator let test_split () = - let a, b = Helpers.split "helper" 2 in - assert_equal a "he" ; assert_equal b "lper" + let helper = Helpers.split "helper" 2 in + Alcotest.(check @@ pair string string) __LOC__ ("he", "lper") helper let test_break () = let pred = function 'x' -> true | _ -> false in - let a, b = Helpers.break pred "helper" in - assert_equal a "helper" ; - assert_equal b "" ; - let a, b = Helpers.break pred "helxper" in - assert_equal a "hel" ; assert_equal b "xper" + let break = Helpers.break pred "helper" in + Alcotest.(check @@ pair string string) __LOC__ ("helper", "") break ; + let break = Helpers.break pred "helxper" in + Alcotest.(check @@ pair string string) __LOC__ ("hel", "xper") break let test_str_drop_while () = let pred = function 'x' -> true | _ -> false in let a = Helpers.str_drop_while pred "helper" in - assert_equal a "helper" ; + Alcotest.(check string) __LOC__ "helper" a ; let b = Helpers.str_drop_while pred "xhelper" in - assert_equal b "helper" + Alcotest.(check string) __LOC__ "helper" b let test_marshal_unmarshal_int () = let generator = QCheck.Gen.ui64 in let nums = gen_nums 10 generator in List.iter - (fun i -> assert_equal i (Helpers.unmarshal_int 8 (Helpers.marshal_int 8 i))) + (fun i -> + Alcotest.(check int64) + __LOC__ i + (Helpers.unmarshal_int 8 (Helpers.marshal_int 8 i)) + ) nums let test_marshal_unmarshal_int8 () = let generator = QCheck.Gen.int_bound 255 in let nums = gen_nums 10 generator in List.iter - (fun i -> assert_equal i (Helpers.unmarshal_int8 (Helpers.marshal_int8 i))) + (fun i -> + Alcotest.(check int) + __LOC__ i + (Helpers.unmarshal_int8 (Helpers.marshal_int8 i)) + ) nums let test_marshal_unmarshal_int16 () = let generator = QCheck.Gen.int_bound 65535 in let nums = gen_nums 10 generator in List.iter - (fun i -> assert_equal i (Helpers.unmarshal_int16 (Helpers.marshal_int16 i))) + (fun i -> + Alcotest.(check int) + __LOC__ i + (Helpers.unmarshal_int16 (Helpers.marshal_int16 i)) + ) nums let test_marshal_unmarshal_int32 () = let generator = QCheck.Gen.ui32 in let nums = gen_nums 10 generator in List.iter - (fun i -> assert_equal i (Helpers.unmarshal_int32 (Helpers.marshal_int32 i))) + (fun i -> + Alcotest.(check int32) + __LOC__ i + (Helpers.unmarshal_int32 (Helpers.marshal_int32 i)) + ) nums let test_marshal_unmarshal_int64 () = let generator = QCheck.Gen.ui64 in let nums = gen_nums 10 generator in List.iter - (fun i -> assert_equal i (Helpers.unmarshal_int64 (Helpers.marshal_int64 i))) + (fun i -> + Alcotest.(check int64) + __LOC__ i + (Helpers.unmarshal_int64 (Helpers.marshal_int64 i)) + ) nums let test_unmask () = let a = Helpers.unmask "01010101" "\x01\x01\x01\x01\x01\x01\x01\x01" in - assert_equal a "10101010" + Alcotest.(check string) "Unmasks match" "10101010" a -let test = - "test_helpers" - >::: [ - "test_split" >:: test_split - ; "test_break" >:: test_break - ; "test_str_drop_while" >:: test_str_drop_while - ; "test_marshal_unmarshal_int" >:: test_marshal_unmarshal_int - ; "test_marshal_unmarshal_int8" >:: test_marshal_unmarshal_int8 - ; "test_marshal_unmarshal_int16" >:: test_marshal_unmarshal_int16 - ; "test_marshal_unmarshal_int32" >:: test_marshal_unmarshal_int32 - ; "test_marshal_unmarshal_int64" >:: test_marshal_unmarshal_int64 - ; "test_unmask" >:: test_unmask - ] +let tests = + ( "helpers" + , [ + ("split", `Quick, test_split) + ; ("break", `Quick, test_break) + ; ("str_drop_while", `Quick, test_str_drop_while) + ; ("marshal_unmarshal_int", `Quick, test_marshal_unmarshal_int) + ; ("marshal_unmarshal_int8", `Quick, test_marshal_unmarshal_int8) + ; ("marshal_unmarshal_int16", `Quick, test_marshal_unmarshal_int16) + ; ("marshal_unmarshal_int32", `Quick, test_marshal_unmarshal_int32) + ; ("marshal_unmarshal_int64", `Quick, test_marshal_unmarshal_int64) + ; ("unmask", `Quick, test_unmask) + ] + ) diff --git a/ocaml/wsproxy/test/test_iteratees.ml b/ocaml/wsproxy/test/test_iteratees.ml index e87510723ea..65fbc1266ce 100644 --- a/ocaml/wsproxy/test/test_iteratees.ml +++ b/ocaml/wsproxy/test/test_iteratees.ml @@ -12,7 +12,6 @@ * GNU Lesser General Public License for more details. *) -open OUnit open Wslib module I = Iteratees.Iteratee (Test.StringMonad) module TestWsIteratee = Websockets.Wsprotocol (Test.StringMonad) @@ -22,97 +21,63 @@ let get_data = function IE_done x -> Some x | IE_cont _ -> None let test_heads () = let res str = - match - get_data (Test.StringMonad.getdata (enum_1chunk "test" (heads str))) - with - | Some x -> - x - | None -> - 1234 + get_data (Test.StringMonad.getdata (enum_1chunk "test" (heads str))) in - assert_equal (res "t") 1 ; - assert_equal (res "te") 2 ; - assert_equal (res "x") 0 + Alcotest.(check @@ option int) __LOC__ (Some 1) (res "t") ; + Alcotest.(check @@ option int) __LOC__ (Some 2) (res "te") ; + Alcotest.(check @@ option int) __LOC__ (Some 0) (res "x") let test_drop () = - assert_equal - (Test.StringMonad.getdata (enum_1chunk "test" (drop 1))) - (IE_done ()) + let res i = + get_data (Test.StringMonad.getdata (enum_1chunk "test" (drop i))) + in + Alcotest.(check @@ option unit) __LOC__ (Some ()) (res 1) let test_readn () = let res i = - match - get_data (Test.StringMonad.getdata (enum_1chunk "test" (readn i))) - with - | Some x -> - x - | None -> - "xxxxx" + get_data (Test.StringMonad.getdata (enum_1chunk "test" (readn i))) in - assert_equal (res 0) "" ; - assert_equal (res 1) "t" ; - assert_equal (res 2) "te" ; - assert_equal (res 4) "test" + Alcotest.(check @@ option string) __LOC__ (Some "") (res 0) ; + Alcotest.(check @@ option string) __LOC__ (Some "t") (res 1) ; + Alcotest.(check @@ option string) __LOC__ (Some "te") (res 2) ; + Alcotest.(check @@ option string) __LOC__ (Some "test") (res 4) let test_read_int8 () = let res str = - match get_data (Test.StringMonad.getdata (enum_1chunk str read_int8)) with - | Some x -> - x - | None -> - 0 + get_data (Test.StringMonad.getdata (enum_1chunk str read_int8)) in - assert_equal 97 (res "a") ; - assert_equal 65 (res "A") ; - assert_equal 125 (res "}") + Alcotest.(check @@ option int) __LOC__ (Some 97) (res "a") ; + Alcotest.(check @@ option int) __LOC__ (Some 65) (res "A") ; + Alcotest.(check @@ option int) __LOC__ (Some 125) (res "}") let test_peek () = - let res str = - match get_data (Test.StringMonad.getdata (enum_1chunk str peek)) with - | Some x -> ( - match x with Some c -> c | None -> 'g' - ) - | None -> - 'g' - in - assert_equal 'a' (res "abc") ; - assert_equal 'x' (res "xyz") + let res str = get_data (Test.StringMonad.getdata (enum_1chunk str peek)) in + Alcotest.(check @@ option @@ option char) __LOC__ (Some (Some 'a')) (res "abc") ; + Alcotest.(check @@ option @@ option char) __LOC__ (Some (Some 'x')) (res "xyz") let test_head () = - let res str = - match get_data (Test.StringMonad.getdata (enum_1chunk str head)) with - | Some x -> ( - match x with Some c -> c | None -> 'g' - ) - | None -> - 'g' - in - assert_equal 'a' (res "abc") ; - assert_equal 'x' (res "xyz") + let res str = get_data (Test.StringMonad.getdata (enum_1chunk str head)) in + Alcotest.(check @@ option @@ option char) __LOC__ (Some (Some 'a')) (res "abc") ; + Alcotest.(check @@ option @@ option char) __LOC__ (Some (Some 'x')) (res "xyz") let test_break () = let alter = function '\n' -> true | _ -> false in let res str = - match - get_data (Test.StringMonad.getdata (enum_1chunk str (break alter))) - with - | Some x -> - x - | None -> - "xxxxx" + get_data (Test.StringMonad.getdata (enum_1chunk str (break alter))) in - assert_equal "" (res "\ntest") ; - assert_equal "test" (res "test\nabc") ; - assert_equal "abcxyz" (res "abcxyz\n") + Alcotest.(check @@ option string) __LOC__ (Some "") (res "\ntest") ; + Alcotest.(check @@ option string) __LOC__ (Some "test") (res "test\nabc") ; + Alcotest.(check @@ option string) __LOC__ (Some "abcxyz") (res "abcxyz\n") -let test = - "test_iteratees" - >::: [ - "test_heads" >:: test_heads - ; "test_drop" >:: test_drop - ; "test_readn" >:: test_readn - ; "test_read_int8" >:: test_read_int8 - ; "test_peek" >:: test_peek - ; "test_head" >:: test_head - ; "test_break" >:: test_break - ] +let tests = + ( "iteratees" + , [ + ("heads", `Quick, test_heads) + ; ("drop", `Quick, test_drop) + ; ("readn", `Quick, test_readn) + ; ("read_int8", `Quick, test_read_int8) + ; ("peek", `Quick, test_peek) + ; ("head", `Quick, test_head) + ; ("break", `Quick, test_break) + ] + ) diff --git a/ocaml/wsproxy/test/test_websockets.ml b/ocaml/wsproxy/test/test_websockets.ml index cf745323670..220594912e4 100644 --- a/ocaml/wsproxy/test/test_websockets.ml +++ b/ocaml/wsproxy/test/test_websockets.ml @@ -12,7 +12,6 @@ * GNU Lesser General Public License for more details. *) -open OUnit open Wslib module TestWsIteratee = Websockets.Wsprotocol (Test.StringMonad) module I = Iteratees.Iteratee (Test.StringMonad) @@ -49,7 +48,7 @@ let test_wsframe () = let x = enum_1chunk (Test.StringMonad.getstr (enum_1chunk str frame)) unframe in - assert_equal str (Test.StringMonad.getstr x) ; + Alcotest.(check string) __LOC__ str (Test.StringMonad.getstr x) ; (* Test with enum_nchunk *) for i = 1 to 10 do let z = @@ -57,7 +56,7 @@ let test_wsframe () = (Test.StringMonad.getstr (enum_nchunk str i frame)) i unframe in - assert_equal str (Test.StringMonad.getstr z) + Alcotest.(check string) __LOC__ str (Test.StringMonad.getstr z) done ) @@ -70,7 +69,7 @@ let test_wsframe_old () = let x = enum_1chunk (Test.StringMonad.getstr (enum_1chunk str frame)) unframe in - assert_equal str (Test.StringMonad.getstr x) ; + Alcotest.(check string) __LOC__ str (Test.StringMonad.getstr x) ; (* Test with enum_nchunk *) for i = 1 to 10 do let z = @@ -78,37 +77,42 @@ let test_wsframe_old () = (Test.StringMonad.getstr (enum_nchunk str i frame)) i unframe in - assert_equal str (Test.StringMonad.getstr z) + Alcotest.(check string) __LOC__ str (Test.StringMonad.getstr z) done ) let test_wsunframe () = let unframe = wsunframe (writer Test.StringMonad.strwr "foo") in (* Test with enum_1chunk *) - assert_equal "Hello" + Alcotest.(check string) + __LOC__ "Hello" (Test.StringMonad.getstr (enum_1chunk test_mask_str unframe)) ; (* Test with enum_nchunk *) for i = 1 to 10 do - assert_equal "Hello" + Alcotest.(check string) + __LOC__ "Hello" (Test.StringMonad.getstr (enum_nchunk test_mask_str i unframe)) done let test_wsunframe_old () = let unframe = wsunframe_old (writer Test.StringMonad.strwr "foo") in (* Test with enum_1chunk *) - assert_equal "HelloThere" + Alcotest.(check string) + __LOC__ "HelloThere" (Test.StringMonad.getstr (enum_1chunk test_old_str unframe)) ; (* Test with enum_nchunk *) for i = 1 to 10 do - assert_equal "HelloThere" + Alcotest.(check string) + __LOC__ "HelloThere" (Test.StringMonad.getstr (enum_nchunk test_old_str i unframe)) done -let test = - "test_websockets" - >::: [ - "test_wsframe" >:: test_wsframe - ; "test_wsunframe" >:: test_wsunframe - ; "test_wsframe_old" >:: test_wsframe_old - ; "test_wsunframe_old" >:: test_wsunframe_old - ] +let tests = + ( "websockets" + , [ + ("wsframe", `Quick, test_wsframe) + ; ("wsunframe", `Quick, test_wsunframe) + ; ("wsframe_old", `Quick, test_wsframe_old) + ; ("wsunframe_old", `Quick, test_wsunframe_old) + ] + ) diff --git a/ocaml/wsproxy/test/wsproxy_tests.ml b/ocaml/wsproxy/test/wsproxy_tests.ml index a460faaa2ec..69cfc07669b 100644 --- a/ocaml/wsproxy/test/wsproxy_tests.ml +++ b/ocaml/wsproxy/test/wsproxy_tests.ml @@ -12,9 +12,6 @@ * GNU Lesser General Public License for more details. *) -open OUnit +let tests = [Test_helpers.tests; Test_iteratees.tests; Test_websockets.tests] -let tests = - "tests" >::: [Test_helpers.test; Test_iteratees.test; Test_websockets.test] - -let () = ounit2_of_ounit1 tests |> OUnit2.run_test_tt_main +let () = Alcotest.run "Wsproxy" tests diff --git a/ocaml/xcp-rrdd/test/transport/dune b/ocaml/xcp-rrdd/test/transport/dune index 1e549451b4c..0ba7d90e8eb 100644 --- a/ocaml/xcp-rrdd/test/transport/dune +++ b/ocaml/xcp-rrdd/test/transport/dune @@ -2,8 +2,8 @@ (names test_unit test_scale) (package rrd-transport) (libraries + alcotest dune-build-info - ounit2 rrd-transport xapi-idl.rrd xapi-rrd diff --git a/ocaml/xcp-rrdd/test/transport/test_common.ml b/ocaml/xcp-rrdd/test/transport/test_common.ml index 49b0df0b3ab..de083183f1e 100644 --- a/ocaml/xcp-rrdd/test/transport/test_common.ml +++ b/ocaml/xcp-rrdd/test/transport/test_common.ml @@ -1,5 +1,3 @@ -open OUnit - let test_payload = Rrd_protocol. { @@ -24,17 +22,7 @@ let test_payload = ] } -let make_list make_one count = - let rec make_list make_one acc = function - | count when count <= 0 -> - acc - | count -> - let thing = make_one () in - make_list make_one (thing :: acc) (count - 1) - in - make_list make_one [] count - -let make_random_datasource () = +let make_random_datasource _ = let owner = if Random.bool () then Rrd.Host @@ -64,21 +52,39 @@ let make_random_datasource () = ) let make_random_payload timestamp datasource_count = - let datasources = make_list make_random_datasource datasource_count in + let datasources = List.init datasource_count make_random_datasource in Rrd_protocol.{timestamp; datasources} -let are_value_types_equal value1 value2 = - match (value1, value2) with +(* pick between absolute or relative tolerance of a number *) +let tolerance x = max 1e-4 (abs_float x *. 1e-12) + +let compare_float message x y = + Alcotest.(check @@ float @@ tolerance x) message x y + +let equal_value eps a b = + match (a, b) with | Rrd.VT_Int64 a, Rrd.VT_Int64 b -> - a = b + Int64.equal a b | Rrd.VT_Unknown, Rrd.VT_Unknown -> true | Rrd.VT_Float a, Rrd.VT_Float b -> - let diff = abs_float (a -. b) in - diff <= 0.01 + let isnan f = FP_nan = classify_float f in + (isnan a && isnan b) + (* compare infinities *) + || a = b + || abs_float (a -. b) <= eps | _, _ -> false +let equal_owner a b = + match (a, b) with + | Rrd.Host, Rrd.Host -> + true + | Rrd.VM a, Rrd.VM b | Rrd.SR a, Rrd.SR b -> + String.equal a b + | _ -> + false + let print_owner = function | Rrd.Host -> "Host" @@ -87,6 +93,8 @@ let print_owner = function | Rrd.SR sr -> "SR " ^ sr +let owner = Alcotest.testable (Fmt.of_to_string print_owner) equal_owner + let print_string x = x let print_type = function @@ -97,37 +105,52 @@ let print_type = function | Rrd.Gauge -> "Gauge" -let print_value_type = function +let print_value = function | Rrd.VT_Float x -> "Float " ^ string_of_float x | Rrd.VT_Int64 x -> - "Float " ^ Int64.to_string x + "Int64 " ^ Int64.to_string x | Rrd.VT_Unknown -> "Unknown" -let assert_ds_equal (owner1, ds1) (owner2, ds2) = - assert_equal ~printer:print_owner owner1 owner2 ; +let value e = Alcotest.testable (Fmt.of_to_string print_value) (equal_value e) + +let assert_ds_equal d1 d2 = let open Ds in - assert_equal ~printer:print_string ds1.ds_name ds2.ds_name ; - assert_equal ~printer:print_string ds1.ds_description ds2.ds_description ; - assert_equal ~cmp:are_value_types_equal ~printer:print_value_type ds1.ds_value - ds2.ds_value ; - assert_equal ~printer:print_type ds1.ds_type ds2.ds_type ; - assert_equal ~printer:string_of_bool ds1.ds_default ds2.ds_default ; - assert_equal ~printer:string_of_float ds1.ds_min ds2.ds_min ; - assert_equal ~printer:string_of_float ds1.ds_max ds2.ds_max ; - assert_equal ~printer:print_string ds1.ds_units ds2.ds_units + Alcotest.(check string) "Names match" d1.ds_name d2.ds_name ; + Alcotest.(check string) + "Descriptions match" d1.ds_description d2.ds_description ; + Alcotest.check (value 0.01) "Values match" d1.ds_value d2.ds_value ; + assert (d1.ds_type = d2.ds_type) ; + Alcotest.(check bool) "Defaults match" d1.ds_default d2.ds_default ; + compare_float "Minimums match" d1.ds_min d2.ds_min ; + compare_float "Maximums match" d1.ds_max d2.ds_max ; + Alcotest.(check string) "Units match" d1.ds_units d2.ds_units + +let assert_ds_equal (owner1, ds1) (owner2, ds2) = + Alcotest.check owner "Owners match" owner1 owner2 ; + assert_ds_equal ds1 ds2 let assert_payloads_equal payload1 payload2 = - Rrd_protocol.( - assert_equal ~msg:"Incorrect timestamp read" ~printer:Int64.to_string - payload1.timestamp payload2.timestamp ; - assert_equal ~msg:"Incorrect number of datasources read" - ~printer:string_of_int - (List.length payload1.datasources) - (List.length payload2.datasources) ; - List.iter2 assert_ds_equal payload1.datasources payload2.datasources - ) + let open Rrd_protocol in + Alcotest.(check int64) + "Timestamps match" payload1.timestamp payload2.timestamp ; + Alcotest.(check int) + "Number of datasources read matches written ones" + (List.length payload1.datasources) + (List.length payload2.datasources) ; + List.iter2 assert_ds_equal payload1.datasources payload2.datasources -let make_shared_file () = - Filename.temp_file ~temp_dir:"/dev/shm" "test-metrics" ".tmp" +let make_shared_file ?(k = 0) () = + Filename.temp_file ~temp_dir:"/dev/shm" + (string_of_int k ^ "-test-metrics") + ".tmp" + +let tests_for_all_protos t = + let on_proto name proto tests = + (name, List.map (fun (name, t) -> (name, `Quick, fun () -> t proto)) tests) + in + [ + on_proto "V1" Rrd_protocol_v1.protocol t + ; on_proto "V2" Rrd_protocol_v2.protocol t + ] diff --git a/ocaml/xcp-rrdd/test/transport/test_scale.ml b/ocaml/xcp-rrdd/test/transport/test_scale.ml index c2c4458c99c..ddfe2d02a30 100644 --- a/ocaml/xcp-rrdd/test/transport/test_scale.ml +++ b/ocaml/xcp-rrdd/test/transport/test_scale.ml @@ -1,5 +1,7 @@ open Test_common +let shared_file_count = ref 4096 + let sync_string = "ready" let send_ready sock = @@ -79,14 +81,12 @@ let run_tests shared_file_count protocol = Random.self_init () ; let timestamp = Int64.of_float (Unix.gettimeofday ()) in let deliveries = - make_list - (fun () -> + List.init shared_file_count (fun k -> { - shared_file= make_shared_file () + shared_file= make_shared_file ~k () ; payload= make_random_payload timestamp (Random.int 4) } - ) - shared_file_count + ) in let reader_sock, writer_sock = Unix.(socketpair PF_UNIX SOCK_STREAM 0) in match Unix.fork () with @@ -99,38 +99,8 @@ let run_tests shared_file_count protocol = Unix.close writer_sock ; read_payloads deliveries protocol reader_sock -let () = - let open Rrd_interface in - let shared_file_count = ref 4096 in - let protocol = ref V2 in - Arg.parse - [ - ("-n", Arg.Set_int shared_file_count, "Number of shared files to use") - ; ( "-p" - , Arg.Int - (function - | 1 -> - protocol := V1 - | 2 -> - protocol := V2 - | _ -> - failwith "Unrecognised protocol" - ) - , "Protocol to use" - ) - ] - (fun _ -> ()) - (Filename.basename Sys.executable_name ^ " [-n ]") ; - if !shared_file_count < 0 then - failwith "I cannot use fewer than 0 shared files!" ; - print_endline "------ Scale tests ------" ; - Printf.printf "Shared files: %d\n" !shared_file_count ; - Printf.printf "Protocol: V%d\n" (match !protocol with V1 -> 1 | V2 -> 2) ; - print_newline () ; - run_tests !shared_file_count - ( match !protocol with - | V1 -> - Rrd_protocol_v1.protocol - | V2 -> - Rrd_protocol_v2.protocol - ) +let tests = + Test_common.tests_for_all_protos + [("Write and read", run_tests !shared_file_count)] + +let () = Alcotest.run "Metrics scalability" tests diff --git a/ocaml/xcp-rrdd/test/transport/test_unit.ml b/ocaml/xcp-rrdd/test/transport/test_unit.ml index ee0283dd055..050eaccedcf 100644 --- a/ocaml/xcp-rrdd/test/transport/test_unit.ml +++ b/ocaml/xcp-rrdd/test/transport/test_unit.ml @@ -11,10 +11,12 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. *) - -open OUnit open Test_common +let bracket setup test teardown () = + let a = setup () in + Fun.protect ~finally:(fun () -> teardown a) (fun () -> test a) + let test_file_io protocol = bracket (fun () -> @@ -29,7 +31,7 @@ let test_file_io protocol = ) (fun (writer, reader) -> (* Check that writing then reading the shared file gives the expected - * timestamp and datasources. *) + timestamp and datasources. *) writer.Rrd_writer.write_payload test_payload ; let received_payload = reader.Rrd_reader.read_payload () in assert_payloads_equal test_payload received_payload @@ -49,16 +51,16 @@ let test_writer_cleanup protocol = in writer.Rrd_writer.write_payload test_payload ; writer.Rrd_writer.cleanup () ; - assert_equal ~msg:"Shared file was not cleaned up" + Alcotest.(check bool) + "Shared file was not cleaned up" (Sys.file_exists shared_file) false ; - assert_raises ~msg:"write_payload should fail after cleanup" + Alcotest.check_raises "write_payload should fail after cleanup" Rrd_io.Resource_closed (fun () -> writer.Rrd_writer.write_payload test_payload ) ; - assert_raises ~msg:"cleanup should fail after cleanup" Rrd_io.Resource_closed - (fun () -> writer.Rrd_writer.cleanup () - ) + Alcotest.check_raises "Cleanup should fail after cleanup" + Rrd_io.Resource_closed writer.Rrd_writer.cleanup let test_reader_cleanup protocol = bracket @@ -76,12 +78,13 @@ let test_reader_cleanup protocol = let reader = Rrd_reader.FileReader.create shared_file protocol in let (_ : Rrd_protocol.payload) = reader.Rrd_reader.read_payload () in reader.Rrd_reader.cleanup () ; - assert_raises ~msg:"read_payload should fail after cleanup" - Rrd_io.Resource_closed (fun () -> reader.Rrd_reader.read_payload () + Alcotest.check_raises "Read_payload should fail after cleanup" + Rrd_io.Resource_closed (fun () -> + let _ = reader.Rrd_reader.read_payload () in + () ) ; - assert_raises ~msg:"cleanup should fail after cleanup" - Rrd_io.Resource_closed (fun () -> reader.Rrd_reader.cleanup () - ) + Alcotest.check_raises "Cleanup should fail after cleanup" + Rrd_io.Resource_closed reader.Rrd_reader.cleanup ) (fun (_, writer) -> writer.Rrd_writer.cleanup ()) () @@ -101,12 +104,14 @@ let test_reader_state protocol = (fun (writer, reader) -> writer.Rrd_writer.write_payload test_payload ; let (_ : Rrd_protocol.payload) = reader.Rrd_reader.read_payload () in - assert_raises - ~msg:"read_payload should raise No_update if there has been no update" - Rrd_protocol.No_update (fun () -> reader.Rrd_reader.read_payload () + Alcotest.check_raises + "read_payload should raise No_update if there has been no update" + Rrd_protocol.No_update (fun () -> + let _ = reader.Rrd_reader.read_payload () in + () ) ; (* After the timestamp has been updated, we should be able to read the - * payload again. *) + payload again. *) let open Rrd_protocol in writer.Rrd_writer.write_payload {test_payload with timestamp= Int64.add test_payload.timestamp 5L} ; @@ -119,19 +124,13 @@ let test_reader_state protocol = ) () -let with_each_protocol prefix_string test_fn = - [ - (prefix_string ^ "_v1" >:: fun () -> test_fn Rrd_protocol_v1.protocol) - ; (prefix_string ^ "_v2" >:: fun () -> test_fn Rrd_protocol_v2.protocol) - ] - -let base_suite = - "test_suite" - >::: with_each_protocol "test_file_io" test_file_io - @ with_each_protocol "test_writer_cleanup" test_writer_cleanup - @ with_each_protocol "test_reader_cleanup" test_reader_cleanup - @ with_each_protocol "test_reader_state" test_reader_state +let tests = + Test_common.tests_for_all_protos + [ + ("File I/O", test_file_io) + ; ("Writer cleanup", test_writer_cleanup) + ; ("Reader cleanup", test_reader_cleanup) + ; ("Reader state", test_reader_state) + ] -let () = - print_endline "------ Unit tests ------" ; - ounit2_of_ounit1 base_suite |> OUnit2.run_test_tt_main +let () = Alcotest.run "Metrics transport" tests diff --git a/ocaml/xen-api-client/lib_test/dune b/ocaml/xen-api-client/lib_test/dune index 70b409f4fb5..12e1921130c 100644 --- a/ocaml/xen-api-client/lib_test/dune +++ b/ocaml/xen-api-client/lib_test/dune @@ -3,8 +3,8 @@ (package xen-api-client) (libraries dune-build-info + alcotest rpclib.xml - ounit2 uri xapi-client xapi-types diff --git a/ocaml/xen-api-client/lib_test/xen_api_test.ml b/ocaml/xen-api-client/lib_test/xen_api_test.ml index 0e7a8a9d753..b8729de197c 100644 --- a/ocaml/xen-api-client/lib_test/xen_api_test.ml +++ b/ocaml/xen-api-client/lib_test/xen_api_test.ml @@ -12,7 +12,6 @@ * GNU Lesser General Public License for more details. *) -open OUnit open Xen_api module Fake_IO = struct @@ -77,7 +76,7 @@ end module C = Client.Client -let test_login_fail _ = +let test_login_fail () = let module M = Xen_api.Make (Fake_IO) in let open Fake_IO in let rpc req = @@ -98,11 +97,11 @@ let test_login_fail _ = () with Xen_api.No_response -> () ) ; - assert_equal ~printer:string_of_float ~msg:"timeofday" 31. !timeofday ; - assert_equal ~printer:string_of_int ~msg:"num_sleeps" 31 !num_sleeps ; + Alcotest.(check @@ float Float.epsilon) "timeofday" 31. !timeofday ; + Alcotest.(check int) "num_sleeps" 31 !num_sleeps ; () -let test_login_success _ = +let test_login_success () = let session_id = "OpaqueRef:9e9cf047-76d7-9f3a-62ca-cb7bacf5a4e1" in let result = Printf.sprintf @@ -138,20 +137,15 @@ let test_login_success _ = C.Session.login_with_password ~rpc ~uname:"root" ~pwd:"password" ~version:"1.0" ~originator:"xen-api test" in - assert_equal ~msg:"session_id" session_id (API.Ref.string_of session_id') - -let _ = - let verbose = ref false in - Arg.parse - [("-verbose", Arg.Unit (fun _ -> verbose := true), "Run in verbose mode")] - (fun x -> Printf.fprintf stderr "Ignoring argument: %s" x) - "Test xen-api protocol code" ; - - let suite = - "xen-api" - >::: [ - "login_fail" >:: test_login_fail - ; "login_success" >:: test_login_success - ] - in - run_test_tt ~verbose:!verbose suite + Alcotest.(check string) "session_id" session_id (API.Ref.string_of session_id') + +let () = + Alcotest.run "xen-api-client" + [ + ( "login" + , [ + ("fail", `Quick, test_login_fail) + ; ("success", `Quick, test_login_success) + ] + ) + ] diff --git a/rrd-transport.opam b/rrd-transport.opam index aa031f21317..55ff4e7b0b2 100644 --- a/rrd-transport.opam +++ b/rrd-transport.opam @@ -1,30 +1,36 @@ # This file is generated by dune, edit dune-project instead -license: "LGPL-2.1-only WITH OCaml-LGPL-linking-exception" opam-version: "2.0" -maintainer: "xen-api@lists.xen.org" -authors: "John Else" -homepage: "https://github.com/xapi-project/xen-api" -dev-repo: "git+https://github.com/xapi-project/xen-api.git" -bug-reports: "https://github.com/xapi-project/xen-api" -build: [ - ["dune" "build" "-p" name "-j" jobs] - ["dune" "runtest" "-p" name "-j" jobs] {with-test} -] +synopsis: "Shared-memory protocols for exposing system metrics" +description: + "VMs running on a Xen host can use this library to expose performance counters which can be sampled by xapi's metric daemon." +maintainer: ["Xapi project maintainers"] +authors: ["John Else"] +license: "LGPL-2.1-only WITH OCaml-LGPL-linking-exception" +homepage: "https://xapi-project.github.io/" +bug-reports: "https://github.com/xapi-project/xen-api/issues" depends: [ - "ocaml" - "dune" {build & >= "1.0+beta10"} + "dune" {>= "3.0"} + "alcotest" {with-test} + "astring" "cstruct" "crc" - "astring" "yojson" - "xapi-idl" {>= "1.0.0"} - "xapi-rrd" {>= "1.0.0"} - "ounit2" {with-test} + "xapi-idl" {= version} + "xapi-rrd" {= version} + "odoc" {with-doc} ] -synopsis: "Shared-memory protocols for exposing performance counters" -description: """ -VMs running on a Xen host can use this library to expose performance -counters which can be sampled by the xapi performance monitoring daemon.""" -url { - src: "https://github.com/xapi-project/xen-api/archive/master.tar.gz" -} +build: [ + ["dune" "subst"] {dev} + [ + "dune" + "build" + "-p" + name + "-j" + jobs + "@install" + "@runtest" {with-test} + "@doc" {with-doc} + ] +] +dev-repo: "git+https://github.com/xapi-project/xen-api.git" diff --git a/rrd-transport.opam.template b/rrd-transport.opam.template deleted file mode 100644 index 11fed3d55c8..00000000000 --- a/rrd-transport.opam.template +++ /dev/null @@ -1,28 +0,0 @@ -opam-version: "2.0" -maintainer: "xen-api@lists.xen.org" -authors: "John Else" -homepage: "https://github.com/xapi-project/xen-api" -dev-repo: "git+https://github.com/xapi-project/xen-api.git" -bug-reports: "https://github.com/xapi-project/xen-api" -build: [ - ["dune" "build" "-p" name "-j" jobs] - ["dune" "runtest" "-p" name "-j" jobs] {with-test} -] -depends: [ - "ocaml" - "dune" {build & >= "1.0+beta10"} - "cstruct" - "crc" - "astring" - "yojson" - "xapi-idl" {>= "1.0.0"} - "xapi-rrd" {>= "1.0.0"} - "ounit2" {with-test} -] -synopsis: "Shared-memory protocols for exposing performance counters" -description: """ -VMs running on a Xen host can use this library to expose performance -counters which can be sampled by the xapi performance monitoring daemon.""" -url { - src: "https://github.com/xapi-project/xen-api/archive/master.tar.gz" -} diff --git a/vhd-format-lwt.opam b/vhd-format-lwt.opam index eac244d61c5..49acf611147 100644 --- a/vhd-format-lwt.opam +++ b/vhd-format-lwt.opam @@ -1,9 +1,7 @@ # This file is generated by dune, edit dune-project instead - opam-version: "2.0" -name: "vhd-format-lwt" synopsis: "Lwt interface to read/write VHD format data" -description: """\ +description: """ A pure OCaml library to read and write [vhd](http://en.wikipedia.org/wiki/VHD_(file_format)) format data, plus a simple command-line tool which allows vhd files to be interrogated, @@ -11,31 +9,38 @@ manipulated, format-converted and streamed to and from files and remote servers. This package provides an Lwt compatible interface to the library.""" -maintainer: "dave@recoil.org" -authors: ["Dave Scott" "Jon Ludlam"] +maintainer: ["Dave Scott "] +authors: ["Jon Ludlam" "Dave Scott"] license: "LGPL-2.1-only WITH OCaml-LGPL-linking-exception" tags: ["org:mirage" "org:xapi-project"] homepage: "https://github.com/mirage/ocaml-vhd" -doc: "https://mirage.github.io/ocaml-vhd/" bug-reports: "https://github.com/mirage/ocaml-vhd/issues" depends: [ + "dune" {>= "3.0"} "ocaml" {>= "4.02.3" & < "5.0.0"} + "alcotest" {with-test} + "alcotest-lwt" {with-test} "cstruct" {< "6.1.0"} "lwt" {>= "3.2.0"} "mirage-block" {>= "2.0.1"} - "ounit2" {with-test} "vhd-format" {= version} - "dune" {>= "1.0"} "io-page" {with-test & >= "2.4.0"} + "odoc" {with-doc} ] -available: os = "linux" | os = "macos" build: [ - ["dune" "build" "-p" name "-j" jobs] - ["dune" "runtest" "-p" name "-j" jobs] {with-test} + ["dune" "subst"] {dev} + [ + "dune" + "build" + "-p" + name + "-j" + jobs + "@install" + "@runtest" {with-test} + "@doc" {with-doc} + ] ] +dev-repo: "git+https://github.com/mirage/ocaml-vhd.git" +available: os = "linux" | os = "macos" depexts: ["linux-headers"] {os-distribution = "alpine"} -dev-repo: "git+https://github.com/xapi-project/xen-api.git" -url { - src: - "https://github.com/xapi-project/xen-api/archive/master.tar.gz" -} diff --git a/vhd-format-lwt.opam.template b/vhd-format-lwt.opam.template index 08d4f82498a..67614c917a5 100644 --- a/vhd-format-lwt.opam.template +++ b/vhd-format-lwt.opam.template @@ -1,39 +1,2 @@ -opam-version: "2.0" -name: "vhd-format-lwt" -synopsis: "Lwt interface to read/write VHD format data" -description: """\ -A pure OCaml library to read and write -[vhd](http://en.wikipedia.org/wiki/VHD_(file_format)) format data, plus a -simple command-line tool which allows vhd files to be interrogated, -manipulated, format-converted and streamed to and from files and remote -servers. - -This package provides an Lwt compatible interface to the library.""" -maintainer: "dave@recoil.org" -authors: ["Dave Scott" "Jon Ludlam"] -license: "LGPL-2.1-only WITH OCaml-LGPL-linking-exception" -tags: ["org:mirage" "org:xapi-project"] -homepage: "https://github.com/mirage/ocaml-vhd" -doc: "https://mirage.github.io/ocaml-vhd/" -bug-reports: "https://github.com/mirage/ocaml-vhd/issues" -depends: [ - "ocaml" {>= "4.02.3" & < "5.0.0"} - "cstruct" {< "6.1.0"} - "lwt" {>= "3.2.0"} - "mirage-block" {>= "2.0.1"} - "ounit2" {with-test} - "vhd-format" {= version} - "dune" {>= "1.0"} - "io-page" {with-test & >= "2.4.0"} -] available: os = "linux" | os = "macos" -build: [ - ["dune" "build" "-p" name "-j" jobs] - ["dune" "runtest" "-p" name "-j" jobs] {with-test} -] depexts: ["linux-headers"] {os-distribution = "alpine"} -dev-repo: "git+https://github.com/xapi-project/xen-api.git" -url { - src: - "https://github.com/xapi-project/xen-api/archive/master.tar.gz" -} diff --git a/wsproxy.opam b/wsproxy.opam index d0ee062cf1c..9e9def30a82 100644 --- a/wsproxy.opam +++ b/wsproxy.opam @@ -1,31 +1,35 @@ # This file is generated by dune, edit dune-project instead - opam-version: "2.0" -name: "wsproxy" -maintainer: "xen-api@lists.xen.org" -authors: [ "Jon Ludlam" "Marcello Seri" ] +synopsis: "Websockets proxy for VNC traffic" +maintainer: ["Xapi project maintainers"] +authors: ["Jon Ludlam" "Marcello Seri"] license: "LGPL-2.0-only WITH OCaml-LGPL-linking-exception" -homepage: "https://github.com/xapi-project/xen-api" -dev-repo: "git+https://github.com/xapi-project/xen-api.git" +homepage: "https://xapi-project.github.io/" bug-reports: "https://github.com/xapi-project/xen-api/issues" -build: [ - ["dune" "build" "-p" name "-j" jobs] - ["dune" "runtest" "-p" name "-j" jobs] {with-test} -] depends: [ - "ocaml" - "dune" + "dune" {>= "3.0"} + "alcotest" {with-test} "base64" {>= "3.1.0"} "fmt" "logs" "lwt" {>= "3.0.0"} "re" "uuid" - "ounit2" {with-test} "qcheck-core" {with-test} + "odoc" {with-doc} ] -tags: [ "org:xapi-project" ] -synopsis: "Websockets proxy for VNC traffic" -url { - src: "https://github.com/xapi-project/xen-api/archive/master.tar.gz" -} +build: [ + ["dune" "subst"] {dev} + [ + "dune" + "build" + "-p" + name + "-j" + jobs + "@install" + "@runtest" {with-test} + "@doc" {with-doc} + ] +] +dev-repo: "git+https://github.com/xapi-project/xen-api.git" diff --git a/wsproxy.opam.template b/wsproxy.opam.template deleted file mode 100644 index 483d486d4c0..00000000000 --- a/wsproxy.opam.template +++ /dev/null @@ -1,29 +0,0 @@ -opam-version: "2.0" -name: "wsproxy" -maintainer: "xen-api@lists.xen.org" -authors: [ "Jon Ludlam" "Marcello Seri" ] -license: "LGPL-2.0-only WITH OCaml-LGPL-linking-exception" -homepage: "https://github.com/xapi-project/xen-api" -dev-repo: "git+https://github.com/xapi-project/xen-api.git" -bug-reports: "https://github.com/xapi-project/xen-api/issues" -build: [ - ["dune" "build" "-p" name "-j" jobs] - ["dune" "runtest" "-p" name "-j" jobs] {with-test} -] -depends: [ - "ocaml" - "dune" - "base64" {>= "3.1.0"} - "fmt" - "logs" - "lwt" {>= "3.0.0"} - "re" - "uuid" - "ounit2" {with-test} - "qcheck-core" {with-test} -] -tags: [ "org:xapi-project" ] -synopsis: "Websockets proxy for VNC traffic" -url { - src: "https://github.com/xapi-project/xen-api/archive/master.tar.gz" -} diff --git a/xapi-rrdd.opam b/xapi-rrdd.opam index 824e9d725be..1d46ca776da 100644 --- a/xapi-rrdd.opam +++ b/xapi-rrdd.opam @@ -12,6 +12,7 @@ depends: [ "dune" {>= "3.0"} "ocaml" {>= "4.02.0"} "dune-build-info" + "alcotest" {with-test} "astring" "gzip" {= version} "http-lib" {= version} diff --git a/xapi-sdk.opam b/xapi-sdk.opam new file mode 100644 index 00000000000..93dbd1d640a --- /dev/null +++ b/xapi-sdk.opam @@ -0,0 +1,32 @@ +# This file is generated by dune, edit dune-project instead +opam-version: "2.0" +synopsis: "Xen API SDK generation code" +maintainer: ["Xapi project maintainers"] +authors: ["xen-api@lists.xen.org"] +license: "BSD-2-Clause" +homepage: "https://xapi-project.github.io/" +bug-reports: "https://github.com/xapi-project/xen-api/issues" +depends: [ + "dune" {>= "3.0"} + "alcotest" {with-test} + "astring" + "mustache" + "xapi-datamodel" {= version} + "xapi-stdext-unix" {= version & with-test} + "odoc" {with-doc} +] +build: [ + ["dune" "subst"] {dev} + [ + "dune" + "build" + "-p" + name + "-j" + jobs + "@install" + "@runtest" {with-test} + "@doc" {with-doc} + ] +] +dev-repo: "git+https://github.com/xapi-project/xen-api.git" diff --git a/xen-api-client.opam b/xen-api-client.opam index 0aa625df24e..3c31159d66c 100644 --- a/xen-api-client.opam +++ b/xen-api-client.opam @@ -1,36 +1,48 @@ # This file is generated by dune, edit dune-project instead - opam-version: "2.0" -maintainer: "xen-api@lists.xen.org" -authors: [ "David Scott" "Anil Madhavapeddy" "Jerome Maloberti" "John Else" "Jon Ludlam" "Thomas Sanders" "Mike McClurg" ] +synopsis: "Xen-API client library for remotely-controlling a xapi host" +maintainer: ["Xapi project maintainers"] +authors: [ + "David Scott" + "Anil Madhavapeddy" + "Jerome Maloberti" + "John Else" + "Jon Ludlam" + "Thomas Sanders" + "Mike McClurg" +] license: "LGPL-2.1-only WITH OCaml-LGPL-linking-exception" -homepage: "https://github.com/xapi-project/xen-api" -dev-repo: "git+https://github.com/xapi-project/xen-api.git" +homepage: "https://xapi-project.github.io/" bug-reports: "https://github.com/xapi-project/xen-api/issues" -tags: [ - "org:xapi-project" -] -build: [ - ["dune" "build" "-p" name "-j" jobs] - ["dune" "runtest" "-p" name "-j" jobs] {with-test} -] depends: [ - "ocaml" - "dune" {>= "2.0"} + "dune" {>= "3.0"} + "dune-build-info" + "alcotest" {with-test} "astring" "cohttp" {>= "0.22.0"} "re" "rpclib" - "xapi-rrd" "uri" - "uuid" - "xapi-client" - "xapi-types" + "uuid" {= version} + "xapi-client" {= version} + "xapi-idl" {= version} + "xapi-rrd" {= version} + "xapi-types" {= version} "xmlm" - "ounit2" {with-test} + "odoc" {with-doc} +] +build: [ + ["dune" "subst"] {dev} + [ + "dune" + "build" + "-p" + name + "-j" + jobs + "@install" + "@runtest" {with-test} + "@doc" {with-doc} + ] ] -synopsis: - "Xen-API client library for remotely-controlling a xapi host" -url { - src: "https://github.com/xapi-project/xen-api/archive/master.tar.gz" -} +dev-repo: "git+https://github.com/xapi-project/xen-api.git" diff --git a/xen-api-client.opam.template b/xen-api-client.opam.template deleted file mode 100644 index 3b2b8b6f272..00000000000 --- a/xen-api-client.opam.template +++ /dev/null @@ -1,34 +0,0 @@ -opam-version: "2.0" -maintainer: "xen-api@lists.xen.org" -authors: [ "David Scott" "Anil Madhavapeddy" "Jerome Maloberti" "John Else" "Jon Ludlam" "Thomas Sanders" "Mike McClurg" ] -license: "LGPL-2.1-only WITH OCaml-LGPL-linking-exception" -homepage: "https://github.com/xapi-project/xen-api" -dev-repo: "git+https://github.com/xapi-project/xen-api.git" -bug-reports: "https://github.com/xapi-project/xen-api/issues" -tags: [ - "org:xapi-project" -] -build: [ - ["dune" "build" "-p" name "-j" jobs] - ["dune" "runtest" "-p" name "-j" jobs] {with-test} -] -depends: [ - "ocaml" - "dune" {>= "2.0"} - "astring" - "cohttp" {>= "0.22.0"} - "re" - "rpclib" - "xapi-rrd" - "uri" - "uuid" - "xapi-client" - "xapi-types" - "xmlm" - "ounit2" {with-test} -] -synopsis: - "Xen-API client library for remotely-controlling a xapi host" -url { - src: "https://github.com/xapi-project/xen-api/archive/master.tar.gz" -}