iPXE
Defines | Functions | Variables
iobuf_test.c File Reference

I/O buffer tests. More...

#include <stdint.h>
#include <string.h>
#include <assert.h>
#include <ipxe/iobuf.h>
#include <ipxe/io.h>
#include <ipxe/test.h>

Go to the source code of this file.

Defines

#define alloc_iob_ok(len, align, offset)   alloc_iob_okx ( len, align, offset, __FILE__, __LINE__ )
#define alloc_iob_fail_ok(len, align, offset)   alloc_iob_fail_okx ( len, align, offset, __FILE__, __LINE__ )

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static void alloc_iob_okx (size_t len, size_t align, size_t offset, const char *file, unsigned int line)
 Report I/O buffer allocation test result.
static void alloc_iob_fail_okx (size_t len, size_t align, size_t offset, const char *file, unsigned int line)
 Report I/O buffer allocation failure test result.
static void iobuf_test_exec (void)
 Perform I/O buffer self-tests.

Variables

struct self_test iobuf_test __self_test
 I/O buffer self-test.

Detailed Description

I/O buffer tests.

Definition in file iobuf_test.c.


Define Documentation

#define alloc_iob_ok (   len,
  align,
  offset 
)    alloc_iob_okx ( len, align, offset, __FILE__, __LINE__ )

Definition at line 79 of file iobuf_test.c.

Referenced by iobuf_test_exec().

#define alloc_iob_fail_ok (   len,
  align,
  offset 
)    alloc_iob_fail_okx ( len, align, offset, __FILE__, __LINE__ )

Definition at line 99 of file iobuf_test.c.

Referenced by iobuf_test_exec().


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static void alloc_iob_okx ( size_t  len,
size_t  align,
size_t  offset,
const char *  file,
unsigned int  line 
) [inline, static]

Report I/O buffer allocation test result.

Parameters:
lenRequired length of buffer
alignPhysical alignment
offsetOffset from physical alignment
fileTest code file
lineTest code line

Definition at line 54 of file iobuf_test.c.

References alloc_iob_raw(), io_buffer::data, DBGC, free_iob(), iob_put, iob_tailroom(), memset(), NULL, okx, and virt_to_phys().

                                                                         {
        struct io_buffer *iobuf;

        /* Allocate I/O buffer */
        iobuf = alloc_iob_raw ( len, align, offset );
        okx ( iobuf != NULL, file, line );
        DBGC ( &iobuf_test, "IOBUF %p (%#08lx+%#zx) for %#zx align %#zx "
               "offset %#zx\n", iobuf, virt_to_phys ( iobuf->data ),
               iob_tailroom ( iobuf ), len, align, offset );

        /* Validate requested length and alignment */
        okx ( ( ( ( intptr_t ) iobuf ) & ( __alignof__ ( *iobuf ) - 1 ) ) == 0,
                file, line );
        okx ( iob_tailroom ( iobuf ) >= len, file, line );
        okx ( ( ( align == 0 ) ||
                ( ( virt_to_phys ( iobuf->data ) & ( align - 1 ) ) ==
                  ( offset & ( align - 1 ) ) ) ), file, line );

        /* Overwrite entire content of I/O buffer (for Valgrind) */
        memset ( iob_put ( iobuf, len ), 0x55, len );

        /* Free I/O buffer */
        free_iob ( iobuf );
}
static void alloc_iob_fail_okx ( size_t  len,
size_t  align,
size_t  offset,
const char *  file,
unsigned int  line 
) [inline, static]

Report I/O buffer allocation failure test result.

Parameters:
lenRequired length of buffer
alignPhysical alignment
offsetOffset from physical alignment
fileTest code file
lineTest code line

Definition at line 91 of file iobuf_test.c.

References alloc_iob_raw(), NULL, and okx.

                                                                              {
        struct io_buffer *iobuf;

        /* Allocate I/O buffer */
        iobuf = alloc_iob_raw ( len, align, offset );
        okx ( iobuf == NULL, file, line );
}
static void iobuf_test_exec ( void  ) [static]

Perform I/O buffer self-tests.

Definition at line 106 of file iobuf_test.c.

References alloc_iob_fail_ok, and alloc_iob_ok.

                                     {

        /* Check zero-length allocations */
        alloc_iob_ok ( 0, 0, 0 );
        alloc_iob_ok ( 0, 0, 1 );
        alloc_iob_ok ( 0, 1, 0 );
        alloc_iob_ok ( 0, 1024, 0 );
        alloc_iob_ok ( 0, 139, -17 );

        /* Check various sensible allocations */
        alloc_iob_ok ( 1, 0, 0 );
        alloc_iob_ok ( 16, 16, 0 );
        alloc_iob_ok ( 64, 0, 0 );
        alloc_iob_ok ( 65, 0, 0 );
        alloc_iob_ok ( 65, 1024, 19 );
        alloc_iob_ok ( 1536, 1536, 0 );
        alloc_iob_ok ( 2048, 2048, 0 );
        alloc_iob_ok ( 2048, 2048, -10 );

        /* Excessively large or excessively aligned allocations should fail */
        alloc_iob_fail_ok ( -1UL, 0, 0 );
        alloc_iob_fail_ok ( -1UL, 1024, 0 );
        alloc_iob_fail_ok ( 0, -1UL, 0 );
        alloc_iob_fail_ok ( 1024, -1UL, 0 );
}

Variable Documentation

struct self_test iobuf_test __self_test
Initial value:
 {
        .name = "iobuf",
        .exec = iobuf_test_exec,
}

I/O buffer self-test.

Definition at line 43 of file iobuf_test.c.