Parcourir la 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 il y a 9 ans
Parent
révision
f58ebbdfb5
4 fichiers modifiés avec 23 ajouts et 18 suppressions
  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 Voir le fichier

@@ -26,6 +26,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
26 26
  * @ret rc		Return status code
27 27
  */
28 28
 __asmcall int main ( void ) {
29
+	int rc;
29 30
 
30 31
 	/* Perform one-time-only initialisation (e.g. heap) */
31 32
 	initialise();
@@ -35,9 +36,11 @@ __asmcall int main ( void ) {
35 36
 	startup();
36 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 44
 	shutdown_exit();
41
-
42
-	return 0;
45
+	return rc;
43 46
 }

+ 1
- 1
src/include/usr/autoboot.h Voir le fichier

@@ -35,7 +35,7 @@ extern int uriboot ( struct uri *filename, struct uri *root_path, int drive,
35 35
 extern struct uri *
36 36
 fetch_next_server_and_filename ( struct settings *settings );
37 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 40
 extern int pxe_menu_boot ( struct net_device *netdev );
41 41
 

+ 5
- 7
src/interface/efi/efi_snp.c Voir le fichier

@@ -871,6 +871,7 @@ efi_snp_load_file ( EFI_LOAD_FILE_PROTOCOL *load_file,
871 871
 	struct efi_snp_device *snpdev =
872 872
 		container_of ( load_file, struct efi_snp_device, load_file );
873 873
 	struct net_device *netdev = snpdev->netdev;
874
+	int rc;
874 875
 
875 876
 	/* Fail unless this is a boot attempt */
876 877
 	if ( ! booting ) {
@@ -886,16 +887,13 @@ efi_snp_load_file ( EFI_LOAD_FILE_PROTOCOL *load_file,
886 887
 	efi_watchdog_start();
887 888
 
888 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 894
 	efi_watchdog_stop();
893
-
894
-	/* Release network devices for use via SNP */
895 895
 	efi_snp_release();
896
-
897
-	/* Assume boot process was aborted */
898
-	return EFI_ABORTED;
896
+	return EFIRC ( rc );
899 897
 }
900 898
 
901 899
 /** Load file protocol */

+ 11
- 7
src/usr/autoboot.c Voir le fichier

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

Chargement…
Annuler
Enregistrer