Skip to content

Commit

Permalink
fix aligment differences in x32 and x64
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuschen committed Oct 7, 2024
1 parent 10ae9fd commit 85c45ce
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
15 changes: 10 additions & 5 deletions iceoryx2/src/service/static_config/message_type_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ mod tests {
use super::*;
use iceoryx2_bb_testing::assert_that;

#[cfg(target_pointer_width = "32")]
const ALIGNMENT: usize = 4;
#[cfg(target_pointer_width = "64")]
const ALIGNMENT: usize = 8;

#[test]
fn test_from() {
#[repr(C)]
Expand All @@ -166,19 +171,19 @@ mod tests {
variant: TypeVariant::FixedSize,
type_name: "i32".to_string(),
size: 4,
alignment: 4,
alignment: 4, // i32 uses 4 bytes, so its aliment is always 4 no matter x32 or x64.
},
user_header: TypeDetail{
variant: TypeVariant::FixedSize,
type_name: "i64".to_string(),
size: 8,
alignment: 8,
alignment: ALIGNMENT,
},
payload: TypeDetail{
variant: TypeVariant::FixedSize,
type_name: "iceoryx2::service::static_config::message_type_details::tests::test_from::MyPayload".to_string(),
size: 16,
alignment: 8,
alignment: ALIGNMENT,
},
};
assert_that!(sut, eq expected);
Expand All @@ -189,7 +194,7 @@ mod tests {
variant: TypeVariant::FixedSize,
type_name: "i32".to_string(),
size: 4,
alignment: 4,
alignment: ALIGNMENT,
},
user_header: TypeDetail {
variant: TypeVariant::FixedSize,
Expand All @@ -201,7 +206,7 @@ mod tests {
variant: TypeVariant::Dynamic,
type_name: "&[iceoryx2::service::static_config::message_type_details::tests::test_from::MyPayload]".to_string(),
size: 16,
alignment: 8,
alignment: ALIGNMENT,
},
};
assert_that!(sut, eq expected);
Expand Down
9 changes: 7 additions & 2 deletions iceoryx2/tests/service_static_config_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ mod service_static_config_message_type_details {
use iceoryx2::service::static_config::message_type_details::{TypeDetail, TypeVariant};
use iceoryx2_bb_testing::assert_that;

#[cfg(target_pointer_width = "32")]
const ALIGNMENT: usize = 4;
#[cfg(target_pointer_width = "64")]
const ALIGNMENT: usize = 8;

#[test]
fn test_internal_new() {
#[repr(C)]
Expand All @@ -33,7 +38,7 @@ mod service_static_config_message_type_details {
variant: TypeVariant::FixedSize,
type_name: "i64".to_string(),
size: 8,
alignment: 8,
alignment: ALIGNMENT,
};

assert_that!(sut, eq expected);
Expand All @@ -44,7 +49,7 @@ mod service_static_config_message_type_details {
type_name: "iceoryx2::service::static_config::message_type_details::TypeDetail"
.to_string(),
size: 48,
alignment: 8,
alignment: ALIGNMENT,
};

assert_that!(sut, eq expected);
Expand Down

0 comments on commit 85c45ce

Please sign in to comment.