david/ipxe
david
/
ipxe
Archived
1
0
Fork 0

[test] Run self-tests as an embedded image

Allow iPXE to exit after running self-tests, rather than locking the
machine.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown 2012-03-18 02:42:00 +00:00
parent b0a1ad9242
commit da76a489d6
2 changed files with 43 additions and 4 deletions

View File

@ -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 )

View File

@ -29,9 +29,11 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <stddef.h>
#include <stdio.h>
#include <errno.h>
#include <assert.h>
#include <ipxe/test.h>
#include <ipxe/init.h>
#include <ipxe/image.h>
/** 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 = "<TESTS>",
.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,
};