Skip to contentSkip to conversation

test/bitops: check worker lcore availability

PATCH Superseded David Marchand 4 participants 8 messages Oct 11, 2024 – Oct 30, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 test/bitops: check worker lcore availability

Coverity is not able to understand that having 2 lcores means that rte_get_next_lcore(-1, 0, 1) can't return RTE_MAX_LCORE. Add an assert.

Coverity issue: 445382, 445383, 445384, 445387, 445389, 445391

Fixes 35326b61aecb ("bitops: add atomic bit operations in new API")

---
Note:
- a better fix would be to check lcore id validity in the EAL launch API, but it requires inspecting all functions and it could result in some API change, so sending this as a simple fix for now,

---
 app/test/test_bitops.c | 3 +++
 1 file changed, 3 insertions(+)
app/test/test_bitops.c +3 -0
index 4200073ae4..4ed54709fb 100644
@@ -159,6 +159,7 @@ test_bit_atomic_parallel_assign ## size(void) \
 		return TEST_SKIPPED; \
 	} \
 	worker_lcore_id = rte_get_next_lcore(-1, 1, 0); \
+	TEST_ASSERT(worker_lcore_id < RTE_MAX_LCORE, "Failed to find a worker lcore"); \
 	lmain.bit = rte_rand_max(size); \
 	do { \
 		lworker.bit = rte_rand_max(size); \
@@ -218,6 +219,7 @@ test_bit_atomic_parallel_test_and_modify ## size(void) \
 		return TEST_SKIPPED; \
 	} \
 	worker_lcore_id = rte_get_next_lcore(-1, 1, 0); \
+	TEST_ASSERT(worker_lcore_id < RTE_MAX_LCORE, "Failed to find a worker lcore"); \
 	int rc = rte_eal_remote_launch(run_parallel_test_and_modify ## size, &lworker, \
 		worker_lcore_id); \
 	TEST_ASSERT(rc == 0, "Worker thread launch failed"); \
@@ -267,6 +269,7 @@ test_bit_atomic_parallel_flip ## size(void) \
 		return TEST_SKIPPED; \
 	} \
 	worker_lcore_id = rte_get_next_lcore(-1, 1, 0); \
+	TEST_ASSERT(worker_lcore_id < RTE_MAX_LCORE, "Failed to find a worker lcore"); \
 	int rc = rte_eal_remote_launch(run_parallel_flip ## size, &lworker, worker_lcore_id); \
 	TEST_ASSERT(rc == 0, "Worker thread launch failed"); \
 	run_parallel_flip ## size(&lmain); \
Signature · 1 line
2.46.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines

From: David Marchand [mailto:[email protected]]
Sent: Friday, 11 October 2024 17.26

Coverity is not able to understand that having 2 lcores means that rte_get_next_lcore(-1, 0, 1) can't return RTE_MAX_LCORE. Add an assert.

Coverity issue: 445382, 445383, 445384, 445387, 445389, 445391

Fixes 35326b61aecb ("bitops: add atomic bit operations in new API")
Quoted 8 lines

---
Note:
- a better fix would be to check lcore id validity in the EAL launch API,
but it requires inspecting all functions and it could result in some API change, so sending this as a simple fix for now,

---

#2 lore raw
In reply to David Marchand
Quoted 23 lines · David Marchand

Coverity is not able to understand that having 2 lcores means that rte_get_next_lcore(-1, 0, 1) can't return RTE_MAX_LCORE. Add an assert.

Coverity issue: 445382, 445383, 445384, 445387, 445389, 445391

Fixes 35326b61aecb ("bitops: add atomic bit operations in new API")

---
Note:
- a better fix would be to check lcore id validity in the EAL launch API, but it requires inspecting all functions and it could result in some API change, so sending this as a simple fix for now,

---
  app/test/test_bitops.c | 3 +++
  1 file changed, 3 insertions(+)
app/test/test_bitops.c +0 -0
index 4200073ae4..4ed54709fb 100644

app/test/test_bitops.c test_bit_atomic_parallel_assign ## size(void) \ · line 162

Quoted 4 lines
app/test/test_bitops.c +1 -0
@@ -159,6 +159,7 @@ test_bit_atomic_parallel_assign ## size(void) \
  		return TEST_SKIPPED; \
  	} \
  	worker_lcore_id = rte_get_next_lcore(-1, 1, 0); \
+	TEST_ASSERT(worker_lcore_id < RTE_MAX_LCORE, "Failed to find a worker lcore"); \

How about:

static unsigned int
get_worker_lcore(void)

{
	unsigned int lcore_id;

	lcore_id = rte_get_next_lcore(-1, 1, 0);

	/* avoid Coverity false positives */
	RTE_VERIFY(lcore_id < RTE_MAX_LCORE);

	return lcore_id;
}

In the macros:
worker_lcore_id = get_worker_lcore(-1, 1, 0);

Makes the macros a tiny bit smaller/less redundant and gives an opportunity for a comment. Also, it's more appropriate to use RTE_VERIFY I would argue, since rte_get_next_lcore() is not the SUT.

Quoted 19 lines
app/test/test_bitops.c +2 -0
  	lmain.bit = rte_rand_max(size); \
  	do { \
  		lworker.bit = rte_rand_max(size); \
@@ -218,6 +219,7 @@ test_bit_atomic_parallel_test_and_modify ## size(void) \
  		return TEST_SKIPPED; \
  	} \
  	worker_lcore_id = rte_get_next_lcore(-1, 1, 0); \
+	TEST_ASSERT(worker_lcore_id < RTE_MAX_LCORE, "Failed to find a worker lcore"); \
  	int rc = rte_eal_remote_launch(run_parallel_test_and_modify ## size, &lworker, \
  		worker_lcore_id); \
  	TEST_ASSERT(rc == 0, "Worker thread launch failed"); \
@@ -267,6 +269,7 @@ test_bit_atomic_parallel_flip ## size(void) \
  		return TEST_SKIPPED; \
  	} \
  	worker_lcore_id = rte_get_next_lcore(-1, 1, 0); \
+	TEST_ASSERT(worker_lcore_id < RTE_MAX_LCORE, "Failed to find a worker lcore"); \
  	int rc = rte_eal_remote_launch(run_parallel_flip ## size, &lworker, worker_lcore_id); \
  	TEST_ASSERT(rc == 0, "Worker thread launch failed"); \
  	run_parallel_flip ## size(&lmain); \
#3 lore raw
Quoted 45 lines · Mattias Rönnblom
Quoted 23 lines · David Marchand

Coverity is not able to understand that having 2 lcores means that rte_get_next_lcore(-1, 0, 1) can't return RTE_MAX_LCORE. Add an assert.

Coverity issue: 445382, 445383, 445384, 445387, 445389, 445391

Fixes 35326b61aecb ("bitops: add atomic bit operations in new API")

---
Note:
- a better fix would be to check lcore id validity in the EAL launch API, but it requires inspecting all functions and it could result in some API change, so sending this as a simple fix for now,

---
  app/test/test_bitops.c | 3 +++
  1 file changed, 3 insertions(+)
app/test/test_bitops.c +0 -0
index 4200073ae4..4ed54709fb 100644

app/test/test_bitops.c test_bit_atomic_parallel_assign ## size(void) \ · line 162

Quoted 4 lines
app/test/test_bitops.c +1 -0
@@ -159,6 +159,7 @@ test_bit_atomic_parallel_assign ## size(void) \
              return TEST_SKIPPED; \
      } \
      worker_lcore_id = rte_get_next_lcore(-1, 1, 0); \
+     TEST_ASSERT(worker_lcore_id < RTE_MAX_LCORE, "Failed to find a worker lcore"); \

How about:

static unsigned int
get_worker_lcore(void)

{
        unsigned int lcore_id;

        lcore_id = rte_get_next_lcore(-1, 1, 0);

        /* avoid Coverity false positives */
        RTE_VERIFY(lcore_id < RTE_MAX_LCORE);

        return lcore_id;
}
Quoted 6 lines

In the macros:
worker_lcore_id = get_worker_lcore(-1, 1, 0);

Makes the macros a tiny bit smaller/less redundant and gives an opportunity for a comment. Also, it's more appropriate to use RTE_VERIFY I would argue, since rte_get_next_lcore() is not the SUT.

I agree on the principle.
I will send a new one when possible.

Signature · 1 line
David Marchand
#4 lore raw

PATCH v2 1/1 test/bitops: check worker lcore availability

In reply to David Marchand

Coverity is not able to understand that having 2 lcores means that rte_get_next_lcore(-1, 0, 1) can't return RTE_MAX_LCORE. Add a check.

Coverity issue: 445382, 445383, 445384, 445387, 445389, 445391

Fixes 35326b61aecb ("bitops: add atomic bit operations in new API")

---
Changes since v2:
- added a helper,
- prefer RTE_VERIFY(),

Note:
- a better fix would be to check lcore id validity in the EAL launch API, but it requires inspecting all functions and it could result in some API change, so sending this as a simple fix for now,

---
 app/test/test_bitops.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
app/test/test_bitops.c +14 -3
index 681e984037..78a7df6bb1 100644
@@ -13,6 +13,17 @@
 #include <rte_random.h>
 #include "test.h"
 
+static unsigned int
+get_worker_lcore(void)
+{
+	unsigned int lcore_id = rte_get_next_lcore(-1, 1, 0);
+
+	/* avoid checkers (like Coverity) false positives */
+	RTE_VERIFY(lcore_id < RTE_MAX_LCORE);
+
+	return lcore_id;
+}
+
 #define GEN_TEST_BIT_ACCESS(test_name, set_fun, clear_fun, assign_fun, flip_fun, test_fun, size, \
 		mod) \
 static int \
@@ -158,7 +169,7 @@ test_bit_atomic_parallel_assign ## size(void) \
 		printf("Need multiple cores to run parallel test.\n"); \
 		return TEST_SKIPPED; \
 	} \
-	worker_lcore_id = rte_get_next_lcore(-1, 1, 0); \
+	worker_lcore_id = get_worker_lcore(); \
 	lmain.bit = rte_rand_max(size); \
 	do { \
 		lworker.bit = rte_rand_max(size); \
@@ -217,7 +228,7 @@ test_bit_atomic_parallel_test_and_modify ## size(void) \
 		printf("Need multiple cores to run parallel test.\n"); \
 		return TEST_SKIPPED; \
 	} \
-	worker_lcore_id = rte_get_next_lcore(-1, 1, 0); \
+	worker_lcore_id = get_worker_lcore(); \
 	int rc = rte_eal_remote_launch(run_parallel_test_and_modify ## size, &lworker, \
 		worker_lcore_id); \
 	TEST_ASSERT(rc == 0, "Worker thread launch failed"); \
@@ -266,7 +277,7 @@ test_bit_atomic_parallel_flip ## size(void) \
 		printf("Need multiple cores to run parallel test.\n"); \
 		return TEST_SKIPPED; \
 	} \
-	worker_lcore_id = rte_get_next_lcore(-1, 1, 0); \
+	worker_lcore_id = get_worker_lcore(); \
 	int rc = rte_eal_remote_launch(run_parallel_flip ## size, &lworker, worker_lcore_id); \
 	TEST_ASSERT(rc == 0, "Worker thread launch failed"); \
 	run_parallel_flip ## size(&lmain); \
Signature · 1 line
2.46.2
Acked-by on v2 1/1
#6 lore raw
In reply to David Marchand
Quoted 71 lines · David Marchand

Coverity is not able to understand that having 2 lcores means that rte_get_next_lcore(-1, 0, 1) can't return RTE_MAX_LCORE. Add a check.

Coverity issue: 445382, 445383, 445384, 445387, 445389, 445391

Fixes 35326b61aecb ("bitops: add atomic bit operations in new API")

---
Changes since v2:
- added a helper,
- prefer RTE_VERIFY(),

Note:
- a better fix would be to check lcore id validity in the EAL launch API, but it requires inspecting all functions and it could result in some API change, so sending this as a simple fix for now,

---
  app/test/test_bitops.c | 17 ++++++++++++++---
  1 file changed, 14 insertions(+), 3 deletions(-)
app/test/test_bitops.c +14 -3
index 681e984037..78a7df6bb1 100644
@@ -13,6 +13,17 @@
  #include <rte_random.h>
  #include "test.h"
 
+static unsigned int
+get_worker_lcore(void)
+{
+	unsigned int lcore_id = rte_get_next_lcore(-1, 1, 0);
+
+	/* avoid checkers (like Coverity) false positives */
+	RTE_VERIFY(lcore_id < RTE_MAX_LCORE);
+
+	return lcore_id;
+}
+
  #define GEN_TEST_BIT_ACCESS(test_name, set_fun, clear_fun, assign_fun, flip_fun, test_fun, size, \
  		mod) \
  static int \
@@ -158,7 +169,7 @@ test_bit_atomic_parallel_assign ## size(void) \
  		printf("Need multiple cores to run parallel test.\n"); \
  		return TEST_SKIPPED; \
  	} \
-	worker_lcore_id = rte_get_next_lcore(-1, 1, 0); \
+	worker_lcore_id = get_worker_lcore(); \
  	lmain.bit = rte_rand_max(size); \
  	do { \
  		lworker.bit = rte_rand_max(size); \
@@ -217,7 +228,7 @@ test_bit_atomic_parallel_test_and_modify ## size(void) \
  		printf("Need multiple cores to run parallel test.\n"); \
  		return TEST_SKIPPED; \
  	} \
-	worker_lcore_id = rte_get_next_lcore(-1, 1, 0); \
+	worker_lcore_id = get_worker_lcore(); \
  	int rc = rte_eal_remote_launch(run_parallel_test_and_modify ## size, &lworker, \
  		worker_lcore_id); \
  	TEST_ASSERT(rc == 0, "Worker thread launch failed"); \
@@ -266,7 +277,7 @@ test_bit_atomic_parallel_flip ## size(void) \
  		printf("Need multiple cores to run parallel test.\n"); \
  		return TEST_SKIPPED; \
  	} \
-	worker_lcore_id = rte_get_next_lcore(-1, 1, 0); \
+	worker_lcore_id = get_worker_lcore(); \
  	int rc = rte_eal_remote_launch(run_parallel_flip ## size, &lworker, worker_lcore_id); \
  	TEST_ASSERT(rc == 0, "Worker thread launch failed"); \
  	run_parallel_flip ## size(&lmain); \
author Applied
#7 lore raw
In reply to David Marchand
Quoted 9 lines · David Marchand

Coverity is not able to understand that having 2 lcores means that rte_get_next_lcore(-1, 0, 1) can't return RTE_MAX_LCORE. Add a check.

Coverity issue: 445382, 445383, 445384, 445387, 445389, 445391

Fixes 35326b61aecb ("bitops: add atomic bit operations in new API")

Applied, thanks.

Signature · 1 line
David Marchand