Commit 0693b276 authored by David S. Miller's avatar David S. Miller

Merge branch 'mctp-kunit-tests'

Jeremy Kerr says:

====================
MCTP kunit tests

This change adds some initial kunit tests for the MCTP core. We'll
expand the coverage in a future series, and augment with a few
selftests, but this establishes a baseline set of tests for now.

Thanks to the kunit folks for the framework!

---

v2:
 - fix MCTP=m, KUNIT={y,m} breakage
 - fix mctp test netdev initialisation
 - strict route reference count checking
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents b8aa1654 1e5e9250
......@@ -11,3 +11,8 @@ menuconfig MCTP
This option enables core MCTP support. For communicating with other
devices, you'll want to enable a driver for a specific hardware
channel.
config MCTP_TEST
bool "MCTP core tests" if !KUNIT_ALL_TESTS
depends on MCTP=y && KUNIT=y
default KUNIT_ALL_TESTS
# SPDX-License-Identifier: GPL-2.0
obj-$(CONFIG_MCTP) += mctp.o
mctp-objs := af_mctp.o device.o route.o neigh.o
# tests
obj-$(CONFIG_MCTP_TEST) += test/utils.o
......@@ -11,6 +11,7 @@
*/
#include <linux/idr.h>
#include <linux/kconfig.h>
#include <linux/mctp.h>
#include <linux/netdevice.h>
#include <linux/rtnetlink.h>
......@@ -1228,3 +1229,7 @@ void __exit mctp_routes_exit(void)
rtnl_unregister(PF_MCTP, RTM_GETROUTE);
dev_remove_pack(&mctp_packet_type);
}
#if IS_ENABLED(CONFIG_MCTP_TEST)
#include "test/route-test.c"
#endif
This diff is collapsed.
// SPDX-License-Identifier: GPL-2.0
#include <linux/netdevice.h>
#include <linux/mctp.h>
#include <linux/if_arp.h>
#include <net/mctpdevice.h>
#include <net/pkt_sched.h>
#include "utils.h"
static netdev_tx_t mctp_test_dev_tx(struct sk_buff *skb,
struct net_device *ndev)
{
kfree(skb);
return NETDEV_TX_OK;
}
static const struct net_device_ops mctp_test_netdev_ops = {
.ndo_start_xmit = mctp_test_dev_tx,
};
static void mctp_test_dev_setup(struct net_device *ndev)
{
ndev->type = ARPHRD_MCTP;
ndev->mtu = MCTP_DEV_TEST_MTU;
ndev->hard_header_len = 0;
ndev->addr_len = 0;
ndev->tx_queue_len = DEFAULT_TX_QUEUE_LEN;
ndev->flags = IFF_NOARP;
ndev->netdev_ops = &mctp_test_netdev_ops;
ndev->needs_free_netdev = true;
}
struct mctp_test_dev *mctp_test_create_dev(void)
{
struct mctp_test_dev *dev;
struct net_device *ndev;
int rc;
ndev = alloc_netdev(sizeof(*dev), "mctptest%d", NET_NAME_ENUM,
mctp_test_dev_setup);
if (!ndev)
return NULL;
dev = netdev_priv(ndev);
dev->ndev = ndev;
rc = register_netdev(ndev);
if (rc) {
free_netdev(ndev);
return NULL;
}
rcu_read_lock();
dev->mdev = __mctp_dev_get(ndev);
mctp_dev_hold(dev->mdev);
rcu_read_unlock();
return dev;
}
void mctp_test_destroy_dev(struct mctp_test_dev *dev)
{
mctp_dev_put(dev->mdev);
unregister_netdev(dev->ndev);
}
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef __NET_MCTP_TEST_UTILS_H
#define __NET_MCTP_TEST_UTILS_H
#include <kunit/test.h>
#define MCTP_DEV_TEST_MTU 68
struct mctp_test_dev {
struct net_device *ndev;
struct mctp_dev *mdev;
};
struct mctp_test_dev;
struct mctp_test_dev *mctp_test_create_dev(void);
void mctp_test_destroy_dev(struct mctp_test_dev *dev);
#endif /* __NET_MCTP_TEST_UTILS_H */
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