tcp: Initial ktest for HPTS

Reviewed by:		rrs, tuexen
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D52979
This commit is contained in:
Nick Banks authored and Michael Tuexen committed 2025-10-13 21:47:31 +02:00
1 parent ea5685ba79
commit be1ad90e6b
7 files changed
+109 -3

No files matched your search

+2 -1
View File
@@ -1,5 +1,6 @@
SUBDIR= ktest \
ktest_example \
ktest_netlink_message_writer
ktest_netlink_message_writer \
ktest_tcphpts
.include <bsd.subdir.mk>
+13
View File
@@ -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>
+76
View File
@@ -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);
+3
View File
@@ -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 */
+10 -2
View File
@@ -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
+1
View File
@@ -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
+4
View File
@@ -0,0 +1,4 @@
from atf_python.ktest import BaseKernelTest
class TestTcpHpts(BaseKernelTest):
KTEST_MODULE_NAME = "ktest_tcphpts"