]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[test] Run self-tests as an embedded image
authorMichael Brown <mcb30@ipxe.org>
Sun, 18 Mar 2012 02:42:00 +0000 (02:42 +0000)
committerMichael Brown <mcb30@ipxe.org>
Sun, 18 Mar 2012 13:13:50 +0000 (13:13 +0000)
Allow iPXE to exit after running self-tests, rather than locking the
machine.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/include/ipxe/errfile.h
src/tests/test.c

index 7c86fdbb7c2baef3e465e4169580c1f0faf869a3..35a0bb7f01b16e994674bbb2fc517daad05d3b33 100644 (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 )
index fa9f579713fbaa0353b18377afdb5a57bb0d79ae..b0a24c084d842d608818b300a972520154d3c37b 100644 (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;
        }
+}
+
+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 */
+}
 
-       /* Lock system */
-       while ( 1 ) {}
+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,
 };