From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
Reshma Pattan <reshma.pattan@intel.com>
Subject: [PATCH v7 5/7] test/pcapng: add tests for comments
Date: Fri, 13 Feb 2026 11:18:22 -0800 [thread overview]
Message-ID: <20260213192039.221213-6-stephen@networkplumber.org> (raw)
In-Reply-To: <20260213192039.221213-1-stephen@networkplumber.org>
Expand pcapng test coverage to exercise comment handling and
additional code paths:
* Add packet comments of varying lengths, including strings longer than
256 bytes, to verify option block encoding.
* Vary packet sizes randomly to test different capture lengths
* Calculate inter-packet delays to ensure timestamp values wrap
around 32 bits at least twice during the test.
* Add a statistics block write before packet capture.
* Use RFC 864 chargen pattern for predictable fill data.
Increase total packets from 4096 to 10000 and refactor mbuf
preparation for more flexible packet construction.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
app/test/test_pcapng.c | 151 ++++++++++++++++++++++++++++++-----------
1 file changed, 113 insertions(+), 38 deletions(-)
diff --git a/app/test/test_pcapng.c b/app/test/test_pcapng.c
index 5d362ec70e..50cc92ad7d 100644
--- a/app/test/test_pcapng.c
+++ b/app/test/test_pcapng.c
@@ -25,13 +25,11 @@
#define PCAPNG_TEST_DEBUG 0
-#define TOTAL_PACKETS 4096
+#define TOTAL_PACKETS 10000
#define MAX_BURST 64
-#define MAX_GAP_US 100000
-#define DUMMY_MBUF_NUM 3
+#define DUMMY_MBUF_NUM 2
static struct rte_mempool *mp;
-static const uint32_t pkt_len = 200;
static uint16_t port_id;
static const char null_dev[] = "net_null0";
@@ -41,13 +39,40 @@ struct dummy_mbuf {
uint8_t buf[DUMMY_MBUF_NUM][RTE_MBUF_DEFAULT_BUF_SIZE];
};
+#define MAX_DATA_SIZE (RTE_MBUF_DEFAULT_BUF_SIZE - RTE_PKTMBUF_HEADROOM)
+
+/* RFC 864 chargen pattern used for comment testing */
+#define FILL_LINE_LENGTH 72
+#define FILL_START 0x21 /* ! */
+#define FILL_END 0x7e /* ~ */
+#define FILL_RANGE (FILL_END - FILL_START)
+
static void
-dummy_mbuf_prep(struct rte_mbuf *mb, uint8_t buf[], uint32_t buf_len,
- uint32_t data_len)
+fill_mbuf(struct rte_mbuf *mb)
{
- uint32_t i;
- uint8_t *db;
+ unsigned int len = rte_pktmbuf_tailroom(mb);
+ char *buf = rte_pktmbuf_append(mb, len);
+ unsigned int n = 0;
+ unsigned int line = 0;
+ while (n < len - 1) {
+ char ch = FILL_START + (line % FILL_RANGE);
+ unsigned int i;
+
+ for (i = 0; i < FILL_LINE_LENGTH && n < len - 1; i++) {
+ buf[n++] = ch;
+ if (++ch > FILL_END)
+ ch = FILL_START;
+ }
+ if (n < len - 1)
+ buf[n++] = '\n';
+ line++;
+ }
+}
+
+static void
+dummy_mbuf_prep(struct rte_mbuf *mb, uint8_t buf[], uint32_t buf_len)
+{
mb->buf_addr = buf;
rte_mbuf_iova_set(mb, (uintptr_t)buf);
mb->buf_len = buf_len;
@@ -57,15 +82,11 @@ dummy_mbuf_prep(struct rte_mbuf *mb, uint8_t buf[], uint32_t buf_len,
mb->pool = (void *)buf;
rte_pktmbuf_reset(mb);
- db = (uint8_t *)rte_pktmbuf_append(mb, data_len);
-
- for (i = 0; i != data_len; i++)
- db[i] = i;
}
/* Make an IP packet consisting of chain of one packets */
static void
-mbuf1_prepare(struct dummy_mbuf *dm, uint32_t plen)
+mbuf1_prepare(struct dummy_mbuf *dm)
{
struct {
struct rte_ether_hdr eth;
@@ -84,32 +105,47 @@ mbuf1_prepare(struct dummy_mbuf *dm, uint32_t plen)
.dst_addr = rte_cpu_to_be_32(RTE_IPV4_BROADCAST),
},
.udp = {
+ .src_port = rte_cpu_to_be_16(19), /* Chargen port */
.dst_port = rte_cpu_to_be_16(9), /* Discard port */
},
};
memset(dm, 0, sizeof(*dm));
- dummy_mbuf_prep(&dm->mb[0], dm->buf[0], sizeof(dm->buf[0]), plen);
+ dummy_mbuf_prep(&dm->mb[0], dm->buf[0], sizeof(dm->buf[0]));
+ dummy_mbuf_prep(&dm->mb[1], dm->buf[1], sizeof(dm->buf[1]));
rte_eth_random_addr(pkt.eth.src_addr.addr_bytes);
- plen -= sizeof(struct rte_ether_hdr);
+ memcpy(rte_pktmbuf_append(&dm->mb[0], sizeof(pkt)), &pkt, sizeof(pkt));
+
+ fill_mbuf(&dm->mb[1]);
+ rte_pktmbuf_chain(&dm->mb[0], &dm->mb[1]);
+
+ rte_mbuf_sanity_check(&dm->mb[0], 1);
+ rte_mbuf_sanity_check(&dm->mb[1], 0);
+}
+
+static void
+mbuf1_resize(struct dummy_mbuf *dm, uint16_t len)
+{
+ struct {
+ struct rte_ether_hdr eth;
+ struct rte_ipv4_hdr ip;
+ struct rte_udp_hdr udp;
+ } *pkt = rte_pktmbuf_mtod(&dm->mb[0], void *);
- pkt.ip.total_length = rte_cpu_to_be_16(plen);
- pkt.ip.hdr_checksum = rte_ipv4_cksum(&pkt.ip);
+ dm->mb[1].data_len = len;
+ dm->mb[0].pkt_len = dm->mb[0].data_len + dm->mb[1].data_len;
- plen -= sizeof(struct rte_ipv4_hdr);
- pkt.udp.src_port = rte_rand();
- pkt.udp.dgram_len = rte_cpu_to_be_16(plen);
+ len += sizeof(struct rte_udp_hdr);
+ pkt->udp.dgram_len = rte_cpu_to_be_16(len);
- memcpy(rte_pktmbuf_mtod(dm->mb, void *), &pkt, sizeof(pkt));
+ len += sizeof(struct rte_ipv4_hdr);
+ pkt->ip.total_length = rte_cpu_to_be_16(len);
+ pkt->ip.hdr_checksum = 0;
+ pkt->ip.hdr_checksum = rte_ipv4_cksum(&pkt->ip);
- /* Idea here is to create mbuf chain big enough that after mbuf deep copy they won't be
- * compressed into single mbuf to properly test store of chained mbufs
- */
- dummy_mbuf_prep(&dm->mb[1], dm->buf[1], sizeof(dm->buf[1]), pkt_len);
- dummy_mbuf_prep(&dm->mb[2], dm->buf[2], sizeof(dm->buf[2]), pkt_len);
- rte_pktmbuf_chain(&dm->mb[0], &dm->mb[1]);
- rte_pktmbuf_chain(&dm->mb[0], &dm->mb[2]);
+ rte_mbuf_sanity_check(&dm->mb[0], 1);
+ rte_mbuf_sanity_check(&dm->mb[1], 0);
}
static int
@@ -126,7 +162,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,
+ rte_pcapng_mbuf_size(MAX_DATA_SIZE),
SOCKET_ID_ANY, "ring_mp_sc");
if (mp == NULL) {
fprintf(stderr, "Cannot create mempool\n");
@@ -142,19 +178,44 @@ test_setup(void)
}
static int
-fill_pcapng_file(rte_pcapng_t *pcapng, unsigned int num_packets)
+fill_pcapng_file(rte_pcapng_t *pcapng)
{
struct dummy_mbuf mbfs;
struct rte_mbuf *orig;
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. You can see these comments by using the dumpcap program on 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."),
+ };
+ /* How many microseconds does it take TSC to wrap around 32 bits */
+ const unsigned wrap_us
+ = (US_PER_S * (uint64_t)UINT32_MAX) / rte_get_tsc_hz();
+
+ /* Want overall test to take to wraparound at least twice. */
+ const unsigned int avg_gap = (2 * wrap_us)
+ / (TOTAL_PACKETS / (MAX_BURST / 2));
- /* make a dummy packet */
- mbuf1_prepare(&mbfs, pkt_len);
+ mbuf1_prepare(&mbfs);
orig = &mbfs.mb[0];
- for (count = 0; count < num_packets; count += burst_size) {
+ for (count = 0; count < TOTAL_PACKETS; count += burst_size) {
struct rte_mbuf *clones[MAX_BURST];
unsigned int i;
@@ -162,9 +223,17 @@ 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 randomized comment on every 100th packet (1%) */
+ if (count % 100 == 0)
+ comment = examples[rte_rand_max(RTE_DIM(examples))];
+
+ /* Vary the size of the packets, okay to allow 0 sized packet */
+ mbuf1_resize(&mbfs, rte_rand_max(MAX_DATA_SIZE));
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;
@@ -182,8 +251,7 @@ fill_pcapng_file(rte_pcapng_t *pcapng, unsigned int num_packets)
return -1;
}
- /* Leave a small gap between packets to test for time wrap */
- usleep(rte_rand_max(MAX_GAP_US));
+ rte_delay_us_block(rte_rand_max(2 * avg_gap));
}
return count;
@@ -386,7 +454,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,7 +481,14 @@ test_write_packets(void)
goto fail;
}
- count = fill_pcapng_file(pcapng, TOTAL_PACKETS);
+ /* 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);
if (count < 0)
goto fail;
--
2.51.0
next prev parent reply other threads:[~2026-02-13 19:21 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-26 5:12 [RFC] pcapng: improve performance of timestamping Stephen Hemminger
2025-12-29 23:01 ` [PATCH v2 0/6] pcapng: timestamping and comment fixes Stephen Hemminger
2025-12-29 23:01 ` [PATCH v2 1/6] pcapng: use alloca instead of fixed buffer Stephen Hemminger
2025-12-29 23:01 ` [PATCH v2 2/6] pcapng: add additional mbuf if space required on copy Stephen Hemminger
2025-12-29 23:01 ` [PATCH v2 3/6] test: add more tests for comments in pcapng Stephen Hemminger
2025-12-29 23:01 ` [PATCH v2 4/6] test: vary size of packets in pcapng test Stephen Hemminger
2025-12-29 23:01 ` [PATCH v2 5/6] test: increase gap " Stephen Hemminger
2025-12-29 23:01 ` [PATCH v2 6/6] pcapng: improve performance of timestamping Stephen Hemminger
2026-01-12 4:50 ` [PATCH v3 0/7] pcapng: fixes and improvements Stephen Hemminger
2026-01-12 4:50 ` [PATCH v3 1/7] pcapng: add length checks to string arguments Stephen Hemminger
2026-01-12 4:50 ` [PATCH v3 2/7] pcapng: use malloc instead of fixed buffer size Stephen Hemminger
2026-01-12 4:50 ` [PATCH v3 3/7] pcapng: add additional mbuf if space required on copy Stephen Hemminger
2026-01-12 4:50 ` [PATCH v3 4/7] test: add more tests for comments in pcapng Stephen Hemminger
2026-01-12 4:50 ` [PATCH v3 5/7] test: vary size of packets in pcapng test Stephen Hemminger
2026-01-12 4:50 ` [PATCH v3 6/7] test: increase gap " Stephen Hemminger
2026-01-12 4:50 ` [PATCH v3 7/7] pcapng: improve performance of timestamping Stephen Hemminger
2026-01-13 0:51 ` [PATCH v4 0/7] pcapng: fixes and improvements Stephen Hemminger
2026-01-13 0:51 ` [PATCH v4 1/7] pcapng: add length checks to string arguments Stephen Hemminger
2026-01-13 0:51 ` [PATCH v4 2/7] pcapng: use malloc instead of fixed buffer size Stephen Hemminger
2026-01-13 0:51 ` [PATCH v4 3/7] pcapng: add additional mbuf if space required on copy Stephen Hemminger
2026-01-13 0:51 ` [PATCH v4 4/7] test: add more tests for comments in pcapng Stephen Hemminger
2026-01-13 0:51 ` [PATCH v4 5/7] test: vary size of packets in pcapng test Stephen Hemminger
2026-01-13 0:51 ` [PATCH v4 6/7] test: increase gap " Stephen Hemminger
2026-01-13 0:51 ` [PATCH v4 7/7] pcapng: improve performance of timestamping Stephen Hemminger
2026-01-19 18:18 ` [PATCH v5 0/5] pcapng: fixes and improvements Stephen Hemminger
2026-01-19 18:18 ` [PATCH v5 1/5] pcapng: add length checks to string arguments Stephen Hemminger
2026-01-19 18:19 ` [PATCH v5 2/5] pcapng: use malloc instead of fixed buffer size Stephen Hemminger
2026-01-19 18:19 ` [PATCH v5 3/5] pcapng: add additional mbuf if space required on copy Stephen Hemminger
2026-01-19 18:19 ` [PATCH v5 4/5] pcapng: improve performance of timestamping Stephen Hemminger
2026-01-19 18:19 ` [PATCH v5 5/5] test: add more tests for pcapng Stephen Hemminger
2026-01-26 21:04 ` [PATCH v6 0/5] pcapng: fixes and improvements Stephen Hemminger
2026-01-26 21:04 ` [PATCH v6 1/5] pcapng: add length checks to string arguments Stephen Hemminger
2026-01-26 21:04 ` [PATCH v6 2/5] pcapng: use malloc instead of fixed buffer size Stephen Hemminger
2026-01-26 21:04 ` [PATCH v6 3/5] pcapng: chain additional mbuf when comment exceeds tailroom Stephen Hemminger
2026-01-26 21:04 ` [PATCH v6 4/5] pcapng: improve performance of timestamping Stephen Hemminger
2026-01-26 21:04 ` [PATCH v6 5/5] test/pcapng: add tests for comments Stephen Hemminger
2026-02-13 19:18 ` [PATCH v7 0/7] pcapng: fixes and improvements Stephen Hemminger
2026-02-13 19:18 ` [PATCH v7 1/7] pcapng: add length checks to string arguments Stephen Hemminger
2026-02-13 19:18 ` [PATCH v7 2/7] pcapng: use malloc instead of fixed buffer size Stephen Hemminger
2026-02-13 19:18 ` [PATCH v7 3/7] pcapng: chain additional mbuf when comment exceeds tailroom Stephen Hemminger
2026-02-13 19:18 ` [PATCH v7 4/7] pcapng: improve performance of timestamping Stephen Hemminger
2026-02-13 19:18 ` Stephen Hemminger [this message]
2026-02-13 19:18 ` [PATCH v7 6/7] test/pcapng: skip test if null driver missing Stephen Hemminger
2026-02-16 10:01 ` David Marchand
2026-02-16 16:26 ` Stephen Hemminger
2026-02-16 16:43 ` David Marchand
2026-02-13 19:18 ` [PATCH v7 7/7] dumpcap: improve pcapng error reporting Stephen Hemminger
2026-02-16 21:37 ` [PATCH v8 0/8] pcapng: fixes and improvements Stephen Hemminger
2026-02-16 21:37 ` [PATCH v8 1/8] pcapng: correct typo in comment Stephen Hemminger
2026-02-16 21:37 ` [PATCH v8 2/8] pcapng: document return values Stephen Hemminger
2026-02-16 21:38 ` [PATCH v8 3/8] pcapng: add length checks to string arguments Stephen Hemminger
2026-02-17 14:34 ` Thomas Monjalon
2026-02-16 21:38 ` [PATCH v8 4/8] pcapng: use malloc instead of fixed buffer size Stephen Hemminger
2026-02-16 21:38 ` [PATCH v8 5/8] pcapng: chain additional mbuf when comment exceeds tailroom Stephen Hemminger
2026-02-16 21:38 ` [PATCH v8 6/8] pcapng: improve performance of timestamping Stephen Hemminger
2026-02-16 21:38 ` [PATCH v8 7/8] test/pcapng: skip test if null driver missing Stephen Hemminger
2026-02-16 21:38 ` [PATCH v8 8/8] test/pcapng: add tests for comments Stephen Hemminger
2026-02-17 16:39 ` [PATCH v8 0/8] pcapng: fixes and improvements Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260213192039.221213-6-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=dev@dpdk.org \
--cc=reshma.pattan@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox