iPXE
Data Structures | Macros | Functions
test.h File Reference

Self-test infrastructure. More...

#include <ipxe/tables.h>

Go to the source code of this file.

Data Structures

struct  self_test
 A self-test set. More...
 

Macros

#define SELF_TESTS   __table ( struct self_test, "self_tests" )
 Self-test table. More...
 
#define __self_test   __table_entry ( SELF_TESTS, 01 )
 Declare a self-test. More...
 
#define okx(success, file, line)   test_ok ( success, file, line, #success )
 Report test result. More...
 
#define ok(success)   okx ( success, __FILE__, __LINE__ )
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
void test_ok (int success, const char *file, unsigned int line, const char *test)
 Report test result. More...
 

Detailed Description

Self-test infrastructure.

Definition in file test.h.

Macro Definition Documentation

◆ SELF_TESTS

#define SELF_TESTS   __table ( struct self_test, "self_tests" )

Self-test table.

Definition at line 29 of file test.h.

◆ __self_test

struct self_test iobuf_test __self_test   __table_entry ( SELF_TESTS, 01 )

Declare a self-test.

I/O buffer self-test.

Definition at line 32 of file test.h.

◆ okx

#define okx (   success,
  file,
  line 
)    test_ok ( success, file, line, #success )

Report test result.

Parameters
successTest succeeded
fileFile name
lineLine number

Definition at line 44 of file test.h.

◆ ok

#define ok (   success)    okx ( success, __FILE__, __LINE__ )

Definition at line 46 of file test.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ test_ok()

void test_ok ( int  success,
const char *  file,
unsigned int  line,
const char *  test 
)

Report test result.

Parameters
successTest succeeded
fileTest code file
lineTest code line
testTest code

Definition at line 55 of file test.c.

56  {
57 
58  /* Sanity check */
59  assert ( current_tests != NULL );
60 
61  /* Increment test counter */
63 
64  /* Report failure if applicable */
65  if ( ! success ) {
67  printf ( "FAILURE: \"%s\" test failed at %s line %d: ( %s )\n",
68  current_tests->name, file, line, test );
69  }
70 }
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
unsigned int failures
Number of test failures.
Definition: test.h:23
unsigned int total
Number of tests run.
Definition: test.h:21
const char * name
Test set name.
Definition: test.h:17
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static struct self_test * current_tests
Current self-test set.
Definition: test.c:45
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
static int test
Definition: epic100.c:73

References assert(), current_tests, self_test::failures, self_test::name, NULL, printf(), test, and self_test::total.