From c62c1c8b441b51b31a23db0a04163afc20343f5c Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Tue, 7 Feb 2023 23:32:43 +0100 Subject: [PATCH] Add assertions for interchange size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch adds assertions on the size of the Request, Reply and TrussedInterchange types so that we don’t accidentally increase it. --- src/pipe.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/pipe.rs b/src/pipe.rs index 8e0b3a2c09a..9dfe9875897 100644 --- a/src/pipe.rs +++ b/src/pipe.rs @@ -39,3 +39,36 @@ pub struct ServiceEndpoint { } // pub type ClientEndpoint = Requester; + +#[cfg(test)] +mod tests { + use super::TrussedInterchange; + use crate::api::{Reply, Request}; + use core::mem; + + // The following checks are used to ensure that we don’t accidentally increase the interchange + // size. Bumping the size is not a breaking change but should only be done if really + // necessary. + + const MAX_SIZE: usize = 2416; + + fn assert_size() { + let size = mem::size_of::(); + assert!(size <= MAX_SIZE, "{size}"); + } + + #[test] + fn test_request_size() { + assert_size::(); + } + + #[test] + fn test_reply_size() { + assert_size::(); + } + + #[test] + fn test_interchange_size() { + assert_size::(); + } +}