[v3,3/6] test/ring: validate the return value of enq/deq elements

Message ID 20200911161002.19816-4-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. 11, 2020, 4:09 p.m. UTC
  Validate the return value of single element enqueue/dequeue operation in
the test.

Suggested-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
Signed-off-by: Feifei Wang <feifei.wang2@arm.com>
Reviewed-by: Phil Yang <phil.yang@arm.com>
---
 app/test/test_ring.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)
  

Comments

Honnappa Nagarahalli Sept. 14, 2020, 4:29 a.m. UTC | #1
<snip>

> 
> Validate the return value of single element enqueue/dequeue operation in
> the test.
> 
> Suggested-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
> Signed-off-by: Feifei Wang <feifei.wang2@arm.com>
> Reviewed-by: Phil Yang <phil.yang@arm.com>
Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>

> ---
>  app/test/test_ring.c | 26 ++++++++++++++++++++++----
>  1 file changed, 22 insertions(+), 4 deletions(-)
> 
> diff --git a/app/test/test_ring.c b/app/test/test_ring.c index
> 6e48cc0b1..63d44d85e 100644
> --- a/app/test/test_ring.c
> +++ b/app/test/test_ring.c
> @@ -823,8 +823,13 @@ test_ring_basic_ex(void)
>  			rte_ring_free_count(rp));
> 
>  		for (j = 0; j < RING_SIZE; j++) {
> -			test_ring_enqueue(rp, cur_src, esize[i], 1,
> +			ret = test_ring_enqueue(rp, cur_src, esize[i], 1,
>  				TEST_RING_THREAD_DEF |
> TEST_RING_ELEM_SINGLE);
> +			if (ret != 0) {
> +				printf("%s: rte_ring_enqueue fails\n",
> +					__func__);
> +				goto fail_test;
> +			}
>  			cur_src = test_ring_inc_ptr(cur_src, esize[i], 1);
>  		}
> 
> @@ -835,8 +840,13 @@ test_ring_basic_ex(void)
>  		}
> 
>  		for (j = 0; j < RING_SIZE; j++) {
> -			test_ring_dequeue(rp, cur_dst, esize[i], 1,
> +			ret = test_ring_dequeue(rp, cur_dst, esize[i], 1,
>  				TEST_RING_THREAD_DEF |
> TEST_RING_ELEM_SINGLE);
> +			if (ret != 0) {
> +				printf("%s: rte_ring_dequeue fails\n",
> +					__func__);
> +				goto fail_test;
> +			}
>  			cur_dst = test_ring_inc_ptr(cur_dst, esize[i], 1);
>  		}
> 
> @@ -990,10 +1000,18 @@ test_ring_with_exact_size(void)
>  		 * than the standard ring. (16 vs 15 elements)
>  		 */
>  		for (j = 0; j < ring_sz - 1; j++) {
> -			test_ring_enqueue(std_r, cur_src, esize[i], 1,
> +			ret = test_ring_enqueue(std_r, cur_src, esize[i], 1,
>  				TEST_RING_THREAD_DEF |
> TEST_RING_ELEM_SINGLE);
> -			test_ring_enqueue(exact_sz_r, cur_src, esize[i], 1,
> +			if (ret != 0) {
> +				printf("%s: error, enqueue failed\n",
> __func__);
> +				goto test_fail;
> +			}
> +			ret = test_ring_enqueue(exact_sz_r, cur_src, esize[i], 1,
>  				TEST_RING_THREAD_DEF |
> TEST_RING_ELEM_SINGLE);
> +			if (ret != 0) {
> +				printf("%s: error, enqueue failed\n",
> __func__);
> +				goto test_fail;
> +			}
>  			cur_src = test_ring_inc_ptr(cur_src, esize[i], 1);
>  		}
>  		ret = test_ring_enqueue(std_r, cur_src, esize[i], 1,
> --
> 2.17.1
  

Patch

diff --git a/app/test/test_ring.c b/app/test/test_ring.c
index 6e48cc0b1..63d44d85e 100644
--- a/app/test/test_ring.c
+++ b/app/test/test_ring.c
@@ -823,8 +823,13 @@  test_ring_basic_ex(void)
 			rte_ring_free_count(rp));
 
 		for (j = 0; j < RING_SIZE; j++) {
-			test_ring_enqueue(rp, cur_src, esize[i], 1,
+			ret = test_ring_enqueue(rp, cur_src, esize[i], 1,
 				TEST_RING_THREAD_DEF | TEST_RING_ELEM_SINGLE);
+			if (ret != 0) {
+				printf("%s: rte_ring_enqueue fails\n",
+					__func__);
+				goto fail_test;
+			}
 			cur_src = test_ring_inc_ptr(cur_src, esize[i], 1);
 		}
 
@@ -835,8 +840,13 @@  test_ring_basic_ex(void)
 		}
 
 		for (j = 0; j < RING_SIZE; j++) {
-			test_ring_dequeue(rp, cur_dst, esize[i], 1,
+			ret = test_ring_dequeue(rp, cur_dst, esize[i], 1,
 				TEST_RING_THREAD_DEF | TEST_RING_ELEM_SINGLE);
+			if (ret != 0) {
+				printf("%s: rte_ring_dequeue fails\n",
+					__func__);
+				goto fail_test;
+			}
 			cur_dst = test_ring_inc_ptr(cur_dst, esize[i], 1);
 		}
 
@@ -990,10 +1000,18 @@  test_ring_with_exact_size(void)
 		 * than the standard ring. (16 vs 15 elements)
 		 */
 		for (j = 0; j < ring_sz - 1; j++) {
-			test_ring_enqueue(std_r, cur_src, esize[i], 1,
+			ret = test_ring_enqueue(std_r, cur_src, esize[i], 1,
 				TEST_RING_THREAD_DEF | TEST_RING_ELEM_SINGLE);
-			test_ring_enqueue(exact_sz_r, cur_src, esize[i], 1,
+			if (ret != 0) {
+				printf("%s: error, enqueue failed\n", __func__);
+				goto test_fail;
+			}
+			ret = test_ring_enqueue(exact_sz_r, cur_src, esize[i], 1,
 				TEST_RING_THREAD_DEF | TEST_RING_ELEM_SINGLE);
+			if (ret != 0) {
+				printf("%s: error, enqueue failed\n", __func__);
+				goto test_fail;
+			}
 			cur_src = test_ring_inc_ptr(cur_src, esize[i], 1);
 		}
 		ret = test_ring_enqueue(std_r, cur_src, esize[i], 1,