summaryrefslogtreecommitdiffstats
path: root/src/tests/netdev_test.h
blob: ddb8c9b11bb170a02275a8045b46603d234a9811 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#ifndef _NETDEV_TEST_H
#define _NETDEV_TEST_H

/** @file
 *
 * Network device tests
 *
 */

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );

#include <ipxe/device.h>
#include <ipxe/netdevice.h>

/** 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 */