diff mbox series

[1/3] app: use RTE_DIM to calculate array size

Message ID 20191028090907.824-1-pbhagavatula@marvell.com (mailing list archive)
State Superseded, archived
Delegated to: David Marchand
Headers show
Series [1/3] app: use RTE_DIM to calculate array size | expand

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-compilation success Compile Testing PASS
ci/Intel-compilation fail Compilation issues
ci/iol-mellanox-Performance success Performance Testing PASS

Commit Message

Pavan Nikhilesh Bhagavatula Oct. 28, 2019, 9:09 a.m. UTC
From: Pavan Nikhilesh <pbhagavatula@marvell.com>

Use RTE_DIM macro to calculate array size

Suggested-by: David Marchand <david.marchand@redhat.com>
Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
---
 app/test-pmd/cmdline.c            |  2 +-
 app/test-pmd/icmpecho.c           |  2 +-
 app/test-pmd/testpmd.c            |  2 +-
 app/test/test.c                   |  2 +-
 app/test/test_cmdline_etheraddr.c | 10 +++-------
 app/test/test_cmdline_ipaddr.c    | 18 ++++++------------
 app/test/test_cmdline_num.c       | 16 +++++-----------
 app/test/test_cmdline_portlist.c  | 12 ++++--------
 app/test/test_cmdline_string.c    | 15 +++++----------
 app/test/test_debug.c             |  2 +-
 app/test/test_eal_flags.c         |  9 ++++-----
 app/test/test_errno.c             |  4 ++--
 app/test/test_lpm.c               |  2 +-
 app/test/test_lpm6.c              |  2 +-
 app/test/test_lpm6_data.h         |  3 +--
 app/test/test_malloc.c            |  2 +-
 app/test/test_memcpy.c            |  2 +-
 app/test/test_memcpy_perf.c       |  4 ++--
 app/test/test_mp_secondary.c      |  3 +--
 app/test/test_pdump.c             |  3 +--
 app/test/test_pmd_ring_perf.c     |  2 +-
 app/test/test_ring_perf.c         |  6 +++---
 app/test/test_timer_secondary.c   |  3 +--
 23 files changed, 48 insertions(+), 78 deletions(-)

--
2.23.0

Comments

David Marchand Oct. 31, 2019, 9:20 a.m. UTC | #1
On Mon, Oct 28, 2019 at 10:09 AM <pbhagavatula@marvell.com> wrote:
>
> From: Pavan Nikhilesh <pbhagavatula@marvell.com>
>
> Use RTE_DIM macro to calculate array size
>
> Suggested-by: David Marchand <david.marchand@redhat.com>
> Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>

Ah, I was not expecting this soon.
Thanks for looking at it.


> ---
>  app/test-pmd/cmdline.c            |  2 +-
>  app/test-pmd/icmpecho.c           |  2 +-
>  app/test-pmd/testpmd.c            |  2 +-
>  app/test/test.c                   |  2 +-
>  app/test/test_cmdline_etheraddr.c | 10 +++-------
>  app/test/test_cmdline_ipaddr.c    | 18 ++++++------------
>  app/test/test_cmdline_num.c       | 16 +++++-----------
>  app/test/test_cmdline_portlist.c  | 12 ++++--------
>  app/test/test_cmdline_string.c    | 15 +++++----------
>  app/test/test_debug.c             |  2 +-
>  app/test/test_eal_flags.c         |  9 ++++-----
>  app/test/test_errno.c             |  4 ++--
>  app/test/test_lpm.c               |  2 +-
>  app/test/test_lpm6.c              |  2 +-
>  app/test/test_lpm6_data.h         |  3 +--
>  app/test/test_malloc.c            |  2 +-
>  app/test/test_memcpy.c            |  2 +-
>  app/test/test_memcpy_perf.c       |  4 ++--
>  app/test/test_mp_secondary.c      |  3 +--
>  app/test/test_pdump.c             |  3 +--
>  app/test/test_pmd_ring_perf.c     |  2 +-
>  app/test/test_ring_perf.c         |  6 +++---
>  app/test/test_timer_secondary.c   |  3 +--
>  23 files changed, 48 insertions(+), 78 deletions(-)
>
> diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
> index 447806991..c6b4e44a2 100644
> --- a/app/test-pmd/cmdline.c
> +++ b/app/test-pmd/cmdline.c
> @@ -5490,7 +5490,7 @@ cmd_show_bypass_config_parsed(void *parsed_result,
>                 "OS/board off",
>                 "power supply off",
>                 "timeout"};
> -       int num_events = (sizeof events) / (sizeof events[0]);
> +       int num_events = RTE_DIM(events);
>
>         /* Display the bypass mode.*/
>         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
> diff --git a/app/test-pmd/icmpecho.c b/app/test-pmd/icmpecho.c
> index 2d359c943..65aece16c 100644
> --- a/app/test-pmd/icmpecho.c
> +++ b/app/test-pmd/icmpecho.c
> @@ -188,7 +188,7 @@ ip_proto_name(uint16_t ip_proto)
>                 "PIM",        /**< Protocol Independent Mcast */
>         };
>
> -       if (ip_proto < sizeof(ip_proto_names) / sizeof(ip_proto_names[0]))
> +       if (ip_proto < RTE_DIM(ip_proto_names))
>                 return ip_proto_names[ip_proto];
>         switch (ip_proto) {
>  #ifdef IPPROTO_PGM
> diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
> index 38acbc58a..1103db629 100644
> --- a/app/test-pmd/testpmd.c
> +++ b/app/test-pmd/testpmd.c
> @@ -2584,7 +2584,7 @@ struct pmd_test_command {
>         cmd_func_t cmd_func;
>  };
>
> -#define PMD_TEST_CMD_NB (sizeof(pmd_test_menu) / sizeof(pmd_test_menu[0]))
> +#define PMD_TEST_CMD_NB RTE_DIM(pmd_test_menu)

This macro is just unused and can be shot.


>
>  /* Check the link status of all ports in up to 9s, and print them finally */
>  static void
> diff --git a/app/test/test.c b/app/test/test.c
> index cd7aaf645..784535095 100644
> --- a/app/test/test.c
> +++ b/app/test/test.c
> @@ -74,7 +74,7 @@ do_recursive_call(void)
>
>         if (recursive_call == NULL)
>                 return -1;
> -       for (i = 0; i < sizeof(actions)/sizeof(actions[0]); i++) {
> +       for (i = 0; i < RTE_DIM(actions); i++) {
>                 if (strcmp(actions[i].env_var, recursive_call) == 0)
>                         return (actions[i].action_fn)();
>         }
> diff --git a/app/test/test_cmdline_etheraddr.c b/app/test/test_cmdline_etheraddr.c
> index 9a32fd7ec..dc7fa944b 100644
> --- a/app/test/test_cmdline_etheraddr.c
> +++ b/app/test/test_cmdline_etheraddr.c
> @@ -72,13 +72,9 @@ const char * ether_addr_invalid_strs[] = {
>                 " ",
>  };
>
> -#define ETHERADDR_VALID_STRS_SIZE \
> -       (sizeof(ether_addr_valid_strs) / sizeof(ether_addr_valid_strs[0]))
> -#define ETHERADDR_GARBAGE_STRS_SIZE \
> -       (sizeof(ether_addr_garbage_strs) / sizeof(ether_addr_garbage_strs[0]))
> -#define ETHERADDR_INVALID_STRS_SIZE \
> -       (sizeof(ether_addr_invalid_strs) / sizeof(ether_addr_invalid_strs[0]))
> -
> +#define ETHERADDR_VALID_STRS_SIZE RTE_DIM(ether_addr_valid_strs)
> +#define ETHERADDR_GARBAGE_STRS_SIZE RTE_DIM(ether_addr_garbage_strs)
> +#define ETHERADDR_INVALID_STRS_SIZE RTE_DIM(ether_addr_invalid_strs)

Those macros are just used once, in loops enumerating the array entries.
Let's remove them and replace inline:

        /* test full strings */
-       for (i = 0; i < ETHERADDR_VALID_STRS_SIZE; i++) {
+       for (i = 0; i < RTE_DIM(ether_addr_valid_strs); i++) {

etc...

>
>
>  static int
> diff --git a/app/test/test_cmdline_ipaddr.c b/app/test/test_cmdline_ipaddr.c
> index 2d11ce936..0c90162e8 100644
> --- a/app/test/test_cmdline_ipaddr.c
> +++ b/app/test/test_cmdline_ipaddr.c
> @@ -264,18 +264,12 @@ const char * ipaddr_invalid_strs[] = {
>                 " ",
>  };
>
> -#define IPADDR_VALID_STRS_SIZE \
> -       (sizeof(ipaddr_valid_strs) / sizeof(ipaddr_valid_strs[0]))
> -#define IPADDR_GARBAGE_ADDR4_STRS_SIZE \
> -       (sizeof(ipaddr_garbage_addr4_strs) / sizeof(ipaddr_garbage_addr4_strs[0]))
> -#define IPADDR_GARBAGE_ADDR6_STRS_SIZE \
> -       (sizeof(ipaddr_garbage_addr6_strs) / sizeof(ipaddr_garbage_addr6_strs[0]))
> -#define IPADDR_GARBAGE_NETWORK4_STRS_SIZE \
> -       (sizeof(ipaddr_garbage_network4_strs) / sizeof(ipaddr_garbage_network4_strs[0]))
> -#define IPADDR_GARBAGE_NETWORK6_STRS_SIZE \
> -       (sizeof(ipaddr_garbage_network6_strs) / sizeof(ipaddr_garbage_network6_strs[0]))
> -#define IPADDR_INVALID_STRS_SIZE \
> -       (sizeof(ipaddr_invalid_strs) / sizeof(ipaddr_invalid_strs[0]))
> +#define IPADDR_VALID_STRS_SIZE RTE_DIM(ipaddr_valid_strs)
> +#define IPADDR_GARBAGE_ADDR4_STRS_SIZE RTE_DIM(ipaddr_garbage_addr4_strs)
> +#define IPADDR_GARBAGE_ADDR6_STRS_SIZE RTE_DIM(ipaddr_garbage_addr6_strs)
> +#define IPADDR_GARBAGE_NETWORK4_STRS_SIZE RTE_DIM(ipaddr_garbage_network4_strs)
> +#define IPADDR_GARBAGE_NETWORK6_STRS_SIZE RTE_DIM(ipaddr_garbage_network6_strs)
> +#define IPADDR_INVALID_STRS_SIZE RTE_DIM(ipaddr_invalid_strs)

Idem.

>
>  static void
>  dump_addr(cmdline_ipaddr_t addr)
> diff --git a/app/test/test_cmdline_num.c b/app/test/test_cmdline_num.c
> index 4c97caf3d..1daeaf840 100644
> --- a/app/test/test_cmdline_num.c
> +++ b/app/test/test_cmdline_num.c
> @@ -216,17 +216,11 @@ const char * num_invalid_strs[] = {
>                 "\0",
>  };
>
> -#define NUM_POSITIVE_STRS_SIZE \
> -       (sizeof(num_valid_positive_strs) / sizeof(num_valid_positive_strs[0]))
> -#define NUM_NEGATIVE_STRS_SIZE \
> -       (sizeof(num_valid_negative_strs) / sizeof(num_valid_negative_strs[0]))
> -#define NUM_POSITIVE_GARBAGE_STRS_SIZE \
> -       (sizeof(num_garbage_positive_strs) / sizeof(num_garbage_positive_strs[0]))
> -#define NUM_NEGATIVE_GARBAGE_STRS_SIZE \
> -       (sizeof(num_garbage_negative_strs) / sizeof(num_garbage_negative_strs[0]))
> -#define NUM_INVALID_STRS_SIZE \
> -       (sizeof(num_invalid_strs) / sizeof(num_invalid_strs[0]))
> -
> +#define NUM_POSITIVE_STRS_SIZE RTE_DIM(num_valid_positive_strs)
> +#define NUM_NEGATIVE_STRS_SIZE RTE_DIM(num_valid_negative_strs)
> +#define NUM_POSITIVE_GARBAGE_STRS_SIZE RTE_DIM(num_garbage_positive_strs)
> +#define NUM_NEGATIVE_GARBAGE_STRS_SIZE RTE_DIM(num_garbage_negative_strs)
> +#define NUM_INVALID_STRS_SIZE RTE_DIM(num_invalid_strs)

Idem.
Stopping at this, I suppose you get the idea for the rest of the changes.


Thanks.
Pavan Nikhilesh Bhagavatula Nov. 7, 2019, 2:12 a.m. UTC | #2
>On Mon, Oct 28, 2019 at 10:09 AM <pbhagavatula@marvell.com> wrote:
>>
>> From: Pavan Nikhilesh <pbhagavatula@marvell.com>
>>
>> Use RTE_DIM macro to calculate array size
>>
>> Suggested-by: David Marchand <david.marchand@redhat.com>
>> Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
>
>Ah, I was not expecting this soon.
>Thanks for looking at it.
>
>
>> ---
>>  app/test-pmd/cmdline.c            |  2 +-
>>  app/test-pmd/icmpecho.c           |  2 +-
>>  app/test-pmd/testpmd.c            |  2 +-
>>  app/test/test.c                   |  2 +-
>>  app/test/test_cmdline_etheraddr.c | 10 +++-------
>>  app/test/test_cmdline_ipaddr.c    | 18 ++++++------------
>>  app/test/test_cmdline_num.c       | 16 +++++-----------
>>  app/test/test_cmdline_portlist.c  | 12 ++++--------
>>  app/test/test_cmdline_string.c    | 15 +++++----------
>>  app/test/test_debug.c             |  2 +-
>>  app/test/test_eal_flags.c         |  9 ++++-----
>>  app/test/test_errno.c             |  4 ++--
>>  app/test/test_lpm.c               |  2 +-
>>  app/test/test_lpm6.c              |  2 +-
>>  app/test/test_lpm6_data.h         |  3 +--
>>  app/test/test_malloc.c            |  2 +-
>>  app/test/test_memcpy.c            |  2 +-
>>  app/test/test_memcpy_perf.c       |  4 ++--
>>  app/test/test_mp_secondary.c      |  3 +--
>>  app/test/test_pdump.c             |  3 +--
>>  app/test/test_pmd_ring_perf.c     |  2 +-
>>  app/test/test_ring_perf.c         |  6 +++---
>>  app/test/test_timer_secondary.c   |  3 +--
>>  23 files changed, 48 insertions(+), 78 deletions(-)
>>
>> diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
>> index 447806991..c6b4e44a2 100644
>> --- a/app/test-pmd/cmdline.c
>> +++ b/app/test-pmd/cmdline.c
>> @@ -5490,7 +5490,7 @@ cmd_show_bypass_config_parsed(void
>*parsed_result,
>>                 "OS/board off",
>>                 "power supply off",
>>                 "timeout"};
>> -       int num_events = (sizeof events) / (sizeof events[0]);
>> +       int num_events = RTE_DIM(events);
>>
>>         /* Display the bypass mode.*/
>>         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode)
>!= 0) {
>> diff --git a/app/test-pmd/icmpecho.c b/app/test-pmd/icmpecho.c
>> index 2d359c943..65aece16c 100644
>> --- a/app/test-pmd/icmpecho.c
>> +++ b/app/test-pmd/icmpecho.c
>> @@ -188,7 +188,7 @@ ip_proto_name(uint16_t ip_proto)
>>                 "PIM",        /**< Protocol Independent Mcast */
>>         };
>>
>> -       if (ip_proto < sizeof(ip_proto_names) /
>sizeof(ip_proto_names[0]))
>> +       if (ip_proto < RTE_DIM(ip_proto_names))
>>                 return ip_proto_names[ip_proto];
>>         switch (ip_proto) {
>>  #ifdef IPPROTO_PGM
>> diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
>> index 38acbc58a..1103db629 100644
>> --- a/app/test-pmd/testpmd.c
>> +++ b/app/test-pmd/testpmd.c
>> @@ -2584,7 +2584,7 @@ struct pmd_test_command {
>>         cmd_func_t cmd_func;
>>  };
>>
>> -#define PMD_TEST_CMD_NB (sizeof(pmd_test_menu) /
>sizeof(pmd_test_menu[0]))
>> +#define PMD_TEST_CMD_NB RTE_DIM(pmd_test_menu)
>
>This macro is just unused and can be shot.

Ill send v2 removing the macros. 

Thanks.
>
>
>>
>>  /* Check the link status of all ports in up to 9s, and print them finally
>*/
>>  static void
>> diff --git a/app/test/test.c b/app/test/test.c
>> index cd7aaf645..784535095 100644
>> --- a/app/test/test.c
>> +++ b/app/test/test.c
>> @@ -74,7 +74,7 @@ do_recursive_call(void)
>>
>>         if (recursive_call == NULL)
>>                 return -1;
>> -       for (i = 0; i < sizeof(actions)/sizeof(actions[0]); i++) {
>> +       for (i = 0; i < RTE_DIM(actions); i++) {
>>                 if (strcmp(actions[i].env_var, recursive_call) == 0)
>>                         return (actions[i].action_fn)();
>>         }
>> diff --git a/app/test/test_cmdline_etheraddr.c
>b/app/test/test_cmdline_etheraddr.c
>> index 9a32fd7ec..dc7fa944b 100644
>> --- a/app/test/test_cmdline_etheraddr.c
>> +++ b/app/test/test_cmdline_etheraddr.c
>> @@ -72,13 +72,9 @@ const char * ether_addr_invalid_strs[] = {
>>                 " ",
>>  };
>>
>> -#define ETHERADDR_VALID_STRS_SIZE \
>> -       (sizeof(ether_addr_valid_strs) /
>sizeof(ether_addr_valid_strs[0]))
>> -#define ETHERADDR_GARBAGE_STRS_SIZE \
>> -       (sizeof(ether_addr_garbage_strs) /
>sizeof(ether_addr_garbage_strs[0]))
>> -#define ETHERADDR_INVALID_STRS_SIZE \
>> -       (sizeof(ether_addr_invalid_strs) /
>sizeof(ether_addr_invalid_strs[0]))
>> -
>> +#define ETHERADDR_VALID_STRS_SIZE
>RTE_DIM(ether_addr_valid_strs)
>> +#define ETHERADDR_GARBAGE_STRS_SIZE
>RTE_DIM(ether_addr_garbage_strs)
>> +#define ETHERADDR_INVALID_STRS_SIZE
>RTE_DIM(ether_addr_invalid_strs)
>
>Those macros are just used once, in loops enumerating the array
>entries.
>Let's remove them and replace inline:
>
>        /* test full strings */
>-       for (i = 0; i < ETHERADDR_VALID_STRS_SIZE; i++) {
>+       for (i = 0; i < RTE_DIM(ether_addr_valid_strs); i++) {
>
>etc...
>
>>
>>
>>  static int
>> diff --git a/app/test/test_cmdline_ipaddr.c
>b/app/test/test_cmdline_ipaddr.c
>> index 2d11ce936..0c90162e8 100644
>> --- a/app/test/test_cmdline_ipaddr.c
>> +++ b/app/test/test_cmdline_ipaddr.c
>> @@ -264,18 +264,12 @@ const char * ipaddr_invalid_strs[] = {
>>                 " ",
>>  };
>>
>> -#define IPADDR_VALID_STRS_SIZE \
>> -       (sizeof(ipaddr_valid_strs) / sizeof(ipaddr_valid_strs[0]))
>> -#define IPADDR_GARBAGE_ADDR4_STRS_SIZE \
>> -       (sizeof(ipaddr_garbage_addr4_strs) /
>sizeof(ipaddr_garbage_addr4_strs[0]))
>> -#define IPADDR_GARBAGE_ADDR6_STRS_SIZE \
>> -       (sizeof(ipaddr_garbage_addr6_strs) /
>sizeof(ipaddr_garbage_addr6_strs[0]))
>> -#define IPADDR_GARBAGE_NETWORK4_STRS_SIZE \
>> -       (sizeof(ipaddr_garbage_network4_strs) /
>sizeof(ipaddr_garbage_network4_strs[0]))
>> -#define IPADDR_GARBAGE_NETWORK6_STRS_SIZE \
>> -       (sizeof(ipaddr_garbage_network6_strs) /
>sizeof(ipaddr_garbage_network6_strs[0]))
>> -#define IPADDR_INVALID_STRS_SIZE \
>> -       (sizeof(ipaddr_invalid_strs) / sizeof(ipaddr_invalid_strs[0]))
>> +#define IPADDR_VALID_STRS_SIZE RTE_DIM(ipaddr_valid_strs)
>> +#define IPADDR_GARBAGE_ADDR4_STRS_SIZE
>RTE_DIM(ipaddr_garbage_addr4_strs)
>> +#define IPADDR_GARBAGE_ADDR6_STRS_SIZE
>RTE_DIM(ipaddr_garbage_addr6_strs)
>> +#define IPADDR_GARBAGE_NETWORK4_STRS_SIZE
>RTE_DIM(ipaddr_garbage_network4_strs)
>> +#define IPADDR_GARBAGE_NETWORK6_STRS_SIZE
>RTE_DIM(ipaddr_garbage_network6_strs)
>> +#define IPADDR_INVALID_STRS_SIZE RTE_DIM(ipaddr_invalid_strs)
>
>Idem.
>
>>
>>  static void
>>  dump_addr(cmdline_ipaddr_t addr)
>> diff --git a/app/test/test_cmdline_num.c
>b/app/test/test_cmdline_num.c
>> index 4c97caf3d..1daeaf840 100644
>> --- a/app/test/test_cmdline_num.c
>> +++ b/app/test/test_cmdline_num.c
>> @@ -216,17 +216,11 @@ const char * num_invalid_strs[] = {
>>                 "\0",
>>  };
>>
>> -#define NUM_POSITIVE_STRS_SIZE \
>> -       (sizeof(num_valid_positive_strs) /
>sizeof(num_valid_positive_strs[0]))
>> -#define NUM_NEGATIVE_STRS_SIZE \
>> -       (sizeof(num_valid_negative_strs) /
>sizeof(num_valid_negative_strs[0]))
>> -#define NUM_POSITIVE_GARBAGE_STRS_SIZE \
>> -       (sizeof(num_garbage_positive_strs) /
>sizeof(num_garbage_positive_strs[0]))
>> -#define NUM_NEGATIVE_GARBAGE_STRS_SIZE \
>> -       (sizeof(num_garbage_negative_strs) /
>sizeof(num_garbage_negative_strs[0]))
>> -#define NUM_INVALID_STRS_SIZE \
>> -       (sizeof(num_invalid_strs) / sizeof(num_invalid_strs[0]))
>> -
>> +#define NUM_POSITIVE_STRS_SIZE
>RTE_DIM(num_valid_positive_strs)
>> +#define NUM_NEGATIVE_STRS_SIZE
>RTE_DIM(num_valid_negative_strs)
>> +#define NUM_POSITIVE_GARBAGE_STRS_SIZE
>RTE_DIM(num_garbage_positive_strs)
>> +#define NUM_NEGATIVE_GARBAGE_STRS_SIZE
>RTE_DIM(num_garbage_negative_strs)
>> +#define NUM_INVALID_STRS_SIZE RTE_DIM(num_invalid_strs)
>
>Idem.
>Stopping at this, I suppose you get the idea for the rest of the changes.
>
>
>Thanks.
>
>--
>David Marchand
diff mbox series

Patch

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 447806991..c6b4e44a2 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -5490,7 +5490,7 @@  cmd_show_bypass_config_parsed(void *parsed_result,
 		"OS/board off",
 		"power supply off",
 		"timeout"};
-	int num_events = (sizeof events) / (sizeof events[0]);
+	int num_events = RTE_DIM(events);

 	/* Display the bypass mode.*/
 	if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
diff --git a/app/test-pmd/icmpecho.c b/app/test-pmd/icmpecho.c
index 2d359c943..65aece16c 100644
--- a/app/test-pmd/icmpecho.c
+++ b/app/test-pmd/icmpecho.c
@@ -188,7 +188,7 @@  ip_proto_name(uint16_t ip_proto)
 		"PIM",        /**< Protocol Independent Mcast */
 	};

-	if (ip_proto < sizeof(ip_proto_names) / sizeof(ip_proto_names[0]))
+	if (ip_proto < RTE_DIM(ip_proto_names))
 		return ip_proto_names[ip_proto];
 	switch (ip_proto) {
 #ifdef IPPROTO_PGM
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 38acbc58a..1103db629 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -2584,7 +2584,7 @@  struct pmd_test_command {
 	cmd_func_t cmd_func;
 };

-#define PMD_TEST_CMD_NB (sizeof(pmd_test_menu) / sizeof(pmd_test_menu[0]))
+#define PMD_TEST_CMD_NB RTE_DIM(pmd_test_menu)

 /* Check the link status of all ports in up to 9s, and print them finally */
 static void
diff --git a/app/test/test.c b/app/test/test.c
index cd7aaf645..784535095 100644
--- a/app/test/test.c
+++ b/app/test/test.c
@@ -74,7 +74,7 @@  do_recursive_call(void)

 	if (recursive_call == NULL)
 		return -1;
-	for (i = 0; i < sizeof(actions)/sizeof(actions[0]); i++) {
+	for (i = 0; i < RTE_DIM(actions); i++) {
 		if (strcmp(actions[i].env_var, recursive_call) == 0)
 			return (actions[i].action_fn)();
 	}
diff --git a/app/test/test_cmdline_etheraddr.c b/app/test/test_cmdline_etheraddr.c
index 9a32fd7ec..dc7fa944b 100644
--- a/app/test/test_cmdline_etheraddr.c
+++ b/app/test/test_cmdline_etheraddr.c
@@ -72,13 +72,9 @@  const char * ether_addr_invalid_strs[] = {
 		" ",
 };

-#define ETHERADDR_VALID_STRS_SIZE \
-	(sizeof(ether_addr_valid_strs) / sizeof(ether_addr_valid_strs[0]))
-#define ETHERADDR_GARBAGE_STRS_SIZE \
-	(sizeof(ether_addr_garbage_strs) / sizeof(ether_addr_garbage_strs[0]))
-#define ETHERADDR_INVALID_STRS_SIZE \
-	(sizeof(ether_addr_invalid_strs) / sizeof(ether_addr_invalid_strs[0]))
-
+#define ETHERADDR_VALID_STRS_SIZE RTE_DIM(ether_addr_valid_strs)
+#define ETHERADDR_GARBAGE_STRS_SIZE RTE_DIM(ether_addr_garbage_strs)
+#define ETHERADDR_INVALID_STRS_SIZE RTE_DIM(ether_addr_invalid_strs)


 static int
diff --git a/app/test/test_cmdline_ipaddr.c b/app/test/test_cmdline_ipaddr.c
index 2d11ce936..0c90162e8 100644
--- a/app/test/test_cmdline_ipaddr.c
+++ b/app/test/test_cmdline_ipaddr.c
@@ -264,18 +264,12 @@  const char * ipaddr_invalid_strs[] = {
 		" ",
 };

-#define IPADDR_VALID_STRS_SIZE \
-	(sizeof(ipaddr_valid_strs) / sizeof(ipaddr_valid_strs[0]))
-#define IPADDR_GARBAGE_ADDR4_STRS_SIZE \
-	(sizeof(ipaddr_garbage_addr4_strs) / sizeof(ipaddr_garbage_addr4_strs[0]))
-#define IPADDR_GARBAGE_ADDR6_STRS_SIZE \
-	(sizeof(ipaddr_garbage_addr6_strs) / sizeof(ipaddr_garbage_addr6_strs[0]))
-#define IPADDR_GARBAGE_NETWORK4_STRS_SIZE \
-	(sizeof(ipaddr_garbage_network4_strs) / sizeof(ipaddr_garbage_network4_strs[0]))
-#define IPADDR_GARBAGE_NETWORK6_STRS_SIZE \
-	(sizeof(ipaddr_garbage_network6_strs) / sizeof(ipaddr_garbage_network6_strs[0]))
-#define IPADDR_INVALID_STRS_SIZE \
-	(sizeof(ipaddr_invalid_strs) / sizeof(ipaddr_invalid_strs[0]))
+#define IPADDR_VALID_STRS_SIZE RTE_DIM(ipaddr_valid_strs)
+#define IPADDR_GARBAGE_ADDR4_STRS_SIZE RTE_DIM(ipaddr_garbage_addr4_strs)
+#define IPADDR_GARBAGE_ADDR6_STRS_SIZE RTE_DIM(ipaddr_garbage_addr6_strs)
+#define IPADDR_GARBAGE_NETWORK4_STRS_SIZE RTE_DIM(ipaddr_garbage_network4_strs)
+#define IPADDR_GARBAGE_NETWORK6_STRS_SIZE RTE_DIM(ipaddr_garbage_network6_strs)
+#define IPADDR_INVALID_STRS_SIZE RTE_DIM(ipaddr_invalid_strs)

 static void
 dump_addr(cmdline_ipaddr_t addr)
diff --git a/app/test/test_cmdline_num.c b/app/test/test_cmdline_num.c
index 4c97caf3d..1daeaf840 100644
--- a/app/test/test_cmdline_num.c
+++ b/app/test/test_cmdline_num.c
@@ -216,17 +216,11 @@  const char * num_invalid_strs[] = {
 		"\0",
 };

-#define NUM_POSITIVE_STRS_SIZE \
-	(sizeof(num_valid_positive_strs) / sizeof(num_valid_positive_strs[0]))
-#define NUM_NEGATIVE_STRS_SIZE \
-	(sizeof(num_valid_negative_strs) / sizeof(num_valid_negative_strs[0]))
-#define NUM_POSITIVE_GARBAGE_STRS_SIZE \
-	(sizeof(num_garbage_positive_strs) / sizeof(num_garbage_positive_strs[0]))
-#define NUM_NEGATIVE_GARBAGE_STRS_SIZE \
-	(sizeof(num_garbage_negative_strs) / sizeof(num_garbage_negative_strs[0]))
-#define NUM_INVALID_STRS_SIZE \
-	(sizeof(num_invalid_strs) / sizeof(num_invalid_strs[0]))
-
+#define NUM_POSITIVE_STRS_SIZE RTE_DIM(num_valid_positive_strs)
+#define NUM_NEGATIVE_STRS_SIZE RTE_DIM(num_valid_negative_strs)
+#define NUM_POSITIVE_GARBAGE_STRS_SIZE RTE_DIM(num_garbage_positive_strs)
+#define NUM_NEGATIVE_GARBAGE_STRS_SIZE RTE_DIM(num_garbage_negative_strs)
+#define NUM_INVALID_STRS_SIZE RTE_DIM(num_invalid_strs)


 static int
diff --git a/app/test/test_cmdline_portlist.c b/app/test/test_cmdline_portlist.c
index 0dc6d0030..851215377 100644
--- a/app/test/test_cmdline_portlist.c
+++ b/app/test/test_cmdline_portlist.c
@@ -6,6 +6,7 @@ 
 #include <string.h>
 #include <inttypes.h>

+#include <rte_common.h>
 #include <cmdline_parse.h>
 #include <cmdline_parse_portlist.h>

@@ -88,14 +89,9 @@  const char * portlist_invalid_strs[] = {
 		"0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,2",
 };

-#define PORTLIST_VALID_STRS_SIZE \
-	(sizeof(portlist_valid_strs) / sizeof(portlist_valid_strs[0]))
-#define PORTLIST_GARBAGE_STRS_SIZE \
-	(sizeof(portlist_garbage_strs) / sizeof(portlist_garbage_strs[0]))
-#define PORTLIST_INVALID_STRS_SIZE \
-	(sizeof(portlist_invalid_strs) / sizeof(portlist_invalid_strs[0]))
-
-
+#define PORTLIST_VALID_STRS_SIZE RTE_DIM(portlist_valid_strs)
+#define PORTLIST_GARBAGE_STRS_SIZE RTE_DIM(portlist_garbage_strs)
+#define PORTLIST_INVALID_STRS_SIZE RTE_DIM(portlist_invalid_strs)


 /* test invalid parameters */
diff --git a/app/test/test_cmdline_string.c b/app/test/test_cmdline_string.c
index 0461a85bb..f6ac76fc9 100644
--- a/app/test/test_cmdline_string.c
+++ b/app/test/test_cmdline_string.c
@@ -115,16 +115,11 @@  const char * string_help_strs[] = {



-#define STRING_PARSE_STRS_SIZE \
-	(sizeof(string_parse_strs) / sizeof(string_parse_strs[0]))
-#define STRING_HELP_STRS_SIZE \
-	(sizeof(string_help_strs) / sizeof(string_help_strs[0]))
-#define STRING_ELT_STRS_SIZE \
-	(sizeof(string_elt_strs) / sizeof(string_elt_strs[0]))
-#define STRING_NB_STRS_SIZE \
-	(sizeof(string_nb_strs) / sizeof(string_nb_strs[0]))
-#define STRING_INVALID_STRS_SIZE \
-	(sizeof(string_invalid_strs) / sizeof(string_invalid_strs[0]))
+#define STRING_PARSE_STRS_SIZE RTE_DIM(string_parse_strs)
+#define STRING_HELP_STRS_SIZE RTE_DIM(string_help_strs)
+#define STRING_ELT_STRS_SIZE RTE_DIM(string_elt_strs)
+#define STRING_NB_STRS_SIZE RTE_DIM(string_nb_strs)
+#define STRING_INVALID_STRS_SIZE RTE_DIM(string_invalid_strs)

 #define SMALL_BUF 8

diff --git a/app/test/test_debug.c b/app/test/test_debug.c
index faf2cf557..25eab97e2 100644
--- a/app/test/test_debug.c
+++ b/app/test/test_debug.c
@@ -81,7 +81,7 @@  test_exit(void)
 {
 	int test_vals[] = { 0, 1, 2, 255, -1 };
 	unsigned i;
-	for (i = 0; i < sizeof(test_vals) / sizeof(test_vals[0]); i++){
+	for (i = 0; i < RTE_DIM(test_vals); i++) {
 		if (test_exit_val(test_vals[i]) < 0)
 			return -1;
 	}
diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c
index 5b2c0f5cd..4ee809e3d 100644
--- a/app/test/test_eal_flags.c
+++ b/app/test/test_eal_flags.c
@@ -36,8 +36,7 @@ 
 #define memtest1 "memtest1"
 #define memtest2 "memtest2"
 #define SOCKET_MEM_STRLEN (RTE_MAX_NUMA_NODES * 20)
-#define launch_proc(ARGV) process_dup(ARGV, \
-		sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
+#define launch_proc(ARGV) process_dup(ARGV, RTE_DIM(ARGV), __func__)

 enum hugepage_action {
 	HUGEPAGE_CHECK_EXISTS = 0,
@@ -268,7 +267,7 @@  test_whitelist_flag(void)
 			pci_whitelist, "08:00.1,type=normal",
 	};

-	for (i = 0; i < sizeof(wlinval) / sizeof(wlinval[0]); i++) {
+	for (i = 0; i < RTE_DIM(wlinval); i++) {
 		if (launch_proc(wlinval[i]) == 0) {
 			printf("Error - process did run ok with invalid "
 			    "whitelist parameter\n");
@@ -324,7 +323,7 @@  test_invalid_b_flag(void)

 	int i;

-	for (i = 0; i != sizeof (blinval) / sizeof (blinval[0]); i++) {
+	for (i = 0; i != RTE_DIM(blinval); i++) {
 		if (launch_proc(blinval[i]) == 0) {
 			printf("Error - process did run ok with invalid "
 			    "blacklist parameter\n");
@@ -425,7 +424,7 @@  test_invalid_r_flag(void)

 	int i;

-	for (i = 0; i != sizeof (rinval) / sizeof (rinval[0]); i++) {
+	for (i = 0; i != RTE_DIM(rinval); i++) {
 		if (launch_proc(rinval[i]) == 0) {
 			printf("Error - process did run ok with invalid "
 			    "-r (rank) parameter\n");
diff --git a/app/test/test_errno.c b/app/test/test_errno.c
index 7df8192d5..3ff0456a5 100644
--- a/app/test/test_errno.c
+++ b/app/test/test_errno.c
@@ -36,7 +36,7 @@  test_errno(void)
 	if (rte_errno != 0)
 		return -1;
 	/* check for standard errors we return the same as libc */
-	for (i = 0; i < sizeof(std_errs)/sizeof(std_errs[0]); i++){
+	for (i = 0; i < RTE_DIM(std_errs); i++) {
 		rte_retval = rte_strerror(std_errs[i]);
 		libc_retval = strerror(std_errs[i]);
 		printf("rte_strerror: '%s', strerror: '%s'\n",
@@ -47,7 +47,7 @@  test_errno(void)
 	/* for rte-specific errors ensure we return a different string
 	 * and that the string for libc is for an unknown error
 	 */
-	for (i = 0; i < sizeof(rte_errs)/sizeof(rte_errs[0]); i++){
+	for (i = 0; i < RTE_DIM(rte_errs); i++) {
 		rte_retval = rte_strerror(rte_errs[i]);
 		libc_retval = strerror(rte_errs[i]);
 		printf("rte_strerror: '%s', strerror: '%s'\n",
diff --git a/app/test/test_lpm.c b/app/test/test_lpm.c
index e969fe051..68f000c1b 100644
--- a/app/test/test_lpm.c
+++ b/app/test/test_lpm.c
@@ -64,7 +64,7 @@  rte_lpm_test tests[] = {
 	test18
 };

-#define NUM_LPM_TESTS (sizeof(tests)/sizeof(tests[0]))
+#define NUM_LPM_TESTS RTE_DIM(tests)
 #define MAX_DEPTH 32
 #define MAX_RULES 256
 #define NUMBER_TBL8S 256
diff --git a/app/test/test_lpm6.c b/app/test/test_lpm6.c
index 670aadb40..1df4af257 100644
--- a/app/test/test_lpm6.c
+++ b/app/test/test_lpm6.c
@@ -85,7 +85,7 @@  rte_lpm6_test tests6[] = {
 	test28,
 };

-#define NUM_LPM6_TESTS                (sizeof(tests6)/sizeof(tests6[0]))
+#define NUM_LPM6_TESTS                                   RTE_DIM(tests6)
 #define MAX_DEPTH                                                    128
 #define MAX_RULES                                                1000000
 #define NUMBER_TBL8S                                           (1 << 16)
diff --git a/app/test/test_lpm6_data.h b/app/test/test_lpm6_data.h
index 565138a31..c3894f730 100644
--- a/app/test/test_lpm6_data.h
+++ b/app/test/test_lpm6_data.h
@@ -1029,8 +1029,7 @@  static struct rules_tbl_entry large_route_table[] = {
 	{{234, 149, 220, 106, 0, 144, 214, 128, 35, 102, 0, 0, 0, 0, 0, 0}, 79, 106},
 };

-#define  NUM_ROUTE_ENTRIES \
-	(sizeof(large_route_table) / sizeof(large_route_table[0]))
+#define  NUM_ROUTE_ENTRIES RTE_DIM(large_route_table)

 #define  NUM_IPS_ENTRIES (NUM_ROUTE_ENTRIES * 100)

diff --git a/app/test/test_malloc.c b/app/test/test_malloc.c
index a16e28cc3..67a48ba38 100644
--- a/app/test/test_malloc.c
+++ b/app/test/test_malloc.c
@@ -255,7 +255,7 @@  test_str_to_size(void)
 			{"18446744073709551616", 0} /* ULLONG_MAX + 1 == out of range*/
 	};
 	unsigned i;
-	for (i = 0; i < sizeof(test_values)/sizeof(test_values[0]); i++)
+	for (i = 0; i < RTE_DIM(test_values); i++)
 		if (rte_str_to_size(test_values[i].str) != test_values[i].value)
 			return -1;
 	return 0;
diff --git a/app/test/test_memcpy.c b/app/test/test_memcpy.c
index 2c69ad964..53eb8433a 100644
--- a/app/test/test_memcpy.c
+++ b/app/test/test_memcpy.c
@@ -103,7 +103,7 @@  static int
 func_test(void)
 {
 	unsigned int off_src, off_dst, i;
-	unsigned int num_buf_sizes = sizeof(buf_sizes) / sizeof(buf_sizes[0]);
+	unsigned int num_buf_sizes = RTE_DIM(buf_sizes);
 	int ret;

 	for (off_src = 0; off_src < ALIGNMENT_UNIT; off_src++) {
diff --git a/app/test/test_memcpy_perf.c b/app/test/test_memcpy_perf.c
index 6f436f3ef..8f06b0f1e 100644
--- a/app/test/test_memcpy_perf.c
+++ b/app/test/test_memcpy_perf.c
@@ -250,7 +250,7 @@  perf_test_constant_unaligned(void)
 static inline void
 perf_test_variable_aligned(void)
 {
-	unsigned n = sizeof(buf_sizes) / sizeof(buf_sizes[0]);
+	unsigned n = RTE_DIM(buf_sizes);
 	unsigned i;
 	for (i = 0; i < n; i++) {
 		ALL_PERF_TESTS_FOR_SIZE((size_t)buf_sizes[i]);
@@ -261,7 +261,7 @@  perf_test_variable_aligned(void)
 static inline void
 perf_test_variable_unaligned(void)
 {
-	unsigned n = sizeof(buf_sizes) / sizeof(buf_sizes[0]);
+	unsigned n = RTE_DIM(buf_sizes);
 	unsigned i;
 	for (i = 0; i < n; i++) {
 		ALL_PERF_TESTS_FOR_SIZE_UNALIGNED((size_t)buf_sizes[i]);
diff --git a/app/test/test_mp_secondary.c b/app/test/test_mp_secondary.c
index 2ac33f781..ac15ddbf2 100644
--- a/app/test/test_mp_secondary.c
+++ b/app/test/test_mp_secondary.c
@@ -47,8 +47,7 @@ 

 #include "process.h"

-#define launch_proc(ARGV) process_dup(ARGV, \
-		sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
+#define launch_proc(ARGV) process_dup(ARGV, RTE_DIM(ARGV), __func__)

 /*
  * This function is called in the primary i.e. main test, to spawn off secondary
diff --git a/app/test/test_pdump.c b/app/test/test_pdump.c
index af206968b..ad183184c 100644
--- a/app/test/test_pdump.c
+++ b/app/test/test_pdump.c
@@ -18,8 +18,7 @@ 
 #include "process.h"
 #include "test_pdump.h"

-#define launch_p(ARGV) process_dup(ARGV, \
-		sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
+#define launch_p(ARGV) process_dup(ARGV, RTE_DIM(ARGV), __func__)

 struct rte_ring *ring_server;
 uint16_t portid;
diff --git a/app/test/test_pmd_ring_perf.c b/app/test/test_pmd_ring_perf.c
index 6318da18f..3b2ff9cb4 100644
--- a/app/test/test_pmd_ring_perf.c
+++ b/app/test/test_pmd_ring_perf.c
@@ -100,7 +100,7 @@  test_bulk_enqueue_dequeue(void)
 	unsigned sz, i = 0;
 	struct rte_mbuf *burst[MAX_BURST] = {0};

-	for (sz = 0; sz < sizeof(bulk_sizes)/sizeof(bulk_sizes[0]); sz++) {
+	for (sz = 0; sz < RTE_DIM(bulk_sizes); sz++) {
 		const uint64_t sc_start = rte_rdtsc();
 		for (i = 0; i < iterations; i++) {
 			rte_ring_sp_enqueue_bulk(r, (void *)burst,
diff --git a/app/test/test_ring_perf.c b/app/test/test_ring_perf.c
index 70ee46ffe..f2accb8a0 100644
--- a/app/test/test_ring_perf.c
+++ b/app/test/test_ring_perf.c
@@ -240,7 +240,7 @@  run_on_core_pair(struct lcore_pair *cores, struct rte_ring *r,
 {
 	struct thread_params param1 = {0}, param2 = {0};
 	unsigned i;
-	for (i = 0; i < sizeof(bulk_sizes)/sizeof(bulk_sizes[0]); i++) {
+	for (i = 0; i < RTE_DIM(bulk_sizes); i++) {
 		lcore_count = 0;
 		param1.size = param2.size = bulk_sizes[i];
 		param1.r = param2.r = r;
@@ -376,7 +376,7 @@  test_burst_enqueue_dequeue(struct rte_ring *r)
 	unsigned sz, i = 0;
 	void *burst[MAX_BURST] = {0};

-	for (sz = 0; sz < sizeof(bulk_sizes)/sizeof(bulk_sizes[0]); sz++) {
+	for (sz = 0; sz < RTE_DIM(bulk_sizes); sz++) {
 		const uint64_t sc_start = rte_rdtsc();
 		for (i = 0; i < iterations; i++) {
 			rte_ring_sp_enqueue_burst(r, burst,
@@ -414,7 +414,7 @@  test_bulk_enqueue_dequeue(struct rte_ring *r)
 	unsigned sz, i = 0;
 	void *burst[MAX_BURST] = {0};

-	for (sz = 0; sz < sizeof(bulk_sizes)/sizeof(bulk_sizes[0]); sz++) {
+	for (sz = 0; sz < RTE_DIM(bulk_sizes); sz++) {
 		const uint64_t sc_start = rte_rdtsc();
 		for (i = 0; i < iterations; i++) {
 			rte_ring_sp_enqueue_bulk(r, burst,
diff --git a/app/test/test_timer_secondary.c b/app/test/test_timer_secondary.c
index 790f18052..7a3bc873b 100644
--- a/app/test/test_timer_secondary.c
+++ b/app/test/test_timer_secondary.c
@@ -23,8 +23,7 @@ 
 #define TEST_INFO_MZ_NAME	"test_timer_info_mz"
 #define MSECPERSEC		1E3

-#define launch_proc(ARGV) \
-	process_dup(ARGV, sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
+#define launch_proc(ARGV) process_dup(ARGV, RTE_DIM(ARGV), __func__)

 struct test_info {
 	unsigned int mstr_lcore;