[v4,5/7] test/ring: fix wrong size used in memcmp

Message ID 20200914143350.18650-6-feifei.wang2@arm.com (mailing list archive)
State Superseded, archived
Delegated to: David Marchand
Headers
Series fix wrong passed pointer and add check |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Feifei Wang Sept. 14, 2020, 2:33 p.m. UTC
  When using memcmp function to check data, the third param should be the
size of all elements, rather than the number of the elements.

Fixes: a9fe152363e2 ("test/ring: add custom element size functional tests")
Cc: honnappa.nagarahalli@arm.com
Cc: stable@dpdk.org

Signed-off-by: Feifei Wang <feifei.wang2@arm.com>
Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
Reviewed-by: Phil Yang <phil.yang@arm.com>
Reviewed-by: Dharmik Thakkar <dharmik.thakkar@arm.com>
Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
---
 app/test/test_ring.c | 49 +++++++++++++++++++++++++++-----------------
 1 file changed, 30 insertions(+), 19 deletions(-)
  

Patch

diff --git a/app/test/test_ring.c b/app/test/test_ring.c
index 811adc523..06498c337 100644
--- a/app/test/test_ring.c
+++ b/app/test/test_ring.c
@@ -444,7 +444,12 @@  test_ring_burst_bulk_tests1(unsigned int test_idx)
 			TEST_RING_VERIFY(rte_ring_empty(r));
 
 			/* check data */
-			TEST_RING_VERIFY(memcmp(src, dst, rsz) == 0);
+			if (esize[i] == -1) {
+				TEST_RING_VERIFY(memcmp(src, dst,
+					rsz * sizeof(void *)) == 0);
+			} else
+				TEST_RING_VERIFY(memcmp(src, dst,
+					rsz * esize[i]) == 0);
 		}
 
 		/* Free memory before test completed */
@@ -538,9 +543,11 @@  test_ring_burst_bulk_tests2(unsigned int test_idx)
 		cur_dst = test_ring_inc_ptr(cur_dst, esize[i], MAX_BULK);
 
 		/* check data */
-		if (memcmp(src, dst, cur_dst - dst)) {
-			rte_hexdump(stdout, "src", src, cur_src - src);
-			rte_hexdump(stdout, "dst", dst, cur_dst - dst);
+		if (memcmp(src, dst, RTE_PTR_DIFF(cur_dst, dst))) {
+			rte_hexdump(stdout, "src", src,
+					RTE_PTR_DIFF(cur_src, src));
+			rte_hexdump(stdout, "dst", dst,
+					RTE_PTR_DIFF(cur_dst, dst));
 			printf("data after dequeue is not the same\n");
 			goto fail;
 		}
@@ -614,9 +621,11 @@  test_ring_burst_bulk_tests3(unsigned int test_idx)
 		}
 
 		/* check data */
-		if (memcmp(src, dst, cur_dst - dst)) {
-			rte_hexdump(stdout, "src", src, cur_src - src);
-			rte_hexdump(stdout, "dst", dst, cur_dst - dst);
+		if (memcmp(src, dst, RTE_PTR_DIFF(cur_dst, dst))) {
+			rte_hexdump(stdout, "src", src,
+					RTE_PTR_DIFF(cur_src, src));
+			rte_hexdump(stdout, "dst", dst,
+					RTE_PTR_DIFF(cur_dst, dst));
 			printf("data after dequeue is not the same\n");
 			goto fail;
 		}
@@ -747,9 +756,11 @@  test_ring_burst_bulk_tests4(unsigned int test_idx)
 			goto fail;
 
 		/* check data */
-		if (memcmp(src, dst, cur_dst - dst)) {
-			rte_hexdump(stdout, "src", src, cur_src - src);
-			rte_hexdump(stdout, "dst", dst, cur_dst - dst);
+		if (memcmp(src, dst, RTE_PTR_DIFF(cur_dst, dst))) {
+			rte_hexdump(stdout, "src", src,
+					RTE_PTR_DIFF(cur_src, src));
+			rte_hexdump(stdout, "dst", dst,
+					RTE_PTR_DIFF(cur_dst, dst));
 			printf("data after dequeue is not the same\n");
 			goto fail;
 		}
@@ -857,9 +868,9 @@  test_ring_basic_ex(void)
 		}
 
 		/* check data */
-		if (memcmp(src, dst, cur_src - src)) {
-			rte_hexdump(stdout, "src", src, cur_src - src);
-			rte_hexdump(stdout, "dst", dst, cur_dst - dst);
+		if (memcmp(src, dst, RTE_PTR_DIFF(cur_src, src))) {
+			rte_hexdump(stdout, "src", src, RTE_PTR_DIFF(cur_src, src));
+			rte_hexdump(stdout, "dst", dst, RTE_PTR_DIFF(cur_dst, dst));
 			printf("data after dequeue is not the same\n");
 			goto fail_test;
 		}
@@ -909,9 +920,9 @@  test_ring_basic_ex(void)
 		cur_dst = test_ring_inc_ptr(cur_dst, esize[i], 2);
 
 		/* check data */
-		if (memcmp(src, dst, cur_dst - dst)) {
-			rte_hexdump(stdout, "src", src, cur_src - src);
-			rte_hexdump(stdout, "dst", dst, cur_dst - dst);
+		if (memcmp(src, dst, RTE_PTR_DIFF(cur_dst, dst))) {
+			rte_hexdump(stdout, "src", src, RTE_PTR_DIFF(cur_src, src));
+			rte_hexdump(stdout, "dst", dst, RTE_PTR_DIFF(cur_dst, dst));
 			printf("data after dequeue is not the same\n");
 			goto fail_test;
 		}
@@ -1047,9 +1058,9 @@  test_ring_with_exact_size(void)
 		}
 
 		/* check data */
-		if (memcmp(src, dst, cur_dst - dst)) {
-			rte_hexdump(stdout, "src", src, cur_src - src);
-			rte_hexdump(stdout, "dst", dst, cur_dst - dst);
+		if (memcmp(src, dst, RTE_PTR_DIFF(cur_dst, dst))) {
+			rte_hexdump(stdout, "src", src, RTE_PTR_DIFF(cur_src, src));
+			rte_hexdump(stdout, "dst", dst, RTE_PTR_DIFF(cur_dst, dst));
 			printf("data after dequeue is not the same\n");
 			goto test_fail;
 		}