In net/core/selftests.c,
net_selftest() supports loopback tests.
However, the loopback content of this interface is a fixed common test
and cannot be expanded to add the driver's own test.
In this patch, the net_selftest_custom() interface is added
to support driver customized loopback tests and
extra common loopback tests.
Signed-off-by: Jijie Shao <shaojijie@xxxxxxxxxx>
---
include/net/selftests.h | 61 +++++++++++++
net/core/selftests.c | 188 +++++++++++++++++++++++++++++++++++++++-
2 files changed, 245 insertions(+), 4 deletions(-)
diff --git a/include/net/selftests.h b/include/net/selftests.h
index e65e8d230d33..a36e6ee0a41f 100644
--- a/include/net/selftests.h
+++ b/include/net/selftests.h
@@ -4,6 +4,48 @@
#include <linux/ethtool.h>
+#define NET_TEST_NETIF_CARRIER BIT(0)
+#define NET_TEST_FULL_DUPLEX BIT(1)
+#define NET_TEST_TCP BIT(2)
+#define NET_TEST_UDP BIT(3)
+#define NET_TEST_UDP_MAX_MTU BIT(4)
+
+#define NET_EXTRA_CARRIER_TEST BIT(0)
+#define NET_EXTRA_FULL_DUPLEX_TEST BIT(1)
+#define NET_EXTRA_PHY_TEST BIT(2)
+struct net_test_entry {
+ char name[ETH_GSTRING_LEN];
+
+ /* can set to NULL */
+ int (*enable)(struct net_device *ndev, bool enable);
+
+ /* can set to NULL */
+ int (*fn)(struct net_device *ndev);
+
+ /* if flag is set, fn() will be ignored,
+ * and will do test according to the flag,
+ * such as NET_TEST_UDP...
+ */
+ unsigned long flags;
+};
+
+#define NET_TEST_E(_name, _enable, _flags) { \
+ .name = _name, \
+ .enable = _enable, \
+ .fn = NULL, \
+ .flags = _flags }
+
+#define NET_TEST_ENTRY_MAX_COUNT 10
+struct net_test {
+ /* extra tests will be added based on this flag */
+ unsigned long extra_flags;
+
+ struct net_test_entry entries[NET_TEST_ENTRY_MAX_COUNT];
+ /* the count of entries, must <= NET_TEST_ENTRY_MAX_COUNT */
+ u32 count;
+};