iPXE
Functions | Variables
netdev_test.c File Reference

Network device tests. More...

#include <string.h>
#include <stdio.h>
#include <ipxe/netdevice.h>
#include <ipxe/ethernet.h>
#include <ipxe/test.h>
#include "netdev_test.h"

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static int testnet_open (struct net_device *netdev __unused)
 Open network device. More...
 
static void testnet_close (struct net_device *netdev __unused)
 Close network device. More...
 
static int testnet_transmit (struct net_device *netdev, struct io_buffer *iobuf)
 Transmit packet. More...
 
static void testnet_poll (struct net_device *netdev __unused)
 Poll for completed and received packets. More...
 
void testnet_okx (struct testnet *testnet, const char *file, unsigned int line)
 Report a network device creation test result. More...
 
void testnet_open_okx (struct testnet *testnet, const char *file, unsigned int line)
 Report a network device opening test result. More...
 
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. More...
 
void testnet_close_okx (struct testnet *testnet, const char *file, unsigned int line)
 Report a network device closing test result. More...
 
void testnet_remove_okx (struct testnet *testnet, const char *file, unsigned int line)
 Report a network device removal test result. More...
 

Variables

static struct net_device_operations testnet_operations
 Test network device operations. More...
 

Detailed Description

Network device tests.

Definition in file netdev_test.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ testnet_open()

static int testnet_open ( struct net_device *netdev  __unused)
static

Open network device.

Parameters
netdevNetwork device
Return values
rcReturn status code

Definition at line 48 of file netdev_test.c.

48  {
49 
50  /* Do nothing, successfully */
51  return 0;
52 }

◆ testnet_close()

static void testnet_close ( struct net_device *netdev  __unused)
static

Close network device.

Parameters
netdevNetwork device

Definition at line 59 of file netdev_test.c.

59  {
60 
61  /* Do nothing */
62 }

◆ testnet_transmit()

static int testnet_transmit ( struct net_device netdev,
struct io_buffer iobuf 
)
static

Transmit packet.

Parameters
netdevNetwork device
iobufI/O buffer
Return values
rcReturn status code

Definition at line 71 of file netdev_test.c.

72  {
73 
74  /* Complete immediately */
75  netdev_tx_complete ( netdev, iobuf );
76  return 0;
77 }
static void netdev_tx_complete(struct net_device *netdev, struct io_buffer *iobuf)
Complete network transmission.
Definition: netdevice.h:766
static struct net_device * netdev
Definition: gdbudp.c:52

References netdev, and netdev_tx_complete().

◆ testnet_poll()

static void testnet_poll ( struct net_device *netdev  __unused)
static

Poll for completed and received packets.

Parameters
netdevNetwork device

Definition at line 84 of file netdev_test.c.

84  {
85 
86  /* Do nothing */
87 }

◆ testnet_okx()

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

Report a network device creation test result.

Parameters
testnetTest network device
fileTest code file
lineTest code line

Definition at line 104 of file netdev_test.c.

105  {
106  struct testnet_setting *testset;
107  unsigned int i;
108 
109  /* Allocate device */
110  testnet->netdev = alloc_etherdev ( 0 );
111  okx ( testnet->netdev != NULL, file, line );
113  testnet->netdev->dev = &testnet->dev;
114  snprintf ( testnet->netdev->name, sizeof ( testnet->netdev->name ),
115  "%s", testnet->dev.name );
116 
117  /* Register device */
118  okx ( register_netdev ( testnet->netdev ) == 0, file, line );
119 
120  /* Open device */
121  testnet_open_okx ( testnet, file, line );
122 
123  /* Apply initial settings */
124  for ( i = 0 ; i < testnet->count ; i++ ) {
125  testset = &testnet->testset[i];
126  testnet_set_okx ( testnet, testset->name, testset->value,
127  file, line );
128  }
129 }
struct device dev
Dummy physical device.
Definition: netdev_test.h:28
A test network device.
Definition: netdev_test.h:24
unsigned int count
Number of initial settings.
Definition: netdev_test.h:32
struct net_device * netdev
Network device.
Definition: netdev_test.h:26
char name[40]
Name.
Definition: device.h:78
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.
Definition: netdev_test.c:157
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition: netdevice.h:518
struct testnet_setting * testset
Initial settings.
Definition: netdev_test.h:30
#define okx(success, file, line)
Report test result.
Definition: test.h:44
const char * value
Value.
Definition: netdev_test.h:20
int register_netdev(struct net_device *netdev)
Register network device.
Definition: netdevice.c:759
A test network device setting.
Definition: netdev_test.h:16
static struct net_device_operations testnet_operations
Test network device operations.
Definition: netdev_test.c:90
const char * name
Setting name (relative to network device's settings)
Definition: netdev_test.h:18
struct device * dev
Underlying hardware device.
Definition: netdevice.h:364
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition: ethernet.c:264
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
void testnet_open_okx(struct testnet *testnet, const char *file, unsigned int line)
Report a network device opening test result.
Definition: netdev_test.c:138

References alloc_etherdev(), testnet::count, testnet::dev, net_device::dev, testnet_setting::name, device::name, net_device::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 
)

Report a network device opening test result.

Parameters
testnetTest network device
fileTest code file
lineTest code line

Definition at line 138 of file netdev_test.c.

139  {
140 
141  /* Sanity check */
142  okx ( testnet->netdev != NULL, file, line );
143 
144  /* Open device */
145  okx ( netdev_open ( testnet->netdev ) == 0, file, line );
146 }
A test network device.
Definition: netdev_test.h:24
struct net_device * netdev
Network device.
Definition: netdev_test.h:26
#define okx(success, file, line)
Report test result.
Definition: test.h:44
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
int netdev_open(struct net_device *netdev)
Open network device.
Definition: netdevice.c:861

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 
)

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 157 of file netdev_test.c.

159  {
160  char fullname[ strlen ( testnet->dev.name ) + 1 /* "." or "/" */ +
161  strlen ( name ) + 1 /* NUL */ ];
162  struct settings *settings;
163  struct setting setting;
164 
165  /* Sanity check */
166  okx ( testnet->netdev != NULL, file, line );
168  okx ( settings != NULL, file, line );
169  okx ( strcmp ( settings->name, testnet->dev.name ) == 0, file, line );
170 
171  /* Construct setting name */
172  snprintf ( fullname, sizeof ( fullname ), "%s%c%s", testnet->dev.name,
173  ( strchr ( name, '/' ) ? '.' : '/' ), name );
174 
175  /* Parse setting name */
177  &settings, &setting ) == 0, file, line );
178 
179  /* Apply setting */
180  okx ( storef_setting ( settings, &setting, value ) == 0, file, line );
181 }
const char * name
Definition: ath9k_hw.c:1984
struct device dev
Dummy physical device.
Definition: netdev_test.h:28
A test network device.
Definition: netdev_test.h:24
struct net_device * netdev
Network device.
Definition: netdev_test.h:26
char name[40]
Name.
Definition: device.h:78
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition: netdevice.h:586
#define okx(success, file, line)
Report test result.
Definition: test.h:44
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
struct settings * autovivify_child_settings(struct settings *parent, const char *name)
Find or create child settings block.
Definition: settings.c:306
int storef_setting(struct settings *settings, const struct setting *setting, const char *value)
Store formatted value of setting.
Definition: settings.c:1319
char * strchr(const char *src, int character)
Find character within a string.
Definition: string.c:271
size_t strlen(const char *src)
Get length of string.
Definition: string.c:243
A settings block.
Definition: settings.h:132
const char * name
Name.
Definition: settings.h:136
A setting.
Definition: settings.h:23
int strcmp(const char *first, const char *second)
Compare strings.
Definition: string.c:173
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
int parse_setting_name(char *name, get_child_settings_t get_child, struct settings **settings, struct setting *setting)
Parse setting name.
Definition: settings.c:1528

References autovivify_child_settings(), testnet::dev, device::name, settings::name, 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 
)

Report a network device closing test result.

Parameters
testnetTest network device
fileTest code file
lineTest code line

Definition at line 190 of file netdev_test.c.

191  {
192 
193  /* Sanity check */
194  okx ( testnet->netdev != NULL, file, line );
195 
196  /* Close device */
198 }
A test network device.
Definition: netdev_test.h:24
struct net_device * netdev
Network device.
Definition: netdev_test.h:26
#define okx(success, file, line)
Report test result.
Definition: test.h:44
void netdev_close(struct net_device *netdev)
Close network device.
Definition: netdevice.c:895
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

◆ testnet_remove_okx()

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

Report a network device removal test result.

Parameters
testnetTest network device
fileTest code file
lineTest code line

Definition at line 207 of file netdev_test.c.

208  {
209 
210  /* Sanity check */
211  okx ( testnet->netdev != NULL, file, line );
212 
213  /* Remove device */
217  testnet->netdev = NULL;
218 }
A test network device.
Definition: netdev_test.h:24
struct net_device * netdev
Network device.
Definition: netdev_test.h:26
#define okx(success, file, line)
Report test result.
Definition: test.h:44
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:575
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:941
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:531
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

Variable Documentation

◆ testnet_operations

struct net_device_operations testnet_operations
static
Initial value:
= {
.open = testnet_open,
.close = testnet_close,
.transmit = testnet_transmit,
.poll = testnet_poll,
}
static void testnet_poll(struct net_device *netdev __unused)
Poll for completed and received packets.
Definition: netdev_test.c:84
static int testnet_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition: netdev_test.c:71
static void testnet_close(struct net_device *netdev __unused)
Close network device.
Definition: netdev_test.c:59
static int testnet_open(struct net_device *netdev __unused)
Open network device.
Definition: netdev_test.c:48

Test network device operations.

Definition at line 90 of file netdev_test.c.

Referenced by testnet_okx().