[v6,04/30] app/test: replace packed attributes

Message ID 1732668761-5556-5-git-send-email-andremue@linux.microsoft.com (mailing list archive)
State Superseded
Delegated to: David Marchand
Headers
Series fix packing of structs when building with MSVC |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Andre Muezerie Nov. 27, 2024, 12:52 a.m. UTC
MSVC struct packing is not compatible with GCC. Replace macro
__rte_packed with __rte_packed_begin to push existing pack value
and set packing to 1-byte and macro __rte_packed_end to restore
the pack value prior to the push.

Macro __rte_packed_end is deliberately utilized to trigger a
MSVC compiler warning if no existing packing has been pushed allowing
easy identification of locations where the __rte_packed_begin is
missing.

Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com>
---
 app/test/test_efd.c    | 3 ++-
 app/test/test_hash.c   | 3 ++-
 app/test/test_member.c | 3 ++-
 3 files changed, 6 insertions(+), 3 deletions(-)
  

Comments

Tyler Retzlaff Dec. 5, 2024, 12:21 a.m. UTC | #1
On Tue, Nov 26, 2024 at 04:52:15PM -0800, Andre Muezerie wrote:
> MSVC struct packing is not compatible with GCC. Replace macro
> __rte_packed with __rte_packed_begin to push existing pack value
> and set packing to 1-byte and macro __rte_packed_end to restore
> the pack value prior to the push.
> 
> Macro __rte_packed_end is deliberately utilized to trigger a
> MSVC compiler warning if no existing packing has been pushed allowing
> easy identification of locations where the __rte_packed_begin is
> missing.
> 
> Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com>
> ---

Reviewed-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
  

Patch

diff --git a/app/test/test_efd.c b/app/test/test_efd.c
index 1c0986b9bc..0c4444c764 100644
--- a/app/test/test_efd.c
+++ b/app/test/test_efd.c
@@ -33,13 +33,14 @@  test_efd(void)
 static unsigned int test_socket_id;
 
 /* 5-tuple key type */
+__rte_packed_begin
 struct flow_key {
 	uint32_t ip_src;
 	uint32_t ip_dst;
 	uint16_t port_src;
 	uint16_t port_dst;
 	uint8_t proto;
-} __rte_packed;
+} __rte_packed_end;
 
 RTE_LOG_REGISTER(efd_logtype_test, test.efd, INFO);
 
diff --git a/app/test/test_hash.c b/app/test/test_hash.c
index 65b9cad93c..6dbd038efd 100644
--- a/app/test/test_hash.c
+++ b/app/test/test_hash.c
@@ -79,13 +79,14 @@  static uint32_t hashtest_key_lens[] = {0, 2, 4, 5, 6, 7, 8, 10, 11, 15, 16, 21,
  * Should be packed to avoid holes with potentially
  * undefined content in the middle.
  */
+__rte_packed_begin
 struct flow_key {
 	uint32_t ip_src;
 	uint32_t ip_dst;
 	uint16_t port_src;
 	uint16_t port_dst;
 	uint32_t proto;
-} __rte_packed;
+} __rte_packed_end;
 
 /*
  * Hash function that always returns the same value, to easily test what
diff --git a/app/test/test_member.c b/app/test/test_member.c
index 5a4d2750db..72ea7c239a 100644
--- a/app/test/test_member.c
+++ b/app/test/test_member.c
@@ -32,13 +32,14 @@  struct rte_member_setsum *setsum_vbf;
 struct rte_member_setsum *setsum_sketch;
 
 /* 5-tuple key type */
+__rte_packed_begin
 struct flow_key {
 	uint32_t ip_src;
 	uint32_t ip_dst;
 	uint16_t port_src;
 	uint16_t port_dst;
 	uint8_t proto;
-} __rte_packed;
+} __rte_packed_end;
 
 /* Set ID Macros for multimatch test usage */
 #define M_MATCH_S 1	/* Not start with 0 since by default 0 means no match */