From 2e1212a46477c7863d48b626c0f5d2f9d6233532 Mon Sep 17 00:00:00 2001 From: Pietro Abate Date: Fri, 17 Mar 2023 10:26:15 +0100 Subject: [PATCH 1/4] p2p: reduce verbosity of all p2p unit tests --- src/lib_p2p/test/common/process.ml | 12 +++-- src/lib_p2p/test/test_p2p_broadcast.ml | 24 +++++----- src/lib_p2p/test/test_p2p_io_scheduler.ml | 8 ++-- src/lib_p2p/test/test_p2p_pool.ml | 56 +++++++++++------------ 4 files changed, 52 insertions(+), 48 deletions(-) diff --git a/src/lib_p2p/test/common/process.ml b/src/lib_p2p/test/common/process.ml index e3ff33308257..495c1e0f81cc 100644 --- a/src/lib_p2p/test/common/process.ml +++ b/src/lib_p2p/test/common/process.ml @@ -35,9 +35,13 @@ let log_f ~level format = Format.ikfprintf (fun _ -> Lwt.return_unit) Format.std_formatter format else Format.kasprintf (fun msg -> Lwt_log.log ~section ~level msg) format -let lwt_log_notice fmt = log_f ~level:Lwt_log.Notice fmt +(* not used at the moment *) +let _lwt_log_notice fmt = log_f ~level:Lwt_log.Notice fmt -let lwt_log_info fmt = log_f ~level:Lwt_log.Info fmt +(* not used at the moment *) +let _lwt_log_info fmt = log_f ~level:Lwt_log.Info fmt + +let lwt_log_debug fmt = log_f ~level:Lwt_log.Debug fmt let lwt_log_error fmt = log_f ~level:Lwt_log.Error fmt @@ -241,7 +245,7 @@ let detach ?(prefix = "") ?canceler ?input_encoding ?output_encoding ~close_mode:`Keep ~channel:Lwt_io.stderr () ; - let* () = lwt_log_notice "PID: %d" (Unix.getpid ()) in + let* () = lwt_log_debug "PID: %d" (Unix.getpid ()) in handle_result ~value_encoding ~flags @@ -442,7 +446,7 @@ let wait_all_results (processes : ('a, 'b, 'c) t list) = let* o = loop terminations in match o with | None -> ( - let* () = lwt_log_info "All done!" in + let* () = lwt_log_debug "All done!" in let* terminated = all terminations in match List.partition_result terminated with | _, _ :: _ -> assert false diff --git a/src/lib_p2p/test/test_p2p_broadcast.ml b/src/lib_p2p/test/test_p2p_broadcast.ml index d6e26e7f54a6..f24c814891cd 100644 --- a/src/lib_p2p/test/test_p2p_broadcast.ml +++ b/src/lib_p2p/test/test_p2p_broadcast.ml @@ -92,7 +92,7 @@ module Simple = struct let rec connect ~timeout connect_handler pool point = let open Lwt_syntax in - let* () = lwt_log_info "Connect to %a" P2p_point.Id.pp point in + let* () = lwt_debug "Connect to %a" P2p_point.Id.pp point in let* r = P2p_connect_handler.connect connect_handler point ~timeout in match r with | Error (Tezos_p2p_services.P2p_errors.Connected :: _) -> ( @@ -107,7 +107,7 @@ module Simple = struct | Timeout | Tezos_p2p_services.P2p_errors.Rejected _ ) as head_err) :: _) -> let* () = - lwt_log_info + lwt_debug "Connection to %a failed (%a)@." P2p_point.Id.pp point @@ -219,7 +219,7 @@ module Simple = struct node.pool node.points in - let*! () = lwt_log_info "Bootstrap OK@." in + let*! () = lwt_debug "Bootstrap OK@." in let* () = Node.sync node in let rec loop n acc gacc msg = if n <= 0 then return (acc, gacc) @@ -233,10 +233,10 @@ module Simple = struct let end_time = Ptime_clock.now () in let span = Ptime.diff end_time start_time in let*! () = - lwt_log_info "Broadcast message in %a.@." Ptime.Span.pp span + lwt_debug "Broadcast message in %a.@." Ptime.Span.pp span in let* () = Node.sync node in - let*! () = lwt_log_info "Wait others.@." in + let*! () = lwt_debug "Wait others.@." in let* () = Node.sync node in let end_global_time = Ptime_clock.now () in let gspan = Ptime.diff end_global_time start_global_time in @@ -249,7 +249,7 @@ module Simple = struct 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 + lwt_debug "%s; %f; %f; %f; %f; %f" name (List.fold_left Float.max Float.min_float ftimes) @@ -259,8 +259,8 @@ module Simple = struct (stddev ftimes) in let*! () = close_all node.pool in - let*! () = lwt_log_info "All connections successfully closed.@." in - let*! () = lwt_log_notice "type; max; min; avg; median; std_dev" in + let*! () = lwt_debug "All connections successfully closed.@." in + let*! () = lwt_debug "type; max; min; avg; median; std_dev" in let*! () = print_stat times "broadcasting" in let*! () = print_stat gtimes "global" in @@ -268,7 +268,7 @@ module Simple = struct let node msgs (node : Node.t) = let open Lwt_result_syntax in - let*! () = lwt_log_info "Bootstrap OK@." in + let*! () = lwt_debug "Bootstrap OK@." in let* () = Node.sync node in let rec loop n msg = if n <= 0 then return_unit @@ -276,10 +276,10 @@ module Simple = struct match msg with | [] -> return_unit | ref_msg :: next -> - let*! () = lwt_log_info "Wait broadcaster.@." in + let*! () = lwt_debug "Wait broadcaster.@." in let* () = Node.sync node in let* _msgs = read_all node.pool ref_msg in - let*! () = lwt_log_info "Read message.@." in + let*! () = lwt_debug "Read message.@." in let* () = Node.sync node in loop (n - 1) (if no_check then next @ [ref_msg] else next) in @@ -288,7 +288,7 @@ module Simple = struct let run points = (* Messages are precomputed for every iteration and shared between processes to allow checking their content *) - log_notice "Running broadcast test on %d points.@." (List.length points) ; + debug "Running broadcast test on %d points.@." (List.length points) ; let msgs = message () in Node.detach_nodes (fun i -> if i = 0 then broadcaster msgs else node msgs) diff --git a/src/lib_p2p/test/test_p2p_io_scheduler.ml b/src/lib_p2p/test/test_p2p_io_scheduler.ml index 30277f19de3d..a4105c8cd372 100644 --- a/src/lib_p2p/test/test_p2p_io_scheduler.ml +++ b/src/lib_p2p/test/test_p2p_io_scheduler.ml @@ -124,10 +124,10 @@ let server ?(display_client_stat = true) ?max_download_speed ?read_queue_size () in Moving_average.on_update (P2p_io_scheduler.ma_state sched) (fun () -> - log_notice "Stat: %a" P2p_stat.pp (P2p_io_scheduler.global_stat sched) ; + debug "Stat: %a" P2p_stat.pp (P2p_io_scheduler.global_stat sched) ; if display_client_stat then P2p_io_scheduler.iter_connection sched (fun conn -> - log_notice + debug " client(%d) %a" (P2p_io_scheduler.id conn) P2p_stat.pp @@ -139,7 +139,7 @@ let server ?(display_client_stat = true) ?max_download_speed ?read_queue_size let* r = List.iter_ep P2p_io_scheduler.close conns in match r with | Ok () -> - log_notice "OK %a" P2p_stat.pp (P2p_io_scheduler.global_stat sched) ; + debug "OK %a" P2p_stat.pp (P2p_io_scheduler.global_stat sched) ; return_ok () | Error _ -> Lwt.fail Alcotest.Test_error @@ -188,7 +188,7 @@ let client ?max_upload_speed ?write_queue_size addr port time _n = | Error err -> Lwt.fail (Error err) | Ok () -> let stat = P2p_io_scheduler.stat conn in - let* () = lwt_log_notice "Client OK %a" P2p_stat.pp stat in + let* () = lwt_debug "Client OK %a" P2p_stat.pp stat in return_ok () (** Listens to address [addr] on port [port] to open a socket [main_socket]. diff --git a/src/lib_p2p/test/test_p2p_pool.ml b/src/lib_p2p/test/test_p2p_pool.ml index e9234a9395ed..0ed47c4db872 100644 --- a/src/lib_p2p/test/test_p2p_pool.ml +++ b/src/lib_p2p/test/test_p2p_pool.ml @@ -46,7 +46,7 @@ type error += Connect | Write | Read module Simple = struct let rec connect ~timeout connect_handler pool point = let open Lwt_syntax in - let* () = lwt_log_info "Connect to %a" P2p_point.Id.pp point in + let* () = lwt_debug "Connect to %a" P2p_point.Id.pp point in let* r = P2p_connect_handler.connect connect_handler point ~timeout in match r with | Error (Tezos_p2p_services.P2p_errors.Connected :: _) -> ( @@ -61,7 +61,7 @@ module Simple = struct | Timeout | Tezos_p2p_services.P2p_errors.Rejected _ ) as head_err) :: _) -> let* () = - lwt_log_info + lwt_debug "Connection to %a failed (%a)@." P2p_point.Id.pp point @@ -126,16 +126,16 @@ module Simple = struct node.pool node.points in - let*! () = lwt_log_info "Bootstrap OK@." in + let*! () = lwt_debug "Bootstrap OK@." in let* () = Node.sync node in let* () = write_all conns Node.Ping in - let*! () = lwt_log_info "Sent all messages.@." in + let*! () = lwt_debug "Sent all messages.@." in let* () = Node.sync node in let* () = read_all conns in - let*! () = lwt_log_info "Read all messages.@." in + let*! () = lwt_debug "Read all messages.@." in let* () = Node.sync node in let*! () = close_all conns in - let*! () = lwt_log_info "All connections successfully closed.@." in + let*! () = lwt_debug "All connections successfully closed.@." in return_unit let run points = Node.detach_nodes (fun _ -> node) points @@ -164,7 +164,7 @@ module Random_connections = struct let*! () = P2p_conn.disconnect conn in let*! () = decr rem ; - if !rem mod total = 0 then lwt_log_info "Remaining: %d.@." (!rem / total) + if !rem mod total = 0 then lwt_debug "Remaining: %d.@." (!rem / total) else Lwt.return_unit in if n > 1 then connect_random connect_handler pool total rem point (pred n) @@ -179,11 +179,11 @@ module Random_connections = struct let node repeat (node : Node.t) = let open Lwt_result_syntax in - let*! () = lwt_log_info "Begin random connections.@." in + let*! () = lwt_debug "Begin random connections.@." in let* () = connect_random_all node.connect_handler node.pool node.points repeat in - let*! () = lwt_log_info "Random connections OK.@." in + let*! () = lwt_debug "Random connections OK.@." in return_unit let run points repeat = Node.detach_nodes (fun _ -> node repeat) points @@ -203,7 +203,7 @@ module Garbled = struct true | Ok _ -> false | Error err -> - log_info "Unexpected error: %a@." pp_print_trace err ; + debug "Unexpected error: %a@." pp_print_trace err ; false let write_bad_all conns = @@ -257,7 +257,7 @@ module Overcrowded = struct let rec connect ?iter_count ~timeout connect_handler pool point = let open Lwt_syntax in let* () = - lwt_log_info + lwt_debug "Connect%a to %a@." (fun ppf iter_count -> Option.iter (Format.fprintf ppf " to peer %d") iter_count) @@ -279,7 +279,7 @@ module Overcrowded = struct | Timeout | Tezos_p2p_services.P2p_errors.Rejected _ ) as err); ] -> let* () = - lwt_log_info + lwt_debug "Connection to%a %a failed (%a)@." (fun ppf iter_count -> Option.iter (Format.fprintf ppf " peer %d") iter_count) @@ -341,7 +341,7 @@ module Overcrowded = struct match r with | Ok conn -> let*! () = - lwt_log_info + lwt_debug "Not good: connection accepted while it should be rejected (local: \ %d, remote: %d).@." port @@ -360,7 +360,7 @@ module Overcrowded = struct ] as err -> if legacy then let*! () = - lwt_log_info + lwt_debug "Good: client is rejected without point list (local: %d, remote: \ %d)@." port @@ -369,7 +369,7 @@ module Overcrowded = struct return_unit else let*! () = - lwt_log_info + lwt_debug "Not good: client is rejected without point list (local: %d, \ remote: %d)@." port @@ -382,7 +382,7 @@ module Overcrowded = struct {alternative_points = Some alternative_points; _}; ] -> let*! () = - lwt_log_info + lwt_debug "Good: client is rejected with point list (local: %d, remote: %d) \ @[%a@]@." port @@ -412,11 +412,11 @@ module Overcrowded = struct let unknowns, _known = client_knowledge pool all_points in let advert_succeed = unknowns = [] in if legacy || advert_succeed then - log_info + debug "Good: Advertisement%s worked as intended.@." (if legacy then " legacy" else "") else - log_info + debug "@[Not Good: advertisement failure. legacy %b. unknowns : @[%a@]\n\ \t knowns : @[%a@].@." legacy @@ -460,7 +460,7 @@ module Overcrowded = struct let* () = client_check node.pool node.points legacy in let* () = Node.sync node in (* sync 4 *) - let*! () = lwt_log_info "client closing.@." in + let*! () = lwt_debug "client closing.@." in return_unit (** Code of the target that should be overcrowded by all the clients. *) @@ -488,7 +488,7 @@ module Overcrowded = struct let _pool_log = Lwt_stream.iter (debug "p2p event %a" P2p_connection.P2p_event.pp) log in - let*! () = lwt_log_info "Target waiting@." in + let*! () = lwt_debug "Target waiting@." in let* () = Node.sync node in (* sync 2 *) let* () = Node.sync node in @@ -496,7 +496,7 @@ module Overcrowded = struct let* () = Node.sync node in (* sync 4 *) Lwt_watcher.shutdown stopper ; - let*! () = lwt_log_info "Target closing.@." in + let*! () = lwt_debug "Target closing.@." in return_unit let node i = if i = 0 then target else client false @@ -569,7 +569,7 @@ module No_common_network = struct let rec connect ?iter_count ~timeout connect_handler pool point = let open Lwt_syntax in let* () = - lwt_log_info + lwt_debug "Connect%a to @[%a@]@." (fun ppf iter_count -> Option.iter (Format.fprintf ppf " to peer %d") iter_count) @@ -591,7 +591,7 @@ module No_common_network = struct | Timeout | Tezos_p2p_services.P2p_errors.Rejected _ ) as err); ] -> let* () = - lwt_log_info + lwt_debug "Connection to%a %a failed (%a)@." (fun ppf iter_count -> Option.iter (Format.fprintf ppf " peer %d") iter_count) @@ -645,7 +645,7 @@ module No_common_network = struct match r with | Ok conn -> let*! () = - lwt_log_info + lwt_debug "Not good: connection accepted while it should be rejected.@." in let*! () = P2p_conn.disconnect conn in @@ -654,7 +654,7 @@ module No_common_network = struct [Tezos_p2p_services.P2p_errors.Rejected_no_common_protocol {announced}] -> let*! () = - lwt_log_info + lwt_debug "Good: Connection cannot be established,no common network with \ @[%a@].@." Network_version.pp @@ -674,16 +674,16 @@ module No_common_network = struct in let* () = Node.sync node in (* sync 2 *) - let*! () = lwt_log_info "client closing.@." in + let*! () = lwt_debug "client closing.@." in return_unit (** Code of the target that should be overcrowded by all the clients. *) let target (node : Node.t) = let open Lwt_result_syntax in - let*! () = lwt_log_info "Target waiting.@." in + let*! () = lwt_debug "Target waiting.@." in let* () = Node.sync node in (* sync 2 *) - let*! () = lwt_log_info "Target closing.@." in + let*! () = lwt_debug "Target closing.@." in return_unit let node i = if i = 0 then target else client -- GitLab From 3da25a3d62795800b0c7128f0546c5723cc7883e Mon Sep 17 00:00:00 2001 From: Pietro Abate Date: Wed, 22 Mar 2023 11:55:56 +0100 Subject: [PATCH 2/4] p2p: tests. update invocation headers --- src/lib_p2p/test/test_p2p_banned_peers.ml | 2 +- src/lib_p2p/test/test_p2p_broadcast.ml | 2 +- src/lib_p2p/test/test_p2p_buffer_reader.ml | 2 +- src/lib_p2p/test/test_p2p_connect_handler.ml | 2 +- src/lib_p2p/test/test_p2p_io_scheduler.ml | 2 +- src/lib_p2p/test/test_p2p_maintenance.ml | 2 +- src/lib_p2p/test/test_p2p_node.ml | 2 +- src/lib_p2p/test/test_p2p_peerset.ml | 2 +- src/lib_p2p/test/test_p2p_pool.ml | 2 +- src/lib_p2p/test/test_p2p_socket.ml | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/lib_p2p/test/test_p2p_banned_peers.ml b/src/lib_p2p/test/test_p2p_banned_peers.ml index 7bad6c360472..8b42dc6050a7 100644 --- a/src/lib_p2p/test/test_p2p_banned_peers.ml +++ b/src/lib_p2p/test/test_p2p_banned_peers.ml @@ -26,7 +26,7 @@ (** Testing ------- Component: P2P - Invocation: dune build @src/lib_p2p/test/runtest_p2p_banned_peers + Invocation: dune exec src/lib_p2p/test/main.exe Subject: On banning peers and usage of Access Control Lists (ACL) using sets and POSIX timestamps. *) diff --git a/src/lib_p2p/test/test_p2p_broadcast.ml b/src/lib_p2p/test/test_p2p_broadcast.ml index f24c814891cd..f3d6dedc3917 100644 --- a/src/lib_p2p/test/test_p2p_broadcast.ml +++ b/src/lib_p2p/test/test_p2p_broadcast.ml @@ -26,7 +26,7 @@ (** Testing ------- Component: P2P - Invocation: dune build @src/lib_p2p/test/runtest_p2p_broadcast + Invocation: dune exec src/lib_p2p/test/main.exe Dependencies: src/lib_p2p/test/process.ml Subject: Testing of the Broadcast Each test launches nodes in separate process, each node diff --git a/src/lib_p2p/test/test_p2p_buffer_reader.ml b/src/lib_p2p/test/test_p2p_buffer_reader.ml index 791c204101d2..02602ccd429a 100644 --- a/src/lib_p2p/test/test_p2p_buffer_reader.ml +++ b/src/lib_p2p/test/test_p2p_buffer_reader.ml @@ -27,7 +27,7 @@ (** Testing ------- Component: P2P - Invocation: dune build @src/lib_p2p/test/runtest_p2p_buffer_reader + Invocation: dune exec src/lib_p2p/test/main.exe Subject: Tests [P2p_buffer_reader] *) diff --git a/src/lib_p2p/test/test_p2p_connect_handler.ml b/src/lib_p2p/test/test_p2p_connect_handler.ml index bdb0c9018a97..fc1ea95d0a23 100644 --- a/src/lib_p2p/test/test_p2p_connect_handler.ml +++ b/src/lib_p2p/test/test_p2p_connect_handler.ml @@ -26,7 +26,7 @@ (** Testing ------- Component: P2P - Invocation: dune build @src/lib_p2p/test/runtest_p2p_connect_handler + Invocation: dune exec src/lib_p2p/test/main.exe Subject: Test that P2p_connect_handler is well-behaved *) diff --git a/src/lib_p2p/test/test_p2p_io_scheduler.ml b/src/lib_p2p/test/test_p2p_io_scheduler.ml index a4105c8cd372..f5763e277b98 100644 --- a/src/lib_p2p/test/test_p2p_io_scheduler.ml +++ b/src/lib_p2p/test/test_p2p_io_scheduler.ml @@ -27,7 +27,7 @@ (** Testing ------- Component: P2P - Invocation: dune build @src/lib_p2p/test/runtest_p2p_io_scheduler_ipv4 + Invocation: dune exec src/lib_p2p/test/main.exe Dependencies: src/lib_p2p/test/process.ml Subject: On I/O scheduling of client-server connections. *) diff --git a/src/lib_p2p/test/test_p2p_maintenance.ml b/src/lib_p2p/test/test_p2p_maintenance.ml index 0dbe587681ec..7aa1eb24ed22 100644 --- a/src/lib_p2p/test/test_p2p_maintenance.ml +++ b/src/lib_p2p/test/test_p2p_maintenance.ml @@ -26,7 +26,7 @@ (* Testing ------- Component: lib_p2p - Invocation: dune exec src/lib_p2p/test/test_p2p_maintenance.exe + Invocation: dune exec src/lib_p2p/test/main.exe Subject: Check maintenance mechanism. *) diff --git a/src/lib_p2p/test/test_p2p_node.ml b/src/lib_p2p/test/test_p2p_node.ml index a239d24a379a..f0a8e1d25dbc 100644 --- a/src/lib_p2p/test/test_p2p_node.ml +++ b/src/lib_p2p/test/test_p2p_node.ml @@ -26,7 +26,7 @@ (* Testing ------- Component: lib_p2p (test lib) - Invocation: dune exec src/lib_p2p/test/test_p2p_node.exe + Invocation: dune exec src/lib_p2p/test/main.exe Subject: Check p2p test framework. *) module Event = struct diff --git a/src/lib_p2p/test/test_p2p_peerset.ml b/src/lib_p2p/test/test_p2p_peerset.ml index 01648efd012f..622a6f9b164c 100644 --- a/src/lib_p2p/test/test_p2p_peerset.ml +++ b/src/lib_p2p/test/test_p2p_peerset.ml @@ -26,7 +26,7 @@ (** Testing ------- Component: P2P - Invocation: dune build @src/lib_p2p/test/runtest_p2p_peerset + Invocation: dune exec src/lib_p2p/test/main.exe Subject: On banning peers and usage of Access Control Lists (ACL) using FIFO caches filled with peers' ids. *) diff --git a/src/lib_p2p/test/test_p2p_pool.ml b/src/lib_p2p/test/test_p2p_pool.ml index 0ed47c4db872..623c3ad86641 100644 --- a/src/lib_p2p/test/test_p2p_pool.ml +++ b/src/lib_p2p/test/test_p2p_pool.ml @@ -27,7 +27,7 @@ (** Testing ------- Component: P2P - Invocation: dune build @src/lib_p2p/test/runtest_p2p_pool + Invocation: dune exec src/lib_p2p/test/main.exe Dependencies: src/lib_p2p/test/process.ml Subject: Testing of the Pool Each test launches nodes in separate process, each node diff --git a/src/lib_p2p/test/test_p2p_socket.ml b/src/lib_p2p/test/test_p2p_socket.ml index d91258bcce1d..fac121cc25c5 100644 --- a/src/lib_p2p/test/test_p2p_socket.ml +++ b/src/lib_p2p/test/test_p2p_socket.ml @@ -27,7 +27,7 @@ (** Testing ------- Component: P2P - Invocation: dune build @src/lib_p2p/test/runtest_p2p_socket_ipv4 + Invocation: dune exec src/lib_p2p/test/main.exe Dependencies: src/lib_p2p/test/process.ml Subject: Sockets and client-server communications. *) -- GitLab From bf03b3b30b518d615c0b34ed8a4ef00bc331c27f Mon Sep 17 00:00:00 2001 From: Pietro Abate Date: Mon, 13 Mar 2023 10:04:42 +0100 Subject: [PATCH 3/4] lib_p2p: port tests to alcotezt --- manifest/main.ml | 75 +-------------- opam/tezos-base-test-helpers.opam | 3 +- opam/tezos-event-logging-test-helpers.opam | 2 +- opam/tezos-p2p.opam | 4 +- src/lib_base/test_helpers/dune | 6 +- src/lib_event_logging/test_helpers/dune | 5 +- src/lib_p2p/test/dune | 106 ++++++--------------- tezt/lib_alcotezt/alcotest.ml | 13 ++- tezt/lib_alcotezt/alcotest.mli | 16 +++- tezt/tests/dune | 1 + 10 files changed, 73 insertions(+), 158 deletions(-) diff --git a/manifest/main.ml b/manifest/main.ml index aabde1cf43a2..6908ced49ff7 100644 --- a/manifest/main.ml +++ b/manifest/main.ml @@ -1019,7 +1019,7 @@ let octez_event_logging_test_helpers = octez_error_monad |> open_ |> open_ ~m:"TzLwtreslib"; octez_event_logging |> open_; octez_test_helpers |> open_; - alcotest; + alcotezt; ] ~js_compatible:true ~linkall:true @@ -1253,12 +1253,12 @@ let octez_base_test_helpers = octez_stdlib_unix; octez_event_logging_test_helpers; octez_test_helpers |> open_; - alcotest; - alcotest_lwt; + alcotezt; qcheck_alcotest; ] ~linkall:true ~bisect_ppx:No + ~release_status:Released let lazy_containers = public_lib @@ -1651,7 +1651,7 @@ let _octez_p2p_tezt = ] let _octez_p2p_tests = - tests + tezt [ "test_p2p_socket"; "test_p2p_pool"; @@ -1682,74 +1682,9 @@ let _octez_p2p_tests = octez_p2p_test_common |> open_; octez_p2p_services |> open_; tezt_tezos; - alcotest_lwt; + alcotezt; astring; ] - ~linkall:true - ~alias:"" - ~dune: - Dune.( - (* At the termination of the tests, or if an unexpected - error occurs, detached processes are terminated through a - SIGKILL. - See https://github.com/aantron/bisect_ppx/blob/master/doc/advanced.md#SIGTERM - See https://gitlab.com/tezos/tezos/-/issues/1946 *) - let run_exe prog args = - setenv "BISECT_SIGTERM" "yes" @@ run_exe prog args - in - [ - alias_rule - "runtest_p2p_pool" - ~locks:"/ports/49152-65535" - ~action:(run_exe "test_p2p_pool" []); - alias_rule - "runtest_p2p_broadcast" - ~locks:"/ports/49152-65535" - ~action:(run_exe "test_p2p_broadcast" []); - alias_rule - "runtest_p2p_io_scheduler" - ~locks:"/ports/49152-65535" - ~action:(run_exe "test_p2p_io_scheduler" []); - alias_rule - "runtest_p2p_socket" - ~locks:"/ports/49152-65535" - ~action:(run_exe "test_p2p_socket" []); - alias_rule - "runtest_p2p_node" - ~locks:"/ports/49152-65535" - ~action:(run_exe "test_p2p_node" []); - alias_rule - "runtest_p2p_peerset" - ~action:(run_exe "test_p2p_peerset" []); - alias_rule - "runtest_p2p_buffer_reader" - ~action:(run_exe "test_p2p_buffer_reader" []); - alias_rule - "runtest_p2p_banned_peers" - ~action:(run_exe "test_p2p_banned_peers" []); - alias_rule - "runtest_p2p_connect_handler" - ~action:(run_exe "test_p2p_connect_handler" []); - alias_rule - "runtest_p2p_maintenance" - ~action:(run_exe "test_p2p_maintenance" []); - alias_rule - "runtest" - ~package:"tezos-p2p" - ~alias_deps: - [ - "runtest_p2p_socket"; - "runtest_p2p_pool"; - "runtest_p2p_broadcast"; - "runtest_p2p_io_scheduler"; - "runtest_p2p_peerset"; - "runtest_p2p_buffer_reader"; - "runtest_p2p_banned_peers"; - "runtest_p2p_node"; - "runtest_p2p_connect_handler"; - "runtest_p2p_maintenance"; - ]; - ]) let octez_gossipsub = public_lib diff --git a/opam/tezos-base-test-helpers.opam b/opam/tezos-base-test-helpers.opam index b90aaa1d71d2..af84036676ee 100644 --- a/opam/tezos-base-test-helpers.opam +++ b/opam/tezos-base-test-helpers.opam @@ -14,8 +14,7 @@ depends: [ "tezos-stdlib-unix" "tezos-event-logging-test-helpers" "tezos-test-helpers" - "alcotest" { >= "1.5.0" } - "alcotest-lwt" { >= "1.5.0" } + "octez-alcotezt" "qcheck-alcotest" { >= "0.20" } ] build: [ diff --git a/opam/tezos-event-logging-test-helpers.opam b/opam/tezos-event-logging-test-helpers.opam index a7c013a54a95..da842a3c3272 100644 --- a/opam/tezos-event-logging-test-helpers.opam +++ b/opam/tezos-event-logging-test-helpers.opam @@ -16,7 +16,7 @@ depends: [ "tezos-error-monad" "tezos-event-logging" "tezos-test-helpers" - "alcotest" { >= "1.5.0" } + "octez-alcotezt" ] build: [ ["rm" "-r" "vendors"] diff --git a/opam/tezos-p2p.opam b/opam/tezos-p2p.opam index 50bafcf58fe4..ea08cbfb3638 100644 --- a/opam/tezos-p2p.opam +++ b/opam/tezos-p2p.opam @@ -20,13 +20,13 @@ depends: [ "tezos-p2p-services" "tezos-version" "prometheus" { >= "1.2" } + "tezt" { with-test & >= "3.0.0" } "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" } + "octez-alcotezt" {with-test} "astring" {with-test} - "tezt" { with-test & >= "3.0.0" } ] build: [ ["rm" "-r" "vendors"] diff --git a/src/lib_base/test_helpers/dune b/src/lib_base/test_helpers/dune index 05c6ec897486..7484d79600a7 100644 --- a/src/lib_base/test_helpers/dune +++ b/src/lib_base/test_helpers/dune @@ -10,11 +10,11 @@ tezos-stdlib-unix tezos-event-logging-test-helpers tezos-test-helpers - alcotest - alcotest-lwt + octez-alcotezt qcheck-alcotest) (library_flags (:standard -linkall)) (flags (:standard) -open Tezos_base.TzPervasives - -open Tezos_test_helpers)) + -open Tezos_test_helpers + -open Octez_alcotezt)) diff --git a/src/lib_event_logging/test_helpers/dune b/src/lib_event_logging/test_helpers/dune index a5049f113411..430c01590019 100644 --- a/src/lib_event_logging/test_helpers/dune +++ b/src/lib_event_logging/test_helpers/dune @@ -11,7 +11,7 @@ tezos-error-monad tezos-event-logging tezos-test-helpers - alcotest) + octez-alcotezt) (js_of_ocaml) (library_flags (:standard -linkall)) (flags @@ -19,4 +19,5 @@ -open Tezos_error_monad -open Tezos_error_monad.TzLwtreslib -open Tezos_event_logging - -open Tezos_test_helpers)) + -open Tezos_test_helpers + -open Octez_alcotezt)) diff --git a/src/lib_p2p/test/dune b/src/lib_p2p/test/dune index 35cfff9d0e3d..32c8bfc3c514 100644 --- a/src/lib_p2p/test/dune +++ b/src/lib_p2p/test/dune @@ -1,19 +1,11 @@ ; This file was automatically generated, do not edit. ; Edit file manifest/main.ml instead. -(executables - (names - test_p2p_socket - test_p2p_pool - test_p2p_broadcast - test_p2p_io_scheduler - test_p2p_peerset - test_p2p_buffer_reader - test_p2p_banned_peers - test_p2p_node - test_p2p_connect_handler - test_p2p_maintenance) +(library + (name src_lib_p2p_test_tezt_lib) + (instrumentation (backend bisect_ppx)) (libraries + tezt.core tezos-base tezos-base.unix tezos-stdlib-unix @@ -25,13 +17,13 @@ tezos_p2p_test_common tezos-p2p-services tezt-tezos - alcotest-lwt + octez-alcotezt astring) - (link_flags - (:standard) - (-linkall)) + (library_flags (:standard -linkall)) (flags (:standard) + -open Tezt_core + -open Tezt_core.Base -open Tezos_base.TzPervasives -open Tezos_stdlib_unix -open Tezos_stdlib @@ -40,66 +32,30 @@ -open Tezos_base_test_helpers -open Tezos_event_logging_test_helpers -open Tezos_p2p_test_common - -open Tezos_p2p_services)) - -(rule - (alias runtest_p2p_pool) - (locks /ports/49152-65535) - (action (setenv BISECT_SIGTERM yes (run %{exe:test_p2p_pool.exe})))) - -(rule - (alias runtest_p2p_broadcast) - (locks /ports/49152-65535) - (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})))) - -(rule - (alias runtest_p2p_socket) - (locks /ports/49152-65535) - (action (setenv BISECT_SIGTERM yes (run %{exe:test_p2p_socket.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_peerset) - (action (setenv BISECT_SIGTERM yes (run %{exe:test_p2p_peerset.exe})))) - -(rule - (alias runtest_p2p_buffer_reader) - (action (setenv BISECT_SIGTERM yes (run %{exe:test_p2p_buffer_reader.exe})))) - -(rule - (alias runtest_p2p_banned_peers) - (action (setenv BISECT_SIGTERM yes (run %{exe:test_p2p_banned_peers.exe})))) + -open Tezos_p2p_services + -open Octez_alcotezt) + (modules + test_p2p_socket + test_p2p_pool + test_p2p_broadcast + test_p2p_io_scheduler + test_p2p_peerset + test_p2p_buffer_reader + test_p2p_banned_peers + test_p2p_node + test_p2p_connect_handler + test_p2p_maintenance)) -(rule - (alias runtest_p2p_connect_handler) - (action - (setenv BISECT_SIGTERM yes (run %{exe:test_p2p_connect_handler.exe})))) +(executable + (name main) + (instrumentation (backend bisect_ppx --bisect-sigterm)) + (libraries + src_lib_p2p_test_tezt_lib + tezt) + (modules main)) -(rule - (alias runtest_p2p_maintenance) - (action (setenv BISECT_SIGTERM yes (run %{exe:test_p2p_maintenance.exe})))) +(rule (alias runtezt) (package tezos-p2p) (action (run %{dep:./main.exe}))) (rule - (alias runtest) - (package tezos-p2p) - (deps - (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) - (alias runtest_p2p_node) - (alias runtest_p2p_connect_handler) - (alias runtest_p2p_maintenance)) - (action (progn))) + (targets main.ml) + (action (with-stdout-to %{targets} (echo "let () = Tezt.Test.run ()")))) diff --git a/tezt/lib_alcotezt/alcotest.ml b/tezt/lib_alcotezt/alcotest.ml index 17654731c758..2d6df52874f2 100644 --- a/tezt/lib_alcotezt/alcotest.ml +++ b/tezt/lib_alcotezt/alcotest.ml @@ -55,7 +55,18 @@ let run library_name tests = body ()) ; Base.unit -type 'a testable = (module Tezt_core.Check.EQUALABLE with type t = 'a) +module type TESTABLE = sig + (** The type to test. *) + type t + + (** A way to pretty-print the value. *) + val pp : Format.formatter -> t -> unit + + (** Test for equality between two values. *) + val equal : t -> t -> bool +end + +type 'a testable = (module TESTABLE with type t = 'a) let testable (type a) (pp : Format.formatter -> a -> return) (eq : a -> a -> bool) : a testable = diff --git a/tezt/lib_alcotezt/alcotest.mli b/tezt/lib_alcotezt/alcotest.mli index d58207d50e7e..7b4efb682156 100644 --- a/tezt/lib_alcotezt/alcotest.mli +++ b/tezt/lib_alcotezt/alcotest.mli @@ -71,8 +71,19 @@ type 'a test = string * 'a test_case list The name of the test suite is used as the filename for the Tezt test. *) val run : string -> unit test list -> return +module type TESTABLE = sig + (** The type to test. *) + type t + + (** A way to pretty-print the value. *) + val pp : Format.formatter -> t -> unit + + (** Test for equality between two values. *) + val equal : t -> t -> bool +end + (** Values that can be tested with {!check}. *) -type 'a testable = (module Tezt_core.Check.EQUALABLE with type t = 'a) +type 'a testable = (module TESTABLE with type t = 'a) (** [testable pp eq] is a new {!type-testable} with the pretty-printer [pp] and equality [eq]. *) @@ -82,7 +93,8 @@ val testable : (** [pp t] is [t]'s pretty-printer. *) val pp : 'a testable -> Format.formatter -> 'a -> return -(** [of_pp pp] tests values which can be printed using [pp] and compared using {!Stdlib.compare} *) +(** [of_pp pp] tests values which can be printed using [pp] and compared using + {!Stdlib.compare} *) val of_pp : (Format.formatter -> 'a -> return) -> 'a testable (** [equal t] is [t]'s equality. *) diff --git a/tezt/tests/dune b/tezt/tests/dune index b95109ecf5f7..1fdb194fd37b 100644 --- a/tezt/tests/dune +++ b/tezt/tests/dune @@ -73,6 +73,7 @@ src_lib_protocol_environment_test_shell_context_tezt_lib src_lib_protocol_environment_test_tezt_lib src_lib_p2p_tezt_tezt_lib + src_lib_p2p_test_tezt_lib src_lib_mockup_test_tezt_lib src_lib_lwt_result_stdlib_test_tezt_lib src_lib_lazy_containers_test_tezt_lib -- GitLab From 805471f0fa9abbe65b63f2fedcf7bce7d28733bb Mon Sep 17 00:00:00 2001 From: Pietro Abate Date: Wed, 22 Mar 2023 11:50:19 +0100 Subject: [PATCH 4/4] p2p: use ::1 as ipv6 localhost --- src/lib_p2p/test/common/node.ml | 2 ++ src/lib_p2p/test/common/node.mli | 2 ++ src/lib_p2p/test/test_p2p_broadcast.ml | 2 +- src/lib_p2p/test/test_p2p_io_scheduler.ml | 2 +- src/lib_p2p/test/test_p2p_maintenance.ml | 2 +- src/lib_p2p/test/test_p2p_node.ml | 2 +- src/lib_p2p/test/test_p2p_pool.ml | 6 ++---- src/lib_p2p/test/test_p2p_socket.ml | 2 +- 8 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/lib_p2p/test/common/node.ml b/src/lib_p2p/test/common/node.ml index c07a8166d91f..ee42b2f2f03a 100644 --- a/src/lib_p2p/test/common/node.ml +++ b/src/lib_p2p/test/common/node.ml @@ -293,6 +293,8 @@ let select_nth_point n points = in loop n [] points +let default_ipv6_addr = Ipaddr.V6.localhost + let gen_points npoints ?port addr = match port with | Some port -> diff --git a/src/lib_p2p/test/common/node.mli b/src/lib_p2p/test/common/node.mli index 48e175051003..a5f33df32451 100644 --- a/src/lib_p2p/test/common/node.mli +++ b/src/lib_p2p/test/common/node.mli @@ -56,6 +56,8 @@ type t = { (** [sync node] join [node] to a synchronization barrier. *) val sync : t -> unit tzresult Lwt.t +val default_ipv6_addr : P2p_addr.t + (** [gen_points npoints ~port addr] generated [npoints] points. If [port] is not specified, it loops and generates points randomly until it finds [npoints] that are not currently used. diff --git a/src/lib_p2p/test/test_p2p_broadcast.ml b/src/lib_p2p/test/test_p2p_broadcast.ml index f3d6dedc3917..dc140c6741d3 100644 --- a/src/lib_p2p/test/test_p2p_broadcast.ml +++ b/src/lib_p2p/test/test_p2p_broadcast.ml @@ -315,7 +315,7 @@ let wrap addr n f = aux n f) let main () = - let addr = Ipaddr.V6.of_string_exn "::ffff:127.0.0.1" in + let addr = Node.default_ipv6_addr in Lwt_main.run @@ Alcotest_lwt.run "tezos-p2p-broadcast" diff --git a/src/lib_p2p/test/test_p2p_io_scheduler.ml b/src/lib_p2p/test/test_p2p_io_scheduler.ml index f5763e277b98..2a5a929b2638 100644 --- a/src/lib_p2p/test/test_p2p_io_scheduler.ml +++ b/src/lib_p2p/test/test_p2p_io_scheduler.ml @@ -251,7 +251,7 @@ 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 addr = Node.default_ipv6_addr in let port = Some (Tezt_tezos.Port.fresh ()) in let max_download_speed = 1048576 in let max_upload_speed = 262144 in diff --git a/src/lib_p2p/test/test_p2p_maintenance.ml b/src/lib_p2p/test/test_p2p_maintenance.ml index 7aa1eb24ed22..20e2719d747f 100644 --- a/src/lib_p2p/test/test_p2p_maintenance.ml +++ b/src/lib_p2p/test/test_p2p_maintenance.ml @@ -527,7 +527,7 @@ let main () = let () = Lwt_main.run (Tezos_base_unix.Internal_event_unix.init ~lwt_log_sink ()) in - let addr = Ipaddr.V6.of_string_exn "::ffff:127.0.0.1" in + let addr = Node.default_ipv6_addr in Lwt_main.run @@ Alcotest_lwt.run "tezos-p2p" diff --git a/src/lib_p2p/test/test_p2p_node.ml b/src/lib_p2p/test/test_p2p_node.ml index f0a8e1d25dbc..cde732282f27 100644 --- a/src/lib_p2p/test/test_p2p_node.ml +++ b/src/lib_p2p/test/test_p2p_node.ml @@ -104,7 +104,7 @@ let main () = in Lwt_main.run (Tezos_base_unix.Internal_event_unix.init ~lwt_log_sink ()) in - let addr = Ipaddr.V6.of_string_exn "::ffff:127.0.0.1" in + let addr = Node.default_ipv6_addr in Lwt_main.run @@ Alcotest_lwt.run "tezos-p2p" diff --git a/src/lib_p2p/test/test_p2p_pool.ml b/src/lib_p2p/test/test_p2p_pool.ml index 623c3ad86641..5b7afb253f19 100644 --- a/src/lib_p2p/test/test_p2p_pool.ml +++ b/src/lib_p2p/test/test_p2p_pool.ml @@ -728,11 +728,9 @@ let init_logs = let points = ref [] -let wrap ?addr ?port ?(clients = 10) n f = +let wrap ?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 addr = Node.default_ipv6_addr in gen_points addr ; Alcotest_lwt.test_case n `Quick (fun _ () -> let open Lwt_syntax in diff --git a/src/lib_p2p/test/test_p2p_socket.ml b/src/lib_p2p/test/test_p2p_socket.ml index fac121cc25c5..65b20bbfa63f 100644 --- a/src/lib_p2p/test/test_p2p_socket.ml +++ b/src/lib_p2p/test/test_p2p_socket.ml @@ -531,7 +531,7 @@ let wrap n f = Format.kasprintf Stdlib.failwith "%a" pp_print_trace error) let main () = - P2p_test_utils.addr := Ipaddr.V6.of_string_exn "::ffff:127.0.0.1" ; + P2p_test_utils.addr := Node.default_ipv6_addr ; Lwt_main.run @@ Alcotest_lwt.run "tezos-p2p" -- GitLab