diff --git a/.gitlab/ci/jobs/packaging/opam_package.yml b/.gitlab/ci/jobs/packaging/opam_package.yml index eae369a837ef6032766b59236b7d4aaed8810b3c..92fba74f5489ae1366b1f49f5b5300fe5d3383a5 100644 --- a/.gitlab/ci/jobs/packaging/opam_package.yml +++ b/.gitlab/ci/jobs/packaging/opam_package.yml @@ -1551,8 +1551,18 @@ opam:tezos-workers: variables: package: tezos-workers -# Ignoring unreleased package tezt-performance-regression. +opam:tezt-performance-regression: + extends: + - .opam_template + - .rules_template__trigger_opam_batch_7 + variables: + package: tezt-performance-regression # Ignoring unreleased package tezt-self-tests. -# Ignoring unreleased package tezt-tezos. +opam:tezt-tezos: + extends: + - .opam_template + - .rules_template__trigger_opam_batch_7 + variables: + package: tezt-tezos diff --git a/manifest/main.ml b/manifest/main.ml index 46aef618513d271c61286564a8dbae04735e7413..98d2e88c5507a2fc420758f409b095b0a1e09154 100644 --- a/manifest/main.ml +++ b/manifest/main.ml @@ -1590,6 +1590,7 @@ let tezt_tezos = cohttp_lwt_unix; ] ~cram:true + ~release_status:Released let _tezt_self_tests = public_exe @@ -1683,6 +1684,7 @@ let _octez_p2p_tests = octez_event_logging_test_helpers |> open_; octez_p2p_test_common |> open_; octez_p2p_services |> open_; + tezt_tezos; alcotest_lwt; astring; ] @@ -1698,86 +1700,27 @@ let _octez_p2p_tests = let run_exe prog args = setenv "BISECT_SIGTERM" "yes" @@ run_exe prog args in - (* BEWARE use "--ports" to target different ranges for each - test to run them in parallel or use locks to run them - sequentially. *) - (* ALSO, `--addr ::ffff:127.0.0.1` should be used for test to run correctly on CI runners *) [ - alias_rule "runtest_p2p_socket" ~action:(run_exe "test_p2p_socket" []); alias_rule "runtest_p2p_pool" ~locks:"/ports/49152-65535" - ~action: - (run_exe "test_p2p_pool" ["--clients"; "10"; "--repeat"; "5"]); + ~action:(run_exe "test_p2p_pool" []); alias_rule - "runtest_p2p_broadcast_ipv4" + "runtest_p2p_broadcast" ~locks:"/ports/49152-65535" - ~action: - (run_exe - "test_p2p_broadcast" - [ - "--clients"; - "3"; - "--addr"; - "::ffff:127.0.0.1"; - "--repeat"; - "5"; - ]); + ~action:(run_exe "test_p2p_broadcast" []); alias_rule "runtest_p2p_io_scheduler" ~locks:"/ports/49152-65535" - ~action: - (run_exe - "test_p2p_io_scheduler" - [ - "--delay"; - "5"; - "--clients"; - "8"; - "--max-upload-speed"; - "262144"; - (* 1 << 18 = 256kB *) - "--max-download-speed"; - "1048576" (* 1 << 20 = 1MB *); - ]); - alias_rule - "runtest_p2p_socket_ipv4" - ~locks:"/ports/49152-65535" - ~action:(run_exe "test_p2p_socket" ["--addr"; "::ffff:127.0.0.1"]); + ~action:(run_exe "test_p2p_io_scheduler" []); alias_rule - "runtest_p2p_pool_ipv4" + "runtest_p2p_socket" ~locks:"/ports/49152-65535" - ~action: - (run_exe - "test_p2p_pool" - [ - "--clients"; - "10"; - "--repeat"; - "5"; - "--addr"; - "::ffff:127.0.0.1"; - ]); + ~action:(run_exe "test_p2p_socket" []); alias_rule - "runtest_p2p_io_scheduler_ipv4" + "runtest_p2p_node" ~locks:"/ports/49152-65535" - ~action: - (run_exe - "test_p2p_io_scheduler" - [ - "--delay"; - "5"; - "--clients"; - "8"; - "--max-upload-speed"; - "262144"; - (* 1 << 18 = 256kB *) - "--max-download-speed"; - "1048576"; - (* 1 << 20 = 1MB *) - "--addr"; - "::ffff:127.0.0.1"; - ]); + ~action:(run_exe "test_p2p_node" []); alias_rule "runtest_p2p_peerset" ~action:(run_exe "test_p2p_peerset" []); @@ -1787,10 +1730,6 @@ let _octez_p2p_tests = alias_rule "runtest_p2p_banned_peers" ~action:(run_exe "test_p2p_banned_peers" []); - alias_rule - "runtest_p2p_node" - ~locks:"/ports/49152-65535" - ~action:(run_exe "test_p2p_node" []); alias_rule "runtest_p2p_connect_handler" ~action:(run_exe "test_p2p_connect_handler" []); @@ -1802,10 +1741,10 @@ let _octez_p2p_tests = ~package:"tezos-p2p" ~alias_deps: [ - "runtest_p2p_socket_ipv4"; - "runtest_p2p_pool_ipv4"; - "runtest_p2p_broadcast_ipv4"; - "runtest_p2p_io_scheduler_ipv4"; + "runtest_p2p_socket"; + "runtest_p2p_pool"; + "runtest_p2p_broadcast"; + "runtest_p2p_io_scheduler"; "runtest_p2p_peerset"; "runtest_p2p_buffer_reader"; "runtest_p2p_banned_peers"; diff --git a/opam/tezos-p2p.opam b/opam/tezos-p2p.opam index 9f690980213488f84bab45382058363448a67f09..50bafcf58fe4ca85a19d1e48afb2f7d86b98d17e 100644 --- a/opam/tezos-p2p.opam +++ b/opam/tezos-p2p.opam @@ -23,6 +23,7 @@ depends: [ "tezos-test-helpers" {with-test} "tezos-base-test-helpers" {with-test} "tezos-event-logging-test-helpers" {with-test} + "tezt-tezos" {with-test} "alcotest-lwt" { with-test & >= "1.5.0" } "astring" {with-test} "tezt" { with-test & >= "3.0.0" } diff --git a/src/lib_p2p/test/dune b/src/lib_p2p/test/dune index 2cf1ea3609572c33feb51278ef1e5d6047de236d..35cfff9d0e3de4ec5b4c90155ac3b1d4d03a2796 100644 --- a/src/lib_p2p/test/dune +++ b/src/lib_p2p/test/dune @@ -24,6 +24,7 @@ tezos-event-logging-test-helpers tezos_p2p_test_common tezos-p2p-services + tezt-tezos alcotest-lwt astring) (link_flags @@ -41,61 +42,30 @@ -open Tezos_p2p_test_common -open Tezos_p2p_services)) -(rule - (alias runtest_p2p_socket) - (action (setenv BISECT_SIGTERM yes (run %{exe:test_p2p_socket.exe})))) - (rule (alias runtest_p2p_pool) (locks /ports/49152-65535) - (action - (setenv BISECT_SIGTERM yes - (run %{exe:test_p2p_pool.exe} --clients 10 --repeat 5)))) + (action (setenv BISECT_SIGTERM yes (run %{exe:test_p2p_pool.exe})))) (rule - (alias runtest_p2p_broadcast_ipv4) + (alias runtest_p2p_broadcast) (locks /ports/49152-65535) - (action - (setenv BISECT_SIGTERM yes - (run - %{exe:test_p2p_broadcast.exe} - --clients 3 --addr ::ffff:127.0.0.1 --repeat 5)))) + (action (setenv BISECT_SIGTERM yes (run %{exe:test_p2p_broadcast.exe})))) (rule (alias runtest_p2p_io_scheduler) (locks /ports/49152-65535) - (action - (setenv BISECT_SIGTERM yes - (run - %{exe:test_p2p_io_scheduler.exe} - --delay 5 --clients 8 --max-upload-speed 262144 --max-download-speed - 1048576)))) - -(rule - (alias runtest_p2p_socket_ipv4) - (locks /ports/49152-65535) - (action - (setenv BISECT_SIGTERM yes - (run %{exe:test_p2p_socket.exe} --addr ::ffff:127.0.0.1)))) + (action (setenv BISECT_SIGTERM yes (run %{exe:test_p2p_io_scheduler.exe})))) (rule - (alias runtest_p2p_pool_ipv4) + (alias runtest_p2p_socket) (locks /ports/49152-65535) - (action - (setenv BISECT_SIGTERM yes - (run - %{exe:test_p2p_pool.exe} - --clients 10 --repeat 5 --addr ::ffff:127.0.0.1)))) + (action (setenv BISECT_SIGTERM yes (run %{exe:test_p2p_socket.exe})))) (rule - (alias runtest_p2p_io_scheduler_ipv4) + (alias runtest_p2p_node) (locks /ports/49152-65535) - (action - (setenv BISECT_SIGTERM yes - (run - %{exe:test_p2p_io_scheduler.exe} - --delay 5 --clients 8 --max-upload-speed 262144 --max-download-speed - 1048576 --addr ::ffff:127.0.0.1)))) + (action (setenv BISECT_SIGTERM yes (run %{exe:test_p2p_node.exe})))) (rule (alias runtest_p2p_peerset) @@ -109,11 +79,6 @@ (alias runtest_p2p_banned_peers) (action (setenv BISECT_SIGTERM yes (run %{exe:test_p2p_banned_peers.exe})))) -(rule - (alias runtest_p2p_node) - (locks /ports/49152-65535) - (action (setenv BISECT_SIGTERM yes (run %{exe:test_p2p_node.exe})))) - (rule (alias runtest_p2p_connect_handler) (action @@ -127,10 +92,10 @@ (alias runtest) (package tezos-p2p) (deps - (alias runtest_p2p_socket_ipv4) - (alias runtest_p2p_pool_ipv4) - (alias runtest_p2p_broadcast_ipv4) - (alias runtest_p2p_io_scheduler_ipv4) + (alias runtest_p2p_socket) + (alias runtest_p2p_pool) + (alias runtest_p2p_broadcast) + (alias runtest_p2p_io_scheduler) (alias runtest_p2p_peerset) (alias runtest_p2p_buffer_reader) (alias runtest_p2p_banned_peers) diff --git a/src/lib_p2p/test/test_p2p_banned_peers.ml b/src/lib_p2p/test/test_p2p_banned_peers.ml index 1ecf090bc8d2b31b8355da2776ce4241033ef1c1..7bad6c3604726b67585603afabb1a6c0bdb8733f 100644 --- a/src/lib_p2p/test/test_p2p_banned_peers.ml +++ b/src/lib_p2p/test/test_p2p_banned_peers.ml @@ -139,7 +139,6 @@ let () = f ()) in Alcotest_lwt.run - ~argv:[|""|] "tezos-p2p" [ ( "p2p.peerset", diff --git a/src/lib_p2p/test/test_p2p_broadcast.ml b/src/lib_p2p/test/test_p2p_broadcast.ml index 5b5fbf4dab01ae65cf991029e71e1f4fdeaf7ec6..d6e26e7f54a6af15495dcf5cce6aca794c114323 100644 --- a/src/lib_p2p/test/test_p2p_broadcast.ml +++ b/src/lib_p2p/test/test_p2p_broadcast.ml @@ -41,76 +41,27 @@ type error += Read | Wrong_message_received | Wrong_message_count let () = Random.self_init () -let addr = ref Ipaddr.V6.localhost +(* options that are hardcoded here *) +let repeat = 5 -let port = ref None +let nb_oph = 1000 -let clients = ref 10 - -let repeat = ref 5 - -let log_config = ref None - -let nb_oph = ref 1000 - -let no_check = ref false +let no_check = false let init_logs = - lazy (Tezos_base_unix.Internal_event_unix.init ?lwt_log_sink:!log_config ()) + let lwt_log_sink = + Some + (Lwt_log_sink_unix.create_cfg + ~rules:"test.p2p.connection-pool -> info; p2p.connection-pool -> info" + ()) + in + lazy (Tezos_base_unix.Internal_event_unix.init ?lwt_log_sink ()) let points = ref [] -let gen_points () = points := Node.gen_points ?port:!port !clients !addr - -let spec = - Arg. - [ - ( "--port", - Int (fun p -> port := Some p), - " Listening port of the first peer." ); - ( "--addr", - String (fun p -> addr := Ipaddr.V6.of_string_exn p), - " Listening addr" ); - ("--clients", Set_int clients, " Number of concurrent clients."); - ("--repeat", Set_int repeat, "Number of iterations of broadcasting."); - ("--oph", Set_int nb_oph, " Number of Operation hashes broadcasted."); - ( "--no-check", - Set no_check, - " Do not check message consistency (can be heavy on RAM)." ); - ( "-v", - Unit - (fun () -> - log_config := - Some - (Lwt_log_sink_unix.create_cfg - ~rules: - "test.p2p.connection-pool -> info; p2p.connection-pool -> \ - info" - ())), - " Log up to info msgs" ); - ( "-vv", - Unit - (fun () -> - log_config := - Some - (Lwt_log_sink_unix.create_cfg - ~rules: - "test.p2p.connection-pool -> debug; p2p.connection-pool \ - -> debug" - ())), - " Log up to debug msgs" ); - ( "-vvv", - Unit - (fun () -> - log_config := - Some - (Lwt_log_sink_unix.create_cfg - ~rules: - "test.p2p.broadcast -> debug;p2p.pool -> \ - debug;p2p.connection -> debug" - ())), - " Log up to debug msgs, socket included" ); - ] +let gen_points addr = + let clients = 3 in + points := Node.gen_points clients addr (** Detaches [!client] nodes. Each of them will send a [BigPing] to each other node, then await for reading one from each other node. @@ -121,12 +72,12 @@ module Simple = struct (fun _ -> List.map (fun _ -> Operation_hash.of_bytes_exn (Bytes.create 32)) - (1 -- !nb_oph)) - (if !no_check then 0 -- 1 else 0 -- !repeat) + (1 -- nb_oph)) + (if no_check then 0 -- 1 else 0 -- repeat) let message_is_ok m1 m2 : (unit, error trace) result = let open Result_syntax in - if !no_check then return_unit + if no_check then return_unit else List.fold_left2_e ~when_different_lengths:(Error_monad.TzTrace.make Wrong_message_count) @@ -293,9 +244,9 @@ module Simple = struct (n - 1) (span :: acc) (gspan :: gacc) - (if !no_check then next @ [ref_msg] else next) + (if no_check then next @ [ref_msg] else next) in - let* times, gtimes = loop !repeat [] [] msgs in + let* times, gtimes = loop repeat [] [] msgs in let print_stat times name = let ftimes = List.map Ptime.Span.to_float_s times in lwt_log_notice @@ -330,9 +281,9 @@ module Simple = struct let* _msgs = read_all node.pool ref_msg in let*! () = lwt_log_info "Read message.@." in let* () = Node.sync node in - loop (n - 1) (if !no_check then next @ [ref_msg] else next) + loop (n - 1) (if no_check then next @ [ref_msg] else next) in - loop !repeat msgs + loop repeat msgs let run points = (* Messages are precomputed for every iteration and shared between @@ -344,7 +295,8 @@ module Simple = struct points end -let wrap n f = +let wrap addr n f = + gen_points addr ; Alcotest_lwt.test_case n `Quick (fun _ () -> let open Lwt_syntax in let* () = Lazy.force init_logs in @@ -355,7 +307,7 @@ let wrap n f = | Error (Exn (Unix.Unix_error ((EADDRINUSE | EADDRNOTAVAIL), _, _)) :: _) -> warn "Conflict on ports, retry the test." ; - gen_points () ; + gen_points addr ; aux n f | Error error -> Format.kasprintf Stdlib.failwith "%a" pp_print_trace error @@ -363,15 +315,11 @@ let wrap n f = aux n f) let main () = - let anon_fun _num_peers = raise (Arg.Bad "No anonymous argument.") in - let usage_msg = "Usage: %s .\nArguments are:" in - Arg.parse spec anon_fun usage_msg ; - gen_points () ; + let addr = Ipaddr.V6.of_string_exn "::ffff:127.0.0.1" in Lwt_main.run @@ Alcotest_lwt.run - ~argv:[|""|] "tezos-p2p-broadcast" - [("p2p-broadcast", [wrap "simple" (fun _ -> Simple.run !points)])] + [("p2p-broadcast", [wrap addr "simple" (fun _ -> Simple.run !points)])] let () = Sys.catch_break true ; diff --git a/src/lib_p2p/test/test_p2p_io_scheduler.ml b/src/lib_p2p/test/test_p2p_io_scheduler.ml index 2764b6b7b7d3059ba3e006f5d836f87995d0c516..30277f19de3d54e4b88800044fca8bbd9c5ec1b3 100644 --- a/src/lib_p2p/test/test_p2p_io_scheduler.ml +++ b/src/lib_p2p/test/test_p2p_io_scheduler.ml @@ -238,63 +238,6 @@ let run ?display_client_stat ?max_download_speed ?max_upload_speed let () = Random.self_init () -let addr = ref Ipaddr.V6.localhost - -let port = ref None - -let max_download_speed = ref None - -let max_upload_speed = ref None - -let read_buffer_size = ref (1 lsl 14) - -let read_queue_size = ref (Some (1 lsl 14)) - -let write_queue_size = ref (Some (1 lsl 14)) - -let delay = ref 60. - -let clients = ref 8 - -let display_client_stat = ref None - -let spec = - Arg. - [ - ("--port", Int (fun p -> port := Some p), " Listening port"); - ( "--addr", - String (fun p -> addr := Ipaddr.V6.of_string_exn p), - " Listening addr" ); - ( "--max-download-speed", - Int (fun i -> max_download_speed := Some i), - " Max download speed in B/s (default: unbounded)" ); - ( "--max-upload-speed", - Int (fun i -> max_upload_speed := Some i), - " Max upload speed in B/s (default: unbounded)" ); - ( "--read-buffer-size", - Set_int read_buffer_size, - " Size of the read buffers" ); - ( "--read-queue-size", - Int (fun i -> read_queue_size := if i <= 0 then None else Some i), - " Size of the read queue (0=unbounded)" ); - ( "--write-queue-size", - Int (fun i -> write_queue_size := if i <= 0 then None else Some i), - " Size of the write queue (0=unbounded)" ); - ("--delay", Set_float delay, " Client execution time."); - ("--clients", Set_int clients, " Number of concurrent clients."); - ( "--hide-clients-stat", - Unit (fun () -> display_client_stat := Some false), - " Hide the client bandwidth statistic." ); - ( "--display_clients_stat", - Unit (fun () -> display_client_stat := Some true), - " Display the client bandwidth statistic." ); - ] - -let () = - let anon_fun _num_peers = raise (Arg.Bad "No anonymous argument.") in - let usage_msg = "Usage: %s .\nArguments are:" in - Arg.parse spec anon_fun usage_msg - let init_logs = lazy (Tezos_base_unix.Internal_event_unix.init ()) let wrap n f = @@ -308,24 +251,32 @@ let wrap n f = Format.kasprintf Stdlib.failwith "%a" pp_print_trace error) let () = + let addr = Ipaddr.V6.of_string_exn "::ffff:127.0.0.1" in + let port = Some (Tezt_tezos.Port.fresh ()) in + let max_download_speed = 1048576 in + let max_upload_speed = 262144 in + (* 1 << 14 = 16kB *) + let read_buffer_size = 1 lsl 14 in + let read_queue_size = 1 lsl 14 in + let write_queue_size = 1 lsl 14 in + let delay = 5. in + let clients = 8 in Lwt_main.run @@ Alcotest_lwt.run - ~argv:[|""|] "tezos-p2p" [ ( "p2p.io-scheduler", [ wrap "trivial-quota" (fun () -> run - ?display_client_stat:!display_client_stat - ?max_download_speed:!max_download_speed - ?max_upload_speed:!max_upload_speed - ~read_buffer_size:!read_buffer_size - ?read_queue_size:!read_queue_size - ?write_queue_size:!write_queue_size - !addr - !port - !delay - !clients); + ~max_download_speed + ~max_upload_speed + ~read_buffer_size + ~read_queue_size + ~write_queue_size + addr + port + delay + clients); ] ); ] diff --git a/src/lib_p2p/test/test_p2p_maintenance.ml b/src/lib_p2p/test/test_p2p_maintenance.ml index 2602cb2f92a10d12df5df07307ca687d95b5d966..0dbe587681ec105f654305947c8aaf40d49bbc20 100644 --- a/src/lib_p2p/test/test_p2p_maintenance.ml +++ b/src/lib_p2p/test/test_p2p_maintenance.ml @@ -499,99 +499,45 @@ module Triggers = struct end end -let points = ref [] +let gen_points ?(clients = 42) addr = Node.gen_points clients addr -let gen_points () = - let clients = 42 in - (*let addr = Ipaddr.V6.localhost in*) - let addr = Ipaddr.v6_of_v4 @@ Ipaddr.V4.make 127 0 0 3 in - let port = 29152 + Random.int 16384 in - let ports = port -- (port + clients - 1) in - points := - List.map - (fun port -> - (* to each node, we add one topic to its state. *) - (addr, port)) - ports - -let wrap n f = +let wrap addr n f = Alcotest_lwt.test_case n `Quick (fun _ () -> let open Lwt_syntax in let rec aux n f = - let* r = f () in + let* r = f (gen_points addr) in match r with | Ok () -> Lwt.return_unit | Error (Exn (Unix.Unix_error ((EADDRINUSE | EADDRNOTAVAIL), _, _)) :: _) -> - gen_points () ; - (*warn "Conflict on ports, retry the test." ;*) aux n f | Error error -> Format.kasprintf Stdlib.failwith "%a" pp_print_trace error in aux n f) -let log_config = ref None - -let spec = - Arg. - [ - ( "-v", - Unit - (fun () -> - log_config := - Some - (Lwt_log_sink_unix.create_cfg - ~rules: - "test.p2p.maintenance -> debug; p2p.maintenance -> debug" - ())), - " Log up to info msgs" ); - ( "-vv", - Unit - (fun () -> - log_config := - Some - (Lwt_log_sink_unix.create_cfg - ~rules: - "test.p2p.maintenance -> debug; p2p.maintenance -> debug; \ - p2p.connect_handler -> debug; test.p2p.node -> debug" - ())), - " Log up to debug msgs" ); - ( "-vvv", - Unit - (fun () -> - log_config := - Some - (Lwt_log_sink_unix.create_cfg - ~rules: - "test.p2p.maintenance -> debug; p2p.maintenance -> debug; \ - p2p.socket -> debug; p2p.io_scheduler -> debug;p2p.fd -> \ - debug;p2p.connect_handler -> debug; test.p2p.node -> \ - debug" - ())), - " Log up to debug msgs, socket included" ); - ] - let main () = - let anon_fun _num_peers = raise (Arg.Bad "No anonymous argument.") in - let usage_msg = "Usage: %s .\nArguments are:" in - Arg.parse spec anon_fun usage_msg ; + let lwt_log_sink = + Lwt_log_sink_unix.create_cfg + ~rules: + "test.p2p.maintenance -> debug; p2p.maintenance -> debug; \ + p2p.connect_handler -> debug; test.p2p.node -> debug" + () + in let () = - Lwt_main.run - (Tezos_base_unix.Internal_event_unix.init ?lwt_log_sink:!log_config ()) + Lwt_main.run (Tezos_base_unix.Internal_event_unix.init ~lwt_log_sink ()) in - gen_points () ; + let addr = Ipaddr.V6.of_string_exn "::ffff:127.0.0.1" in Lwt_main.run @@ Alcotest_lwt.run - ~argv:[|""|] "tezos-p2p" [ ( "p2p-maintenance", [ - wrap "triggers.too-few-connections" (fun _ -> - Triggers.Too_few_connections.run !points); - wrap "triggers.too-many-connections" (fun _ -> - Triggers.Too_many_connections.run !points); + wrap addr "triggers.too-few-connections" (fun points -> + Triggers.Too_few_connections.run points); + wrap addr "triggers.too-many-connections" (fun points -> + Triggers.Too_many_connections.run points); ] ); ] diff --git a/src/lib_p2p/test/test_p2p_node.ml b/src/lib_p2p/test/test_p2p_node.ml index 57150df60ff5c5257a2a2e9e060d98044037a6d1..a239d24a379a18082c656648a5bd74694d82e3ae 100644 --- a/src/lib_p2p/test/test_p2p_node.ml +++ b/src/lib_p2p/test/test_p2p_node.ml @@ -79,26 +79,18 @@ let propagation_tzresult points = in match r with Ok () -> tzfail Invalid_test_result | Error _ -> return_unit -let points = ref [] +let gen_points ?(clients = 4) addr = Node.gen_points clients addr -let gen_points () = - let clients = 4 in - let addr = Ipaddr.V6.localhost in - let port = 49152 + Random.int 16384 in - let ports = port -- (port + clients - 1) in - points := List.map (fun port -> (addr, port)) ports - -let wrap n f = +let wrap addr n f = Alcotest_lwt.test_case n `Quick (fun _ () -> let rec aux n f = let open Lwt_syntax in - let* r = f () in + let* r = f (gen_points addr) in match r with | Ok () -> Lwt.return_unit | Error (Exn (Unix.Unix_error ((EADDRINUSE | EADDRNOTAVAIL), _, _)) :: _) -> let* () = Event.(emit port_conflicts) () in - gen_points () ; aux n f | Error error -> Format.kasprintf Stdlib.failwith "%a" pp_print_trace error @@ -108,19 +100,20 @@ let wrap n f = let main () = let () = let lwt_log_sink = - Lwt_log_sink_unix.create_cfg ~rules:"test.p2p.node -> debug;" () + Lwt_log_sink_unix.create_cfg ~rules:"test.p2p.node -> info;" () in Lwt_main.run (Tezos_base_unix.Internal_event_unix.init ~lwt_log_sink ()) in - gen_points () ; + let addr = Ipaddr.V6.of_string_exn "::ffff:127.0.0.1" in Lwt_main.run @@ Alcotest_lwt.run - ~argv:[|""|] "tezos-p2p" [ ( "p2p-node", - [wrap "propagation-tzresult" (fun _ -> propagation_tzresult !points)] - ); + [ + wrap addr "propagation-tzresult" (fun points -> + propagation_tzresult points); + ] ); ] let () = diff --git a/src/lib_p2p/test/test_p2p_peerset.ml b/src/lib_p2p/test/test_p2p_peerset.ml index bb7c4c794ec3abe050d451ca6fb7d94704fb038f..01648efd012fe71ec22e479806bc0083e78e1117 100644 --- a/src/lib_p2p/test/test_p2p_peerset.ml +++ b/src/lib_p2p/test/test_p2p_peerset.ml @@ -37,7 +37,7 @@ open P2p_acl.Internal_for_tests include Internal_event.Legacy_logging.Make (struct - let name = "test-p2p-banned_peers" + let name = "test-p2p-banned_peerset" end) let assert_equal_bool ~msg a b = if a <> b then Alcotest.fail msg @@ -100,7 +100,6 @@ let test_LRU_overflow _ = let () = Alcotest.run - ~argv:[|""|] "tezos-p2p" [ ( "p2p.peerset", diff --git a/src/lib_p2p/test/test_p2p_pool.ml b/src/lib_p2p/test/test_p2p_pool.ml index c6dcbcbf391bd8ca7d7e10852193b71976ea5541..e9234a9395ed861a96e35bcbf5520e20861d39be 100644 --- a/src/lib_p2p/test/test_p2p_pool.ml +++ b/src/lib_p2p/test/test_p2p_pool.ml @@ -718,79 +718,22 @@ end let () = Random.self_init () -let addr = ref Ipaddr.V6.localhost - -let port = ref None - -let clients = ref 10 - -let repeat_connections = ref 5 - -let log_config = ref None - -let spec = - Arg. - [ - ( "--port", - Int (fun p -> port := Some p), - " Listening port of the first peer." ); - ( "--addr", - String (fun p -> addr := Ipaddr.V6.of_string_exn p), - " Listening addr" ); - ("--clients", Set_int clients, " Number of concurrent clients."); - ( "--repeat", - Set_int repeat_connections, - " Number of connections/disconnections." ); - ( "-v", - Unit - (fun () -> - log_config := - Some - (Lwt_log_sink_unix.create_cfg - ~rules: - "test.p2p.connection-pool -> info; p2p.connection-pool -> \ - info" - ())), - " Log up to info msgs" ); - ( "-vv", - Unit - (fun () -> - log_config := - Some - (Lwt_log_sink_unix.create_cfg - ~rules: - "test.p2p.connection-pool -> debug; p2p.connection-pool \ - -> debug" - ())), - " Log up to debug msgs" ); - ( "-vvv", - Unit - (fun () -> - log_config := - Some - (Lwt_log_sink_unix.create_cfg - ~rules: - "test.p2p.connection-pool -> debug;p2p.connection-pool -> \ - debug;p2p.connection -> debug" - ())), - " Log up to debug msgs, socket included" ); - ] - let init_logs = - lazy (Tezos_base_unix.Internal_event_unix.init ?lwt_log_sink:!log_config ()) + let lwt_log_sink = + Lwt_log_sink_unix.create_cfg + ~rules:"test.p2p.connection-pool -> info; p2p.connection-pool -> info" + () + in + lazy (Tezos_base_unix.Internal_event_unix.init ~lwt_log_sink ()) let points = ref [] -let gen_points () = - let clients = !clients in - let addr = !addr in - let port = - Option.value_f ~default:(fun () -> 49152 + Random.int 16384) !port +let wrap ?addr ?port ?(clients = 10) n f = + let gen_points addr = points := Node.gen_points ?port clients addr in + let addr = + Option.value ~default:(Ipaddr.V6.of_string_exn "::ffff:127.0.0.1") addr in - let ports = port -- (port + clients - 1) in - points := List.map (fun port -> (addr, port)) ports - -let wrap n f = + gen_points addr ; Alcotest_lwt.test_case n `Quick (fun _ () -> let open Lwt_syntax in let* () = Lazy.force init_logs in @@ -801,7 +744,7 @@ let wrap n f = | Error (Exn (Unix.Unix_error ((EADDRINUSE | EADDRNOTAVAIL), _, _)) :: _) -> warn "Conflict on ports, retry the test." ; - gen_points () ; + gen_points addr ; aux n f | Error error -> Format.kasprintf Stdlib.failwith "%a" pp_print_trace error @@ -809,20 +752,16 @@ let wrap n f = aux n f) let main () = - let anon_fun _num_peers = raise (Arg.Bad "No anonymous argument.") in - let usage_msg = "Usage: %s .\nArguments are:" in - Arg.parse spec anon_fun usage_msg ; - gen_points () ; + let repeat_connections = 5 in Lwt_main.run @@ Alcotest_lwt.run - ~argv:[|""|] "tezos-p2p" [ ( "p2p-connection-pool", [ wrap "simple" (fun _ -> Simple.run !points); wrap "random" (fun _ -> - Random_connections.run !points !repeat_connections); + Random_connections.run !points repeat_connections); wrap "garbled" (fun _ -> Garbled.run !points); wrap "overcrowded" (fun _ -> Overcrowded.run !points); wrap "overcrowded-mixed" (fun _ -> diff --git a/src/lib_p2p/test/test_p2p_socket.ml b/src/lib_p2p/test/test_p2p_socket.ml index 137567eaaf04ab098d9a75604537f4761263beb5..d91258bcce1d58b90c644de1a232d1bfdef136b6 100644 --- a/src/lib_p2p/test/test_p2p_socket.ml +++ b/src/lib_p2p/test/test_p2p_socket.ml @@ -35,7 +35,7 @@ open P2p_test_utils include Internal_event.Legacy_logging.Make (struct - let name = "test.p2p.connection" + let name = "test.p2p.socket" end) let tzassert b pos = @@ -45,8 +45,6 @@ let tzassert b pos = let high_pow_target = Tezos_crypto.Crypto_box.make_pow_target 100. -let port = ref None - let sync ch = let open Lwt_result_syntax in let* () = Process.Channel.push ch () in @@ -214,7 +212,7 @@ module Pow_check = struct let* conn = connect sched addr port id in tzassert (is_connection_closed conn) __POS__ - let run _dir = run_nodes ?port:!port client server + let run _dir = run_nodes client server end (** Spawns a client and a server. After the client getting connected to @@ -514,51 +512,13 @@ module Garbled_data = struct let run _dir = run_nodes client server end -let log_config = ref None - -let spec = - Arg. - [ - ( "--addr", - String (fun p -> addr := Ipaddr.V6.of_string_exn p), - " Listening addr" ); - ( "-v", - Unit - (fun () -> - log_config := - Some - (Lwt_log_sink_unix.create_cfg - ~rules:"test.p2p.connection -> info; p2p.connection -> info" - ())), - " Log up to info msgs" ); - ( "-vv", - Unit - (fun () -> - log_config := - Some - (Lwt_log_sink_unix.create_cfg - ~rules: - "test.p2p.connection -> debug; p2p.connection -> debug" - ())), - " Log up to debug msgs" ); - ( "-vvv", - Unit - (fun () -> - log_config := - Some - (Lwt_log_sink_unix.create_cfg - ~rules: - "test.p2p.connection -> debug; p2p.connection -> debug; \ - p2p.io-scheduler -> debug " - ())), - " Log up to debug msgs even in io_scheduler" ); - ( "--port", - Int (fun p -> port := Some p), - " Listening port of the first peer." ); - ] - let init_logs = - lazy (Tezos_base_unix.Internal_event_unix.init ?lwt_log_sink:!log_config ()) + let lwt_log_sink = + Lwt_log_sink_unix.create_cfg + ~rules:"test.p2p.connection -> info; p2p.connection -> info" + () + in + lazy (Tezos_base_unix.Internal_event_unix.init ~lwt_log_sink ()) let wrap n f = Alcotest_lwt.test_case n `Quick (fun _ () -> @@ -571,15 +531,12 @@ let wrap n f = Format.kasprintf Stdlib.failwith "%a" pp_print_trace error) let main () = - let anon_fun _num_peers = raise (Arg.Bad "No anonymous argument.") in - let usage_msg = "Usage: %s.\nArguments are:" in - Arg.parse spec anon_fun usage_msg ; + P2p_test_utils.addr := Ipaddr.V6.of_string_exn "::ffff:127.0.0.1" ; Lwt_main.run @@ Alcotest_lwt.run - ~argv:[|""|] "tezos-p2p" [ - ( "p2p-connection.", + ( "p2p-socket.", [ wrap "low-level" Low_level.run; wrap "pow" Pow_check.run;