Skip site navigation (1)Skip section navigation (2)


| raw e-mail | index | archive | help
The branch main has been updated by tuexen:

URL: https://cgit.FreeBSD.org/src/commit/?id=be1ad90e6bb6ea915d122f7abe407dc18d38a673

commit be1ad90e6bb6ea915d122f7abe407dc18d38a673
Author:     Nick Banks <nickbanks@netflix.com>
AuthorDate: 2025-10-13 19:47:31 +0000
Commit:     Michael Tuexen <tuexen@FreeBSD.org>
CommitDate: 2025-10-13 19:47:31 +0000

    tcp: Initial ktest for HPTS
    
    Reviewed by:            rrs, tuexen
    Sponsored by:           Netflix, Inc.
    Differential Revision:  https://reviews.freebsd.org/D52979
---
 sys/modules/ktest/Makefile               |  3 +-
 sys/modules/ktest/ktest_tcphpts/Makefile | 13 ++++++
 sys/netinet/tcp_hpts_test.c              | 76 ++++++++++++++++++++++++++++++++
 sys/tests/ktest.h                        |  3 ++
 tests/atf_python/ktest.py                | 12 ++++-
 tests/sys/netinet/Makefile               |  1 +
 tests/sys/netinet/tcp_hpts_test.py       |  4 ++
 7 files changed, 109 insertions(+), 3 deletions(-)

diff --git a/sys/modules/ktest/Makefile b/sys/modules/ktest/Makefile
index a3052efa9ed9..d5f15576f38b 100644
--- a/sys/modules/ktest/Makefile
+++ b/sys/modules/ktest/Makefile
@@ -1,5 +1,6 @@
 SUBDIR=	ktest \
 	ktest_example \
-	ktest_netlink_message_writer
+	ktest_netlink_message_writer \
+	ktest_tcphpts
 
 .include <bsd.subdir.mk>
diff --git a/sys/modules/ktest/ktest_tcphpts/Makefile b/sys/modules/ktest/ktest_tcphpts/Makefile
new file mode 100644
index 000000000000..b642c0cb4209
--- /dev/null
+++ b/sys/modules/ktest/ktest_tcphpts/Makefile
@@ -0,0 +1,13 @@
+PACKAGE=	tests
+WARNS?=		6
+
+SYSDIR?=${SRCTOP}/sys
+.include "${SYSDIR}/conf/kern.opts.mk"
+
+.PATH: ${SYSDIR}/netinet
+
+KMOD=	ktest_tcphpts
+SRCS=	tcp_hpts_test.c
+
+.include <bsd.kmod.mk>
+
diff --git a/sys/netinet/tcp_hpts_test.c b/sys/netinet/tcp_hpts_test.c
new file mode 100644
index 000000000000..085da37e44c8
--- /dev/null
+++ b/sys/netinet/tcp_hpts_test.c
@@ -0,0 +1,76 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2025 Netflix, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <tests/ktest.h>
+#include <sys/cdefs.h>
+#include <sys/param.h>
+#include <sys/errno.h>
+#include <sys/malloc.h>
+#include <sys/socket.h>
+#include <sys/systm.h>
+
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#define	_WANT_INPCB
+#include <netinet/in_pcb.h>
+#include <netinet/tcp_seq.h>
+#define	_WANT_TCPCB
+#include <netinet/tcp_var.h>
+#include <netinet/tcp_hpts.h>
+#include <dev/tcp_log/tcp_log_dev.h>
+#include <netinet/tcp_log_buf.h>
+
+#define	KTEST_ERR(_ctx, _fmt, ...)	\
+	KTEST_LOG_LEVEL(_ctx, LOG_ERR, _fmt, ## __VA_ARGS__)
+
+#define KTEST_VERIFY(x) do { \
+	if (!(x)) { \
+		KTEST_ERR(ctx, "FAIL: %s", #x); \
+		return (EINVAL); \
+	} else { \
+		KTEST_LOG(ctx, "PASS: %s", #x); \
+	} \
+} while (0)
+
+static int
+test_hpts_init(struct ktest_test_context *ctx)
+{
+	/* TODO: Refactor HPTS code so that it may be tested. */
+	KTEST_VERIFY(tcp_min_hptsi_time != 0);
+	return (0);
+}
+
+static const struct ktest_test_info tests[] = {
+	{
+		.name = "test_hpts_init",
+		.desc = "Tests HPTS initialization and cleanup",
+		.func = &test_hpts_init,
+	},
+};
+
+KTEST_MODULE_DECLARE(ktest_tcphpts, tests);
+KTEST_MODULE_DEPEND(ktest_tcphpts, tcphpts);
diff --git a/sys/tests/ktest.h b/sys/tests/ktest.h
index c767aa31e8e5..8af92f1e0c18 100644
--- a/sys/tests/ktest.h
+++ b/sys/tests/ktest.h
@@ -104,6 +104,9 @@ MODULE_VERSION(ktest_##_n, 1);						\
 MODULE_DEPEND(ktest_##_n, ktestmod, 1, 1, 1);				\
 MODULE_DEPEND(ktest_##_n, netlink, 1, 1, 1);				\
 
+#define	KTEST_MODULE_DEPEND(_n, _d)		\
+MODULE_DEPEND(ktest_##_n, _d, 1, 1, 1);	\
+
 #endif /* _KERNEL */
 
 /* genetlink definitions */
diff --git a/tests/atf_python/ktest.py b/tests/atf_python/ktest.py
index a18f47d1dd06..a671aaa1fd4c 100644
--- a/tests/atf_python/ktest.py
+++ b/tests/atf_python/ktest.py
@@ -67,6 +67,10 @@ class KtestLoader(object):
     def __init__(self, module_name: str, autoload: bool):
         self.module_name = module_name
         self.autoload = autoload
+        # Ensure the base ktest.ko module is loaded
+        result = libc.kldload("ktest")
+        if result != 0 and result != 17:  # 17 is EEXIST (already loaded)
+            logger.debug(f"Failed to load base ktest module (error {result})")
         self.helper = NlHelper()
         self.nlsock = Nlsock(NlConst.NETLINK_GENERIC, self.helper)
         self.family_id = self._get_family_id()
@@ -76,7 +80,9 @@ class KtestLoader(object):
             family_id = self.nlsock.get_genl_family_id(NETLINK_FAMILY)
         except ValueError:
             if self.autoload:
-                libc.kldload(self.module_name)
+                result = libc.kldload(self.module_name)
+                if result != 0 and result != 17:  # 17 is EEXIST (already loaded)
+                    raise RuntimeError(f"Failed to load kernel module '{self.module_name}' (error {result})")
                 family_id = self.nlsock.get_genl_family_id(NETLINK_FAMILY)
             else:
                 raise
@@ -103,7 +109,9 @@ class KtestLoader(object):
     def load_ktests(self):
         ret = self._load_ktests()
         if not ret and self.autoload:
-            libc.kldload(self.module_name)
+            result = libc.kldload(self.module_name)
+            if result != 0 and result != 17:  # 17 is EEXIST (already loaded)
+                raise RuntimeError(f"Failed to load kernel module '{self.module_name}' (error {result})")
             ret = self._load_ktests()
         return ret
 
diff --git a/tests/sys/netinet/Makefile b/tests/sys/netinet/Makefile
index b742342beecb..9739221676ce 100644
--- a/tests/sys/netinet/Makefile
+++ b/tests/sys/netinet/Makefile
@@ -30,6 +30,7 @@ ATF_TESTS_SH=	arp \
 
 ATF_TESTS_PYTEST+=	carp.py
 ATF_TESTS_PYTEST+=	igmp.py
+ATF_TESTS_PYTEST+=	tcp_hpts_test.py
 
 LIBADD.so_reuseport_lb_test=	pthread
 LIBADD.udp_bindings=		pthread
diff --git a/tests/sys/netinet/tcp_hpts_test.py b/tests/sys/netinet/tcp_hpts_test.py
new file mode 100644
index 000000000000..c56383fb310f
--- /dev/null
+++ b/tests/sys/netinet/tcp_hpts_test.py
@@ -0,0 +1,4 @@
+from atf_python.ktest import BaseKernelTest
+
+class TestTcpHpts(BaseKernelTest):
+    KTEST_MODULE_NAME = "ktest_tcphpts"



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?>