Browse Source

[test] Allow self-tests to report exit status when running under Linux

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>
tags/v1.20.1
Michael Brown 9 years ago
parent
commit
f58ebbdfb5
4 changed files with 23 additions and 18 deletions
  1. 6
    3
      src/core/main.c
  2. 1
    1
      src/include/usr/autoboot.h
  3. 5
    7
      src/interface/efi/efi_snp.c
  4. 11
    7
      src/usr/autoboot.c

+ 6
- 3
src/core/main.c View File

26
  * @ret rc		Return status code
26
  * @ret rc		Return status code
27
  */
27
  */
28
 __asmcall int main ( void ) {
28
 __asmcall int main ( void ) {
29
+	int rc;
29
 
30
 
30
 	/* Perform one-time-only initialisation (e.g. heap) */
31
 	/* Perform one-time-only initialisation (e.g. heap) */
31
 	initialise();
32
 	initialise();
35
 	startup();
36
 	startup();
36
 	printf ( "ok\n" );
37
 	printf ( "ok\n" );
37
 
38
 
38
-	ipxe ( NULL );
39
+	/* Attempt to boot */
40
+	if ( ( rc = ipxe ( NULL ) ) != 0 )
41
+		goto err_ipxe;
39
 
42
 
43
+ err_ipxe:
40
 	shutdown_exit();
44
 	shutdown_exit();
41
-
42
-	return 0;
45
+	return rc;
43
 }
46
 }

+ 1
- 1
src/include/usr/autoboot.h View File

35
 extern struct uri *
35
 extern struct uri *
36
 fetch_next_server_and_filename ( struct settings *settings );
36
 fetch_next_server_and_filename ( struct settings *settings );
37
 extern int netboot ( struct net_device *netdev );
37
 extern int netboot ( struct net_device *netdev );
38
-extern void ipxe ( struct net_device *netdev );
38
+extern int ipxe ( struct net_device *netdev );
39
 
39
 
40
 extern int pxe_menu_boot ( struct net_device *netdev );
40
 extern int pxe_menu_boot ( struct net_device *netdev );
41
 
41
 

+ 5
- 7
src/interface/efi/efi_snp.c View File

871
 	struct efi_snp_device *snpdev =
871
 	struct efi_snp_device *snpdev =
872
 		container_of ( load_file, struct efi_snp_device, load_file );
872
 		container_of ( load_file, struct efi_snp_device, load_file );
873
 	struct net_device *netdev = snpdev->netdev;
873
 	struct net_device *netdev = snpdev->netdev;
874
+	int rc;
874
 
875
 
875
 	/* Fail unless this is a boot attempt */
876
 	/* Fail unless this is a boot attempt */
876
 	if ( ! booting ) {
877
 	if ( ! booting ) {
886
 	efi_watchdog_start();
887
 	efi_watchdog_start();
887
 
888
 
888
 	/* Boot from network device */
889
 	/* Boot from network device */
889
-	ipxe ( netdev );
890
+	if ( ( rc = ipxe ( netdev ) ) != 0 )
891
+		goto err_ipxe;
890
 
892
 
891
-	/* Stop watchdog holdoff timer */
893
+ err_ipxe:
892
 	efi_watchdog_stop();
894
 	efi_watchdog_stop();
893
-
894
-	/* Release network devices for use via SNP */
895
 	efi_snp_release();
895
 	efi_snp_release();
896
-
897
-	/* Assume boot process was aborted */
898
-	return EFI_ABORTED;
896
+	return EFIRC ( rc );
899
 }
897
 }
900
 
898
 
901
 /** Load file protocol */
899
 /** Load file protocol */

+ 11
- 7
src/usr/autoboot.c View File

542
  * Main iPXE flow of execution
542
  * Main iPXE flow of execution
543
  *
543
  *
544
  * @v netdev		Network device, or NULL
544
  * @v netdev		Network device, or NULL
545
+ * @ret rc		Return status code
545
  */
546
  */
546
-void ipxe ( struct net_device *netdev ) {
547
+int ipxe ( struct net_device *netdev ) {
547
 	struct feature *feature;
548
 	struct feature *feature;
548
 	struct image *image;
549
 	struct image *image;
549
 	char *scriptlet;
550
 	char *scriptlet;
551
+	int rc;
550
 
552
 
551
 	/*
553
 	/*
552
 	 * Print welcome banner
554
 	 * Print welcome banner
570
 	/* Boot system */
572
 	/* Boot system */
571
 	if ( ( image = first_image() ) != NULL ) {
573
 	if ( ( image = first_image() ) != NULL ) {
572
 		/* We have an embedded image; execute it */
574
 		/* We have an embedded image; execute it */
573
-		image_exec ( image );
575
+		return image_exec ( image );
574
 	} else if ( shell_banner() ) {
576
 	} else if ( shell_banner() ) {
575
 		/* User wants shell; just give them a shell */
577
 		/* User wants shell; just give them a shell */
576
-		shell();
578
+		return shell();
577
 	} else {
579
 	} else {
578
 		fetch_string_setting_copy ( NULL, &scriptlet_setting,
580
 		fetch_string_setting_copy ( NULL, &scriptlet_setting,
579
 					    &scriptlet );
581
 					    &scriptlet );
580
 		if ( scriptlet ) {
582
 		if ( scriptlet ) {
581
 			/* User has defined a scriptlet; execute it */
583
 			/* User has defined a scriptlet; execute it */
582
-			system ( scriptlet );
584
+			rc = system ( scriptlet );
583
 			free ( scriptlet );
585
 			free ( scriptlet );
586
+			return rc;
584
 		} else {
587
 		} else {
585
 			/* Try booting.  If booting fails, offer the
588
 			/* Try booting.  If booting fails, offer the
586
 			 * user another chance to enter the shell.
589
 			 * user another chance to enter the shell.
587
 			 */
590
 			 */
588
 			if ( netdev ) {
591
 			if ( netdev ) {
589
-				netboot ( netdev );
592
+				rc = netboot ( netdev );
590
 			} else {
593
 			} else {
591
-				autoboot();
594
+				rc = autoboot();
592
 			}
595
 			}
593
 			if ( shell_banner() )
596
 			if ( shell_banner() )
594
-				shell();
597
+				rc = shell();
598
+			return rc;
595
 		}
599
 		}
596
 	}
600
 	}
597
 }
601
 }

Loading…
Cancel
Save