From 1ae75a3bde3f1b87c79de5af9881cb9374489784 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 10 Jun 2025 13:32:10 +0100 Subject: [test] Add infrastructure for test network devices Signed-off-by: Michael Brown --- src/tests/netdev_test.h | 111 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 src/tests/netdev_test.h (limited to 'src/tests/netdev_test.h') diff --git a/src/tests/netdev_test.h b/src/tests/netdev_test.h new file mode 100644 index 000000000..ddb8c9b11 --- /dev/null +++ b/src/tests/netdev_test.h @@ -0,0 +1,111 @@ +#ifndef _NETDEV_TEST_H +#define _NETDEV_TEST_H + +/** @file + * + * Network device tests + * + */ + +FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); + +#include +#include + +/** A test network device setting */ +struct testnet_setting { + /** Setting name (relative to network device's settings) */ + const char *name; + /** Value */ + const char *value; +}; + +/** A test network device */ +struct testnet { + /** Network device */ + struct net_device *netdev; + /** Dummy physical device */ + struct device dev; + /** Initial settings */ + struct testnet_setting *testset; + /** Number of initial settings */ + unsigned int count; +}; + +/** + * Declare a test network device + * + * @v NAME Network device name + * @v ... Initial network device settings + */ +#define TESTNET( NAME, ... ) \ + static struct testnet_setting NAME ## _setting[] = { \ + __VA_ARGS__ \ + }; \ + static struct testnet NAME = { \ + .dev = { \ + .name = #NAME, \ + .driver_name = "testnet", \ + .siblings = \ + LIST_HEAD_INIT ( NAME.dev.siblings ), \ + .children = \ + LIST_HEAD_INIT ( NAME.dev.children ), \ + }, \ + .testset = NAME ## _setting, \ + .count = ( sizeof ( NAME ## _setting ) / \ + sizeof ( NAME ## _setting[0] ) ), \ + }; + +/** + * Report a network device creation test result + * + * @v testnet Test network device + */ +#define testnet_ok( testnet ) testnet_okx ( testnet, __FILE__, __LINE__ ) +extern void testnet_okx ( struct testnet *testnet, const char *file, + unsigned int line ); + +/** + * Report a network device opening test result + * + * @v testnet Test network device + */ +#define testnet_open_ok( testnet ) \ + testnet_open_okx ( testnet, __FILE__, __LINE__ ) +extern void testnet_open_okx ( struct testnet *testnet, const char *file, + unsigned int line ); + +/** + * Report a network device setting test result + * + * @v testnet Test network device + * @v name Setting name (relative to network device's settings) + * @v value Setting value + */ +#define testnet_set_ok( testnet, name, value ) \ + testnet_set_okx ( testnet, name, value, __FILE__, __LINE__ ) +extern void testnet_set_okx ( struct testnet *testnet, const char *name, + const char *value, const char *file, + unsigned int line ); + +/** + * Report a network device closing test result + * + * @v testnet Test network device + */ +#define testnet_close_ok( testnet ) \ + testnet_close_okx ( testnet, __FILE__, __LINE__ ) +extern void testnet_close_okx ( struct testnet *testnet, const char *file, + unsigned int line ); + +/** + * Report a network device removal test result + * + * @v testnet Test network device + */ +#define testnet_remove_ok( testnet ) \ + testnet_remove_okx ( testnet, __FILE__, __LINE__ ) +extern void testnet_remove_okx ( struct testnet *testnet, const char *file, + unsigned int line ); + +#endif /* _NETDEV_TEST_H */ -- cgit v1.2.3-55-g7522