[PATCH 2/2] test: add more tests for comments

Stephen Hemminger stephen at networkplumber.org
Wed Nov 5 22:03:59 CET 2025


Add some more cases where comment is set in pcapng file.

Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
---
 app/test/test_pcapng.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/app/test/test_pcapng.c b/app/test/test_pcapng.c
index bcf99724fa..7e50457794 100644
--- a/app/test/test_pcapng.c
+++ b/app/test/test_pcapng.c
@@ -162,13 +162,20 @@ fill_pcapng_file(rte_pcapng_t *pcapng, unsigned int num_packets)
 		burst_size = rte_rand_max(MAX_BURST) + 1;
 		for (i = 0; i < burst_size; i++) {
 			struct rte_mbuf *mc;
+			char *comment = NULL;
+
+			/* Put comment on one out of hundred packets */
+			if ((count + i % 100) == 0)
+				asprintf(&comment, "Function: %s\nPacket %u\n",
+					 __func__, count + i);
 
 			mc = rte_pcapng_copy(port_id, 0, orig, mp, rte_pktmbuf_pkt_len(orig),
-					     RTE_PCAPNG_DIRECTION_IN, NULL);
+					     RTE_PCAPNG_DIRECTION_IN, comment);
 			if (mc == NULL) {
 				fprintf(stderr, "Cannot copy packet\n");
 				return -1;
 			}
+			free(comment);
 			clones[i] = mc;
 		}
 
@@ -386,7 +393,7 @@ static int
 test_write_packets(void)
 {
 	char file_name[] = "/tmp/pcapng_test_XXXXXX.pcapng";
-	static rte_pcapng_t *pcapng;
+	rte_pcapng_t *pcapng = NULL;
 	int ret, tmp_fd, count;
 	uint64_t now = current_timestamp();
 
@@ -413,6 +420,13 @@ test_write_packets(void)
 		goto fail;
 	}
 
+	/* write a statistics block */
+	ret = rte_pcapng_write_stats(pcapng, port_id, 0, 0, NULL);
+	if (ret <= 0) {
+		fprintf(stderr, "Write of statistics failed\n");
+		goto fail;
+	}
+
 	count = fill_pcapng_file(pcapng, TOTAL_PACKETS);
 	if (count < 0)
 		goto fail;
-- 
2.51.0



More information about the dev mailing list