diff options
| author | Nick Banks <nickbanks@netflix.com> | 2025-10-13 19:47:31 +0000 |
|---|---|---|
| committer | Michael Tuexen <tuexen@FreeBSD.org> | 2025-10-13 19:47:31 +0000 |
| commit | be1ad90e6bb6ea915d122f7abe407dc18d38a673 (patch) | |
| tree | 09d7a2c4a0c7f488dbd09423a399ee9cb7501b17 /sys | |
| parent | ea5685ba79fc9309698ef72cf48bc1f0c91ad3dd (diff) | |
Diffstat (limited to 'sys')
| -rw-r--r-- | sys/modules/ktest/Makefile | 3 | ||||
| -rw-r--r-- | sys/modules/ktest/ktest_tcphpts/Makefile | 13 | ||||
| -rw-r--r-- | sys/netinet/tcp_hpts_test.c | 76 | ||||
| -rw-r--r-- | sys/tests/ktest.h | 3 |
4 files changed, 94 insertions, 1 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 */ |
