]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[test] Allow self-tests to report exit status when running under Linux
authorMichael Brown <mcb30@ipxe.org>
Fri, 21 Aug 2015 14:41:35 +0000 (15:41 +0100)
committerMichael Brown <mcb30@ipxe.org>
Fri, 21 Aug 2015 14:46:28 +0000 (15:46 +0100)
Allow the return status from an embedded image to propagate out to the
eventual return status from main().  When running under Linux, this
allows the pass/fail result of unit tests to be observable without
having to visually inspect the console output.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/core/main.c
src/include/usr/autoboot.h
src/interface/efi/efi_snp.c
src/usr/autoboot.c

index 97394d71d0d86b08ac038f8c2c7e704fc76c4b63..638dea9cf9010f9cdca37d7081ffdc0e7d5a157a 100644 (file)
@@ -26,6 +26,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  * @ret rc             Return status code
  */
 __asmcall int main ( void ) {
+       int rc;
 
        /* Perform one-time-only initialisation (e.g. heap) */
        initialise();
@@ -35,9 +36,11 @@ __asmcall int main ( void ) {
        startup();
        printf ( "ok\n" );
 
-       ipxe ( NULL );
+       /* Attempt to boot */
+       if ( ( rc = ipxe ( NULL ) ) != 0 )
+               goto err_ipxe;
 
+ err_ipxe:
        shutdown_exit();
-
-       return 0;
+       return rc;
 }
index c0603a0a37c6d8850532766445a2afd4b271cffb..4db226b9ce7df68d33795f0b2178d108e80efde0 100644 (file)
@@ -35,7 +35,7 @@ extern int uriboot ( struct uri *filename, struct uri *root_path, int drive,
 extern struct uri *
 fetch_next_server_and_filename ( struct settings *settings );
 extern int netboot ( struct net_device *netdev );
-extern void ipxe ( struct net_device *netdev );
+extern int ipxe ( struct net_device *netdev );
 
 extern int pxe_menu_boot ( struct net_device *netdev );
 
index 1b21c40c4df8f72754424df9ac8c4453b34adaec..3dfcc5e168da7628ee4871f84eee2985697ed042 100644 (file)
@@ -871,6 +871,7 @@ efi_snp_load_file ( EFI_LOAD_FILE_PROTOCOL *load_file,
        struct efi_snp_device *snpdev =
                container_of ( load_file, struct efi_snp_device, load_file );
        struct net_device *netdev = snpdev->netdev;
+       int rc;
 
        /* Fail unless this is a boot attempt */
        if ( ! booting ) {
@@ -886,16 +887,13 @@ efi_snp_load_file ( EFI_LOAD_FILE_PROTOCOL *load_file,
        efi_watchdog_start();
 
        /* Boot from network device */
-       ipxe ( netdev );
+       if ( ( rc = ipxe ( netdev ) ) != 0 )
+               goto err_ipxe;
 
-       /* Stop watchdog holdoff timer */
+ err_ipxe:
        efi_watchdog_stop();
-
-       /* Release network devices for use via SNP */
        efi_snp_release();
-
-       /* Assume boot process was aborted */
-       return EFI_ABORTED;
+       return EFIRC ( rc );
 }
 
 /** Load file protocol */
index ccafeae7c744a4969664acc6a8d38b66e13d6789..6dbe25ca492880347de99c3b91a0270993af914a 100644 (file)
@@ -542,11 +542,13 @@ static int shell_banner ( void ) {
  * Main iPXE flow of execution
  *
  * @v netdev           Network device, or NULL
+ * @ret rc             Return status code
  */
-void ipxe ( struct net_device *netdev ) {
+int ipxe ( struct net_device *netdev ) {
        struct feature *feature;
        struct image *image;
        char *scriptlet;
+       int rc;
 
        /*
         * Print welcome banner
@@ -570,28 +572,30 @@ void ipxe ( struct net_device *netdev ) {
        /* Boot system */
        if ( ( image = first_image() ) != NULL ) {
                /* We have an embedded image; execute it */
-               image_exec ( image );
+               return image_exec ( image );
        } else if ( shell_banner() ) {
                /* User wants shell; just give them a shell */
-               shell();
+               return shell();
        } else {
                fetch_string_setting_copy ( NULL, &scriptlet_setting,
                                            &scriptlet );
                if ( scriptlet ) {
                        /* User has defined a scriptlet; execute it */
-                       system ( scriptlet );
+                       rc = system ( scriptlet );
                        free ( scriptlet );
+                       return rc;
                } else {
                        /* Try booting.  If booting fails, offer the
                         * user another chance to enter the shell.
                         */
                        if ( netdev ) {
-                               netboot ( netdev );
+                               rc = netboot ( netdev );
                        } else {
-                               autoboot();
+                               rc = autoboot();
                        }
                        if ( shell_banner() )
-                               shell();
+                               rc = shell();
+                       return rc;
                }
        }
 }