Commit 88232ec1 authored by Chuck Lever's avatar Chuck Lever Committed by Jakub Kicinski

net/handshake: Add Kunit tests for the handshake consumer API

These verify the API contracts and help exercise lifetime rules for
consumer sockets and handshake_req structures.

One way to run these tests:

./tools/testing/kunit/kunit.py run --kunitconfig ./net/handshake/.kunitconfig
Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 2fd55320
......@@ -73,6 +73,21 @@ config NET_HANDSHAKE
depends on SUNRPC || NVME_TARGET_TCP || NVME_TCP
default y
config NET_HANDSHAKE_KUNIT_TEST
tristate "KUnit tests for the handshake upcall mechanism" if !KUNIT_ALL_TESTS
default KUNIT_ALL_TESTS
depends on KUNIT
help
This builds the KUnit tests for the handshake upcall mechanism.
KUnit tests run during boot and output the results to the debug
log in TAP format (https://testanything.org/). Only useful for
kernel devs running KUnit test harness and are not for inclusion
into a production build.
For more information on KUnit and unit tests in general, refer
to the KUnit documentation in Documentation/dev-tools/kunit/.
config INET
bool "TCP/IP networking"
help
......
CONFIG_KUNIT=y
CONFIG_UBSAN=y
CONFIG_STACKTRACE=y
CONFIG_NET=y
CONFIG_NETWORK_FILESYSTEMS=y
CONFIG_INET=y
CONFIG_MULTIUSER=y
CONFIG_NFS_FS=y
CONFIG_SUNRPC=y
CONFIG_NET_HANDSHAKE=y
CONFIG_NET_HANDSHAKE_KUNIT_TEST=y
......@@ -9,3 +9,5 @@
obj-y += handshake.o
handshake-y := genl.o netlink.o request.o tlshd.o trace.o
obj-$(CONFIG_NET_HANDSHAKE_KUNIT_TEST) += handshake-test.o
This diff is collapsed.
......@@ -49,6 +49,7 @@ enum hr_flags_bits {
struct handshake_proto {
int hp_handler_class;
size_t hp_privsize;
unsigned long hp_flags;
int (*hp_accept)(struct handshake_req *req,
struct genl_info *info, int fd);
......@@ -58,6 +59,10 @@ struct handshake_proto {
void (*hp_destroy)(struct handshake_req *req);
};
enum hp_flags_bits {
HANDSHAKE_F_PROTO_NOTIFY,
};
/* netlink.c */
int handshake_genl_notify(struct net *net, const struct handshake_proto *proto,
gfp_t flags);
......
......@@ -18,6 +18,8 @@
#include <net/genetlink.h>
#include <net/netns/generic.h>
#include <kunit/visibility.h>
#include <uapi/linux/handshake.h>
#include "handshake.h"
#include "genl.h"
......@@ -38,6 +40,10 @@ int handshake_genl_notify(struct net *net, const struct handshake_proto *proto,
struct sk_buff *msg;
void *hdr;
/* Disable notifications during unit testing */
if (!test_bit(HANDSHAKE_F_PROTO_NOTIFY, &proto->hp_flags))
return 0;
if (!genl_has_listeners(&handshake_nl_family, net,
proto->hp_handler_class))
return -ESRCH;
......@@ -262,6 +268,7 @@ struct handshake_net *handshake_pernet(struct net *net)
return handshake_net_id ?
net_generic(net, handshake_net_id) : NULL;
}
EXPORT_SYMBOL_IF_KUNIT(handshake_pernet);
static int __init handshake_init(void)
{
......
......@@ -20,6 +20,8 @@
#include <net/genetlink.h>
#include <net/netns/generic.h>
#include <kunit/visibility.h>
#include <uapi/linux/handshake.h>
#include "handshake.h"
......@@ -60,6 +62,7 @@ struct handshake_req *handshake_req_hash_lookup(struct sock *sk)
return rhashtable_lookup_fast(&handshake_rhashtbl, &sk,
handshake_rhash_params);
}
EXPORT_SYMBOL_IF_KUNIT(handshake_req_hash_lookup);
static bool handshake_req_hash_add(struct handshake_req *req)
{
......@@ -192,6 +195,7 @@ struct handshake_req *handshake_req_next(struct handshake_net *hn, int class)
return req;
}
EXPORT_SYMBOL_IF_KUNIT(handshake_req_next);
/**
* handshake_req_submit - Submit a handshake request
......@@ -293,6 +297,7 @@ void handshake_complete(struct handshake_req *req, unsigned int status,
sock_put(sk);
}
}
EXPORT_SYMBOL_IF_KUNIT(handshake_complete);
/**
* handshake_req_cancel - Cancel an in-progress handshake
......
......@@ -249,6 +249,7 @@ static int tls_handshake_accept(struct handshake_req *req,
static const struct handshake_proto tls_handshake_proto = {
.hp_handler_class = HANDSHAKE_HANDLER_CLASS_TLSHD,
.hp_privsize = sizeof(struct tls_handshake_req),
.hp_flags = BIT(HANDSHAKE_F_PROTO_NOTIFY),
.hp_accept = tls_handshake_accept,
.hp_done = tls_handshake_done,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment