Skip to contentSkip to conversation

unit test bugs

RFC Superseded Stephen Hemminger 9 participants 69 messages Nov 14, 2024 – Nov 26, 2024

lore
Share & tools
lore
#0 lore raw

cover unit test bugs

Recent blog post from PVS studio referenced lots bugs found by their analyzer against DPDK. This set addresses the ones in the test suite.

Stephen Hemminger (10):
app/test: do not duplicate loop variable app/test: fix typo in mac address compare app/test: fix paren typo
app/test: avoid duplicate initialization app/test: fix TLS zero length record
test/eal: fix core check in c flag test app/test-pmd: remove redundant condition app/test-pmd: avoid potential outside of array reference app/test-dma-perf: fix parsing of dma address app/test: fix operator precedence bug

 app/test-dma-perf/main.c                      |  9 +++---
 app/test-pmd/cmdline_flow.c                   |  2 +-
 app/test-pmd/config.c                         |  3 +-
 app/test/test_common.c                        | 31 ++++++++++---------
 app/test/test_cryptodev.c                     |  5 +--
 app/test/test_eal_flags.c                     |  4 +--
 app/test/test_event_crypto_adapter.c          | 24 ++++++--------
 app/test/test_link_bonding.c                  |  9 ++----
 app/test/test_security_inline_proto_vectors.h |  8 +++--
 9 files changed, 43 insertions(+), 52 deletions(-)
Signature · 1 line
2.45.2
#1 lore raw

RFC 1/10 app/test: do not duplicate loop variable

Do not use same variable for outer and inner loop in bonding test. Since the loop is just freeing the resulting burst use bulk free.

Fixes 92073ef961ee ("bond: unit tests")
---
 app/test/test_link_bonding.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
app/test/test_link_bonding.c +1 -6
index 4d54706c21..805613d7dd 100644
@@ -2288,12 +2288,7 @@ test_activebackup_rx_burst(void)
 		}
 
 		/* free mbufs */
-		for (i = 0; i < MAX_PKT_BURST; i++) {
-			if (rx_pkt_burst[i] != NULL) {
-				rte_pktmbuf_free(rx_pkt_burst[i]);
-				rx_pkt_burst[i] = NULL;
-			}
-		}
+		rte_pktmbuf_free_bulk(rx_pkt_burst, burst_size);
 
 		/* reset bonding device stats */
 		rte_eth_stats_reset(test_params->bonding_port_id);
Signature · 1 line
2.45.2
#2 lore raw

RFC 2/10 app/test: fix typo in mac address compare

In reply to Stephen Hemminger

The first argument of 'memcmp' function was equal to the second argument. Therefore ASSERT would always be true.

Fixes 92073ef961ee ("bond: unit tests")
---
 app/test/test_link_bonding.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
app/test/test_link_bonding.c +1 -1
index 805613d7dd..b752a5ecbf 100644
@@ -792,7 +792,7 @@ test_set_primary_member(void)
 				&read_mac_addr),
 				"Failed to get mac address (port %d)",
 				test_params->bonding_port_id);
-		TEST_ASSERT_SUCCESS(memcmp(&read_mac_addr, &read_mac_addr,
+		TEST_ASSERT_SUCCESS(memcmp(expected_mac_addr, &read_mac_addr,
 				sizeof(read_mac_addr)),
 				"bonding port mac address not set to that of primary port\n");
 
Signature · 1 line
2.45.2
#3 lore raw

RFC 3/10 app/test: fix paren typo

In reply to Stephen Hemminger

The parenthesis were in the wrong place so that comparison took precedence over assignment in handling IPv6 extension headers. Break up the loop condition to avoid the problem.

Fixes 15ccc647526e ("test/security: test inline reassembly with multi-segment")
---
 app/test/test_security_inline_proto_vectors.h | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
app/test/test_security_inline_proto_vectors.h +5 -3
index b3d724bac6..86dfa54777 100644
@@ -519,10 +519,12 @@ test_vector_payload_populate(struct ip_reassembly_test_packet *pkt,
 			if (extra_data_sum) {
 				proto = hdr->proto;
 				p += sizeof(struct rte_ipv6_hdr);
-				while (proto != IPPROTO_FRAGMENT &&
-				       (proto = rte_ipv6_get_next_ext(p, proto, &ext_len) >= 0))
+				while (proto != IPPROTO_FRAGMENT) {
+					proto = rte_ipv6_get_next_ext(p, proto, &ext_len);
+					if (proto < 0)
+						break;
 					p += ext_len;
-
+				}
 				/* Found fragment header, update the frag offset */
 				if (proto == IPPROTO_FRAGMENT) {
 					frag_ext = (struct rte_ipv6_fragment_ext *)p;
Signature · 1 line
2.45.2
#4 lore raw

RFC 4/10 app/test: avoid duplicate initialization

In reply to Stephen Hemminger

The event_dev_config initialization had duplicate assignments to the same element. Change to use structure initialization so that compiler will catch this type of bug.

Fixes f8f9d233ea0e ("test/eventdev: add unit tests")
---
 app/test/test_event_crypto_adapter.c | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)
app/test/test_event_crypto_adapter.c +10 -14
index 9d38a66bfa..ab24e30a97 100644
@@ -1154,21 +1154,17 @@ configure_cryptodev(void)
 
 static inline void
 evdev_set_conf_values(struct rte_event_dev_config *dev_conf,
-			struct rte_event_dev_info *info)
+		      const struct rte_event_dev_info *info)
 {
-	memset(dev_conf, 0, sizeof(struct rte_event_dev_config));
-	dev_conf->dequeue_timeout_ns = info->min_dequeue_timeout_ns;
-	dev_conf->nb_event_ports = NB_TEST_PORTS;
-	dev_conf->nb_event_queues = NB_TEST_QUEUES;
-	dev_conf->nb_event_queue_flows = info->max_event_queue_flows;
-	dev_conf->nb_event_port_dequeue_depth =
-			info->max_event_port_dequeue_depth;
-	dev_conf->nb_event_port_enqueue_depth =
-			info->max_event_port_enqueue_depth;
-	dev_conf->nb_event_port_enqueue_depth =
-			info->max_event_port_enqueue_depth;
-	dev_conf->nb_events_limit =
-			info->max_num_events;
+	*dev_conf = (struct rte_event_dev_config) {
+		.dequeue_timeout_ns = info->min_dequeue_timeout_ns,
+		.nb_event_ports = NB_TEST_PORTS,
+		.nb_event_queues = NB_TEST_QUEUES,
+		.nb_event_queue_flows = info->max_event_queue_flows,
+		.nb_event_port_dequeue_depth = info->max_event_port_dequeue_depth,
+		.nb_event_port_enqueue_depth = info->max_event_port_enqueue_depth,
+		.nb_events_limit = info->max_num_events,
+	};
 }
 
 static int
Signature · 1 line
2.45.2
#5 lore raw

RFC 5/10 app/test: fix TLS zero length record

In reply to Stephen Hemminger

The code was duplicating the same condition three times? Reading the commit message, the intention was:

Add unit tests to verify the zero len TLS records. Zero len packets are allowed when content type is app data while zero packet length with other content type (such as handshake) would result in an error.

Fixes 79a58624369a ("test/security: verify zero length TLS records")
---
 app/test/test_cryptodev.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
app/test/test_cryptodev.c +1 -4
index c647baeee1..a33ef574cc 100644
@@ -12253,10 +12253,7 @@ test_tls_record_proto_all(const struct tls_record_test_flags *flags)
 		if (flags->skip_sess_destroy && sec_session_outb == NULL)
 			sec_session_outb = ut_params->sec_session;
 
-		if (flags->zero_len &&
-		    ((flags->content_type == TLS_RECORD_TEST_CONTENT_TYPE_HANDSHAKE) ||
-		    (flags->content_type == TLS_RECORD_TEST_CONTENT_TYPE_HANDSHAKE) ||
-		    (flags->content_type == TLS_RECORD_TEST_CONTENT_TYPE_HANDSHAKE))) {
+		if (flags->zero_len && flags->content_type != TLS_RECORD_TEST_CONTENT_TYPE_APP) {
 			if (ret == TEST_SUCCESS)
 				return TEST_FAILED;
 			goto skip_decrypt;
Signature · 1 line
2.45.2
#6 lore raw

RFC 6/10 test/eal: fix core check in c flag test

In reply to Stephen Hemminger

The expression for checking which lcore is enabled for 0-7 was wrong (missing case for 6).

Fixes b0209034f2bb ("test/eal: check number of cores before running subtests")
---
 app/test/test_eal_flags.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
app/test/test_eal_flags.c +2 -2
index d37d6b8627..e32f83d3c8 100644
@@ -677,8 +677,8 @@ test_missing_c_flag(void)
 
 	if (rte_lcore_is_enabled(0) && rte_lcore_is_enabled(1) &&
 	    rte_lcore_is_enabled(2) && rte_lcore_is_enabled(3) &&
-	    rte_lcore_is_enabled(3) && rte_lcore_is_enabled(5) &&
-	    rte_lcore_is_enabled(4) && rte_lcore_is_enabled(7) &&
+	    rte_lcore_is_enabled(4) && rte_lcore_is_enabled(5) &&
+	    rte_lcore_is_enabled(6) && rte_lcore_is_enabled(7) &&
 	    launch_proc(argv29) != 0) {
 		printf("Error - "
 		       "process did not run ok with valid corelist value\n");
Signature · 1 line
2.45.2
#7 lore raw

RFC 7/10 app/test-pmd: remove redundant condition

In reply to Stephen Hemminger

The loop over policy actions will always exit when it sees the flow end action, so the next check is redundant.

Fixes f29fa2c59b85 ("app/testpmd: support policy actions per color")
---
 app/test-pmd/config.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
app/test-pmd/config.c +1 -2
index 88770b4dfc..32c4e86c84 100644
@@ -2288,7 +2288,7 @@ port_meter_policy_add(portid_t port_id, uint32_t policy_id,
 		for (act_n = 0, start = act;
 			act->type != RTE_FLOW_ACTION_TYPE_END; act++)
 			act_n++;
-		if (act_n && act->type == RTE_FLOW_ACTION_TYPE_END)
+		if (act_n > 0)
 			policy.actions[i] = start;
 		else
 			policy.actions[i] = NULL;
@@ -7316,4 +7316,3 @@ show_mcast_macs(portid_t port_id)
 		printf("  %s\n", buf);
 	}
 }
-
Signature · 1 line
2.45.2
#8 lore raw

RFC 8/10 app/test-pmd: avoid potential outside of array reference

In reply to Stephen Hemminger

The order of comparison is wrong, and potentially allows referencing past the array.

Fixes 3e3edab530a1 ("ethdev: add flow quota")
---
 app/test-pmd/cmdline_flow.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
app/test-pmd/cmdline_flow.c +1 -1
index 1e4f2ebc55..9e4fc2d95d 100644
@@ -12892,7 +12892,7 @@ comp_names_to_index(struct context *ctx, const struct token *token,
 	RTE_SET_USED(token);
 	if (!buf)
 		return names_size;
-	if (names[ent] && ent < names_size)
+	if (ent < names_size && names[ent] != NULL)
 		return rte_strscpy(buf, names[ent], size);
 	return -1;
 
Signature · 1 line
2.45.2
#9 lore raw

RFC 9/10 app/test-dma-perf: fix parsing of dma address

In reply to Stephen Hemminger

There was useless loop when looking at the DMA address. It looks like it was meant to skip whitespace before calling strtok.

Good time to replace strtok with strtok_r as well.

Fixes 623dc9364dc6 ("app/dma-perf: introduce DMA performance test")
---
 app/test-dma-perf/main.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
app/test-dma-perf/main.c +4 -5
index 18219918cc..dabf4e02e6 100644
@@ -217,19 +217,18 @@ parse_lcore_dma(struct test_configure *test_case, const char *value)
 	struct lcore_dma_map_t *lcore_dma_map;
 	char *input, *addrs;
 	char *ptrs[2];
-	char *start, *end, *substr;
+	char *start, *end, *substr, *saveptr;
 	uint16_t lcore_id;
 	int ret = 0;
 
 	if (test_case == NULL || value == NULL)
 		return -1;
 
-	input = strndup(value, strlen(value) + 1);
+	input = strdup(value);
 	if (input == NULL)
 		return -1;
 	addrs = input;
-
-	while (*addrs == '\0')
+	while (*addrs == '\0' && isspace(*addrs))
 		addrs++;
 	if (*addrs == '\0') {
 		fprintf(stderr, "No input DMA addresses\n");
@@ -237,7 +236,7 @@ parse_lcore_dma(struct test_configure *test_case, const char *value)
 		goto out;
 	}
 
-	substr = strtok(addrs, ",");
+	substr = strtok_r(addrs, ",", &saveptr);
 	if (substr == NULL) {
 		fprintf(stderr, "No input DMA address\n");
 		ret = -1;
Signature · 1 line
2.45.2
#10 lore raw

RE: [RFC 09/10] app/test-dma-perf: fix parsing of dma address

app/test-dma-perf/main.c parse_lcore_dma(struct test_configure *test_case, const char *value) · line 232

Quoted 2 lines
app/test-dma-perf/main.c +1 -0
+	while (*addrs == '\0' && isspace(*addrs))
 		addrs++;

This is never going to happen. Did you mean ||?

#11 lore raw

Re: [RFC 09/10] app/test-dma-perf: fix parsing of dma address

Quoted 4 lines · On Thu, 14 Nov 2024 08:00:52 +0100 Morten Brørup <[email protected]>…

app/test-dma-perf/main.c parse_lcore_dma(struct test_configure *test_case, const char *value) · line 232

Quoted 2 lines
app/test-dma-perf/main.c +1 -0
+	while (*addrs == '\0' && isspace(*addrs))
 		addrs++;  

This is never going to happen. Did you mean ||?

Good catch.

#12 lore raw

Re: [RFC 09/10] app/test-dma-perf: fix parsing of dma address

In reply to Stephen Hemminger
Quoted 5 lines · Stephen Hemminger

There was useless loop when looking at the DMA address. It looks like it was meant to skip whitespace before calling strtok.

Good time to replace strtok with strtok_r as well.

Incomplete modification for strtok, I suggest the strtok adopt HaiJie's patchset [1], This commit just modify non-strtok logic.

[1] https://inbox.dpdk.org/dev/[email protected]/

Quoted 47 lines
Fixes 623dc9364dc6 ("app/dma-perf: introduce DMA performance test")
---
 app/test-dma-perf/main.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
app/test-dma-perf/main.c +4 -5
index 18219918cc..dabf4e02e6 100644
@@ -217,19 +217,18 @@ parse_lcore_dma(struct test_configure *test_case, const char *value)
 	struct lcore_dma_map_t *lcore_dma_map;
 	char *input, *addrs;
 	char *ptrs[2];
-	char *start, *end, *substr;
+	char *start, *end, *substr, *saveptr;
 	uint16_t lcore_id;
 	int ret = 0;
 
 	if (test_case == NULL || value == NULL)
 		return -1;
 
-	input = strndup(value, strlen(value) + 1);
+	input = strdup(value);
 	if (input == NULL)
 		return -1;
 	addrs = input;
-
-	while (*addrs == '\0')
+	while (*addrs == '\0' && isspace(*addrs))
 		addrs++;
 	if (*addrs == '\0') {
 		fprintf(stderr, "No input DMA addresses\n");
@@ -237,7 +236,7 @@ parse_lcore_dma(struct test_configure *test_case, const char *value)
 		goto out;
 	}
 
-	substr = strtok(addrs, ",");
+	substr = strtok_r(addrs, ",", &saveptr);
 	if (substr == NULL) {
 		fprintf(stderr, "No input DMA address\n");
 		ret = -1;
#13 lore raw

RFC 10/10 app/test: fix operator precedence bug

In reply to Stephen Hemminger

The test loop was much shorter than desired because when MAX_NUM is defined with out paren's the divide operator / takes precedence over shift.

But when MAX_NUM is fixed, some tests take too long and have to modified to avoid running over full N^2 space of 1<<20.

Note: this is a very old bug, goes back to 2013.

Fixes 1fb8b07ee511 ("app: add some tests")
---
 app/test/test_common.c | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)
app/test/test_common.c +17 -14
index 21eb2285e1..6dbd7fc9a9 100644
@@ -9,11 +9,12 @@
 #include <rte_common.h>
 #include <rte_bitops.h>
 #include <rte_hexdump.h>
+#include <rte_random.h>
 #include <rte_pause.h>
 
 #include "test.h"
 
-#define MAX_NUM 1 << 20
+#define MAX_NUM (1 << 20)
 
 #define FAIL(x)\
 	{printf(x "() test failed!\n");\
@@ -218,19 +219,21 @@ test_align(void)
 		}
 	}
 
-	for (p = 1; p <= MAX_NUM / 2; p++) {
-		for (i = 1; i <= MAX_NUM / 2; i++) {
-			val = RTE_ALIGN_MUL_CEIL(i, p);
-			if (val % p != 0 || val < i)
-				FAIL_ALIGN("RTE_ALIGN_MUL_CEIL", i, p);
-			val = RTE_ALIGN_MUL_FLOOR(i, p);
-			if (val % p != 0 || val > i)
-				FAIL_ALIGN("RTE_ALIGN_MUL_FLOOR", i, p);
-			val = RTE_ALIGN_MUL_NEAR(i, p);
-			if (val % p != 0 || ((val != RTE_ALIGN_MUL_CEIL(i, p))
-				& (val != RTE_ALIGN_MUL_FLOOR(i, p))))
-				FAIL_ALIGN("RTE_ALIGN_MUL_NEAR", i, p);
-		}
+	/* testing the whole space of 2^20^2 takes too long. */
+	for (j = 1; j <= MAX_NUM ; j++) {
+		i = rte_rand_max(MAX_NUM - 1) + 1;
+		p = rte_rand_max(MAX_NUM - 1) + 1;
+
+		val = RTE_ALIGN_MUL_CEIL(i, p);
+		if (val % p != 0 || val < i)
+			FAIL_ALIGN("RTE_ALIGN_MUL_CEIL", i, p);
+		val = RTE_ALIGN_MUL_FLOOR(i, p);
+		if (val % p != 0 || val > i)
+			FAIL_ALIGN("RTE_ALIGN_MUL_FLOOR", i, p);
+		val = RTE_ALIGN_MUL_NEAR(i, p);
+		if (val % p != 0 || ((val != RTE_ALIGN_MUL_CEIL(i, p))
+				     & (val != RTE_ALIGN_MUL_FLOOR(i, p))))
+			FAIL_ALIGN("RTE_ALIGN_MUL_NEAR", i, p);
 	}
 
 	return 0;
Signature · 1 line
2.45.2
#14 lore raw

v2 cover Bug fixes for unit tests

In reply to Stephen Hemminger

Recent blog post from PVS studio referenced lots bugs found by their analyzer against DPDK. This set addresses the ones in the test suite.

v2 - fix dma address parsing
- add stable where needed

Stephen Hemminger (10):
app/test: do not duplicated loop variable app/test: fix typo in address compare
app/test: fix paren typo
app/test: avoid duplicate initialization app/test: fix TLS zero length record
app/test: fix operator precedence bug
test/eal: fix core check in c flag test app/test-pmd: remove redundant condition app/test-pmd: avoid potential outside of array reference app/test-dma-perf: fix parsing of DMA address

 app/test-dma-perf/main.c                      | 12 +++----
 app/test-pmd/cmdline_flow.c                   |  2 +-
 app/test-pmd/config.c                         |  3 +-
 app/test/test_common.c                        | 31 ++++++++++---------
 app/test/test_cryptodev.c                     |  5 +--
 app/test/test_eal_flags.c                     |  4 +--
 app/test/test_event_crypto_adapter.c          | 24 ++++++--------
 app/test/test_link_bonding.c                  |  9 ++----
 app/test/test_security_inline_proto_vectors.h |  8 +++--
 9 files changed, 45 insertions(+), 53 deletions(-)
Signature · 1 line
2.45.2
#15 lore raw

PATCH v2 1/10 app/test: do not duplicated loop variable

Do not use same variable for outer and inner loop in bonding test. Since the loop is just freeing the resulting burst use bulk free.

Fixes 92073ef961ee ("bond: unit tests")
---
 app/test/test_link_bonding.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
app/test/test_link_bonding.c +1 -6
index 4d54706c21..805613d7dd 100644
@@ -2288,12 +2288,7 @@ test_activebackup_rx_burst(void)
 		}
 
 		/* free mbufs */
-		for (i = 0; i < MAX_PKT_BURST; i++) {
-			if (rx_pkt_burst[i] != NULL) {
-				rte_pktmbuf_free(rx_pkt_burst[i]);
-				rx_pkt_burst[i] = NULL;
-			}
-		}
+		rte_pktmbuf_free_bulk(rx_pkt_burst, burst_size);
 
 		/* reset bonding device stats */
 		rte_eth_stats_reset(test_params->bonding_port_id);
Signature · 1 line
2.45.2
Acked-by on v2 1/10
#16 lore raw

Re: [PATCH v2 01/10] app/test: do not duplicated loop variable

Quoted 10 lines · Stephen Hemminger

Do not use same variable for outer and inner loop in bonding test. Since the loop is just freeing the resulting burst use bulk free.

Fixes 92073ef961ee ("bond: unit tests")
#17 lore raw

PATCH v2 2/10 app/test: fix typo in address compare

In reply to Stephen Hemminger

The first argument of 'memcmp' function was equal to the second argument. Therefore ASSERT would always be true.

Fixes 92073ef961ee ("bond: unit tests")
---
 app/test/test_link_bonding.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
app/test/test_link_bonding.c +1 -1
index 805613d7dd..b752a5ecbf 100644
@@ -792,7 +792,7 @@ test_set_primary_member(void)
 				&read_mac_addr),
 				"Failed to get mac address (port %d)",
 				test_params->bonding_port_id);
-		TEST_ASSERT_SUCCESS(memcmp(&read_mac_addr, &read_mac_addr,
+		TEST_ASSERT_SUCCESS(memcmp(expected_mac_addr, &read_mac_addr,
 				sizeof(read_mac_addr)),
 				"bonding port mac address not set to that of primary port\n");
 
Signature · 1 line
2.45.2
#18 lore raw

PATCH v2 3/10 app/test: fix paren typo

In reply to Stephen Hemminger

The parenthesis were in the wrong place so that comparison took precedence over assignment in handling IPv6 extension headers. Break up the loop condition to avoid the problem.

Fixes 15ccc647526e ("test/security: test inline reassembly with multi-segment")
---
 app/test/test_security_inline_proto_vectors.h | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
app/test/test_security_inline_proto_vectors.h +5 -3
index b3d724bac6..86dfa54777 100644
@@ -519,10 +519,12 @@ test_vector_payload_populate(struct ip_reassembly_test_packet *pkt,
 			if (extra_data_sum) {
 				proto = hdr->proto;
 				p += sizeof(struct rte_ipv6_hdr);
-				while (proto != IPPROTO_FRAGMENT &&
-				       (proto = rte_ipv6_get_next_ext(p, proto, &ext_len) >= 0))
+				while (proto != IPPROTO_FRAGMENT) {
+					proto = rte_ipv6_get_next_ext(p, proto, &ext_len);
+					if (proto < 0)
+						break;
 					p += ext_len;
-
+				}
 				/* Found fragment header, update the frag offset */
 				if (proto == IPPROTO_FRAGMENT) {
 					frag_ext = (struct rte_ipv6_fragment_ext *)p;
Signature · 1 line
2.45.2
Acked-by on v2 3/10
#19 lore raw

Re: [PATCH v2 03/10] app/test: fix paren typo

Quoted 11 lines · Stephen Hemminger

The parenthesis were in the wrong place so that comparison took precedence over assignment in handling IPv6 extension headers. Break up the loop condition to avoid the problem.

Fixes 15ccc647526e ("test/security: test inline reassembly with multi-segment")
#20 lore raw

PATCH v2 4/10 app/test: avoid duplicate initialization

In reply to Stephen Hemminger

The event_dev_config initialization had duplicate assignments to the same element. Change to use structure initialization so that compiler will catch this type of bug.

Fixes f8f9d233ea0e ("test/eventdev: add unit tests")
---
 app/test/test_event_crypto_adapter.c | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)
app/test/test_event_crypto_adapter.c +10 -14
index 9d38a66bfa..ab24e30a97 100644
@@ -1154,21 +1154,17 @@ configure_cryptodev(void)
 
 static inline void
 evdev_set_conf_values(struct rte_event_dev_config *dev_conf,
-			struct rte_event_dev_info *info)
+		      const struct rte_event_dev_info *info)
 {
-	memset(dev_conf, 0, sizeof(struct rte_event_dev_config));
-	dev_conf->dequeue_timeout_ns = info->min_dequeue_timeout_ns;
-	dev_conf->nb_event_ports = NB_TEST_PORTS;
-	dev_conf->nb_event_queues = NB_TEST_QUEUES;
-	dev_conf->nb_event_queue_flows = info->max_event_queue_flows;
-	dev_conf->nb_event_port_dequeue_depth =
-			info->max_event_port_dequeue_depth;
-	dev_conf->nb_event_port_enqueue_depth =
-			info->max_event_port_enqueue_depth;
-	dev_conf->nb_event_port_enqueue_depth =
-			info->max_event_port_enqueue_depth;
-	dev_conf->nb_events_limit =
-			info->max_num_events;
+	*dev_conf = (struct rte_event_dev_config) {
+		.dequeue_timeout_ns = info->min_dequeue_timeout_ns,
+		.nb_event_ports = NB_TEST_PORTS,
+		.nb_event_queues = NB_TEST_QUEUES,
+		.nb_event_queue_flows = info->max_event_queue_flows,
+		.nb_event_port_dequeue_depth = info->max_event_port_dequeue_depth,
+		.nb_event_port_enqueue_depth = info->max_event_port_enqueue_depth,
+		.nb_events_limit = info->max_num_events,
+	};
 }
 
 static int
Signature · 1 line
2.45.2
Acked-by on v2 4/10
#21 lore raw

Re: [PATCH v2 04/10] app/test: avoid duplicate initialization

Quoted 10 lines · Stephen Hemminger

The event_dev_config initialization had duplicate assignments to the same element. Change to use structure initialization so that compiler will catch this type of bug.

Fixes f8f9d233ea0e ("test/eventdev: add unit tests")
#22 lore raw

PATCH v2 5/10 app/test: fix TLS zero length record

In reply to Stephen Hemminger

The code was duplicating the same condition three times? Reading the commit message, the intention was:

Add unit tests to verify the zero len TLS records. Zero len packets are allowed when content type is app data while zero packet length with other content type (such as handshake) would result in an error.

Fixes 79a58624369a ("test/security: verify zero length TLS records")
---
 app/test/test_cryptodev.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
app/test/test_cryptodev.c +1 -4
index c647baeee1..a33ef574cc 100644
@@ -12253,10 +12253,7 @@ test_tls_record_proto_all(const struct tls_record_test_flags *flags)
 		if (flags->skip_sess_destroy && sec_session_outb == NULL)
 			sec_session_outb = ut_params->sec_session;
 
-		if (flags->zero_len &&
-		    ((flags->content_type == TLS_RECORD_TEST_CONTENT_TYPE_HANDSHAKE) ||
-		    (flags->content_type == TLS_RECORD_TEST_CONTENT_TYPE_HANDSHAKE) ||
-		    (flags->content_type == TLS_RECORD_TEST_CONTENT_TYPE_HANDSHAKE))) {
+		if (flags->zero_len && flags->content_type != TLS_RECORD_TEST_CONTENT_TYPE_APP) {
 			if (ret == TEST_SUCCESS)
 				return TEST_FAILED;
 			goto skip_decrypt;
Signature · 1 line
2.45.2
#23 lore raw

PATCH v2 6/10 app/test: fix operator precedence bug

In reply to Stephen Hemminger

The test loop was much shorter than desired because when MAX_NUM is defined with out paren's the divide operator / takes precedence over shift.

But when MAX_NUM is fixed, some tests take too long and have to modified to avoid running over full N^2 space of 1<<20.

Note: this is a very old bug, goes back to 2013.

Fixes 1fb8b07ee511 ("app: add some tests")
---
 app/test/test_common.c | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)
app/test/test_common.c +17 -14
index 21eb2285e1..6dbd7fc9a9 100644
@@ -9,11 +9,12 @@
 #include <rte_common.h>
 #include <rte_bitops.h>
 #include <rte_hexdump.h>
+#include <rte_random.h>
 #include <rte_pause.h>
 
 #include "test.h"
 
-#define MAX_NUM 1 << 20
+#define MAX_NUM (1 << 20)
 
 #define FAIL(x)\
 	{printf(x "() test failed!\n");\
@@ -218,19 +219,21 @@ test_align(void)
 		}
 	}
 
-	for (p = 1; p <= MAX_NUM / 2; p++) {
-		for (i = 1; i <= MAX_NUM / 2; i++) {
-			val = RTE_ALIGN_MUL_CEIL(i, p);
-			if (val % p != 0 || val < i)
-				FAIL_ALIGN("RTE_ALIGN_MUL_CEIL", i, p);
-			val = RTE_ALIGN_MUL_FLOOR(i, p);
-			if (val % p != 0 || val > i)
-				FAIL_ALIGN("RTE_ALIGN_MUL_FLOOR", i, p);
-			val = RTE_ALIGN_MUL_NEAR(i, p);
-			if (val % p != 0 || ((val != RTE_ALIGN_MUL_CEIL(i, p))
-				& (val != RTE_ALIGN_MUL_FLOOR(i, p))))
-				FAIL_ALIGN("RTE_ALIGN_MUL_NEAR", i, p);
-		}
+	/* testing the whole space of 2^20^2 takes too long. */
+	for (j = 1; j <= MAX_NUM ; j++) {
+		i = rte_rand_max(MAX_NUM - 1) + 1;
+		p = rte_rand_max(MAX_NUM - 1) + 1;
+
+		val = RTE_ALIGN_MUL_CEIL(i, p);
+		if (val % p != 0 || val < i)
+			FAIL_ALIGN("RTE_ALIGN_MUL_CEIL", i, p);
+		val = RTE_ALIGN_MUL_FLOOR(i, p);
+		if (val % p != 0 || val > i)
+			FAIL_ALIGN("RTE_ALIGN_MUL_FLOOR", i, p);
+		val = RTE_ALIGN_MUL_NEAR(i, p);
+		if (val % p != 0 || ((val != RTE_ALIGN_MUL_CEIL(i, p))
+				     & (val != RTE_ALIGN_MUL_FLOOR(i, p))))
+			FAIL_ALIGN("RTE_ALIGN_MUL_NEAR", i, p);
 	}
 
 	return 0;
Signature · 1 line
2.45.2
Acked-by on v2 6/10
#24 lore raw

Re: [PATCH v2 06/10] app/test: fix operator precedence bug

Quoted 8 lines · Stephen Hemminger

The test loop was much shorter than desired because when MAX_NUM is defined with out paren's the divide operator / takes precedence over shift.

But when MAX_NUM is fixed, some tests take too long and have to modified to avoid running over full N^2 space of 1<<20.

Quoted 8 lines

Note: this is a very old bug, goes back to 2013.

Fixes 1fb8b07ee511 ("app: add some tests")
#25 lore raw

PATCH v2 7/10 test/eal: fix core check in c flag test

In reply to Stephen Hemminger

The expression for checking which lcore is enabled for 0-7 was wrong (missing case for 6).

Fixes b0209034f2bb ("test/eal: check number of cores before running subtests")
---
 app/test/test_eal_flags.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
app/test/test_eal_flags.c +2 -2
index d37d6b8627..e32f83d3c8 100644
@@ -677,8 +677,8 @@ test_missing_c_flag(void)
 
 	if (rte_lcore_is_enabled(0) && rte_lcore_is_enabled(1) &&
 	    rte_lcore_is_enabled(2) && rte_lcore_is_enabled(3) &&
-	    rte_lcore_is_enabled(3) && rte_lcore_is_enabled(5) &&
-	    rte_lcore_is_enabled(4) && rte_lcore_is_enabled(7) &&
+	    rte_lcore_is_enabled(4) && rte_lcore_is_enabled(5) &&
+	    rte_lcore_is_enabled(6) && rte_lcore_is_enabled(7) &&
 	    launch_proc(argv29) != 0) {
 		printf("Error - "
 		       "process did not run ok with valid corelist value\n");
Signature · 1 line
2.45.2
Acked-by on v2 7/10
#26 lore raw

Re: [PATCH v2 07/10] test/eal: fix core check in c flag test

Quoted 10 lines · Stephen Hemminger

The expression for checking which lcore is enabled for 0-7 was wrong (missing case for 6).

Fixes b0209034f2bb ("test/eal: check number of cores before running subtests")

Just wondering would it not be better/safer to put in an actual loop check here?
However, I'm also ok with keeping the fix as-is, so:

Quoted 22 lines
---
 app/test/test_eal_flags.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
app/test/test_eal_flags.c +2 -2
index d37d6b8627..e32f83d3c8 100644
@@ -677,8 +677,8 @@ test_missing_c_flag(void)
 
 	if (rte_lcore_is_enabled(0) && rte_lcore_is_enabled(1) &&
 	    rte_lcore_is_enabled(2) && rte_lcore_is_enabled(3) &&
-	    rte_lcore_is_enabled(3) && rte_lcore_is_enabled(5) &&
-	    rte_lcore_is_enabled(4) && rte_lcore_is_enabled(7) &&
+	    rte_lcore_is_enabled(4) && rte_lcore_is_enabled(5) &&
+	    rte_lcore_is_enabled(6) && rte_lcore_is_enabled(7) &&
 	    launch_proc(argv29) != 0) {
 		printf("Error - "
 		       "process did not run ok with valid corelist value\n");
Signature · 1 line
2.45.2
#27 lore raw

Re: [PATCH v2 07/10] test/eal: fix core check in c flag test

Quoted 10 lines · On Fri, 15 Nov 2024 09:07:42 +0000 Bruce Richardson…
Quoted 9 lines · Stephen Hemminger

The expression for checking which lcore is enabled for 0-7 was wrong (missing case for 6).

Fixes b0209034f2bb ("test/eal: check number of cores before running subtests")
Quoted 7 lines
Quoted 1 line

Just wondering would it not be better/safer to put in an actual loop check here?
However, I'm also ok with keeping the fix as-is, so:

My goal was to do minimum changes for now, to avoid introducing new bugs.

#28 lore raw

PATCH v2 8/10 app/test-pmd: remove redundant condition

In reply to Stephen Hemminger

The loop over policy actions will always exit when it sees the flow end action, so the next check is redundant.

Fixes f29fa2c59b85 ("app/testpmd: support policy actions per color")
---
 app/test-pmd/config.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
app/test-pmd/config.c +1 -2
index 88770b4dfc..32c4e86c84 100644
@@ -2288,7 +2288,7 @@ port_meter_policy_add(portid_t port_id, uint32_t policy_id,
 		for (act_n = 0, start = act;
 			act->type != RTE_FLOW_ACTION_TYPE_END; act++)
 			act_n++;
-		if (act_n && act->type == RTE_FLOW_ACTION_TYPE_END)
+		if (act_n > 0)
 			policy.actions[i] = start;
 		else
 			policy.actions[i] = NULL;
@@ -7316,4 +7316,3 @@ show_mcast_macs(portid_t port_id)
 		printf("  %s\n", buf);
 	}
 }
-
Signature · 1 line
2.45.2
Reviewed-by on v2 8/10
#29 lore raw

Re: [PATCH v2 08/10] app/test-pmd: remove redundant condition

Quoted 9 lines · Stephen Hemminger

The loop over policy actions will always exit when it sees the flow end action, so the next check is redundant.

Fixes f29fa2c59b85 ("app/testpmd: support policy actions per color")
Quoted 25 lines
---
 app/test-pmd/config.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
app/test-pmd/config.c +1 -3
index 88770b4dfc..32c4e86c84 100644
@@ -2288,7 +2288,7 @@ port_meter_policy_add(portid_t port_id, uint32_t policy_id,
                for (act_n = 0, start = act;
                        act->type != RTE_FLOW_ACTION_TYPE_END; act++)
                        act_n++;
-               if (act_n && act->type == RTE_FLOW_ACTION_TYPE_END)
+               if (act_n > 0)
                        policy.actions[i] = start;
                else
                        policy.actions[i] = NULL;
@@ -7316,4 +7316,3 @@ show_mcast_macs(portid_t port_id)
                printf("  %s\n", buf);
        }
 }
-
--

2.45.2

Acked-by on v2 8/10
#30 lore raw

Re: [PATCH v2 08/10] app/test-pmd: remove redundant condition

In reply to Stephen Hemminger
Quoted 9 lines · Stephen Hemminger

The loop over policy actions will always exit when it sees the flow end action, so the next check is redundant.

Fixes f29fa2c59b85 ("app/testpmd: support policy actions per color")

---

#31 lore raw

PATCH v2 9/10 app/test-pmd: avoid potential outside of array reference

In reply to Stephen Hemminger

The order of comparison is wrong, and potentially allows referencing past the array.

Fixes 3e3edab530a1 ("ethdev: add flow quota")
---
 app/test-pmd/cmdline_flow.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
app/test-pmd/cmdline_flow.c +1 -1
index 1e4f2ebc55..9e4fc2d95d 100644
@@ -12892,7 +12892,7 @@ comp_names_to_index(struct context *ctx, const struct token *token,
 	RTE_SET_USED(token);
 	if (!buf)
 		return names_size;
-	if (names[ent] && ent < names_size)
+	if (ent < names_size && names[ent] != NULL)
 		return rte_strscpy(buf, names[ent], size);
 	return -1;
 
Signature · 1 line
2.45.2
Acked-by on v2 9/10
#32 lore raw

Re: [PATCH v2 09/10] app/test-pmd: avoid potential outside of array reference

Quoted 10 lines · Stephen Hemminger

The order of comparison is wrong, and potentially allows referencing past the array.

Fixes 3e3edab530a1 ("ethdev: add flow quota")
#33 lore raw

PATCH v2 10/10 app/test-dma-perf: fix parsing of DMA address

In reply to Stephen Hemminger

There was useless loop when looking at the DMA address. It looks like it was meant to skip whitespace before calling strtok.

Good time to replace strtok with strtok_r as well.

Fixes 623dc9364dc6 ("app/dma-perf: introduce DMA performance test")
---
 app/test-dma-perf/main.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
app/test-dma-perf/main.c +6 -6
index 18219918cc..dccb0a3541 100644
@@ -217,27 +217,27 @@ parse_lcore_dma(struct test_configure *test_case, const char *value)
 	struct lcore_dma_map_t *lcore_dma_map;
 	char *input, *addrs;
 	char *ptrs[2];
-	char *start, *end, *substr;
+	char *start, *end, *substr, *saveptr;
 	uint16_t lcore_id;
 	int ret = 0;
 
 	if (test_case == NULL || value == NULL)
 		return -1;
 
-	input = strndup(value, strlen(value) + 1);
+	input = strdup(value);
 	if (input == NULL)
 		return -1;
-	addrs = input;
 
-	while (*addrs == '\0')
-		addrs++;
+	addrs = input;
+	while (isspace(*addrs))
+		++addrs;
 	if (*addrs == '\0') {
 		fprintf(stderr, "No input DMA addresses\n");
 		ret = -1;
 		goto out;
 	}
 
-	substr = strtok(addrs, ",");
+	substr = strtok_r(addrs, ",", &saveptr);
 	if (substr == NULL) {
 		fprintf(stderr, "No input DMA address\n");
 		ret = -1;
Signature · 1 line
2.45.2
Acked-by on v2 10/10
#34 lore raw

Re: [PATCH v2 10/10] app/test-dma-perf: fix parsing of DMA address

Quoted 6 lines · Stephen Hemminger

There was useless loop when looking at the DMA address. It looks like it was meant to skip whitespace before calling strtok.

Good time to replace strtok with strtok_r as well.

Quoted 7 lines
Fixes 623dc9364dc6 ("app/dma-perf: introduce DMA performance test")

One comment inline below. With that fixed:

Quoted 29 lines
---
 app/test-dma-perf/main.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
app/test-dma-perf/main.c +3 -5
index 18219918cc..dccb0a3541 100644
@@ -217,27 +217,27 @@ parse_lcore_dma(struct test_configure *test_case, const char *value)
 	struct lcore_dma_map_t *lcore_dma_map;
 	char *input, *addrs;
 	char *ptrs[2];
-	char *start, *end, *substr;
+	char *start, *end, *substr, *saveptr;
 	uint16_t lcore_id;
 	int ret = 0;
 
 	if (test_case == NULL || value == NULL)
 		return -1;
 
-	input = strndup(value, strlen(value) + 1);
+	input = strdup(value);
 	if (input == NULL)
 		return -1;
-	addrs = input;
 
-	while (*addrs == '\0')
-		addrs++;
+	addrs = input;

app/test-dma-perf/main.c parse_lcore_dma(struct test_configure *test_case, const char *value) · line 240

Quoted 10 lines
app/test-dma-perf/main.c +3 -1
+	while (isspace(*addrs))
+		++addrs;
 	if (*addrs == '\0') {
 		fprintf(stderr, "No input DMA addresses\n");
 		ret = -1;
 		goto out;
 	}
 
-	substr = strtok(addrs, ",");
+	substr = strtok_r(addrs, ",", &saveptr);

Don't need to use strtok here at all. Just use strchr, and then no need for a new temporary variable.

Quoted 6 lines
app/test-dma-perf/main.c +0 -0
 	if (substr == NULL) {
 		fprintf(stderr, "No input DMA address\n");
 		ret = -1;
Signature · 1 line
2.45.2
#35 lore raw

Re: [PATCH v2 10/10] app/test-dma-perf: fix parsing of DMA address

Quoted 56 lines · On Fri, 15 Nov 2024 09:13:12 +0000 Bruce Richardson…
Quoted 6 lines · Stephen Hemminger

There was useless loop when looking at the DMA address. It looks like it was meant to skip whitespace before calling strtok.

Good time to replace strtok with strtok_r as well.

Quoted 7 lines
Fixes 623dc9364dc6 ("app/dma-perf: introduce DMA performance test")

One comment inline below. With that fixed:

Quoted 37 lines
---
 app/test-dma-perf/main.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
app/test-dma-perf/main.c +5 -5
index 18219918cc..dccb0a3541 100644
@@ -217,27 +217,27 @@ parse_lcore_dma(struct test_configure *test_case, const char *value)
 	struct lcore_dma_map_t *lcore_dma_map;
 	char *input, *addrs;
 	char *ptrs[2];
-	char *start, *end, *substr;
+	char *start, *end, *substr, *saveptr;
 	uint16_t lcore_id;
 	int ret = 0;
 
 	if (test_case == NULL || value == NULL)
 		return -1;
 
-	input = strndup(value, strlen(value) + 1);
+	input = strdup(value);
 	if (input == NULL)
 		return -1;
-	addrs = input;
 
-	while (*addrs == '\0')
-		addrs++;
+	addrs = input;
+	while (isspace(*addrs))
+		++addrs;
 	if (*addrs == '\0') {
 		fprintf(stderr, "No input DMA addresses\n");
 		ret = -1;
 		goto out;
 	}
 
Quoted 5 lines

app/test-dma-perf/main.c parse_lcore_dma(struct test_configure *test_case, const char *value) · line 240

Quoted 2 lines
app/test-dma-perf/main.c +1 -1
-	substr = strtok(addrs, ",");
+	substr = strtok_r(addrs, ",", &saveptr);  

Don't need to use strtok here at all. Just use strchr, and then no need for a new temporary variable.

The issue is that the test is passing each comma seperated section to rte_strsplit and that needs the first part to be null terminated.
But using strtok_r in only one spot is wrong, will fix.

#36 lore raw

v3 cover bug fixes for unit tests

In reply to Stephen Hemminger

Recent blog post from PVS studio referenced lots bugs found by their analyzer against DPDK. This set addresses the ones in the test suite.

v3 - minimize change to test-dma-perf

Stephen Hemminger (10):
app/test: do not duplicate loop variable app/test: fix typo in address compare
app/test: fix paren typo
app/test: avoid duplicate initialization app/test: fix TLS zero length record
app/test: fix operator precedence bug
test/eal: fix core check in c flag test app/test-pmd: remove redundant condition app/test-pmd: avoid potential outside of array reference app/test-dma-perf: fix parsing of DMA address

 app/test-dma-perf/main.c                      |  4 +--
 app/test-pmd/cmdline_flow.c                   |  2 +-
 app/test-pmd/config.c                         |  3 +-
 app/test/test_common.c                        | 31 ++++++++++---------
 app/test/test_cryptodev.c                     |  5 +--
 app/test/test_eal_flags.c                     |  4 +--
 app/test/test_event_crypto_adapter.c          | 24 ++++++--------
 app/test/test_link_bonding.c                  |  9 ++----
 app/test/test_security_inline_proto_vectors.h |  8 +++--
 9 files changed, 41 insertions(+), 49 deletions(-)
Signature · 1 line
2.45.2
#37 lore raw

PATCH v3 1/10 app/test: do not duplicate loop variable

Do not use same variable for outer and inner loop in bonding test. Since the loop is just freeing the resulting burst use bulk free.

Fixes 92073ef961ee ("bond: unit tests")
---
 app/test/test_link_bonding.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
app/test/test_link_bonding.c +1 -6
index 4d54706c21..805613d7dd 100644
@@ -2288,12 +2288,7 @@ test_activebackup_rx_burst(void)
 		}
 
 		/* free mbufs */
-		for (i = 0; i < MAX_PKT_BURST; i++) {
-			if (rx_pkt_burst[i] != NULL) {
-				rte_pktmbuf_free(rx_pkt_burst[i]);
-				rx_pkt_burst[i] = NULL;
-			}
-		}
+		rte_pktmbuf_free_bulk(rx_pkt_burst, burst_size);
 
 		/* reset bonding device stats */
 		rte_eth_stats_reset(test_params->bonding_port_id);
Signature · 1 line
2.45.2
#38 lore raw

PATCH v3 2/10 app/test: fix typo in address compare

In reply to Stephen Hemminger

The first argument of 'memcmp' function was equal to the second argument. Therefore ASSERT would always be true.

Fixes 92073ef961ee ("bond: unit tests")
---
 app/test/test_link_bonding.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
app/test/test_link_bonding.c +1 -1
index 805613d7dd..b752a5ecbf 100644
@@ -792,7 +792,7 @@ test_set_primary_member(void)
 				&read_mac_addr),
 				"Failed to get mac address (port %d)",
 				test_params->bonding_port_id);
-		TEST_ASSERT_SUCCESS(memcmp(&read_mac_addr, &read_mac_addr,
+		TEST_ASSERT_SUCCESS(memcmp(expected_mac_addr, &read_mac_addr,
 				sizeof(read_mac_addr)),
 				"bonding port mac address not set to that of primary port\n");
 
Signature · 1 line
2.45.2
#39 lore raw

PATCH v3 3/10 app/test: fix paren typo

In reply to Stephen Hemminger

The parenthesis were in the wrong place so that comparison took precedence over assignment in handling IPv6 extension headers. Break up the loop condition to avoid the problem.

Fixes 15ccc647526e ("test/security: test inline reassembly with multi-segment")
---
 app/test/test_security_inline_proto_vectors.h | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
app/test/test_security_inline_proto_vectors.h +5 -3
index b3d724bac6..86dfa54777 100644
@@ -519,10 +519,12 @@ test_vector_payload_populate(struct ip_reassembly_test_packet *pkt,
 			if (extra_data_sum) {
 				proto = hdr->proto;
 				p += sizeof(struct rte_ipv6_hdr);
-				while (proto != IPPROTO_FRAGMENT &&
-				       (proto = rte_ipv6_get_next_ext(p, proto, &ext_len) >= 0))
+				while (proto != IPPROTO_FRAGMENT) {
+					proto = rte_ipv6_get_next_ext(p, proto, &ext_len);
+					if (proto < 0)
+						break;
 					p += ext_len;
-
+				}
 				/* Found fragment header, update the frag offset */
 				if (proto == IPPROTO_FRAGMENT) {
 					frag_ext = (struct rte_ipv6_fragment_ext *)p;
Signature · 1 line
2.45.2
#40 lore raw

PATCH v3 4/10 app/test: avoid duplicate initialization

In reply to Stephen Hemminger

The event_dev_config initialization had duplicate assignments to the same element. Change to use structure initialization so that compiler will catch this type of bug.

Fixes f8f9d233ea0e ("test/eventdev: add unit tests")
---
 app/test/test_event_crypto_adapter.c | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)
app/test/test_event_crypto_adapter.c +10 -14
index 9d38a66bfa..ab24e30a97 100644
@@ -1154,21 +1154,17 @@ configure_cryptodev(void)
 
 static inline void
 evdev_set_conf_values(struct rte_event_dev_config *dev_conf,
-			struct rte_event_dev_info *info)
+		      const struct rte_event_dev_info *info)
 {
-	memset(dev_conf, 0, sizeof(struct rte_event_dev_config));
-	dev_conf->dequeue_timeout_ns = info->min_dequeue_timeout_ns;
-	dev_conf->nb_event_ports = NB_TEST_PORTS;
-	dev_conf->nb_event_queues = NB_TEST_QUEUES;
-	dev_conf->nb_event_queue_flows = info->max_event_queue_flows;
-	dev_conf->nb_event_port_dequeue_depth =
-			info->max_event_port_dequeue_depth;
-	dev_conf->nb_event_port_enqueue_depth =
-			info->max_event_port_enqueue_depth;
-	dev_conf->nb_event_port_enqueue_depth =
-			info->max_event_port_enqueue_depth;
-	dev_conf->nb_events_limit =
-			info->max_num_events;
+	*dev_conf = (struct rte_event_dev_config) {
+		.dequeue_timeout_ns = info->min_dequeue_timeout_ns,
+		.nb_event_ports = NB_TEST_PORTS,
+		.nb_event_queues = NB_TEST_QUEUES,
+		.nb_event_queue_flows = info->max_event_queue_flows,
+		.nb_event_port_dequeue_depth = info->max_event_port_dequeue_depth,
+		.nb_event_port_enqueue_depth = info->max_event_port_enqueue_depth,
+		.nb_events_limit = info->max_num_events,
+	};
 }
 
 static int
Signature · 1 line
2.45.2
Acked-by on v3 4/10
#41 lore raw

RE: [PATCH v3 04/10] app/test: avoid duplicate initialization

Quoted 16 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Saturday, November 16, 2024 1:37 AM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>; [email protected]; Richardson, Bruce <[email protected]>; Gujjar, Abhinandan S <[email protected]>
Subject: [PATCH v3 04/10] app/test: avoid duplicate initialization

The event_dev_config initialization had duplicate assignments to the same element. Change to use structure initialization so that compiler will catch this type of bug.

Quoted 6 lines
Fixes f8f9d233ea0e ("test/eventdev: add unit tests")
Quoted 46 lines
---
 app/test/test_event_crypto_adapter.c | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)
app/test/test_event_crypto_adapter.c +10 -14
index 9d38a66bfa..ab24e30a97 100644
@@ -1154,21 +1154,17 @@ configure_cryptodev(void)
 
 static inline void
 evdev_set_conf_values(struct rte_event_dev_config *dev_conf,
-			struct rte_event_dev_info *info)
+		      const struct rte_event_dev_info *info)
 {
-	memset(dev_conf, 0, sizeof(struct rte_event_dev_config));
-	dev_conf->dequeue_timeout_ns = info->min_dequeue_timeout_ns;
-	dev_conf->nb_event_ports = NB_TEST_PORTS;
-	dev_conf->nb_event_queues = NB_TEST_QUEUES;
-	dev_conf->nb_event_queue_flows = info->max_event_queue_flows;
-	dev_conf->nb_event_port_dequeue_depth =
-			info->max_event_port_dequeue_depth;
-	dev_conf->nb_event_port_enqueue_depth =
-			info->max_event_port_enqueue_depth;
-	dev_conf->nb_event_port_enqueue_depth =
-			info->max_event_port_enqueue_depth;
-	dev_conf->nb_events_limit =
-			info->max_num_events;
+	*dev_conf = (struct rte_event_dev_config) {
+		.dequeue_timeout_ns = info->min_dequeue_timeout_ns,
+		.nb_event_ports = NB_TEST_PORTS,
+		.nb_event_queues = NB_TEST_QUEUES,
+		.nb_event_queue_flows = info->max_event_queue_flows,
+		.nb_event_port_dequeue_depth = info-
 >max_event_port_dequeue_depth,
+		.nb_event_port_enqueue_depth = info-
 >max_event_port_enqueue_depth,
+		.nb_events_limit = info->max_num_events,
+	};
 }

static int
--
2.45.2

#42 lore raw

PATCH v3 5/10 app/test: fix TLS zero length record

In reply to Stephen Hemminger

The code was duplicating the same condition three times? Reading the commit message, the intention was:

Add unit tests to verify the zero len TLS records. Zero len packets are allowed when content type is app data while zero packet length with other content type (such as handshake) would result in an error.

Fixes 79a58624369a ("test/security: verify zero length TLS records")
---
 app/test/test_cryptodev.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
app/test/test_cryptodev.c +1 -4
index c647baeee1..a33ef574cc 100644
@@ -12253,10 +12253,7 @@ test_tls_record_proto_all(const struct tls_record_test_flags *flags)
 		if (flags->skip_sess_destroy && sec_session_outb == NULL)
 			sec_session_outb = ut_params->sec_session;
 
-		if (flags->zero_len &&
-		    ((flags->content_type == TLS_RECORD_TEST_CONTENT_TYPE_HANDSHAKE) ||
-		    (flags->content_type == TLS_RECORD_TEST_CONTENT_TYPE_HANDSHAKE) ||
-		    (flags->content_type == TLS_RECORD_TEST_CONTENT_TYPE_HANDSHAKE))) {
+		if (flags->zero_len && flags->content_type != TLS_RECORD_TEST_CONTENT_TYPE_APP) {
 			if (ret == TEST_SUCCESS)
 				return TEST_FAILED;
 			goto skip_decrypt;
Signature · 1 line
2.45.2
#43 lore raw

PATCH v3 6/10 app/test: fix operator precedence bug

In reply to Stephen Hemminger

The test loop was much shorter than desired because when MAX_NUM is defined with out paren's the divide operator / takes precedence over shift.

But when MAX_NUM is fixed, some tests take too long and have to be modified to avoid running over full N^2 space of 1<<20.

Note: this is a very old bug, goes back to 2013.

Fixes 1fb8b07ee511 ("app: add some tests")
---
 app/test/test_common.c | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)
app/test/test_common.c +17 -14
index 21eb2285e1..6dbd7fc9a9 100644
@@ -9,11 +9,12 @@
 #include <rte_common.h>
 #include <rte_bitops.h>
 #include <rte_hexdump.h>
+#include <rte_random.h>
 #include <rte_pause.h>
 
 #include "test.h"
 
-#define MAX_NUM 1 << 20
+#define MAX_NUM (1 << 20)
 
 #define FAIL(x)\
 	{printf(x "() test failed!\n");\
@@ -218,19 +219,21 @@ test_align(void)
 		}
 	}
 
-	for (p = 1; p <= MAX_NUM / 2; p++) {
-		for (i = 1; i <= MAX_NUM / 2; i++) {
-			val = RTE_ALIGN_MUL_CEIL(i, p);
-			if (val % p != 0 || val < i)
-				FAIL_ALIGN("RTE_ALIGN_MUL_CEIL", i, p);
-			val = RTE_ALIGN_MUL_FLOOR(i, p);
-			if (val % p != 0 || val > i)
-				FAIL_ALIGN("RTE_ALIGN_MUL_FLOOR", i, p);
-			val = RTE_ALIGN_MUL_NEAR(i, p);
-			if (val % p != 0 || ((val != RTE_ALIGN_MUL_CEIL(i, p))
-				& (val != RTE_ALIGN_MUL_FLOOR(i, p))))
-				FAIL_ALIGN("RTE_ALIGN_MUL_NEAR", i, p);
-		}
+	/* testing the whole space of 2^20^2 takes too long. */
+	for (j = 1; j <= MAX_NUM ; j++) {
+		i = rte_rand_max(MAX_NUM - 1) + 1;
+		p = rte_rand_max(MAX_NUM - 1) + 1;
+
+		val = RTE_ALIGN_MUL_CEIL(i, p);
+		if (val % p != 0 || val < i)
+			FAIL_ALIGN("RTE_ALIGN_MUL_CEIL", i, p);
+		val = RTE_ALIGN_MUL_FLOOR(i, p);
+		if (val % p != 0 || val > i)
+			FAIL_ALIGN("RTE_ALIGN_MUL_FLOOR", i, p);
+		val = RTE_ALIGN_MUL_NEAR(i, p);
+		if (val % p != 0 || ((val != RTE_ALIGN_MUL_CEIL(i, p))
+				     & (val != RTE_ALIGN_MUL_FLOOR(i, p))))
+			FAIL_ALIGN("RTE_ALIGN_MUL_NEAR", i, p);
 	}
 
 	return 0;
Signature · 1 line
2.45.2
#44 lore raw

PATCH v3 7/10 test/eal: fix core check in c flag test

In reply to Stephen Hemminger

The expression for checking which lcore is enabled for 0-7 was wrong (missing case for 6).

Fixes b0209034f2bb ("test/eal: check number of cores before running subtests")
---
 app/test/test_eal_flags.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
app/test/test_eal_flags.c +2 -2
index d37d6b8627..e32f83d3c8 100644
@@ -677,8 +677,8 @@ test_missing_c_flag(void)
 
 	if (rte_lcore_is_enabled(0) && rte_lcore_is_enabled(1) &&
 	    rte_lcore_is_enabled(2) && rte_lcore_is_enabled(3) &&
-	    rte_lcore_is_enabled(3) && rte_lcore_is_enabled(5) &&
-	    rte_lcore_is_enabled(4) && rte_lcore_is_enabled(7) &&
+	    rte_lcore_is_enabled(4) && rte_lcore_is_enabled(5) &&
+	    rte_lcore_is_enabled(6) && rte_lcore_is_enabled(7) &&
 	    launch_proc(argv29) != 0) {
 		printf("Error - "
 		       "process did not run ok with valid corelist value\n");
Signature · 1 line
2.45.2
#45 lore raw

PATCH v3 8/10 app/test-pmd: remove redundant condition

In reply to Stephen Hemminger

The loop over policy actions will always exit when it sees the flow end action, so the next check is redundant.

Fixes f29fa2c59b85 ("app/testpmd: support policy actions per color")
---
 app/test-pmd/config.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
app/test-pmd/config.c +1 -2
index 88770b4dfc..32c4e86c84 100644
@@ -2288,7 +2288,7 @@ port_meter_policy_add(portid_t port_id, uint32_t policy_id,
 		for (act_n = 0, start = act;
 			act->type != RTE_FLOW_ACTION_TYPE_END; act++)
 			act_n++;
-		if (act_n && act->type == RTE_FLOW_ACTION_TYPE_END)
+		if (act_n > 0)
 			policy.actions[i] = start;
 		else
 			policy.actions[i] = NULL;
@@ -7316,4 +7316,3 @@ show_mcast_macs(portid_t port_id)
 		printf("  %s\n", buf);
 	}
 }
-
Signature · 1 line
2.45.2
Acked-by on v3 8/10
#46 lore raw

Re: [PATCH v3 08/10] app/test-pmd: remove redundant condition

Quoted 10 lines · Stephen Hemminger

The loop over policy actions will always exit when it sees the flow end action, so the next check is redundant.

Fixes f29fa2c59b85 ("app/testpmd: support policy actions per color")
Quoted 25 lines
---
 app/test-pmd/config.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
app/test-pmd/config.c +1 -3
index 88770b4dfc..32c4e86c84 100644
@@ -2288,7 +2288,7 @@ port_meter_policy_add(portid_t port_id, uint32_t policy_id,
                for (act_n = 0, start = act;
                        act->type != RTE_FLOW_ACTION_TYPE_END; act++)
                        act_n++;
-               if (act_n && act->type == RTE_FLOW_ACTION_TYPE_END)
+               if (act_n > 0)
                        policy.actions[i] = start;
                else
                        policy.actions[i] = NULL;
@@ -7316,4 +7316,3 @@ show_mcast_macs(portid_t port_id)
                printf("  %s\n", buf);
        }
 }
-
--

2.45.2

#47 lore raw

PATCH v3 9/10 app/test-pmd: avoid potential outside of array reference

In reply to Stephen Hemminger

The order of comparison is wrong, and potentially allows referencing past the array.

Fixes 3e3edab530a1 ("ethdev: add flow quota")
---
 app/test-pmd/cmdline_flow.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
app/test-pmd/cmdline_flow.c +1 -1
index 1e4f2ebc55..9e4fc2d95d 100644
@@ -12892,7 +12892,7 @@ comp_names_to_index(struct context *ctx, const struct token *token,
 	RTE_SET_USED(token);
 	if (!buf)
 		return names_size;
-	if (names[ent] && ent < names_size)
+	if (ent < names_size && names[ent] != NULL)
 		return rte_strscpy(buf, names[ent], size);
 	return -1;
 
Signature · 1 line
2.45.2
#48 lore raw

PATCH v3 10/10 app/test-dma-perf: fix parsing of DMA address

In reply to Stephen Hemminger

There was useless loop when looking at the DMA address. It looks like it was meant to skip whitespace before calling strtok.

Good time to replace strtok with strtok_r as well.

Fixes 623dc9364dc6 ("app/dma-perf: introduce DMA performance test")
---
 app/test-dma-perf/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
app/test-dma-perf/main.c +2 -2
index 18219918cc..8d46b1258b 100644
@@ -229,8 +229,8 @@ parse_lcore_dma(struct test_configure *test_case, const char *value)
 		return -1;
 	addrs = input;
 
-	while (*addrs == '\0')
-		addrs++;
+	while (isspace(*addrs))
+		++addrs;
 	if (*addrs == '\0') {
 		fprintf(stderr, "No input DMA addresses\n");
 		ret = -1;
Signature · 1 line
2.45.2
Acked-by on v3 10/10
#49 lore raw

Re: [PATCH v3 10/10] app/test-dma-perf: fix parsing of DMA address

Quoted 5 lines · Stephen Hemminger

There was useless loop when looking at the DMA address. It looks like it was meant to skip whitespace before calling strtok.

Good time to replace strtok with strtok_r as well.

Please delete this line, with this fixed:

Quoted 28 lines
Fixes 623dc9364dc6 ("app/dma-perf: introduce DMA performance test")
---
 app/test-dma-perf/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
app/test-dma-perf/main.c +2 -2
index 18219918cc..8d46b1258b 100644
@@ -229,8 +229,8 @@ parse_lcore_dma(struct test_configure *test_case, const char *value)
 		return -1;
 	addrs = input;
 
-	while (*addrs == '\0')
-		addrs++;
+	while (isspace(*addrs))
+		++addrs;
 	if (*addrs == '\0') {
 		fprintf(stderr, "No input DMA addresses\n");
 		ret = -1;
#50 lore raw

v4 cover Bug fixes for standalone tests

In reply to Stephen Hemminger

Recent blog post from PVS studio referenced lots bugs found by their analyzer against DPDK. This set addresses the ones in the test suite.

v4 - rebase and drop code that was already fixed (removed)

Stephen Hemminger (9):
app/test: do not duplicate loop variable app/test: fix typo in address compare
app/test: fix paren typo
app/test: avoid duplicate initialization app/test: fix TLS zero length record
app/test: fix operator precedence bug
test/eal: fix core check in c flag test app/test-pmd: remove redundant condition app/test-pmd: avoid potential outside of array reference

 app/test-pmd/cmdline_flow.c                   |  2 +-
 app/test-pmd/config.c                         |  3 +-
 app/test/test_common.c                        | 31 ++++++++++---------
 app/test/test_cryptodev.c                     |  5 +--
 app/test/test_eal_flags.c                     |  4 +--
 app/test/test_event_crypto_adapter.c          | 24 ++++++--------
 app/test/test_link_bonding.c                  |  9 ++----
 app/test/test_security_inline_proto_vectors.h |  8 +++--
 8 files changed, 39 insertions(+), 47 deletions(-)
Signature · 1 line
2.45.2
#51 lore raw

PATCH v4 1/9 app/test: do not duplicate loop variable

Do not use same variable for outer and inner loop in bonding test. Since the loop is just freeing the resulting burst use bulk free.

Fixes 92073ef961ee ("bond: unit tests")
---
 app/test/test_link_bonding.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
app/test/test_link_bonding.c +1 -6
index 4d54706c21..805613d7dd 100644
@@ -2288,12 +2288,7 @@ test_activebackup_rx_burst(void)
 		}
 
 		/* free mbufs */
-		for (i = 0; i < MAX_PKT_BURST; i++) {
-			if (rx_pkt_burst[i] != NULL) {
-				rte_pktmbuf_free(rx_pkt_burst[i]);
-				rx_pkt_burst[i] = NULL;
-			}
-		}
+		rte_pktmbuf_free_bulk(rx_pkt_burst, burst_size);
 
 		/* reset bonding device stats */
 		rte_eth_stats_reset(test_params->bonding_port_id);
Signature · 1 line
2.45.2
Acked-by on v4 1/9
#52 lore raw

Re: [PATCH v4 1/9] app/test: do not duplicate loop variable

Quoted 33 lines · Stephen Hemminger

Do not use same variable for outer and inner loop in bonding test. Since the loop is just freeing the resulting burst use bulk free.

Fixes 92073ef961ee ("bond: unit tests")
---
 app/test/test_link_bonding.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
app/test/test_link_bonding.c +1 -6
index 4d54706c21..805613d7dd 100644
@@ -2288,12 +2288,7 @@ test_activebackup_rx_burst(void)
 		}
 
 		/* free mbufs */
-		for (i = 0; i < MAX_PKT_BURST; i++) {
-			if (rx_pkt_burst[i] != NULL) {
-				rte_pktmbuf_free(rx_pkt_burst[i]);
-				rx_pkt_burst[i] = NULL;
-			}
-		}
+		rte_pktmbuf_free_bulk(rx_pkt_burst, burst_size);
 
 		/* reset bonding device stats */
 		rte_eth_stats_reset(test_params->bonding_port_id);
#53 lore raw

PATCH v4 2/9 app/test: fix typo in address compare

In reply to Stephen Hemminger

The first argument of 'memcmp' function was equal to the second argument. Therefore ASSERT would always be true.

Fixes 92073ef961ee ("bond: unit tests")
---
 app/test/test_link_bonding.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
app/test/test_link_bonding.c +1 -1
index 805613d7dd..b752a5ecbf 100644
@@ -792,7 +792,7 @@ test_set_primary_member(void)
 				&read_mac_addr),
 				"Failed to get mac address (port %d)",
 				test_params->bonding_port_id);
-		TEST_ASSERT_SUCCESS(memcmp(&read_mac_addr, &read_mac_addr,
+		TEST_ASSERT_SUCCESS(memcmp(expected_mac_addr, &read_mac_addr,
 				sizeof(read_mac_addr)),
 				"bonding port mac address not set to that of primary port\n");
 
Signature · 1 line
2.45.2
Acked-by on v4 2/9
#54 lore raw

Re: [PATCH v4 2/9] app/test: fix typo in address compare

Quoted 27 lines · Stephen Hemminger

The first argument of 'memcmp' function was equal to the second argument. Therefore ASSERT would always be true.

Fixes 92073ef961ee ("bond: unit tests")
---
 app/test/test_link_bonding.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
app/test/test_link_bonding.c +1 -1
index 805613d7dd..b752a5ecbf 100644
@@ -792,7 +792,7 @@ test_set_primary_member(void)
 				&read_mac_addr),
 				"Failed to get mac address (port %d)",
 				test_params->bonding_port_id);
-		TEST_ASSERT_SUCCESS(memcmp(&read_mac_addr, &read_mac_addr,
+		TEST_ASSERT_SUCCESS(memcmp(expected_mac_addr, &read_mac_addr,
 				sizeof(read_mac_addr)),
 				"bonding port mac address not set to that of primary port\n");
 
Acked-by on v4 2/9
#55 lore raw

Re: [PATCH v4 2/9] app/test: fix typo in address compare

In reply to Stephen Hemminger
Quoted 19 lines · Stephen Hemminger

The first argument of 'memcmp' function was equal to the second argument. Therefore ASSERT would always be true.

Fixes 92073ef961ee ("bond: unit tests")
---
 app/test/test_link_bonding.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
app/test/test_link_bonding.c +0 -0
index 805613d7dd..b752a5ecbf 100644

app/test/test_link_bonding.c test_set_primary_member(void) · line 798

Quoted 8 lines
app/test/test_link_bonding.c +1 -1
@@ -792,7 +792,7 @@ test_set_primary_member(void)
 				&read_mac_addr),
 				"Failed to get mac address (port %d)",
 				test_params->bonding_port_id);
-		TEST_ASSERT_SUCCESS(memcmp(&read_mac_addr, &read_mac_addr,
+		TEST_ASSERT_SUCCESS(memcmp(expected_mac_addr, &read_mac_addr,
 				sizeof(read_mac_addr)),
 				"bonding port mac address not set to that of primary port\n");
 
#56 lore raw

PATCH v4 3/9 app/test: fix paren typo

In reply to Stephen Hemminger

The parenthesis were in the wrong place so that comparison took precedence over assignment in handling IPv6 extension headers. Break up the loop condition to avoid the problem.

Fixes 15ccc647526e ("test/security: test inline reassembly with multi-segment")
---
 app/test/test_security_inline_proto_vectors.h | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
app/test/test_security_inline_proto_vectors.h +5 -3
index b3d724bac6..86dfa54777 100644
@@ -519,10 +519,12 @@ test_vector_payload_populate(struct ip_reassembly_test_packet *pkt,
 			if (extra_data_sum) {
 				proto = hdr->proto;
 				p += sizeof(struct rte_ipv6_hdr);
-				while (proto != IPPROTO_FRAGMENT &&
-				       (proto = rte_ipv6_get_next_ext(p, proto, &ext_len) >= 0))
+				while (proto != IPPROTO_FRAGMENT) {
+					proto = rte_ipv6_get_next_ext(p, proto, &ext_len);
+					if (proto < 0)
+						break;
 					p += ext_len;
-
+				}
 				/* Found fragment header, update the frag offset */
 				if (proto == IPPROTO_FRAGMENT) {
 					frag_ext = (struct rte_ipv6_fragment_ext *)p;
Signature · 1 line
2.45.2
Acked-by on v4 3/9
#57 lore raw

Re: [PATCH v4 3/9] app/test: fix paren typo

Quoted 36 lines · Stephen Hemminger

The parenthesis were in the wrong place so that comparison took precedence over assignment in handling IPv6 extension headers. Break up the loop condition to avoid the problem.

Fixes 15ccc647526e ("test/security: test inline reassembly with multi-segment")
---
 app/test/test_security_inline_proto_vectors.h | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
app/test/test_security_inline_proto_vectors.h +5 -3
index b3d724bac6..86dfa54777 100644
@@ -519,10 +519,12 @@ test_vector_payload_populate(struct ip_reassembly_test_packet *pkt,
 			if (extra_data_sum) {
 				proto = hdr->proto;
 				p += sizeof(struct rte_ipv6_hdr);
-				while (proto != IPPROTO_FRAGMENT &&
-				       (proto = rte_ipv6_get_next_ext(p, proto, &ext_len) >= 0))
+				while (proto != IPPROTO_FRAGMENT) {
+					proto = rte_ipv6_get_next_ext(p, proto, &ext_len);
+					if (proto < 0)
+						break;
 					p += ext_len;
-
+				}
 				/* Found fragment header, update the frag offset */
 				if (proto == IPPROTO_FRAGMENT) {
 					frag_ext = (struct rte_ipv6_fragment_ext *)p;
#58 lore raw

PATCH v4 4/9 app/test: avoid duplicate initialization

In reply to Stephen Hemminger

The event_dev_config initialization had duplicate assignments to the same element. Change to use structure initialization so that compiler will catch this type of bug.

Fixes f8f9d233ea0e ("test/eventdev: add unit tests")
---
 app/test/test_event_crypto_adapter.c | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)
app/test/test_event_crypto_adapter.c +10 -14
index 9d38a66bfa..ab24e30a97 100644
@@ -1154,21 +1154,17 @@ configure_cryptodev(void)
 
 static inline void
 evdev_set_conf_values(struct rte_event_dev_config *dev_conf,
-			struct rte_event_dev_info *info)
+		      const struct rte_event_dev_info *info)
 {
-	memset(dev_conf, 0, sizeof(struct rte_event_dev_config));
-	dev_conf->dequeue_timeout_ns = info->min_dequeue_timeout_ns;
-	dev_conf->nb_event_ports = NB_TEST_PORTS;
-	dev_conf->nb_event_queues = NB_TEST_QUEUES;
-	dev_conf->nb_event_queue_flows = info->max_event_queue_flows;
-	dev_conf->nb_event_port_dequeue_depth =
-			info->max_event_port_dequeue_depth;
-	dev_conf->nb_event_port_enqueue_depth =
-			info->max_event_port_enqueue_depth;
-	dev_conf->nb_event_port_enqueue_depth =
-			info->max_event_port_enqueue_depth;
-	dev_conf->nb_events_limit =
-			info->max_num_events;
+	*dev_conf = (struct rte_event_dev_config) {
+		.dequeue_timeout_ns = info->min_dequeue_timeout_ns,
+		.nb_event_ports = NB_TEST_PORTS,
+		.nb_event_queues = NB_TEST_QUEUES,
+		.nb_event_queue_flows = info->max_event_queue_flows,
+		.nb_event_port_dequeue_depth = info->max_event_port_dequeue_depth,
+		.nb_event_port_enqueue_depth = info->max_event_port_enqueue_depth,
+		.nb_events_limit = info->max_num_events,
+	};
 }
 
 static int
Signature · 1 line
2.45.2
#59 lore raw

PATCH v4 5/9 app/test: fix TLS zero length record

In reply to Stephen Hemminger

The code was duplicating the same condition three times? Reading the commit message, the intention was:

Add unit tests to verify the zero len TLS records. Zero len packets are allowed when content type is app data while zero packet length with other content type (such as handshake) would result in an error.

Fixes 79a58624369a ("test/security: verify zero length TLS records")
---
 app/test/test_cryptodev.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
app/test/test_cryptodev.c +1 -4
index c647baeee1..a33ef574cc 100644
@@ -12253,10 +12253,7 @@ test_tls_record_proto_all(const struct tls_record_test_flags *flags)
 		if (flags->skip_sess_destroy && sec_session_outb == NULL)
 			sec_session_outb = ut_params->sec_session;
 
-		if (flags->zero_len &&
-		    ((flags->content_type == TLS_RECORD_TEST_CONTENT_TYPE_HANDSHAKE) ||
-		    (flags->content_type == TLS_RECORD_TEST_CONTENT_TYPE_HANDSHAKE) ||
-		    (flags->content_type == TLS_RECORD_TEST_CONTENT_TYPE_HANDSHAKE))) {
+		if (flags->zero_len && flags->content_type != TLS_RECORD_TEST_CONTENT_TYPE_APP) {
 			if (ret == TEST_SUCCESS)
 				return TEST_FAILED;
 			goto skip_decrypt;
Signature · 1 line
2.45.2
Acked-by on v4 5/9
#60 lore raw

RE: [EXTERNAL] [PATCH v4 5/9] app/test: fix TLS zero length record

Quoted 7 lines

The code was duplicating the same condition three times? Reading the commit message, the intention was:

Add unit tests to verify the zero len TLS records. Zero len packets are allowed when content type is app data while zero packet length with other content type (such as handshake) would result in an error.

Quoted 8 lines

WYLn1v9SyTMrT5EQqh2TU&m=XameIFsYmmvHMhJycVwGxFucfJNVntjVlTBXIykV7kmsF4i5OLtyrXHT9KSTJnkm&s=JaPpRUXDxqq1KFX_JG2CQI0viz-YZG33I8zoO25Fr6k&e=

Fixes 79a58624369a ("test/security: verify zero length TLS records")

Good catch. Looks like remnants after a rename exercise. Originally it was intended as separate for TLS 1.2, DTLS 1.2 & TLS 1.3.

#61 lore raw

PATCH v4 6/9 app/test: fix operator precedence bug

In reply to Stephen Hemminger

The test loop was much shorter than desired because when MAX_NUM is defined with out paren's the divide operator / takes precedence over shift.

But when MAX_NUM is fixed, some tests take too long and have to be modified to avoid running over full N^2 space of 1<<20.

Note: this is a very old bug, goes back to 2013.

Fixes 1fb8b07ee511 ("app: add some tests")
---
 app/test/test_common.c | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)
app/test/test_common.c +17 -14
index 21eb2285e1..6dbd7fc9a9 100644
@@ -9,11 +9,12 @@
 #include <rte_common.h>
 #include <rte_bitops.h>
 #include <rte_hexdump.h>
+#include <rte_random.h>
 #include <rte_pause.h>
 
 #include "test.h"
 
-#define MAX_NUM 1 << 20
+#define MAX_NUM (1 << 20)
 
 #define FAIL(x)\
 	{printf(x "() test failed!\n");\
@@ -218,19 +219,21 @@ test_align(void)
 		}
 	}
 
-	for (p = 1; p <= MAX_NUM / 2; p++) {
-		for (i = 1; i <= MAX_NUM / 2; i++) {
-			val = RTE_ALIGN_MUL_CEIL(i, p);
-			if (val % p != 0 || val < i)
-				FAIL_ALIGN("RTE_ALIGN_MUL_CEIL", i, p);
-			val = RTE_ALIGN_MUL_FLOOR(i, p);
-			if (val % p != 0 || val > i)
-				FAIL_ALIGN("RTE_ALIGN_MUL_FLOOR", i, p);
-			val = RTE_ALIGN_MUL_NEAR(i, p);
-			if (val % p != 0 || ((val != RTE_ALIGN_MUL_CEIL(i, p))
-				& (val != RTE_ALIGN_MUL_FLOOR(i, p))))
-				FAIL_ALIGN("RTE_ALIGN_MUL_NEAR", i, p);
-		}
+	/* testing the whole space of 2^20^2 takes too long. */
+	for (j = 1; j <= MAX_NUM ; j++) {
+		i = rte_rand_max(MAX_NUM - 1) + 1;
+		p = rte_rand_max(MAX_NUM - 1) + 1;
+
+		val = RTE_ALIGN_MUL_CEIL(i, p);
+		if (val % p != 0 || val < i)
+			FAIL_ALIGN("RTE_ALIGN_MUL_CEIL", i, p);
+		val = RTE_ALIGN_MUL_FLOOR(i, p);
+		if (val % p != 0 || val > i)
+			FAIL_ALIGN("RTE_ALIGN_MUL_FLOOR", i, p);
+		val = RTE_ALIGN_MUL_NEAR(i, p);
+		if (val % p != 0 || ((val != RTE_ALIGN_MUL_CEIL(i, p))
+				     & (val != RTE_ALIGN_MUL_FLOOR(i, p))))
+			FAIL_ALIGN("RTE_ALIGN_MUL_NEAR", i, p);
 	}
 
 	return 0;
Signature · 1 line
2.45.2
#62 lore raw

PATCH v4 7/9 test/eal: fix core check in c flag test

In reply to Stephen Hemminger

The expression for checking which lcore is enabled for 0-7 was wrong (missing case for 6).

Fixes b0209034f2bb ("test/eal: check number of cores before running subtests")
---
 app/test/test_eal_flags.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
app/test/test_eal_flags.c +2 -2
index d37d6b8627..e32f83d3c8 100644
@@ -677,8 +677,8 @@ test_missing_c_flag(void)
 
 	if (rte_lcore_is_enabled(0) && rte_lcore_is_enabled(1) &&
 	    rte_lcore_is_enabled(2) && rte_lcore_is_enabled(3) &&
-	    rte_lcore_is_enabled(3) && rte_lcore_is_enabled(5) &&
-	    rte_lcore_is_enabled(4) && rte_lcore_is_enabled(7) &&
+	    rte_lcore_is_enabled(4) && rte_lcore_is_enabled(5) &&
+	    rte_lcore_is_enabled(6) && rte_lcore_is_enabled(7) &&
 	    launch_proc(argv29) != 0) {
 		printf("Error - "
 		       "process did not run ok with valid corelist value\n");
Signature · 1 line
2.45.2
Acked-by on v4 7/9
#63 lore raw

Re: [PATCH v4 7/9] test/eal: fix core check in c flag test

Quoted 5 lines · Stephen Hemminger

The expression for checking which lcore is enabled for 0-7 was wrong (missing case for 6).

Quoted 7 lines
Fixes b0209034f2bb ("test/eal: check number of cores before running subtests")

---

Quoted 18 lines
 app/test/test_eal_flags.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
app/test/test_eal_flags.c +2 -2
index d37d6b8627..e32f83d3c8 100644
@@ -677,8 +677,8 @@ test_missing_c_flag(void)
 
 	if (rte_lcore_is_enabled(0) && rte_lcore_is_enabled(1) &&
 	    rte_lcore_is_enabled(2) && rte_lcore_is_enabled(3) &&
-	    rte_lcore_is_enabled(3) && rte_lcore_is_enabled(5) &&
-	    rte_lcore_is_enabled(4) && rte_lcore_is_enabled(7) &&
+	    rte_lcore_is_enabled(4) && rte_lcore_is_enabled(5) &&
+	    rte_lcore_is_enabled(6) && rte_lcore_is_enabled(7) &&
 	    launch_proc(argv29) != 0) {
 		printf("Error - "
 		       "process did not run ok with valid corelist value\n");
#64 lore raw

PATCH v4 8/9 app/test-pmd: remove redundant condition

In reply to Stephen Hemminger

The loop over policy actions will always exit when it sees the flow end action, so the next check is redundant.

Fixes f29fa2c59b85 ("app/testpmd: support policy actions per color")
---
 app/test-pmd/config.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
app/test-pmd/config.c +1 -2
index 28d45568ac..4e7fb69183 100644
@@ -2288,7 +2288,7 @@ port_meter_policy_add(portid_t port_id, uint32_t policy_id,
 		for (act_n = 0, start = act;
 			act->type != RTE_FLOW_ACTION_TYPE_END; act++)
 			act_n++;
-		if (act_n && act->type == RTE_FLOW_ACTION_TYPE_END)
+		if (act_n > 0)
 			policy.actions[i] = start;
 		else
 			policy.actions[i] = NULL;
@@ -7338,4 +7338,3 @@ show_mcast_macs(portid_t port_id)
 		printf("  %s\n", buf);
 	}
 }
-
Signature · 1 line
2.45.2
Acked-by on v4 8/9
#65 lore raw

Re: [PATCH v4 8/9] app/test-pmd: remove redundant condition

Quoted 32 lines · Stephen Hemminger

The loop over policy actions will always exit when it sees the flow end action, so the next check is redundant.

Fixes f29fa2c59b85 ("app/testpmd: support policy actions per color")
---
 app/test-pmd/config.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
app/test-pmd/config.c +1 -2
index 28d45568ac..4e7fb69183 100644
@@ -2288,7 +2288,7 @@ port_meter_policy_add(portid_t port_id, uint32_t policy_id,
 		for (act_n = 0, start = act;
 			act->type != RTE_FLOW_ACTION_TYPE_END; act++)
 			act_n++;
-		if (act_n && act->type == RTE_FLOW_ACTION_TYPE_END)
+		if (act_n > 0)
 			policy.actions[i] = start;
 		else
 			policy.actions[i] = NULL;
@@ -7338,4 +7338,3 @@ show_mcast_macs(portid_t port_id)
 		printf("  %s\n", buf);
 	}
 }
-
#66 lore raw

PATCH v4 9/9 app/test-pmd: avoid potential outside of array reference

In reply to Stephen Hemminger

The order of comparison is wrong, and potentially allows referencing past the array.

Fixes 3e3edab530a1 ("ethdev: add flow quota")
---
 app/test-pmd/cmdline_flow.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
app/test-pmd/cmdline_flow.c +1 -1
index 1e4f2ebc55..9e4fc2d95d 100644
@@ -12892,7 +12892,7 @@ comp_names_to_index(struct context *ctx, const struct token *token,
 	RTE_SET_USED(token);
 	if (!buf)
 		return names_size;
-	if (names[ent] && ent < names_size)
+	if (ent < names_size && names[ent] != NULL)
 		return rte_strscpy(buf, names[ent], size);
 	return -1;
 
Signature · 1 line
2.45.2
Acked-by on v4 9/9
#67 lore raw

Re: [PATCH v4 9/9] app/test-pmd: avoid potential outside of array reference

Quoted 28 lines · Stephen Hemminger

The order of comparison is wrong, and potentially allows referencing past the array.

Fixes 3e3edab530a1 ("ethdev: add flow quota")
---
 app/test-pmd/cmdline_flow.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
app/test-pmd/cmdline_flow.c +1 -1
index 1e4f2ebc55..9e4fc2d95d 100644
@@ -12892,7 +12892,7 @@ comp_names_to_index(struct context *ctx, const struct token *token,
 	RTE_SET_USED(token);
 	if (!buf)
 		return names_size;
-	if (names[ent] && ent < names_size)
+	if (ent < names_size && names[ent] != NULL)
 		return rte_strscpy(buf, names[ent], size);
 	return -1;
 
#68 lore raw

Re: [PATCH v4 0/9] Bug fixes for standalone tests

In reply to Stephen Hemminger

21/11/2024 19:23, Stephen Hemminger:

Quoted 6 lines

Recent blog post from PVS studio referenced lots bugs found by their analyzer against DPDK. This set addresses the ones in the test suite.

v4 - rebase and drop code that was already fixed (removed)

Quoted 10 lines

Stephen Hemminger (9):
app/test: do not duplicate loop variable app/test: fix typo in address compare
app/test: fix paren typo
app/test: avoid duplicate initialization app/test: fix TLS zero length record
app/test: fix operator precedence bug
test/eal: fix core check in c flag test app/test-pmd: remove redundant condition app/test-pmd: avoid potential outside of array reference

Applied, thanks.