From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
stable@dpdk.org, Reshma Pattan <reshma.pattan@intel.com>,
Jie Zhou <jizh@linux.microsoft.com>,
Bruce Richardson <bruce.richardson@intel.com>
Subject: [PATCH 1/2] test: fix pcapng test to work on Windows
Date: Fri, 20 Feb 2026 10:41:55 -0800 [thread overview]
Message-ID: <20260220184255.306368-2-stephen@networkplumber.org> (raw)
In-Reply-To: <20260220184255.306368-1-stephen@networkplumber.org>
The pcapng test needs additional wrappers to be able to
build and run on Windows.
This is a pre-existing problem, only exposed when the
test was enabled on Windows builds, and when libpcap
is setup on Windows.
Fixes: 0edc1f408a8b ("test: enable subset of tests on Windows")
Cc: stable@dpdk.org
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
app/test/test_pcapng.c | 65 +++++++++++++++++++++++++++++++++++++++---
1 file changed, 61 insertions(+), 4 deletions(-)
diff --git a/app/test/test_pcapng.c b/app/test/test_pcapng.c
index ad9ad51f4c..f0faead728 100644
--- a/app/test/test_pcapng.c
+++ b/app/test/test_pcapng.c
@@ -4,7 +4,16 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+
+#ifdef RTE_EXEC_ENV_WINDOWS
+#include <winsock2.h>
+#include <io.h>
+#include <fcntl.h>
+#include <windows.h>
+#else
#include <unistd.h>
+#endif
#include <rte_bus_vdev.h>
#include <rte_ethdev.h>
@@ -23,6 +32,52 @@
#include "test.h"
+#ifdef RTE_EXEC_ENV_WINDOWS
+static uint64_t
+current_timestamp(void)
+{
+ FILETIME ft;
+ ULARGE_INTEGER ul;
+
+ GetSystemTimeAsFileTime(&ft);
+ ul.LowPart = ft.dwLowDateTime;
+ ul.HighPart = ft.dwHighDateTime;
+ /* FILETIME is 100ns intervals since 1601-01-01, convert to ns since Unix epoch */
+ return (ul.QuadPart - 116444736000000000ULL) * 100;
+}
+
+/*
+ * Create temporary file with suffix for Windows.
+ * Returns file descriptor or -1 on failure.
+ */
+static int
+mkstemps(char *tmpl, int suffixlen)
+{
+ char temp_dir[MAX_PATH];
+ char temp_file[MAX_PATH];
+ DWORD ret;
+
+ ret = GetTempPathA(sizeof(temp_dir), temp_dir);
+ if (ret == 0 || ret > sizeof(temp_dir))
+ return -1;
+
+ if (GetTempFileNameA(temp_dir, "pcap", 0, temp_file) == 0)
+ return -1;
+
+ /*
+ * GetTempFileNameA with uUnique=0 creates the file to reserve the name.
+ * Remove it since we open a different name with the original suffix appended.
+ */
+ DeleteFileA(temp_file);
+
+ /* Append the original suffix (e.g. ".pcapng") to the temp file */
+ strlcat(temp_file, tmpl + strlen(tmpl) - suffixlen, sizeof(temp_file));
+ strlcpy(tmpl, temp_file, PATH_MAX);
+
+ return _open(tmpl, _O_RDWR | _O_BINARY | _O_CREAT | _O_EXCL, 0666);
+}
+#endif /* RTE_EXEC_ENV_WINDOWS */
+
#define PCAPNG_TEST_DEBUG 0
#define TOTAL_PACKETS 10000
@@ -344,6 +399,7 @@ parse_pcap_packet(u_char *user, const struct pcap_pkthdr *h,
pcap_breakloop(ctx->pcap);
}
+#ifndef RTE_EXEC_ENV_WINDOWS
static uint64_t
current_timestamp(void)
{
@@ -352,6 +408,7 @@ current_timestamp(void)
clock_gettime(CLOCK_REALTIME, &ts);
return rte_timespec_to_ns(&ts);
}
+#endif
/*
* Open the resulting pcapng file with libpcap
@@ -395,7 +452,7 @@ valid_pcapng_file(const char *file_name, uint64_t started, unsigned int expected
static int
test_add_interface(void)
{
- char file_name[] = "/tmp/pcapng_test_XXXXXX.pcapng";
+ char file_name[PATH_MAX] = "/tmp/pcapng_test_XXXXXX.pcapng";
static rte_pcapng_t *pcapng;
int ret, tmp_fd;
uint64_t now = current_timestamp();
@@ -444,7 +501,7 @@ test_add_interface(void)
ret = valid_pcapng_file(file_name, now, 0);
/* if test fails want to investigate the file */
if (ret == 0)
- unlink(file_name);
+ remove(file_name);
return ret;
@@ -456,7 +513,7 @@ test_add_interface(void)
static int
test_write_packets(void)
{
- char file_name[] = "/tmp/pcapng_test_XXXXXX.pcapng";
+ char file_name[PATH_MAX] = "/tmp/pcapng_test_XXXXXX.pcapng";
rte_pcapng_t *pcapng = NULL;
int ret, tmp_fd, count;
uint64_t now = current_timestamp();
@@ -508,7 +565,7 @@ test_write_packets(void)
ret = valid_pcapng_file(file_name, now, count);
/* if test fails want to investigate the file */
if (ret == 0)
- unlink(file_name);
+ remove(file_name);
return ret;
--
2.51.0
next prev parent reply other threads:[~2026-02-20 18:43 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-20 18:41 [PATCH 0/2] pcapng: bug fixes Stephen Hemminger
2026-02-20 18:41 ` Stephen Hemminger [this message]
2026-02-20 18:41 ` [PATCH 2/2] pcapng: handle packets copied before file open Stephen Hemminger
2026-02-24 15:25 ` [PATCH v2 0/4] pcapng: fix test and copy before open Stephen Hemminger
2026-02-24 15:25 ` [PATCH v2 1/4] test: fix pcapng test to work on Windows Stephen Hemminger
2026-02-24 15:25 ` [PATCH v2 2/4] pcapng: handle packets copied before file open Stephen Hemminger
2026-02-24 15:25 ` [PATCH v2 3/4] test: add pcapng test for copy before open Stephen Hemminger
2026-02-24 15:25 ` [PATCH v2 4/4] test: use fixed time length for write packet test Stephen Hemminger
2026-02-25 22:57 ` [PATCH v3 0/4] pcapng: enhancements and test fix Stephen Hemminger
2026-02-25 22:57 ` [PATCH v3 1/4] test: fix pcapng test to work on Windows Stephen Hemminger
2026-02-25 22:57 ` [PATCH v3 2/4] test: use fixed time length for write packet test Stephen Hemminger
2026-02-25 22:57 ` [PATCH v3 3/4] pcapng: handle packets copied before file open Stephen Hemminger
2026-02-25 22:57 ` [PATCH v3 4/4] test: add pcapng test for copy before open Stephen Hemminger
2026-02-28 17:34 ` [PATCH v3 0/5] pcapng: fixes for Windows and timestamps Stephen Hemminger
2026-02-28 17:35 ` [PATCH v3 1/5] test: fix pcapng test to work on Windows Stephen Hemminger
2026-02-28 17:35 ` [PATCH v3 2/5] test: use fixed time length for write packet test Stephen Hemminger
2026-02-28 17:35 ` [PATCH v3 3/5] test: better logging for pcapng test Stephen Hemminger
2026-02-28 17:35 ` [PATCH v3 4/5] pcapng: handle packets copied before file open Stephen Hemminger
2026-03-19 10:34 ` Kevin Traynor
2026-03-31 18:07 ` Stephen Hemminger
2026-02-28 17:35 ` [PATCH v3 5/5] test: add pcapng test for copy before open Stephen Hemminger
2026-03-17 10:38 ` [PATCH v3 0/5] pcapng: fixes for Windows and timestamps 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=20260220184255.306368-2-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
--cc=jizh@linux.microsoft.com \
--cc=reshma.pattan@intel.com \
--cc=stable@dpdk.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.