diff mbox series

[v2,1/2] app/test: use RTE_DIM instead of ARRAY_SIZE

Message ID 20191017121001.2546-1-pbhagavatula@marvell.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers show
Series [v2,1/2] app/test: use RTE_DIM instead of ARRAY_SIZE | expand

Checks

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

Commit Message

Pavan Nikhilesh Bhagavatula Oct. 17, 2019, 12:09 p.m. UTC
From: Pavan Nikhilesh <pbhagavatula@marvell.com>

Use RTE_DIM instead of re-defining ARRAY_SIZE.

Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
Acked-by: Gage Eads <gage.eads@intel.com>
---
 v2 Changes:
 ----------
 - Drop [2/3] drivers: use RTE_DIM instead of ARRAY_SIZE as the same sources
 might be reused outside DPDK.

 app/test/test_cryptodev_asym.c |  8 ++------
 app/test/test_metrics.c        | 11 +++++------
 app/test/test_stack_perf.c     |  8 +++-----
 3 files changed, 10 insertions(+), 17 deletions(-)

--
2.17.1

Comments

David Marchand Oct. 27, 2019, 1:35 p.m. UTC | #1
On Thu, Oct 17, 2019 at 2:10 PM <pbhagavatula@marvell.com> wrote:
>
> From: Pavan Nikhilesh <pbhagavatula@marvell.com>
>
> Use RTE_DIM instead of re-defining ARRAY_SIZE.
>
> Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
> Acked-by: Gage Eads <gage.eads@intel.com>

Applied, thanks.

I had a similar patch in store :-).

If you want to continue on this topic, look at other files in app/test:
$ git grep -l sizeof.*sizeof.*\\[ app/test
app/test/test.c
app/test/test_cmdline_etheraddr.c
app/test/test_cmdline_ipaddr.c
app/test/test_cmdline_num.c
app/test/test_cmdline_portlist.c
app/test/test_cmdline_string.c
app/test/test_debug.c
app/test/test_eal_flags.c
app/test/test_errno.c
app/test/test_lpm.c
app/test/test_lpm6.c
app/test/test_lpm6_data.h
app/test/test_malloc.c
app/test/test_memcpy.c
app/test/test_memcpy_perf.c
app/test/test_mp_secondary.c
app/test/test_pdump.c
app/test/test_pmd_ring_perf.c
app/test/test_ring_perf.c
app/test/test_timer_secondary.c
diff mbox series

Patch

diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c
index e8177e73a..7ff631600 100644
--- a/app/test/test_cryptodev_asym.c
+++ b/app/test/test_cryptodev_asym.c
@@ -26,10 +26,6 @@ 
 #define TEST_NUM_BUFS 10
 #define TEST_NUM_SESSIONS 4

-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
-
 #ifndef TEST_DATA_SIZE
 	#define TEST_DATA_SIZE 4096
 #endif
@@ -473,7 +469,7 @@  load_test_vectors(void)
 {
 	uint32_t i = 0, v_size = 0;
 	/* Load MODEX vector*/
-	v_size = ARRAY_SIZE(modex_test_case);
+	v_size = RTE_DIM(modex_test_case);
 	for (i = 0; i < v_size; i++) {
 		if (test_vector.size >= (TEST_VECTOR_SIZE)) {
 			RTE_LOG(DEBUG, USER1,
@@ -484,7 +480,7 @@  load_test_vectors(void)
 		test_vector.size++;
 	}
 	/* Load MODINV vector*/
-	v_size = ARRAY_SIZE(modinv_test_case);
+	v_size = RTE_DIM(modinv_test_case);
 	for (i = 0; i < v_size; i++) {
 		if (test_vector.size >= (TEST_VECTOR_SIZE)) {
 			RTE_LOG(DEBUG, USER1,
diff --git a/app/test/test_metrics.c b/app/test/test_metrics.c
index 78b3936ee..e736019ae 100644
--- a/app/test/test_metrics.c
+++ b/app/test/test_metrics.c
@@ -12,7 +12,6 @@ 

 #include "test.h"

-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 #define	REG_METRIC_COUNT	6
 #define	METRIC_LESSER_COUNT	3
 #define	KEY	1
@@ -106,7 +105,7 @@  test_metrics_reg_names(void)
 		};

 	/* Success Test: valid array and count size */
-	err = rte_metrics_reg_names(&mnames[0], ARRAY_SIZE(mnames));
+	err = rte_metrics_reg_names(&mnames[0], RTE_DIM(mnames));
 	TEST_ASSERT(err >= 0, "%s, %d", __func__, __LINE__);

 	return TEST_SUCCESS;
@@ -167,20 +166,20 @@  test_metrics_update_values(void)

 	/* Failed Test: Invalid count size */
 	err = rte_metrics_update_values(RTE_METRICS_GLOBAL,
-			 KEY, &value[0], ARRAY_SIZE(value));
+			 KEY, &value[0], RTE_DIM(value));
 	TEST_ASSERT(err < 0, "%s, %d", __func__, __LINE__);

 	/* Failed Test: Invalid port_id(lower value) and valid data */
-	err = rte_metrics_update_values(-2, KEY, &value[0], ARRAY_SIZE(value));
+	err = rte_metrics_update_values(-2, KEY, &value[0], RTE_DIM(value));
 	TEST_ASSERT(err == -EINVAL, "%s, %d", __func__, __LINE__);

 	/* Failed Test: Invalid port_id(higher value) and valid data */
-	err = rte_metrics_update_values(39, 1, &value[0], ARRAY_SIZE(value));
+	err = rte_metrics_update_values(39, 1, &value[0], RTE_DIM(value));
 	TEST_ASSERT(err == -EINVAL, "%s, %d", __func__, __LINE__);

 	/* Failed Test: Invalid array */
 	err = rte_metrics_update_values(RTE_METRICS_GLOBAL,
-			 KEY, NULL, ARRAY_SIZE(value));
+			 KEY, NULL, RTE_DIM(value));
 	TEST_ASSERT(err == -EINVAL, "%s, %d", __func__, __LINE__);

 	return TEST_SUCCESS;
diff --git a/app/test/test_stack_perf.c b/app/test/test_stack_perf.c
index 70561fecd..3ab7267b1 100644
--- a/app/test/test_stack_perf.c
+++ b/app/test/test_stack_perf.c
@@ -18,8 +18,6 @@ 
 #define MAX_BURST 32
 #define STACK_SIZE (RTE_MAX_LCORE * MAX_BURST)

-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-
 /*
  * Push/pop bulk sizes, marked volatile so they aren't treated as compile-time
  * constants.
@@ -176,7 +174,7 @@  run_on_core_pair(struct lcore_pair *cores, struct rte_stack *s,
 	struct thread_args args[2];
 	unsigned int i;

-	for (i = 0; i < ARRAY_SIZE(bulk_sizes); i++) {
+	for (i = 0; i < RTE_DIM(bulk_sizes); i++) {
 		rte_atomic32_set(&lcore_barrier, 2);

 		args[0].sz = args[1].sz = bulk_sizes[i];
@@ -205,7 +203,7 @@  run_on_n_cores(struct rte_stack *s, lcore_function_t fn, int n)
 	struct thread_args args[RTE_MAX_LCORE];
 	unsigned int i;

-	for (i = 0; i < ARRAY_SIZE(bulk_sizes); i++) {
+	for (i = 0; i < RTE_DIM(bulk_sizes); i++) {
 		unsigned int lcore_id;
 		int cnt = 0;
 		double avg;
@@ -280,7 +278,7 @@  test_bulk_push_pop(struct rte_stack *s)
 	void *objs[MAX_BURST];
 	unsigned int sz, i;

-	for (sz = 0; sz < ARRAY_SIZE(bulk_sizes); sz++) {
+	for (sz = 0; sz < RTE_DIM(bulk_sizes); sz++) {
 		uint64_t start = rte_rdtsc();

 		for (i = 0; i < iterations; i++) {