summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Kconfig.debug20
-rw-r--r--lib/Makefile1
-rw-r--r--lib/cpu_rmap.c2
-rw-r--r--lib/dynamic_queue_limits.c2
-rw-r--r--lib/net_utils.c4
-rw-r--r--lib/tests/Makefile1
-rw-r--r--lib/tests/blackhole_dev_kunit.c (renamed from lib/test_blackhole_dev.c)47
7 files changed, 31 insertions, 46 deletions
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index c7086ed09cde..8fb1d685f696 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -2580,15 +2580,6 @@ config TEST_BPF
If unsure, say N.
-config TEST_BLACKHOLE_DEV
- tristate "Test blackhole netdev functionality"
- depends on m && NET
- help
- This builds the "test_blackhole_dev" module that validates the
- data path through this blackhole netdev.
-
- If unsure, say N.
-
config FIND_BIT_BENCHMARK
tristate "Test find_bit functions"
help
@@ -2926,6 +2917,17 @@ config USERCOPY_KUNIT_TEST
on the copy_to/from_user infrastructure, making sure basic
user/kernel boundary testing is working.
+config BLACKHOLE_DEV_KUNIT_TEST
+ tristate "Test blackhole netdev functionality" if !KUNIT_ALL_TESTS
+ depends on NET
+ depends on KUNIT
+ default KUNIT_ALL_TESTS
+ help
+ This builds the "blackhole_dev_kunit" module that validates the
+ data path through this blackhole netdev.
+
+ If unsure, say N.
+
config TEST_UDELAY
tristate "udelay test driver"
help
diff --git a/lib/Makefile b/lib/Makefile
index 0fdcd6d635ad..f07b24ce1b3f 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -97,7 +97,6 @@ obj-$(CONFIG_TEST_KMOD) += test_kmod.o
obj-$(CONFIG_TEST_DEBUG_VIRTUAL) += test_debug_virtual.o
obj-$(CONFIG_TEST_MEMCAT_P) += test_memcat_p.o
obj-$(CONFIG_TEST_OBJAGG) += test_objagg.o
-obj-$(CONFIG_TEST_BLACKHOLE_DEV) += test_blackhole_dev.o
obj-$(CONFIG_TEST_MEMINIT) += test_meminit.o
obj-$(CONFIG_TEST_LOCKUP) += test_lockup.o
obj-$(CONFIG_TEST_HMM) += test_hmm.o
diff --git a/lib/cpu_rmap.c b/lib/cpu_rmap.c
index 4c348670da31..f03d9be3f06b 100644
--- a/lib/cpu_rmap.c
+++ b/lib/cpu_rmap.c
@@ -73,7 +73,7 @@ static void cpu_rmap_release(struct kref *ref)
* cpu_rmap_get - internal helper to get new ref on a cpu_rmap
* @rmap: reverse-map allocated with alloc_cpu_rmap()
*/
-static inline void cpu_rmap_get(struct cpu_rmap *rmap)
+void cpu_rmap_get(struct cpu_rmap *rmap)
{
kref_get(&rmap->refcount);
}
diff --git a/lib/dynamic_queue_limits.c b/lib/dynamic_queue_limits.c
index c1b7638a594a..f97a752e900a 100644
--- a/lib/dynamic_queue_limits.c
+++ b/lib/dynamic_queue_limits.c
@@ -190,7 +190,7 @@ EXPORT_SYMBOL(dql_completed);
void dql_reset(struct dql *dql)
{
/* Reset all dynamic values */
- dql->limit = 0;
+ dql->limit = dql->min_limit;
dql->num_queued = 0;
dql->num_completed = 0;
dql->last_obj_cnt = 0;
diff --git a/lib/net_utils.c b/lib/net_utils.c
index 42bb0473fb22..215cda672fee 100644
--- a/lib/net_utils.c
+++ b/lib/net_utils.c
@@ -7,11 +7,9 @@
bool mac_pton(const char *s, u8 *mac)
{
- size_t maxlen = 3 * ETH_ALEN - 1;
int i;
- /* XX:XX:XX:XX:XX:XX */
- if (strnlen(s, maxlen) < maxlen)
+ if (strnlen(s, MAC_ADDR_STR_LEN) < MAC_ADDR_STR_LEN)
return false;
/* Don't dirty result unless string is valid MAC. */
diff --git a/lib/tests/Makefile b/lib/tests/Makefile
index 498915255860..a434c7cb733a 100644
--- a/lib/tests/Makefile
+++ b/lib/tests/Makefile
@@ -6,6 +6,7 @@
CFLAGS_bitfield_kunit.o := $(DISABLE_STRUCTLEAK_PLUGIN)
obj-$(CONFIG_BITFIELD_KUNIT) += bitfield_kunit.o
obj-$(CONFIG_BITS_TEST) += test_bits.o
+obj-$(CONFIG_BLACKHOLE_DEV_KUNIT_TEST) += blackhole_dev_kunit.o
obj-$(CONFIG_CHECKSUM_KUNIT) += checksum_kunit.o
obj-$(CONFIG_CMDLINE_KUNIT_TEST) += cmdline_kunit.o
obj-$(CONFIG_CPUMASK_KUNIT_TEST) += cpumask_kunit.o
diff --git a/lib/test_blackhole_dev.c b/lib/tests/blackhole_dev_kunit.c
index ec290ac2a0d9..06834ab35f43 100644
--- a/lib/test_blackhole_dev.c
+++ b/lib/tests/blackhole_dev_kunit.c
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
/*
- * This module tests the blackhole_dev that is created during the
+ * This tests the blackhole_dev that is created during the
* net subsystem initialization. The test this module performs is
* by injecting an skb into the stack with skb->dev as the
* blackhole_dev and expects kernel to behave in a sane manner
@@ -9,9 +9,8 @@
* Copyright (c) 2018, Mahesh Bandewar <maheshb@google.com>
*/
-#include <linux/init.h>
+#include <kunit/test.h>
#include <linux/module.h>
-#include <linux/printk.h>
#include <linux/skbuff.h>
#include <linux/netdevice.h>
#include <linux/udp.h>
@@ -25,17 +24,15 @@
#define UDP_PORT 1234
-static int __init test_blackholedev_init(void)
+static void test_blackholedev(struct kunit *test)
{
struct ipv6hdr *ip6h;
struct sk_buff *skb;
struct udphdr *uh;
int data_len;
- int ret;
skb = alloc_skb(SKB_SIZE, GFP_KERNEL);
- if (!skb)
- return -ENOMEM;
+ KUNIT_ASSERT_NOT_NULL(test, skb);
/* Reserve head-room for the headers */
skb_reserve(skb, HEAD_SIZE);
@@ -55,7 +52,7 @@ static int __init test_blackholedev_init(void)
ip6h = (struct ipv6hdr *)skb_push(skb, sizeof(struct ipv6hdr));
skb_set_network_header(skb, 0);
ip6h->hop_limit = 32;
- ip6h->payload_len = data_len + sizeof(struct udphdr);
+ ip6h->payload_len = htons(data_len + sizeof(struct udphdr));
ip6h->nexthdr = IPPROTO_UDP;
ip6h->saddr = in6addr_loopback;
ip6h->daddr = in6addr_loopback;
@@ -68,32 +65,20 @@ static int __init test_blackholedev_init(void)
skb->dev = blackhole_netdev;
/* Now attempt to send the packet */
- ret = dev_queue_xmit(skb);
-
- switch (ret) {
- case NET_XMIT_SUCCESS:
- pr_warn("dev_queue_xmit() returned NET_XMIT_SUCCESS\n");
- break;
- case NET_XMIT_DROP:
- pr_warn("dev_queue_xmit() returned NET_XMIT_DROP\n");
- break;
- case NET_XMIT_CN:
- pr_warn("dev_queue_xmit() returned NET_XMIT_CN\n");
- break;
- default:
- pr_err("dev_queue_xmit() returned UNKNOWN(%d)\n", ret);
- }
-
- return 0;
+ KUNIT_EXPECT_EQ(test, dev_queue_xmit(skb), NET_XMIT_SUCCESS);
}
-static void __exit test_blackholedev_exit(void)
-{
- pr_warn("test_blackholedev module terminating.\n");
-}
+static struct kunit_case blackholedev_cases[] = {
+ KUNIT_CASE(test_blackholedev),
+ {},
+};
+
+static struct kunit_suite blackholedev_suite = {
+ .name = "blackholedev",
+ .test_cases = blackholedev_cases,
+};
-module_init(test_blackholedev_init);
-module_exit(test_blackholedev_exit);
+kunit_test_suite(blackholedev_suite);
MODULE_AUTHOR("Mahesh Bandewar <maheshb@google.com>");
MODULE_DESCRIPTION("module test of the blackhole_dev");