iPXE
netdev_test.h File Reference

Network device tests. More...

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

Go to the source code of this file.

Data Structures

struct  testnet_setting
 A test network device setting. More...
struct  testnet
 A test network device. More...

Macros

#define TESTNET(NAME, HWADDR, ...)
 Declare a test network device.
#define testnet_ok(testnet)
 Report a network device creation test result.
#define testnet_open_ok(testnet)
 Report a network device opening test result.
#define testnet_set_ok(testnet, name, value)
 Report a network device setting test result.
#define testnet_close_ok(testnet)
 Report a network device closing test result.
#define testnet_remove_ok(testnet)
 Report a network device removal test result.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
void testnet_okx (struct testnet *testnet, const char *file, unsigned int line)
 Report a network device creation test result.
void testnet_open_okx (struct testnet *testnet, const char *file, unsigned int line)
 Report a network device opening test result.
void testnet_set_okx (struct testnet *testnet, const char *name, const char *value, const char *file, unsigned int line)
 Report a network device setting test result.
void testnet_close_okx (struct testnet *testnet, const char *file, unsigned int line)
 Report a network device closing test result.
void testnet_remove_okx (struct testnet *testnet, const char *file, unsigned int line)
 Report a network device removal test result.

Detailed Description

Network device tests.

Definition in file netdev_test.h.

Macro Definition Documentation

◆ TESTNET

#define TESTNET ( NAME,
HWADDR,
... )
Value:
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 ), \
}, \
.hwaddr= HWADDR, \
.testset = NAME ## _setting, \
.count = ( sizeof ( NAME ## _setting ) / \
sizeof ( NAME ## _setting[0] ) ), \
};
struct list_head children
Devices attached to this device.
Definition device.h:87
struct list_head siblings
Devices on the same bus.
Definition device.h:85
A test network device setting.
Definition netdev_test.h:16
A test network device.
Definition netdev_test.h:24
struct device dev
Dummy physical device.
Definition netdev_test.h:28

Declare a test network device.

Parameters
NAMENetwork device name
HWADDRMAC address
...Initial network device settings

Definition at line 44 of file netdev_test.h.

44#define TESTNET( NAME, HWADDR, ... ) \
45 static struct testnet_setting NAME ## _setting[] = { \
46 __VA_ARGS__ \
47 }; \
48 static struct testnet NAME = { \
49 .dev = { \
50 .name = #NAME, \
51 .driver_name = "testnet", \
52 .siblings = \
53 LIST_HEAD_INIT ( NAME.dev.siblings ), \
54 .children = \
55 LIST_HEAD_INIT ( NAME.dev.children ), \
56 }, \
57 .hwaddr= HWADDR, \
58 .testset = NAME ## _setting, \
59 .count = ( sizeof ( NAME ## _setting ) / \
60 sizeof ( NAME ## _setting[0] ) ), \
61 };

◆ testnet_ok

#define testnet_ok ( testnet)
Value:
testnet_okx ( testnet, __FILE__, __LINE__ )
void testnet_okx(struct testnet *testnet, const char *file, unsigned int line)
Report a network device creation test result.

Report a network device creation test result.

Parameters
testnetTest network device

Definition at line 68 of file netdev_test.h.

Referenced by ipv4_test_exec().

◆ testnet_open_ok

#define testnet_open_ok ( testnet)
Value:
testnet_open_okx ( testnet, __FILE__, __LINE__ )
void testnet_open_okx(struct testnet *testnet, const char *file, unsigned int line)
Report a network device opening test result.

Report a network device opening test result.

Parameters
testnetTest network device

Definition at line 77 of file netdev_test.h.

77#define testnet_open_ok( testnet ) \
78 testnet_open_okx ( testnet, __FILE__, __LINE__ )

Referenced by ipv4_test_exec().

◆ testnet_set_ok

#define testnet_set_ok ( testnet,
name,
value )
Value:
testnet_set_okx ( testnet, name, value, __FILE__, __LINE__ )
pseudo_bit_t value[0x00020]
Definition arbel.h:2
const char * name
Definition ath9k_hw.c:1986
void testnet_set_okx(struct testnet *testnet, const char *name, const char *value, const char *file, unsigned int line)
Report a network device setting test result.

Report a network device setting test result.

Parameters
testnetTest network device
nameSetting name (relative to network device's settings)
valueSetting value

Definition at line 89 of file netdev_test.h.

89#define testnet_set_ok( testnet, name, value ) \
90 testnet_set_okx ( testnet, name, value, __FILE__, __LINE__ )

Referenced by ipv4_test_exec().

◆ testnet_close_ok

#define testnet_close_ok ( testnet)
Value:
testnet_close_okx ( testnet, __FILE__, __LINE__ )
void testnet_close_okx(struct testnet *testnet, const char *file, unsigned int line)
Report a network device closing test result.

Report a network device closing test result.

Parameters
testnetTest network device

Definition at line 100 of file netdev_test.h.

100#define testnet_close_ok( testnet ) \
101 testnet_close_okx ( testnet, __FILE__, __LINE__ )

Referenced by ipv4_test_exec().

◆ testnet_remove_ok

#define testnet_remove_ok ( testnet)
Value:
testnet_remove_okx ( testnet, __FILE__, __LINE__ )
void testnet_remove_okx(struct testnet *testnet, const char *file, unsigned int line)
Report a network device removal test result.

Report a network device removal test result.

Parameters
testnetTest network device

Definition at line 110 of file netdev_test.h.

110#define testnet_remove_ok( testnet ) \
111 testnet_remove_okx ( testnet, __FILE__, __LINE__ )

Referenced by ipv4_test_exec().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ testnet_okx()

void testnet_okx ( struct testnet * testnet,
const char * file,
unsigned int line )
extern

Report a network device creation test result.

Parameters
testnetTest network device
fileTest code file
lineTest code line

Definition at line 106 of file netdev_test.c.

107 {
108 struct testnet_setting *testset;
109 unsigned int i;
110
111 /* Allocate device */
113 okx ( testnet->netdev != NULL, file, line );
116 snprintf ( testnet->netdev->name, sizeof ( testnet->netdev->name ),
117 "%s", testnet->dev.name );
119 ETH_ALEN ) == ETH_ALEN, file, line );
120
121 /* Register device */
122 okx ( register_netdev ( testnet->netdev ) == 0, file, line );
123
124 /* Open device */
125 testnet_open_okx ( testnet, file, line );
126
127 /* Apply initial settings */
128 for ( i = 0 ; i < testnet->count ; i++ ) {
129 testset = &testnet->testset[i];
130 testnet_set_okx ( testnet, testset->name, testset->value,
131 file, line );
132 }
133}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
int hex_decode(char separator, const char *encoded, void *data, size_t len)
Decode hexadecimal string (with optional byte separator character)
Definition base16.c:77
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition ethernet.c:265
#define ETH_ALEN
Definition if_ether.h:9
static struct net_device_operations testnet_operations
Test network device operations.
Definition netdev_test.c:92
int register_netdev(struct net_device *netdev)
Register network device.
Definition netdevice.c:760
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition netdevice.h:522
char name[40]
Name.
Definition device.h:79
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition netdevice.h:382
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition netdevice.h:363
struct device * dev
Underlying hardware device.
Definition netdevice.h:365
const char * name
Setting name (relative to network device's settings)
Definition netdev_test.h:18
const char * value
Value.
Definition netdev_test.h:20
const char * hwaddr
MAC address.
Definition netdev_test.h:30
unsigned int count
Number of initial settings.
Definition netdev_test.h:34
struct net_device * netdev
Network device.
Definition netdev_test.h:26
struct testnet_setting * testset
Initial settings.
Definition netdev_test.h:32
#define okx(success, file, line)
Report test result.
Definition test.h:44
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition vsprintf.c:383

References alloc_etherdev(), testnet::count, net_device::dev, testnet::dev, ETH_ALEN, hex_decode(), net_device::hw_addr, testnet::hwaddr, device::name, net_device::name, testnet_setting::name, testnet::netdev, netdev_init(), NULL, okx, register_netdev(), snprintf(), testnet_open_okx(), testnet_operations, testnet_set_okx(), testnet::testset, and testnet_setting::value.

◆ testnet_open_okx()

void testnet_open_okx ( struct testnet * testnet,
const char * file,
unsigned int line )
extern

Report a network device opening test result.

Parameters
testnetTest network device
fileTest code file
lineTest code line

Definition at line 142 of file netdev_test.c.

143 {
144
145 /* Sanity check */
146 okx ( testnet->netdev != NULL, file, line );
147
148 /* Open device */
149 okx ( netdev_open ( testnet->netdev ) == 0, file, line );
150}
int netdev_open(struct net_device *netdev)
Open network device.
Definition netdevice.c:866

References testnet::netdev, netdev_open(), NULL, and okx.

Referenced by testnet_okx().

◆ testnet_set_okx()

void testnet_set_okx ( struct testnet * testnet,
const char * name,
const char * value,
const char * file,
unsigned int line )
extern

Report a network device setting test result.

Parameters
testnetTest network device
nameSetting name (relative to network device's settings)
valueSetting value
fileTest code file
lineTest code line

Definition at line 161 of file netdev_test.c.

163 {
164 char fullname[ strlen ( testnet->dev.name ) + 1 /* "." or "/" */ +
165 strlen ( name ) + 1 /* NUL */ ];
166 struct settings *settings;
167 struct setting setting;
168
169 /* Sanity check */
170 okx ( testnet->netdev != NULL, file, line );
172 okx ( settings != NULL, file, line );
173 okx ( strcmp ( settings->name, testnet->dev.name ) == 0, file, line );
174
175 /* Construct setting name */
176 snprintf ( fullname, sizeof ( fullname ), "%s%c%s", testnet->dev.name,
177 ( strchr ( name, '/' ) ? '.' : '/' ), name );
178
179 /* Parse setting name */
181 &settings, &setting ) == 0, file, line );
182
183 /* Apply setting */
184 okx ( storef_setting ( settings, &setting, value ) == 0, file, line );
185}
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition netdevice.h:590
struct settings * autovivify_child_settings(struct settings *parent, const char *name)
Find or create child settings block.
Definition settings.c:307
int parse_setting_name(char *name, get_child_settings_t get_child, struct settings **settings, struct setting *setting)
Parse setting name.
Definition settings.c:1529
int storef_setting(struct settings *settings, const struct setting *setting, const char *value)
Store formatted value of setting.
Definition settings.c:1320
int strcmp(const char *first, const char *second)
Compare strings.
Definition string.c:174
char * strchr(const char *src, int character)
Find character within a string.
Definition string.c:272
size_t strlen(const char *src)
Get length of string.
Definition string.c:244
A setting.
Definition settings.h:24
A settings block.
Definition settings.h:133
const char * name
Name.
Definition settings.h:137

References autovivify_child_settings(), testnet::dev, device::name, name, settings::name, testnet::netdev, netdev_settings(), NULL, okx, parse_setting_name(), snprintf(), storef_setting(), strchr(), strcmp(), strlen(), and value.

Referenced by testnet_okx().

◆ testnet_close_okx()

void testnet_close_okx ( struct testnet * testnet,
const char * file,
unsigned int line )
extern

Report a network device closing test result.

Parameters
testnetTest network device
fileTest code file
lineTest code line

Definition at line 194 of file netdev_test.c.

195 {
196
197 /* Sanity check */
198 okx ( testnet->netdev != NULL, file, line );
199
200 /* Close device */
202}
void netdev_close(struct net_device *netdev)
Close network device.
Definition netdevice.c:900

References testnet::netdev, netdev_close(), NULL, and okx.

◆ testnet_remove_okx()

void testnet_remove_okx ( struct testnet * testnet,
const char * file,
unsigned int line )
extern

Report a network device removal test result.

Parameters
testnetTest network device
fileTest code file
lineTest code line

Definition at line 211 of file netdev_test.c.

212 {
213
214 /* Sanity check */
215 okx ( testnet->netdev != NULL, file, line );
216
217 /* Remove device */
222}
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition netdevice.c:946
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition netdevice.h:535
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition netdevice.h:579

References testnet::netdev, netdev_nullify(), netdev_put(), NULL, okx, and unregister_netdev().