diff --git a/src/include/ipxe/errfile.h b/src/include/ipxe/errfile.h index 7c86fdbb..35a0bb7f 100644 --- a/src/include/ipxe/errfile.h +++ b/src/include/ipxe/errfile.h @@ -60,6 +60,7 @@ FILE_LICENCE ( GPL2_OR_LATER ); #define ERRFILE_null_sanboot ( ERRFILE_CORE | 0x00140000 ) #define ERRFILE_edd ( ERRFILE_CORE | 0x00150000 ) #define ERRFILE_parseopt ( ERRFILE_CORE | 0x00160000 ) +#define ERRFILE_test ( ERRFILE_CORE | 0x00170000 ) #define ERRFILE_eisa ( ERRFILE_DRIVER | 0x00000000 ) #define ERRFILE_isa ( ERRFILE_DRIVER | 0x00010000 ) diff --git a/src/tests/test.c b/src/tests/test.c index fa9f5797..b0a24c08 100644 --- a/src/tests/test.c +++ b/src/tests/test.c @@ -29,9 +29,11 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include #include +#include #include #include #include +#include /** Current self-test set */ static struct self_test *current_tests; @@ -100,8 +102,9 @@ static void run_tests ( struct self_test *tests ) { /** * Run all self-tests * + * @ret rc Return status code */ -static void test_init ( void ) { +static int run_all_tests ( void ) { struct self_test *tests; unsigned int failures = 0; unsigned int assertions = 0; @@ -125,15 +128,50 @@ static void test_init ( void ) { printf ( " with %d assertion failures", assertions ); } printf ( "\n" ); + return -EINPROGRESS; } else { printf ( "OK: all %d tests passed\n", total ); + return 0; } +} - /* Lock system */ - while ( 1 ) {} +static int test_image_probe ( struct image *image __unused ) { + return -ENOTTY; +} + +static int test_image_exec ( struct image *image __unused ) { + return run_all_tests(); +} + +static struct image_type test_image_type = { + .name = "self-tests", + .probe = test_image_probe, + .exec = test_image_exec, +}; + +static void test_image_free ( struct refcnt *refcnt __unused ) { + /* Do nothing */ +} + +static struct image test_image = { + .refcnt = REF_INIT ( test_image_free ), + .name = "", + .type = &test_image_type, +}; + +static void test_init ( void ) { + int rc; + + /* Register self-tests image */ + if ( ( rc = register_image ( &test_image ) ) != 0 ) { + DBG ( "Could not register self-test image: %s\n", + strerror ( rc ) ); + /* No way to report failure */ + return; + } } /** Self-test initialisation function */ -struct init_fn test_init_fn __init_fn ( INIT_NORMAL ) = { +struct init_fn test_init_fn __init_fn ( INIT_EARLY ) = { .initialise = test_init, };