FreeBSD kernel /amd64 XEN device code
netback_unit_tests.c File Reference

Unit tests for the Xen netback driver. More...

#include <sys/cdefs.h>
Include dependency graph for netback_unit_tests.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  test_fixture
 

Macros

#define SNCATF(buffer, buflen, ...)
 
#define STRINGIFY(x)   #x
 
#define TOSTRING(x)   STRINGIFY(x)
 
#define XNB_ASSERT(cond)
 
#define TOTAL_TESTS   (53)
 
#define TOTAL_BUFLEN   (400 * TOTAL_TESTS + 2)
 

Typedefs

typedef void testcase_t(char *buffer, size_t buflen)
 
typedef int setup_t(void)
 
typedef void teardown_t(void)
 
typedef struct test_fixture test_fixture_t
 

Functions

 __FBSDID ("$FreeBSD$")
 
static int xnb_get1pkt (struct xnb_pkt *pkt, size_t size, uint16_t flags)
 
static int xnb_unit_test_runner (test_fixture_t const tests[], int ntests, char *buffer, size_t buflen)
 
static int __unused null_setup (void)
 
static void __unused null_teardown (void)
 
static void safe_m_freem (struct mbuf **ppMbuf)
 
static int xnb_unit_test_main (SYSCTL_HANDLER_ARGS)
 
static void xnb_ring2pkt_emptyring (char *buffer, size_t buflen)
 
static void xnb_ring2pkt_1req (char *buffer, size_t buflen)
 
static void xnb_ring2pkt_2req (char *buffer, size_t buflen)
 
static void xnb_ring2pkt_3req (char *buffer, size_t buflen)
 
static void xnb_ring2pkt_extra (char *buffer, size_t buflen)
 
static void xnb_ring2pkt_partial (char *buffer, size_t buflen)
 
static void xnb_ring2pkt_wraps (char *buffer, size_t buflen)
 
static void xnb_txpkt2rsp_emptypkt (char *buffer, size_t buflen)
 
static void xnb_txpkt2rsp_1req (char *buffer, size_t buflen)
 
static void xnb_txpkt2rsp_extra (char *buffer, size_t buflen)
 
static void xnb_txpkt2rsp_long (char *buffer, size_t buflen)
 
static void xnb_txpkt2rsp_invalid (char *buffer, size_t buflen)
 
static void xnb_txpkt2rsp_error (char *buffer, size_t buflen)
 
static void xnb_txpkt2rsp_wraps (char *buffer, size_t buflen)
 
static void xnb_pkt2mbufc_empty (char *buffer, size_t buflen)
 
static void xnb_pkt2mbufc_short (char *buffer, size_t buflen)
 
static void xnb_pkt2mbufc_csum (char *buffer, size_t buflen)
 
static void xnb_pkt2mbufc_1cluster (char *buffer, size_t buflen)
 
static void xnb_pkt2mbufc_largecluster (char *buffer, size_t buflen)
 
static void xnb_pkt2mbufc_2cluster (char *buffer, size_t buflen)
 
static void xnb_txpkt2gnttab_empty (char *buffer, size_t buflen)
 
static void xnb_txpkt2gnttab_short (char *buffer, size_t buflen)
 
static void xnb_txpkt2gnttab_2req (char *buffer, size_t buflen)
 
static void xnb_txpkt2gnttab_2cluster (char *buffer, size_t buflen)
 
static void xnb_update_mbufc_short (char *buffer, size_t buflen)
 
static void xnb_update_mbufc_2req (char *buffer, size_t buflen)
 
static void xnb_update_mbufc_2cluster (char *buffer, size_t buflen)
 
static void xnb_mbufc2pkt_empty (char *buffer, size_t buflen)
 
static void xnb_mbufc2pkt_short (char *buffer, size_t buflen)
 
static void xnb_mbufc2pkt_1cluster (char *buffer, size_t buflen)
 
static void xnb_mbufc2pkt_2short (char *buffer, size_t buflen)
 
static void xnb_mbufc2pkt_long (char *buffer, size_t buflen)
 
static void xnb_mbufc2pkt_extra (char *buffer, size_t buflen)
 
static void xnb_mbufc2pkt_nospace (char *buffer, size_t buflen)
 
static void xnb_rxpkt2gnttab_empty (char *buffer, size_t buflen)
 
static void xnb_rxpkt2gnttab_short (char *buffer, size_t buflen)
 
static void xnb_rxpkt2gnttab_2req (char *buffer, size_t buflen)
 
static void xnb_rxpkt2rsp_empty (char *buffer, size_t buflen)
 
static void xnb_rxpkt2rsp_short (char *buffer, size_t buflen)
 
static void xnb_rxpkt2rsp_extra (char *buffer, size_t buflen)
 
static void xnb_rxpkt2rsp_2slots (char *buffer, size_t buflen)
 
static void xnb_rxpkt2rsp_2short (char *buffer, size_t buflen)
 
static void xnb_rxpkt2rsp_copyerror (char *buffer, size_t buflen)
 
static void xnb_sscanf_hhu (char *buffer, size_t buflen)
 
static void xnb_sscanf_hhd (char *buffer, size_t buflen)
 
static void xnb_sscanf_lld (char *buffer, size_t buflen)
 
static void xnb_sscanf_llu (char *buffer, size_t buflen)
 
static void xnb_sscanf_hhn (char *buffer, size_t buflen)
 

Variables

static setup_t setup_pvt_data
 
static teardown_t teardown_pvt_data
 
static testcase_t xnb_ring2pkt_emptyring
 
static testcase_t xnb_ring2pkt_1req
 
static testcase_t xnb_ring2pkt_2req
 
static testcase_t xnb_ring2pkt_3req
 
static testcase_t xnb_ring2pkt_extra
 
static testcase_t xnb_ring2pkt_partial
 
static testcase_t xnb_ring2pkt_wraps
 
static testcase_t xnb_txpkt2rsp_emptypkt
 
static testcase_t xnb_txpkt2rsp_1req
 
static testcase_t xnb_txpkt2rsp_extra
 
static testcase_t xnb_txpkt2rsp_long
 
static testcase_t xnb_txpkt2rsp_invalid
 
static testcase_t xnb_txpkt2rsp_error
 
static testcase_t xnb_txpkt2rsp_wraps
 
static testcase_t xnb_pkt2mbufc_empty
 
static testcase_t xnb_pkt2mbufc_short
 
static testcase_t xnb_pkt2mbufc_csum
 
static testcase_t xnb_pkt2mbufc_1cluster
 
static testcase_t xnb_pkt2mbufc_largecluster
 
static testcase_t xnb_pkt2mbufc_2cluster
 
static testcase_t xnb_txpkt2gnttab_empty
 
static testcase_t xnb_txpkt2gnttab_short
 
static testcase_t xnb_txpkt2gnttab_2req
 
static testcase_t xnb_txpkt2gnttab_2cluster
 
static testcase_t xnb_update_mbufc_short
 
static testcase_t xnb_update_mbufc_2req
 
static testcase_t xnb_update_mbufc_2cluster
 
static testcase_t xnb_mbufc2pkt_empty
 
static testcase_t xnb_mbufc2pkt_short
 
static testcase_t xnb_mbufc2pkt_1cluster
 
static testcase_t xnb_mbufc2pkt_2short
 
static testcase_t xnb_mbufc2pkt_long
 
static testcase_t xnb_mbufc2pkt_extra
 
static testcase_t xnb_mbufc2pkt_nospace
 
static testcase_t xnb_rxpkt2gnttab_empty
 
static testcase_t xnb_rxpkt2gnttab_short
 
static testcase_t xnb_rxpkt2gnttab_2req
 
static testcase_t xnb_rxpkt2rsp_empty
 
static testcase_t xnb_rxpkt2rsp_short
 
static testcase_t xnb_rxpkt2rsp_extra
 
static testcase_t xnb_rxpkt2rsp_2short
 
static testcase_t xnb_rxpkt2rsp_2slots
 
static testcase_t xnb_rxpkt2rsp_copyerror
 
static testcase_t xnb_sscanf_llu
 
static testcase_t xnb_sscanf_lld
 
static testcase_t xnb_sscanf_hhu
 
static testcase_t xnb_sscanf_hhd
 
static testcase_t xnb_sscanf_hhn
 
struct {
   gnttab_copy_table   gnttab
 
   netif_rx_back_ring_t   rxb
 
   netif_rx_front_ring_t   rxf
 
   netif_tx_back_ring_t   txb
 
   netif_tx_front_ring_t   txf
 
   struct ifnet *   ifp
 
   netif_rx_sring_t *   rxs
 
   netif_tx_sring_t *   txs
 
xnb_unit_pvt
 

Detailed Description

Unit tests for the Xen netback driver.

Due to the driver's use of static functions, these tests cannot be compiled standalone; they must be #include'd from the driver's .c file.

Definition in file netback_unit_tests.c.

Macro Definition Documentation

◆ SNCATF

#define SNCATF (   buffer,
  buflen,
  ... 
)
Value:
do { \
size_t new_chars = snprintf(buffer, buflen, __VA_ARGS__); \
buffer += new_chars; \
/* be careful; snprintf's return value can be > buflen */ \
buflen -= MIN(buflen, new_chars); \
} while (0)

Helper macro used to snprintf to a buffer and update the buffer pointer

Definition at line 50 of file netback_unit_tests.c.

◆ STRINGIFY

#define STRINGIFY (   x)    #x

Definition at line 58 of file netback_unit_tests.c.

◆ TOSTRING

#define TOSTRING (   x)    STRINGIFY(x)

Definition at line 59 of file netback_unit_tests.c.

◆ TOTAL_BUFLEN

#define TOTAL_BUFLEN   (400 * TOTAL_TESTS + 2)

Max memory available for returning results. 400 chars/test should give enough space for a five line error message for every test

Definition at line 255 of file netback_unit_tests.c.

◆ TOTAL_TESTS

#define TOTAL_TESTS   (53)

Number of unit tests. Must match the length of the tests array below

Definition at line 250 of file netback_unit_tests.c.

◆ XNB_ASSERT

#define XNB_ASSERT (   cond)
Value:
({ \
int passed = (cond); \
char *_buffer = (buffer); \
size_t _buflen = (buflen); \
if (! passed) { \
strlcat(_buffer, __func__, _buflen); \
strlcat(_buffer, ":" TOSTRING(__LINE__) \
" Assertion Error: " #cond "\n", _buflen); \
} \
})
#define TOSTRING(x)

Writes an error message to buffer if cond is false Note the implied parameters buffer and buflen

Definition at line 66 of file netback_unit_tests.c.

Typedef Documentation

◆ setup_t

typedef int setup_t(void)

Signature used by setup functions

Returns
nonzero on error

Definition at line 89 of file netback_unit_tests.c.

◆ teardown_t

typedef void teardown_t(void)

Definition at line 91 of file netback_unit_tests.c.

◆ test_fixture_t

typedef struct test_fixture test_fixture_t

Definition at line 105 of file netback_unit_tests.c.

◆ testcase_t

typedef void testcase_t(char *buffer, size_t buflen)

The signature used by all testcases. If the test writes anything to buffer, then it will be considered a failure

Parameters
bufferReturn storage for error messages
buflenThe space available in the buffer

Definition at line 83 of file netback_unit_tests.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ null_setup()

static int __unused null_setup ( void  )
static

Definition at line 112 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

Here is the caller graph for this function:

◆ null_teardown()

static void __unused null_teardown ( void  )
static

Definition at line 115 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

Here is the caller graph for this function:

◆ safe_m_freem()

◆ xnb_get1pkt()

static int xnb_get1pkt ( struct xnb_pkt pkt,
size_t  size,
uint16_t  flags 
)
static

Helper function used to setup pkt2mbufc tests

Parameters
sizesize in bytes of the single request to push to the ring
flagsoptional flags to put in the netif request
[out]pktthe returned packet object
Returns
number of requests consumed from the ring

Definition at line 967 of file netback_unit_tests.c.

References xnb_ring2pkt(), and xnb_unit_pvt.

Referenced by xnb_pkt2mbufc_1cluster(), xnb_pkt2mbufc_2cluster(), xnb_pkt2mbufc_csum(), xnb_pkt2mbufc_largecluster(), and xnb_pkt2mbufc_short().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xnb_mbufc2pkt_1cluster()

static void xnb_mbufc2pkt_1cluster ( char *  buffer,
size_t  buflen 
)
static

xnb_mbufc2pkt on a single mbuf with an mbuf cluster

Definition at line 1462 of file netback_unit_tests.c.

References xnb_pkt::car, xnb_pkt::car_size, xnb_pkt::flags, xnb_pkt::list_len, safe_m_freem(), xnb_pkt::size, XNB_ASSERT, xnb_mbufc2pkt(), and xnb_pkt_is_valid().

Here is the call graph for this function:

◆ xnb_mbufc2pkt_2short()

static void xnb_mbufc2pkt_2short ( char *  buffer,
size_t  buflen 
)
static

xnb_mbufc2pkt on a two-mbuf chain with short data regions

Definition at line 1488 of file netback_unit_tests.c.

References xnb_pkt::car, xnb_pkt::car_size, xnb_pkt::cdr, xnb_pkt::list_len, safe_m_freem(), xnb_pkt::size, XNB_ASSERT, xnb_mbufc2pkt(), and xnb_pkt_is_valid().

Here is the call graph for this function:

◆ xnb_mbufc2pkt_empty()

static void xnb_mbufc2pkt_empty ( char *  buffer,
size_t  buflen 
)
static

xnb_mbufc2pkt on an empty mbufc

Definition at line 1416 of file netback_unit_tests.c.

References safe_m_freem(), XNB_ASSERT, xnb_mbufc2pkt(), and xnb_pkt_is_valid().

Here is the call graph for this function:

◆ xnb_mbufc2pkt_extra()

static void xnb_mbufc2pkt_extra ( char *  buffer,
size_t  buflen 
)
static

xnb_mbufc2pkt on a mbuf chain with >1 mbuf cluster and extra info

Definition at line 1568 of file netback_unit_tests.c.

References xnb_pkt::car, xnb_pkt::car_size, xnb_pkt::cdr, xnb_pkt::extra, xnb_pkt::flags, safe_m_freem(), xnb_pkt::size, XNB_ASSERT, xnb_mbufc2pkt(), and xnb_pkt_is_valid().

Here is the call graph for this function:

◆ xnb_mbufc2pkt_long()

static void xnb_mbufc2pkt_long ( char *  buffer,
size_t  buflen 
)
static

xnb_mbufc2pkt on a mbuf chain with >1 mbuf cluster

Definition at line 1530 of file netback_unit_tests.c.

References xnb_pkt::car, xnb_pkt::car_size, xnb_pkt::cdr, xnb_pkt::flags, safe_m_freem(), xnb_pkt::size, XNB_ASSERT, xnb_mbufc2pkt(), and xnb_pkt_is_valid().

Here is the call graph for this function:

◆ xnb_mbufc2pkt_nospace()

static void xnb_mbufc2pkt_nospace ( char *  buffer,
size_t  buflen 
)
static

xnb_mbufc2pkt with insufficient space in the ring

Definition at line 1609 of file netback_unit_tests.c.

References safe_m_freem(), xnb_pkt::size, XNB_ASSERT, xnb_mbufc2pkt(), and xnb_pkt_is_valid().

Here is the call graph for this function:

◆ xnb_mbufc2pkt_short()

static void xnb_mbufc2pkt_short ( char *  buffer,
size_t  buflen 
)
static

xnb_mbufc2pkt on a short mbufc

Definition at line 1436 of file netback_unit_tests.c.

References xnb_pkt::car, xnb_pkt::car_size, xnb_pkt::flags, xnb_pkt::list_len, safe_m_freem(), xnb_pkt::size, XNB_ASSERT, xnb_mbufc2pkt(), and xnb_pkt_is_valid().

Here is the call graph for this function:

◆ xnb_pkt2mbufc_1cluster()

static void xnb_pkt2mbufc_1cluster ( char *  buffer,
size_t  buflen 
)
static

xnb_pkt2mbufc on packet that can fit in one cluster

Definition at line 1044 of file netback_unit_tests.c.

References safe_m_freem(), XNB_ASSERT, xnb_get1pkt(), xnb_pkt2mbufc(), and xnb_unit_pvt.

Here is the call graph for this function:

◆ xnb_pkt2mbufc_2cluster()

static void xnb_pkt2mbufc_2cluster ( char *  buffer,
size_t  buflen 
)
static

xnb_pkt2mbufc on packet that cannot fit in one clusters

Definition at line 1078 of file netback_unit_tests.c.

References safe_m_freem(), XNB_ASSERT, xnb_get1pkt(), xnb_pkt2mbufc(), and xnb_unit_pvt.

Here is the call graph for this function:

◆ xnb_pkt2mbufc_csum()

static void xnb_pkt2mbufc_csum ( char *  buffer,
size_t  buflen 
)
static

xnb_pkt2mbufc on short packet whose checksum was validated by the netfron

Definition at line 1023 of file netback_unit_tests.c.

References safe_m_freem(), XNB_ASSERT, xnb_get1pkt(), xnb_pkt2mbufc(), and xnb_unit_pvt.

Here is the call graph for this function:

◆ xnb_pkt2mbufc_empty()

static void xnb_pkt2mbufc_empty ( char *  buffer,
size_t  buflen 
)
static

xnb_pkt2mbufc on an empty packet

Definition at line 987 of file netback_unit_tests.c.

References xnb_pkt::list_len, safe_m_freem(), xnb_pkt::size, xnb_pkt2mbufc(), xnb_ring2pkt(), and xnb_unit_pvt.

Here is the call graph for this function:

◆ xnb_pkt2mbufc_largecluster()

static void xnb_pkt2mbufc_largecluster ( char *  buffer,
size_t  buflen 
)
static

xnb_pkt2mbufc on packet that cannot fit in one regular cluster

Definition at line 1061 of file netback_unit_tests.c.

References safe_m_freem(), XNB_ASSERT, xnb_get1pkt(), xnb_pkt2mbufc(), and xnb_unit_pvt.

Here is the call graph for this function:

◆ xnb_pkt2mbufc_short()

static void xnb_pkt2mbufc_short ( char *  buffer,
size_t  buflen 
)
static

xnb_pkt2mbufc on short packet that can fit in an mbuf internal buffer

Definition at line 1006 of file netback_unit_tests.c.

References safe_m_freem(), XNB_ASSERT, xnb_get1pkt(), xnb_pkt2mbufc(), and xnb_unit_pvt.

Here is the call graph for this function:

◆ xnb_ring2pkt_1req()

static void xnb_ring2pkt_1req ( char *  buffer,
size_t  buflen 
)
static

Verify that xnb_ring2pkt can convert a single request packet correctly

Definition at line 406 of file netback_unit_tests.c.

References xnb_pkt::car, xnb_pkt::car_size, xnb_pkt::flags, xnb_pkt::list_len, xnb_pkt::size, XNB_ASSERT, xnb_pkt_is_valid(), xnb_ring2pkt(), and xnb_unit_pvt.

Here is the call graph for this function:

◆ xnb_ring2pkt_2req()

static void xnb_ring2pkt_2req ( char *  buffer,
size_t  buflen 
)
static

Verify that xnb_ring2pkt can convert a two request packet correctly. This tests handling of the MORE_DATA flag and cdr

Definition at line 437 of file netback_unit_tests.c.

References xnb_pkt::car, xnb_pkt::car_size, xnb_pkt::cdr, xnb_pkt::flags, xnb_pkt::list_len, xnb_pkt::size, XNB_ASSERT, xnb_pkt_is_valid(), xnb_ring2pkt(), and xnb_unit_pvt.

Here is the call graph for this function:

◆ xnb_ring2pkt_3req()

static void xnb_ring2pkt_3req ( char *  buffer,
size_t  buflen 
)
static

Verify that xnb_ring2pkt can convert a three request packet correctly

Definition at line 474 of file netback_unit_tests.c.

References xnb_pkt::car, xnb_pkt::car_size, xnb_pkt::cdr, xnb_pkt::flags, xnb_pkt::list_len, xnb_pkt::size, XNB_ASSERT, xnb_pkt_is_valid(), xnb_ring2pkt(), and xnb_unit_pvt.

Here is the call graph for this function:

◆ xnb_ring2pkt_emptyring()

static void xnb_ring2pkt_emptyring ( char *  buffer,
size_t  buflen 
)
static

Verify that xnb_ring2pkt will not consume any requests from an empty ring

Definition at line 392 of file netback_unit_tests.c.

References XNB_ASSERT, xnb_ring2pkt(), and xnb_unit_pvt.

Here is the call graph for this function:

◆ xnb_ring2pkt_extra()

static void xnb_ring2pkt_extra ( char *  buffer,
size_t  buflen 
)
static

Verify that xnb_ring2pkt can read extra inf

Definition at line 518 of file netback_unit_tests.c.

References xnb_pkt::car, xnb_pkt::car_size, xnb_pkt::cdr, xnb_pkt::extra, xnb_pkt::flags, xnb_pkt::list_len, xnb_pkt::size, XNB_ASSERT, xnb_pkt_is_valid(), xnb_ring2pkt(), and xnb_unit_pvt.

Here is the call graph for this function:

◆ xnb_ring2pkt_partial()

static void xnb_ring2pkt_partial ( char *  buffer,
size_t  buflen 
)
static

Verify that xnb_ring2pkt will consume no requests if the entire packet is not yet in the ring

Definition at line 571 of file netback_unit_tests.c.

References XNB_ASSERT, xnb_pkt_is_valid(), xnb_ring2pkt(), and xnb_unit_pvt.

Here is the call graph for this function:

◆ xnb_ring2pkt_wraps()

static void xnb_ring2pkt_wraps ( char *  buffer,
size_t  buflen 
)
static

Verity that xnb_ring2pkt can read a packet whose requests wrap around the end of the ring

Definition at line 596 of file netback_unit_tests.c.

References xnb_pkt::cdr, xnb_pkt::list_len, XNB_ASSERT, xnb_pkt_is_valid(), xnb_ring2pkt(), and xnb_unit_pvt.

Here is the call graph for this function:

◆ xnb_rxpkt2gnttab_2req()

static void xnb_rxpkt2gnttab_2req ( char *  buffer,
size_t  buflen 
)
static

xnb_rxpkt2gnttab on a packet with two different mbufs in a single chai

Definition at line 1703 of file netback_unit_tests.c.

References xnb_pkt::size, XNB_ASSERT, xnb_mbufc2pkt(), xnb_rxpkt2gnttab(), and xnb_unit_pvt.

Here is the call graph for this function:

◆ xnb_rxpkt2gnttab_empty()

static void xnb_rxpkt2gnttab_empty ( char *  buffer,
size_t  buflen 
)
static

xnb_rxpkt2gnttab on an empty packet. Should return empty gnttab

Definition at line 1642 of file netback_unit_tests.c.

References safe_m_freem(), XNB_ASSERT, xnb_mbufc2pkt(), xnb_rxpkt2gnttab(), and xnb_unit_pvt.

Here is the call graph for this function:

◆ xnb_rxpkt2gnttab_short()

static void xnb_rxpkt2gnttab_short ( char *  buffer,
size_t  buflen 
)
static

xnb_rxpkt2gnttab on a short packet without extra data

Definition at line 1662 of file netback_unit_tests.c.

References safe_m_freem(), xnb_pkt::size, virt_to_mfn, virt_to_offset, XNB_ASSERT, xnb_mbufc2pkt(), xnb_rxpkt2gnttab(), and xnb_unit_pvt.

Here is the call graph for this function:

◆ xnb_rxpkt2rsp_2short()

static void xnb_rxpkt2rsp_2short ( char *  buffer,
size_t  buflen 
)
static

xnb_rxpkt2rsp on a grant table with two sub-page entries

Definition at line 1958 of file netback_unit_tests.c.

References safe_m_freem(), XNB_ASSERT, xnb_mbufc2pkt(), xnb_rxpkt2gnttab(), xnb_rxpkt2rsp(), and xnb_unit_pvt.

Here is the call graph for this function:

◆ xnb_rxpkt2rsp_2slots()

static void xnb_rxpkt2rsp_2slots ( char *  buffer,
size_t  buflen 
)
static

xnb_rxpkt2rsp on a packet with more than a pages's worth of data. It should generate two response slot

Definition at line 1892 of file netback_unit_tests.c.

References safe_m_freem(), xnb_pkt::size, XNB_ASSERT, xnb_mbufc2pkt(), xnb_rxpkt2gnttab(), xnb_rxpkt2rsp(), and xnb_unit_pvt.

Here is the call graph for this function:

◆ xnb_rxpkt2rsp_copyerror()

static void xnb_rxpkt2rsp_copyerror ( char *  buffer,
size_t  buflen 
)
static

xnb_rxpkt2rsp on a long packet with a hypervisor gnttab_copy error Note: this test will result in an error message being printed to the console such as: xnb(xnb_rxpkt2rsp:1720): Got error -1 for hypervisor gnttab_copy status

Definition at line 2017 of file netback_unit_tests.c.

References safe_m_freem(), xnb_pkt::size, XNB_ASSERT, xnb_mbufc2pkt(), xnb_rxpkt2gnttab(), xnb_rxpkt2rsp(), and xnb_unit_pvt.

Here is the call graph for this function:

◆ xnb_rxpkt2rsp_empty()

static void xnb_rxpkt2rsp_empty ( char *  buffer,
size_t  buflen 
)
static

xnb_rxpkt2rsp on an empty packet. Shouldn't make any response

Definition at line 1747 of file netback_unit_tests.c.

References safe_m_freem(), XNB_ASSERT, xnb_mbufc2pkt(), xnb_rxpkt2gnttab(), xnb_rxpkt2rsp(), and xnb_unit_pvt.

Here is the call graph for this function:

◆ xnb_rxpkt2rsp_extra()

static void xnb_rxpkt2rsp_extra ( char *  buffer,
size_t  buflen 
)
static

xnb_rxpkt2rsp with extra data

Definition at line 1823 of file netback_unit_tests.c.

References safe_m_freem(), xnb_pkt::size, XNB_ASSERT, xnb_mbufc2pkt(), xnb_rxpkt2gnttab(), xnb_rxpkt2rsp(), and xnb_unit_pvt.

Here is the call graph for this function:

◆ xnb_rxpkt2rsp_short()

static void xnb_rxpkt2rsp_short ( char *  buffer,
size_t  buflen 
)
static

xnb_rxpkt2rsp on a short packet with no extras

Definition at line 1778 of file netback_unit_tests.c.

References safe_m_freem(), xnb_pkt::size, XNB_ASSERT, xnb_mbufc2pkt(), xnb_rxpkt2gnttab(), xnb_rxpkt2rsp(), and xnb_unit_pvt.

Here is the call graph for this function:

◆ xnb_sscanf_hhd()

static void xnb_sscanf_hhd ( char *  buffer,
size_t  buflen 
)
static

sscanf on signed chars

Definition at line 2457 of file netback_unit_tests.c.

References XNB_ASSERT.

◆ xnb_sscanf_hhn()

static void xnb_sscanf_hhn ( char *  buffer,
size_t  buflen 
)
static

sscanf on unsigned short short n's

Definition at line 2513 of file netback_unit_tests.c.

References XNB_ASSERT.

◆ xnb_sscanf_hhu()

static void xnb_sscanf_hhu ( char *  buffer,
size_t  buflen 
)
static

sscanf on unsigned chars

Definition at line 2439 of file netback_unit_tests.c.

References XNB_ASSERT.

◆ xnb_sscanf_lld()

static void xnb_sscanf_lld ( char *  buffer,
size_t  buflen 
)
static

sscanf on signed long longs

Definition at line 2475 of file netback_unit_tests.c.

References XNB_ASSERT.

◆ xnb_sscanf_llu()

static void xnb_sscanf_llu ( char *  buffer,
size_t  buflen 
)
static

sscanf on unsigned long longs

Definition at line 2494 of file netback_unit_tests.c.

References XNB_ASSERT.

◆ xnb_txpkt2gnttab_2cluster()

static void xnb_txpkt2gnttab_2cluster ( char *  buffer,
size_t  buflen 
)
static

xnb_txpkt2gnttab on a single request that spans two mbuf clusters

Definition at line 1209 of file netback_unit_tests.c.

References virt_to_offset, XNB_ASSERT, xnb_pkt2mbufc(), xnb_ring2pkt(), xnb_txpkt2gnttab(), and xnb_unit_pvt.

Here is the call graph for this function:

◆ xnb_txpkt2gnttab_2req()

static void xnb_txpkt2gnttab_2req ( char *  buffer,
size_t  buflen 
)
static

xnb_txpkt2gnttab on a packet with two requests, that can fit into a single mbuf cluster

Definition at line 1164 of file netback_unit_tests.c.

References safe_m_freem(), virt_to_offset, XNB_ASSERT, xnb_pkt2mbufc(), xnb_ring2pkt(), xnb_txpkt2gnttab(), and xnb_unit_pvt.

Here is the call graph for this function:

◆ xnb_txpkt2gnttab_empty()

static void xnb_txpkt2gnttab_empty ( char *  buffer,
size_t  buflen 
)
static

xnb_txpkt2gnttab on an empty packet. Should return empty gnttab

Definition at line 1101 of file netback_unit_tests.c.

References xnb_pkt::list_len, safe_m_freem(), xnb_pkt::size, XNB_ASSERT, xnb_pkt2mbufc(), xnb_ring2pkt(), xnb_txpkt2gnttab(), and xnb_unit_pvt.

Here is the call graph for this function:

◆ xnb_txpkt2gnttab_short()

static void xnb_txpkt2gnttab_short ( char *  buffer,
size_t  buflen 
)
static

xnb_txpkt2gnttab on a short packet, that can fit in one mbuf internal buffer and has one request

Definition at line 1123 of file netback_unit_tests.c.

References safe_m_freem(), virt_to_mfn, virt_to_offset, XNB_ASSERT, xnb_pkt2mbufc(), xnb_ring2pkt(), xnb_txpkt2gnttab(), and xnb_unit_pvt.

Here is the call graph for this function:

◆ xnb_txpkt2rsp_1req()

static void xnb_txpkt2rsp_1req ( char *  buffer,
size_t  buflen 
)
static

xnb_txpkt2rsp responding to one request

Definition at line 671 of file netback_unit_tests.c.

References XNB_ASSERT, xnb_ring2pkt(), xnb_txpkt2rsp(), and xnb_unit_pvt.

Here is the call graph for this function:

◆ xnb_txpkt2rsp_emptypkt()

static void xnb_txpkt2rsp_emptypkt ( char *  buffer,
size_t  buflen 
)
static

xnb_txpkt2rsp should do nothing for an empty packet

Definition at line 649 of file netback_unit_tests.c.

References xnb_pkt::list_len, XNB_ASSERT, xnb_ring2pkt(), xnb_txpkt2rsp(), and xnb_unit_pvt.

Here is the call graph for this function:

◆ xnb_txpkt2rsp_error()

static void xnb_txpkt2rsp_error ( char *  buffer,
size_t  buflen 
)
static

xnb_txpkt2rsp responding to one request which caused an error

Definition at line 869 of file netback_unit_tests.c.

References XNB_ASSERT, xnb_ring2pkt(), xnb_txpkt2rsp(), and xnb_unit_pvt.

Here is the call graph for this function:

◆ xnb_txpkt2rsp_extra()

static void xnb_txpkt2rsp_extra ( char *  buffer,
size_t  buflen 
)
static

xnb_txpkt2rsp responding to 1 data request and 1 extra info

Definition at line 703 of file netback_unit_tests.c.

References XNB_ASSERT, xnb_ring2pkt(), xnb_txpkt2rsp(), and xnb_unit_pvt.

Here is the call graph for this function:

◆ xnb_txpkt2rsp_invalid()

static void xnb_txpkt2rsp_invalid ( char *  buffer,
size_t  buflen 
)
static

xnb_txpkt2rsp responding to an invalid packet. Note: this test will result in an error message being printed to the console such as: xnb(xnb_ring2pkt:1306): Unknown extra info type 255. Discarding packet

Definition at line 823 of file netback_unit_tests.c.

References XNB_ASSERT, xnb_pkt_is_valid(), xnb_ring2pkt(), xnb_txpkt2rsp(), and xnb_unit_pvt.

Here is the call graph for this function:

◆ xnb_txpkt2rsp_long()

static void xnb_txpkt2rsp_long ( char *  buffer,
size_t  buflen 
)
static

xnb_pkg2rsp responding to 3 data requests and 1 extra info

Definition at line 748 of file netback_unit_tests.c.

References XNB_ASSERT, xnb_ring2pkt(), xnb_txpkt2rsp(), and xnb_unit_pvt.

Here is the call graph for this function:

◆ xnb_txpkt2rsp_wraps()

static void xnb_txpkt2rsp_wraps ( char *  buffer,
size_t  buflen 
)
static

xnb_txpkt2rsp's responses wrap around the end of the ring

Definition at line 901 of file netback_unit_tests.c.

References XNB_ASSERT, xnb_ring2pkt(), xnb_txpkt2rsp(), and xnb_unit_pvt.

Here is the call graph for this function:

◆ xnb_unit_test_main()

static int xnb_unit_test_main ( SYSCTL_HANDLER_ARGS  )
static

Called from userspace by a sysctl. Runs all internal unit tests, and returns the results to userspace as a string

Parameters
oidpunused
arg1pointer to an xnb_softc for a specific xnb device
arg2unused
reqsysctl access structure
Returns
a string via the special SYSCTL_OUT macro.

results is static so that the data will persist after this function returns. The sysctl code expects us to return a constant string.

Todo:
: the static variable is not thread safe. Put a mutex around it.

Definition at line 268 of file netback_unit_tests.c.

References null_setup(), null_teardown(), setup_pvt_data, teardown_pvt_data, TOTAL_BUFLEN, TOTAL_TESTS, xnb_mbufc2pkt_1cluster, xnb_mbufc2pkt_2short, xnb_mbufc2pkt_empty, xnb_mbufc2pkt_extra, xnb_mbufc2pkt_long, xnb_mbufc2pkt_nospace, xnb_mbufc2pkt_short, xnb_pkt2mbufc_1cluster, xnb_pkt2mbufc_2cluster, xnb_pkt2mbufc_csum, xnb_pkt2mbufc_empty, xnb_pkt2mbufc_largecluster, xnb_pkt2mbufc_short, xnb_ring2pkt_1req, xnb_ring2pkt_2req, xnb_ring2pkt_3req, xnb_ring2pkt_emptyring, xnb_ring2pkt_extra, xnb_ring2pkt_partial, xnb_ring2pkt_wraps, xnb_rxpkt2gnttab_2req, xnb_rxpkt2gnttab_empty, xnb_rxpkt2gnttab_short, xnb_rxpkt2rsp_2short, xnb_rxpkt2rsp_2slots, xnb_rxpkt2rsp_copyerror, xnb_rxpkt2rsp_empty, xnb_rxpkt2rsp_extra, xnb_rxpkt2rsp_short, xnb_sscanf_hhd, xnb_sscanf_hhn, xnb_sscanf_hhu, xnb_sscanf_lld, xnb_sscanf_llu, xnb_txpkt2gnttab_2cluster, xnb_txpkt2gnttab_2req, xnb_txpkt2gnttab_empty, xnb_txpkt2gnttab_short, xnb_txpkt2rsp_1req, xnb_txpkt2rsp_emptypkt, xnb_txpkt2rsp_error, xnb_txpkt2rsp_extra, xnb_txpkt2rsp_invalid, xnb_txpkt2rsp_long, xnb_txpkt2rsp_wraps, xnb_unit_test_runner(), xnb_update_mbufc_2cluster, xnb_update_mbufc_2req, and xnb_update_mbufc_short.

Here is the call graph for this function:

◆ xnb_unit_test_runner()

static int xnb_unit_test_runner ( test_fixture_t const  tests[],
int  ntests,
char *  buffer,
size_t  buflen 
)
static

The unit test runner. It will run every supplied test and return an output message as a string

Parameters
testsAn array of tests. Every test will be attempted.
ntestsThe length of tests
bufferReturn storage for the result string
buflenThe length of buffer
Returns
The number of tests that failed

Definition at line 210 of file netback_unit_tests.c.

References test_fixture::setup, SNCATF, test_fixture::teardown, and test_fixture::test.

Referenced by xnb_unit_test_main().

Here is the caller graph for this function:

◆ xnb_update_mbufc_2cluster()

static void xnb_update_mbufc_2cluster ( char *  buffer,
size_t  buflen 
)
static

xnb_update_mbufc on a single request that spans two mbuf clusters

Definition at line 1366 of file netback_unit_tests.c.

References safe_m_freem(), XNB_ASSERT, xnb_pkt2mbufc(), xnb_ring2pkt(), xnb_txpkt2gnttab(), xnb_unit_pvt, and xnb_update_mbufc().

Here is the call graph for this function:

◆ xnb_update_mbufc_2req()

static void xnb_update_mbufc_2req ( char *  buffer,
size_t  buflen 
)
static

xnb_update_mbufc on a packet with two requests, that can fit into a single mbuf cluster

Definition at line 1320 of file netback_unit_tests.c.

References safe_m_freem(), XNB_ASSERT, xnb_pkt2mbufc(), xnb_ring2pkt(), xnb_txpkt2gnttab(), xnb_unit_pvt, and xnb_update_mbufc().

Here is the call graph for this function:

◆ xnb_update_mbufc_short()

static void xnb_update_mbufc_short ( char *  buffer,
size_t  buflen 
)
static

xnb_update_mbufc on a short packet that only has one gnttab entry

Definition at line 1283 of file netback_unit_tests.c.

References safe_m_freem(), XNB_ASSERT, xnb_pkt2mbufc(), xnb_ring2pkt(), xnb_txpkt2gnttab(), xnb_unit_pvt, and xnb_update_mbufc().

Here is the call graph for this function:

Variable Documentation

◆ gnttab

◆ ifp

◆ rxb

netif_rx_back_ring_t rxb

Definition at line 184 of file netback_unit_tests.c.

Referenced by xnb_dump_rings(), xnb_rxpkt2gnttab(), and xnb_start_locked().

◆ rxf

netif_rx_front_ring_t rxf

Definition at line 185 of file netback_unit_tests.c.

◆ rxs

netif_rx_sring_t* rxs

Definition at line 189 of file netback_unit_tests.c.

Referenced by setup_rxqs().

◆ setup_pvt_data

static int setup_pvt_data ( void  )
static

Definition at line 117 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ teardown_pvt_data

static void teardown_pvt_data ( void  )
static

Definition at line 118 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ txb

netif_tx_back_ring_t txb

Definition at line 186 of file netback_unit_tests.c.

Referenced by xnb_dump_rings(), xnb_intr(), xnb_recv(), and xnb_txpkt2gnttab().

◆ txf

netif_tx_front_ring_t txf

Definition at line 187 of file netback_unit_tests.c.

◆ txs

netif_tx_sring_t* txs

Definition at line 190 of file netback_unit_tests.c.

Referenced by setup_txqs().

◆ xnb_mbufc2pkt_1cluster

testcase_t xnb_mbufc2pkt_1cluster
static

Definition at line 148 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_mbufc2pkt_2short

testcase_t xnb_mbufc2pkt_2short
static

Definition at line 149 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_mbufc2pkt_empty

testcase_t xnb_mbufc2pkt_empty
static

Definition at line 146 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_mbufc2pkt_extra

testcase_t xnb_mbufc2pkt_extra
static

Definition at line 151 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_mbufc2pkt_long

testcase_t xnb_mbufc2pkt_long
static

Definition at line 150 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_mbufc2pkt_nospace

testcase_t xnb_mbufc2pkt_nospace
static

Definition at line 152 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_mbufc2pkt_short

testcase_t xnb_mbufc2pkt_short
static

Definition at line 147 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_pkt2mbufc_1cluster

testcase_t xnb_pkt2mbufc_1cluster
static

Definition at line 136 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_pkt2mbufc_2cluster

testcase_t xnb_pkt2mbufc_2cluster
static

Definition at line 138 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_pkt2mbufc_csum

testcase_t xnb_pkt2mbufc_csum
static

Definition at line 135 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_pkt2mbufc_empty

testcase_t xnb_pkt2mbufc_empty
static

Definition at line 133 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_pkt2mbufc_largecluster

testcase_t xnb_pkt2mbufc_largecluster
static

Definition at line 137 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_pkt2mbufc_short

testcase_t xnb_pkt2mbufc_short
static

Definition at line 134 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_ring2pkt_1req

testcase_t xnb_ring2pkt_1req
static

Definition at line 120 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_ring2pkt_2req

testcase_t xnb_ring2pkt_2req
static

Definition at line 121 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_ring2pkt_3req

testcase_t xnb_ring2pkt_3req
static

Definition at line 122 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_ring2pkt_emptyring

testcase_t xnb_ring2pkt_emptyring
static

Definition at line 119 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_ring2pkt_extra

testcase_t xnb_ring2pkt_extra
static

Definition at line 123 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_ring2pkt_partial

testcase_t xnb_ring2pkt_partial
static

Definition at line 124 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_ring2pkt_wraps

testcase_t xnb_ring2pkt_wraps
static

Definition at line 125 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_rxpkt2gnttab_2req

testcase_t xnb_rxpkt2gnttab_2req
static

Definition at line 155 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_rxpkt2gnttab_empty

testcase_t xnb_rxpkt2gnttab_empty
static

Definition at line 153 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_rxpkt2gnttab_short

testcase_t xnb_rxpkt2gnttab_short
static

Definition at line 154 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_rxpkt2rsp_2short

testcase_t xnb_rxpkt2rsp_2short
static

Definition at line 159 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_rxpkt2rsp_2slots

testcase_t xnb_rxpkt2rsp_2slots
static

Definition at line 160 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_rxpkt2rsp_copyerror

testcase_t xnb_rxpkt2rsp_copyerror
static

Definition at line 161 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_rxpkt2rsp_empty

testcase_t xnb_rxpkt2rsp_empty
static

Definition at line 156 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_rxpkt2rsp_extra

testcase_t xnb_rxpkt2rsp_extra
static

Definition at line 158 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_rxpkt2rsp_short

testcase_t xnb_rxpkt2rsp_short
static

Definition at line 157 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_sscanf_hhd

testcase_t xnb_sscanf_hhd
static

Definition at line 165 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_sscanf_hhn

testcase_t xnb_sscanf_hhn
static

Definition at line 166 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_sscanf_hhu

testcase_t xnb_sscanf_hhu
static

Definition at line 164 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_sscanf_lld

testcase_t xnb_sscanf_lld
static

Definition at line 163 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_sscanf_llu

testcase_t xnb_sscanf_llu
static

Definition at line 162 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_txpkt2gnttab_2cluster

testcase_t xnb_txpkt2gnttab_2cluster
static

Definition at line 142 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_txpkt2gnttab_2req

testcase_t xnb_txpkt2gnttab_2req
static

Definition at line 141 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_txpkt2gnttab_empty

testcase_t xnb_txpkt2gnttab_empty
static

Definition at line 139 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_txpkt2gnttab_short

testcase_t xnb_txpkt2gnttab_short
static

Definition at line 140 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_txpkt2rsp_1req

testcase_t xnb_txpkt2rsp_1req
static

Definition at line 127 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_txpkt2rsp_emptypkt

testcase_t xnb_txpkt2rsp_emptypkt
static

Definition at line 126 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_txpkt2rsp_error

testcase_t xnb_txpkt2rsp_error
static

Definition at line 131 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_txpkt2rsp_extra

testcase_t xnb_txpkt2rsp_extra
static

Definition at line 128 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_txpkt2rsp_invalid

testcase_t xnb_txpkt2rsp_invalid
static

Definition at line 130 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_txpkt2rsp_long

testcase_t xnb_txpkt2rsp_long
static

Definition at line 129 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_txpkt2rsp_wraps

testcase_t xnb_txpkt2rsp_wraps
static

Definition at line 132 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ 

◆ xnb_update_mbufc_2cluster

testcase_t xnb_update_mbufc_2cluster
static

Definition at line 145 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_update_mbufc_2req

testcase_t xnb_update_mbufc_2req
static

Definition at line 144 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().

◆ xnb_update_mbufc_short

testcase_t xnb_update_mbufc_short
static

Definition at line 143 of file netback_unit_tests.c.

Referenced by xnb_unit_test_main().