diff --git a/crates/irtt-client/src/client/tests/mod.rs b/crates/irtt-client/src/client/tests/mod.rs index 8212f33..7e4ebc8 100644 --- a/crates/irtt-client/src/client/tests/mod.rs +++ b/crates/irtt-client/src/client/tests/mod.rs @@ -1,8 +1,8 @@ use super::*; use crate::config::{NegotiationPolicy, DEFAULT_OPEN_TIMEOUTS}; use irtt_proto::{ - echo_packet_len, flags::FLAG_HMAC, flags::FLAG_OPEN, flags::FLAG_REPLY, verify_hmac, Clock, - ReceivedStats, StampAt, HMAC_SIZE, MAGIC, + flags::FLAG_HMAC, flags::FLAG_OPEN, flags::FLAG_REPLY, verify_hmac, Clock, ReceivedStats, + StampAt, HMAC_SIZE, MAGIC, }; use std::{thread, time::SystemTime}; diff --git a/crates/irtt-client/src/client/tests/probes_replies.rs b/crates/irtt-client/src/client/tests/probes_replies.rs index c4daaca..aa5a1f7 100644 --- a/crates/irtt-client/src/client/tests/probes_replies.rs +++ b/crates/irtt-client/src/client/tests/probes_replies.rs @@ -1,4 +1,5 @@ use super::*; +use support::echo_packet_len; #[cfg(not(all(target_os = "linux", feature = "ancillary")))] fn assert_packet_meta_unavailable(packet_meta: &crate::event::PacketMeta) { diff --git a/crates/irtt-client/src/client/tests/support.rs b/crates/irtt-client/src/client/tests/support.rs index 27a8f60..a3cddd7 100644 --- a/crates/irtt-client/src/client/tests/support.rs +++ b/crates/irtt-client/src/client/tests/support.rs @@ -1,7 +1,8 @@ use super::*; use irtt_proto::{ - compute_hmac_in_place, echo_packet_len, flags::FLAG_HMAC, flags::FLAG_OPEN, flags::FLAG_REPLY, - layout::PacketLayout, Clock, ReceivedStats, StampAt, HMAC_SIZE, MAGIC, + compute_hmac_in_place, echo_packet_len as checked_echo_packet_len, flags::FLAG_HMAC, + flags::FLAG_OPEN, flags::FLAG_REPLY, layout::PacketLayout, Clock, ReceivedStats, StampAt, + HMAC_SIZE, MAGIC, }; use std::{ net::UdpSocket, @@ -74,6 +75,11 @@ pub(super) fn open_reply( packet } +pub(crate) fn echo_packet_len(hmac: bool, params: &Params) -> usize { + checked_echo_packet_len(hmac, params) + .expect("test params must have a non-negative packet length") +} + pub(super) fn echo_reply_packet( token: u64, seq: u32, diff --git a/crates/irtt-client/src/managed/runner.rs b/crates/irtt-client/src/managed/runner.rs index 3fc15db..7df4742 100644 --- a/crates/irtt-client/src/managed/runner.rs +++ b/crates/irtt-client/src/managed/runner.rs @@ -311,8 +311,10 @@ mod tests { use super::*; use crate::{config::NegotiationPolicy, SubscriberOverflow}; use irtt_proto::{ - echo_packet_len, flags, flags::FLAG_OPEN, flags::FLAG_REPLY, layout::PacketLayout, Clock, - Params, ReceivedStats, StampAt, TimestampFields, MAGIC, PROTOCOL_VERSION, + echo_packet_len, + flags::{self, FLAG_OPEN, FLAG_REPLY}, + layout::PacketLayout, + Clock, Params, ReceivedStats, StampAt, TimestampFields, MAGIC, PROTOCOL_VERSION, }; use std::{ net::{SocketAddr, UdpSocket}, @@ -331,6 +333,11 @@ mod tests { } } + fn test_echo_packet_len(hmac: bool, params: &Params) -> usize { + echo_packet_len(hmac, params) + .expect("managed runner test params must have a non-negative packet length") + } + fn test_params(duration: Option, interval: Duration) -> Params { Params { protocol_version: PROTOCOL_VERSION, diff --git a/crates/irtt-client/tests/hmac.rs b/crates/irtt-client/tests/hmac.rs index 42ddcb4..d1534a9 100644 --- a/crates/irtt-client/tests/hmac.rs +++ b/crates/irtt-client/tests/hmac.rs @@ -13,6 +13,8 @@ use support::{ start_hmac_required_open_drop_server, BackendPeer, ServerObservation, TOKEN, }; +use crate::support::test_echo_packet_len; + #[test] fn hmac_open_success_negotiates_without_warnings() { let key = b"compat-secret".to_vec(); diff --git a/crates/irtt-client/tests/large_packets.rs b/crates/irtt-client/tests/large_packets.rs index aa06109..084ef65 100644 --- a/crates/irtt-client/tests/large_packets.rs +++ b/crates/irtt-client/tests/large_packets.rs @@ -1,10 +1,12 @@ mod support; use irtt_client::{Client, ClientConfig, ClientEvent, NegotiationPolicy}; -use irtt_proto::{echo_header_len, echo_packet_len, Params, TimestampFields}; +use irtt_proto::{echo_header_len, Params, TimestampFields}; use support::{config_for_params, default_params, run_one_probe, BackendPeer, ServerObservation}; +use crate::support::test_echo_packet_len; + fn params_with_length(length: i64) -> Params { Params { length, diff --git a/crates/irtt-client/tests/protocol_options.rs b/crates/irtt-client/tests/protocol_options.rs index 6e1c12b..19e6a8a 100644 --- a/crates/irtt-client/tests/protocol_options.rs +++ b/crates/irtt-client/tests/protocol_options.rs @@ -14,6 +14,8 @@ use support::{ ServerObservation, RECV_COUNT, RECV_WINDOW, TOKEN, }; +use crate::support::test_echo_packet_len; + struct ReplyView<'a> { seq: u32, rtt: &'a RttSample, diff --git a/crates/irtt-client/tests/server_fill.rs b/crates/irtt-client/tests/server_fill.rs index 021f29f..1dfdb08 100644 --- a/crates/irtt-client/tests/server_fill.rs +++ b/crates/irtt-client/tests/server_fill.rs @@ -1,13 +1,15 @@ mod support; use irtt_client::{Client, ClientConfig, ClientError, ClientEvent, NegotiationPolicy}; -use irtt_proto::{echo_packet_len, Params, TimestampFields}; +use irtt_proto::{Params, TimestampFields}; use support::{ config_for_params, default_params, run_one_probe, run_one_probe_with_config, server_fill, start_open_server, OneProbeRun, ServerObservation, }; +use crate::support::test_echo_packet_len; + fn open_observation_params(run: &OneProbeRun) -> &Params { match &run.observations[0] { ServerObservation::Open { params, .. } => params, diff --git a/crates/irtt-client/tests/support/mod.rs b/crates/irtt-client/tests/support/mod.rs index 92e5d0f..4620c51 100644 --- a/crates/irtt-client/tests/support/mod.rs +++ b/crates/irtt-client/tests/support/mod.rs @@ -520,6 +520,11 @@ fn open_reply(flags: u8, token: u64, params: &Params, hmac_key: Option<&[u8]>) - packet } +pub(super) fn test_echo_packet_len(hmac: bool, params: &Params) -> usize { + echo_packet_len(hmac, params) + .expect("managed runner test params must have a non-negative packet length") +} + fn echo_reply_packet( token: u64, seq: u32,