[PATCH v4 4/7] test: add more tests for comments in pcapng

Stephen Hemminger
2026-01-13T00:52:27Z

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

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
app/test/test_pcapng.c | 35 +++++++++++++++++++++++++++++++----
1 file changed, 31 insertions(+), 4 deletions(-)

diff --git a/app/test/test_pcapng.c b/app/test/test_pcapng.c
index bcf99724fa..09a963c676 100644
--- a/app/test/test_pcapng.c
+++ b/app/test/test_pcapng.c
@@ -125,8 +125,7 @@ test_setup(void)

/* Make a pool for cloned packets */
mp = rte_pktmbuf_pool_create_by_ops("pcapng_test_pool",
- MAX_BURST * 32, 0, 0,
- rte_pcapng_mbuf_size(pkt_len) + 128,
+ MAX_BURST * 32, 0, 0, rte_pcapng_mbuf_size(pkt_len),
SOCKET_ID_ANY, "ring_mp_sc");
if (mp == NULL) {
fprintf(stderr, "Cannot create mempool\n");
@@ -149,6 +148,22 @@ fill_pcapng_file(rte_pcapng_t *pcapng, unsigned int num_packets)
unsigned int burst_size;
unsigned int count;
ssize_t len;
+ /* These are some silly comments to test various lengths and alignments sprinkle into the file */
+ static const char * const examples[] = {
+ "Lockless and fearless - that’s how we roll in userspace.",
+ "Memory pool deep / Mbufs swim in lockless rings / Zero copy dreams,"
+ "Poll mode driver waits / No interrupts disturb its zen / Busy loop finds peace,"
+ "Memory barriers / rte_atomic_thread_fence() / Guards our shared state",
+ "Hugepages so vast / Two megabytes of glory / TLB misses weep",
+ "Packets flow like streams / Through the graph node pipeline / Iterate in place",
+
+ /* Long one to make sure we can do > 256 characters */
+ ("Dear future maintainer: I am sorry. This packet was captured at 3 AM while "
+ "debugging a priority flow control issue that turned out to be a loose cable. "
+ "The rte_eth_tx_burst() call you see here has been cargo-culted through four "
+ "generations of example code. The magic number 32 is not documented because "
+ "nobody remembers why. Trust the process."),
+ };

/* make a dummy packet */
mbuf1_prepare(&mbfs, pkt_len);
@@ -162,9 +177,14 @@ 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;
+ const char *comment = NULL;
+
+ /* Put comment on occasional packets */
+ if ((count + i) % 41 == 0)
+ comment = examples[rte_rand_max(RTE_DIM(examples))];

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;
@@ -386,7 +406,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 +433,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