[2/3] uefirtvariable: add checking the EFI_UNSUPPORTED return code
diff mbox series

Message ID 1560248337-10100-2-git-send-email-ivan.hu@canonical.com
State Superseded
Headers show
Series
  • [1/3] uefitime: add checking the EFI_UNSUPPORTED return code
Related show

Commit Message

Ivan June 11, 2019, 10:18 a.m. UTC
The UEFI spec 2.8(Matis 1961) adds EFI_UNSUPPORTED as a return code to most
UEFI runtime services for those embeded devices such as specified by the
ARM EBBR specification which are impractical or impossible to implement
in such a way that they can be used at runtime.

Add checking the EFI_UNSUPPORTED return code and skip the test for those
unsupported runtime services.

Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
---
 src/uefi/uefirtvariable/uefirtvariable.c | 86 ++++++++++++++++++++++++++++++--
 1 file changed, 83 insertions(+), 3 deletions(-)

Comments

Colin King June 11, 2019, 10:29 a.m. UTC | #1
On 11/06/2019 11:18, Ivan Hu wrote:
> The UEFI spec 2.8(Matis 1961) adds EFI_UNSUPPORTED as a return code to most
> UEFI runtime services for those embeded devices such as specified by the
> ARM EBBR specification which are impractical or impossible to implement
> in such a way that they can be used at runtime.
> 
> Add checking the EFI_UNSUPPORTED return code and skip the test for those
> unsupported runtime services.
> 
> Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
> ---
>  src/uefi/uefirtvariable/uefirtvariable.c | 86 ++++++++++++++++++++++++++++++--
>  1 file changed, 83 insertions(+), 3 deletions(-)
> 
> diff --git a/src/uefi/uefirtvariable/uefirtvariable.c b/src/uefi/uefirtvariable/uefirtvariable.c
> index 6aa44d3..9dffcab 100644
> --- a/src/uefi/uefirtvariable/uefirtvariable.c
> +++ b/src/uefi/uefirtvariable/uefirtvariable.c
> @@ -156,6 +156,11 @@ static int getvariable_test(
>  	ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
>  
>  	if (ioret == -1) {
> +		if (status == EFI_UNSUPPORTED) {
> +			fwts_skipped(fw, "Skipping test, SetVariable runtime "
> +				"service is not supported on this platform.");
> +			return FWTS_SKIP;
> +		}
>  		if (status == EFI_OUT_OF_RESOURCES) {
>  			fwts_uefi_print_status_info(fw, status);
>  			fwts_skipped(fw,
> @@ -231,6 +236,11 @@ static int getvariable_test(
>  	ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
>  
>  	if (ioret == -1) {
> +		if (status == EFI_UNSUPPORTED) {
> +			fwts_skipped(fw, "Skipping test, SetVariable runtime "
> +				"service is not supported on this platform.");
> +			return FWTS_SKIP;
> +		}
>  		fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetVariable",
>  			"Failed to delete variable with UEFI runtime service.");
>  		fwts_uefi_print_status_info(fw, status);
> @@ -247,6 +257,11 @@ err_restore_env:
>  	ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
>  
>  	if (ioret == -1) {
> +		if (status == EFI_UNSUPPORTED) {
> +			fwts_skipped(fw, "Skipping test, SetVariable runtime "
> +				"service is not supported on this platform.");
> +			return FWTS_SKIP;
> +		}
>  		fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetVariable",
>  			"Failed to delete variable with UEFI runtime service.");
>  		fwts_uefi_print_status_info(fw, status);
> @@ -323,6 +338,11 @@ static int getnextvariable_test1(fwts_framework *fw)
>  	ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
>  
>  	if (ioret == -1) {
> +		if (status == EFI_UNSUPPORTED) {
> +			fwts_skipped(fw, "Skipping test, SetVariable runtime "
> +				"service is not supported on this platform.");
> +			return FWTS_SKIP;
> +		}
>  		if (status == EFI_OUT_OF_RESOURCES) {
>  			fwts_uefi_print_status_info(fw, status);
>  			fwts_skipped(fw,
> @@ -362,7 +382,11 @@ static int getnextvariable_test1(fwts_framework *fw)
>  		ioret = ioctl(fd, EFI_RUNTIME_GET_NEXTVARIABLENAME, &getnextvariablename);
>  
>  		if (ioret == -1) {
> -
> +			if (status == EFI_UNSUPPORTED) {
> +				fwts_skipped(fw, "Skipping test, GetNextVariable runtime "
> +					"service is not supported on this platform.");
> +				return FWTS_SKIP;
> +			}
>  			/* no next variable was found*/
>  			if (*getnextvariablename.status == EFI_NOT_FOUND)
>  				break;
> @@ -429,6 +453,11 @@ static int getnextvariable_test1(fwts_framework *fw)
>  	ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
>  
>  	if (ioret == -1) {
> +		if (status == EFI_UNSUPPORTED) {
> +			fwts_skipped(fw, "Skipping test, SetVariable runtime "
> +				"service is not supported on this platform.");
> +			return FWTS_SKIP;
> +		}
>  		fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetVariable",
>  			"Failed to delete variable with UEFI runtime service.");
>  		fwts_uefi_print_status_info(fw, status);
> @@ -445,6 +474,11 @@ err_restore_env:
>  	ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
>  
>  	if (ioret == -1) {
> +		if (status == EFI_UNSUPPORTED) {
> +			fwts_skipped(fw, "Skipping test, SetVariable runtime "
> +				"service is not supported on this platform.");
> +			return FWTS_SKIP;
> +		}
>  		fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetVariable",
>  			"Failed to delete variable with UEFI runtime service.");
>  		fwts_uefi_print_status_info(fw, status);
> @@ -512,7 +546,11 @@ static int getnextvariable_test2(fwts_framework *fw)
>  		ioret = ioctl(fd, EFI_RUNTIME_GET_NEXTVARIABLENAME, &getnextvariablename);
>  
>  		if (ioret == -1) {
> -
> +			if (status == EFI_UNSUPPORTED) {
> +				fwts_skipped(fw, "Skipping test, SetVariable runtime "
> +					"service is not supported on this platform.");
> +				return FWTS_SKIP;
> +			}
>  			/* no next variable was found*/
>  			if (*getnextvariablename.status == EFI_NOT_FOUND)
>  				break;
> @@ -673,7 +711,11 @@ static int getnextvariable_test3(fwts_framework *fw)
>  		ioret = ioctl(fd, EFI_RUNTIME_GET_NEXTVARIABLENAME, &getnextvariablename);
>  
>  		if (ioret == -1) {
> -
> +			if (status == EFI_UNSUPPORTED) {
> +				fwts_skipped(fw, "Skipping test, SetVariable runtime "
> +					"service is not supported on this platform.");
> +				return FWTS_SKIP;
> +			}
>  			/* no next variable was found*/
>  			if (*getnextvariablename.status == EFI_NOT_FOUND)
>  				break;
> @@ -789,6 +831,12 @@ static int getnextvariable_test4(fwts_framework *fw)
>  
>  	ioret = ioctl(fd, EFI_RUNTIME_GET_NEXTVARIABLENAME, &getnextvariablename);
>  
> +	if (status == EFI_UNSUPPORTED) {
> +		fwts_skipped(fw, "Skipping test, GetNextVaiable runtime "
> +			"service is not supported on this platform.");
> +		return FWTS_SKIP;
> +	}
> +
>  	if (ioret != -1 || status != EFI_INVALID_PARAMETER) {
>  		fwts_failed(fw, LOG_LEVEL_HIGH,
>  			"UEFIRuntimeGetNextVariableName",
> @@ -898,6 +946,12 @@ static int setvariable_insertvariable(
>  	setvariable.status = &status;
>  	ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
>  
> +	if (status == EFI_UNSUPPORTED) {
> +		fwts_skipped(fw, "Skipping test, SetVariable runtime "
> +			"service is not supported on this platform.");
> +		return FWTS_SKIP;
> +	}
> +
>  	if (ioret == -1) {
>  		if ((status == EFI_INVALID_PARAMETER) &&
>  			((attributes & FWTS_UEFI_VARIABLE_ENHANCED_AUTHENTICATED_ACCESS) ||
> @@ -966,6 +1020,11 @@ static int setvariable_checkvariable(
>  
>  	ioret = ioctl(fd, EFI_RUNTIME_GET_VARIABLE, &getvariable);
>  	if (ioret == -1) {
> +		if (status == EFI_UNSUPPORTED) {
> +			fwts_skipped(fw, "Skipping test, GetVariable runtime "
> +				"service is not supported on this platform.");
> +			return FWTS_SKIP;
> +		}
>  		fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetVariable",
>  			"Failed to get variable with UEFI runtime service.");
>  		fwts_uefi_print_status_info(fw, status);
> @@ -1021,6 +1080,11 @@ static int setvariable_checkvariable_notfound(
>  
>  	ioret = ioctl(fd, EFI_RUNTIME_GET_VARIABLE, &getvariable);
>  
> +	if (status == EFI_UNSUPPORTED) {
> +		fwts_skipped(fw, "Skipping test, GetVariable runtime "
> +			"service is not supported on this platform.");
> +		return FWTS_SKIP;
> +	}

Other EFI_UNSUPPORTED checks are performed when ioret == -1, so why is
this one like this? What is different here?

>  	/* expect the uefi runtime interface return EFI_NOT_FOUND */
>  	if (ioret == -1) {
>  		if (*getvariable.status == EFI_NOT_FOUND)
> @@ -1059,6 +1123,12 @@ static int setvariable_invalidattr(
>  
>  	ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
>  
> +	if (status == EFI_UNSUPPORTED) {
> +		fwts_skipped(fw, "Skipping test, SetVariable runtime "
> +			"service is not supported on this platform.");
> +		return FWTS_SKIP;
> +	}
> +

Same question as above.

>  	if ((status == EFI_SUCCESS) && (ioret != -1)) {
>  		if ((attributes & FWTS_UEFI_VARIABLE_ENHANCED_AUTHENTICATED_ACCESS) &&
>  			(attributes & FWTS_UEFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) &&
> @@ -1838,6 +1908,11 @@ static void getvariable_test_invalid(
>  	*(getvariable->status) = ~0ULL;
>  
>  	ioret = ioctl(fd, EFI_RUNTIME_GET_VARIABLE, getvariable);
> +	if (*(getvariable->status) == EFI_UNSUPPORTED) {
> +		fwts_skipped(fw, "Skipping test, GetVariable runtime "
> +			"service is not supported on this platform.");
> +		return;
> +	}
>  	if (ioret == -1) {
>  		if (*(getvariable->status) == EFI_INVALID_PARAMETER) {
>  			fwts_passed(fw, "GetVariable with %s returned error "
> @@ -1882,6 +1957,11 @@ static int uefirtvariable_test8(fwts_framework *fw)
>  	setvariable.status = &status;
>  
>  	ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
> +	if (status == EFI_UNSUPPORTED) {
> +		fwts_skipped(fw, "Skipping test, SetVariable runtime "
> +			"service is not supported on this platform.");
> +		return FWTS_OK;
> +	}

And here too.

>  	if (ioret == -1) {
>  		if (status == EFI_OUT_OF_RESOURCES) {
>  			fwts_uefi_print_status_info(fw, status);
>

Patch
diff mbox series

diff --git a/src/uefi/uefirtvariable/uefirtvariable.c b/src/uefi/uefirtvariable/uefirtvariable.c
index 6aa44d3..9dffcab 100644
--- a/src/uefi/uefirtvariable/uefirtvariable.c
+++ b/src/uefi/uefirtvariable/uefirtvariable.c
@@ -156,6 +156,11 @@  static int getvariable_test(
 	ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
 
 	if (ioret == -1) {
+		if (status == EFI_UNSUPPORTED) {
+			fwts_skipped(fw, "Skipping test, SetVariable runtime "
+				"service is not supported on this platform.");
+			return FWTS_SKIP;
+		}
 		if (status == EFI_OUT_OF_RESOURCES) {
 			fwts_uefi_print_status_info(fw, status);
 			fwts_skipped(fw,
@@ -231,6 +236,11 @@  static int getvariable_test(
 	ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
 
 	if (ioret == -1) {
+		if (status == EFI_UNSUPPORTED) {
+			fwts_skipped(fw, "Skipping test, SetVariable runtime "
+				"service is not supported on this platform.");
+			return FWTS_SKIP;
+		}
 		fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetVariable",
 			"Failed to delete variable with UEFI runtime service.");
 		fwts_uefi_print_status_info(fw, status);
@@ -247,6 +257,11 @@  err_restore_env:
 	ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
 
 	if (ioret == -1) {
+		if (status == EFI_UNSUPPORTED) {
+			fwts_skipped(fw, "Skipping test, SetVariable runtime "
+				"service is not supported on this platform.");
+			return FWTS_SKIP;
+		}
 		fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetVariable",
 			"Failed to delete variable with UEFI runtime service.");
 		fwts_uefi_print_status_info(fw, status);
@@ -323,6 +338,11 @@  static int getnextvariable_test1(fwts_framework *fw)
 	ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
 
 	if (ioret == -1) {
+		if (status == EFI_UNSUPPORTED) {
+			fwts_skipped(fw, "Skipping test, SetVariable runtime "
+				"service is not supported on this platform.");
+			return FWTS_SKIP;
+		}
 		if (status == EFI_OUT_OF_RESOURCES) {
 			fwts_uefi_print_status_info(fw, status);
 			fwts_skipped(fw,
@@ -362,7 +382,11 @@  static int getnextvariable_test1(fwts_framework *fw)
 		ioret = ioctl(fd, EFI_RUNTIME_GET_NEXTVARIABLENAME, &getnextvariablename);
 
 		if (ioret == -1) {
-
+			if (status == EFI_UNSUPPORTED) {
+				fwts_skipped(fw, "Skipping test, GetNextVariable runtime "
+					"service is not supported on this platform.");
+				return FWTS_SKIP;
+			}
 			/* no next variable was found*/
 			if (*getnextvariablename.status == EFI_NOT_FOUND)
 				break;
@@ -429,6 +453,11 @@  static int getnextvariable_test1(fwts_framework *fw)
 	ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
 
 	if (ioret == -1) {
+		if (status == EFI_UNSUPPORTED) {
+			fwts_skipped(fw, "Skipping test, SetVariable runtime "
+				"service is not supported on this platform.");
+			return FWTS_SKIP;
+		}
 		fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetVariable",
 			"Failed to delete variable with UEFI runtime service.");
 		fwts_uefi_print_status_info(fw, status);
@@ -445,6 +474,11 @@  err_restore_env:
 	ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
 
 	if (ioret == -1) {
+		if (status == EFI_UNSUPPORTED) {
+			fwts_skipped(fw, "Skipping test, SetVariable runtime "
+				"service is not supported on this platform.");
+			return FWTS_SKIP;
+		}
 		fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetVariable",
 			"Failed to delete variable with UEFI runtime service.");
 		fwts_uefi_print_status_info(fw, status);
@@ -512,7 +546,11 @@  static int getnextvariable_test2(fwts_framework *fw)
 		ioret = ioctl(fd, EFI_RUNTIME_GET_NEXTVARIABLENAME, &getnextvariablename);
 
 		if (ioret == -1) {
-
+			if (status == EFI_UNSUPPORTED) {
+				fwts_skipped(fw, "Skipping test, SetVariable runtime "
+					"service is not supported on this platform.");
+				return FWTS_SKIP;
+			}
 			/* no next variable was found*/
 			if (*getnextvariablename.status == EFI_NOT_FOUND)
 				break;
@@ -673,7 +711,11 @@  static int getnextvariable_test3(fwts_framework *fw)
 		ioret = ioctl(fd, EFI_RUNTIME_GET_NEXTVARIABLENAME, &getnextvariablename);
 
 		if (ioret == -1) {
-
+			if (status == EFI_UNSUPPORTED) {
+				fwts_skipped(fw, "Skipping test, SetVariable runtime "
+					"service is not supported on this platform.");
+				return FWTS_SKIP;
+			}
 			/* no next variable was found*/
 			if (*getnextvariablename.status == EFI_NOT_FOUND)
 				break;
@@ -789,6 +831,12 @@  static int getnextvariable_test4(fwts_framework *fw)
 
 	ioret = ioctl(fd, EFI_RUNTIME_GET_NEXTVARIABLENAME, &getnextvariablename);
 
+	if (status == EFI_UNSUPPORTED) {
+		fwts_skipped(fw, "Skipping test, GetNextVaiable runtime "
+			"service is not supported on this platform.");
+		return FWTS_SKIP;
+	}
+
 	if (ioret != -1 || status != EFI_INVALID_PARAMETER) {
 		fwts_failed(fw, LOG_LEVEL_HIGH,
 			"UEFIRuntimeGetNextVariableName",
@@ -898,6 +946,12 @@  static int setvariable_insertvariable(
 	setvariable.status = &status;
 	ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
 
+	if (status == EFI_UNSUPPORTED) {
+		fwts_skipped(fw, "Skipping test, SetVariable runtime "
+			"service is not supported on this platform.");
+		return FWTS_SKIP;
+	}
+
 	if (ioret == -1) {
 		if ((status == EFI_INVALID_PARAMETER) &&
 			((attributes & FWTS_UEFI_VARIABLE_ENHANCED_AUTHENTICATED_ACCESS) ||
@@ -966,6 +1020,11 @@  static int setvariable_checkvariable(
 
 	ioret = ioctl(fd, EFI_RUNTIME_GET_VARIABLE, &getvariable);
 	if (ioret == -1) {
+		if (status == EFI_UNSUPPORTED) {
+			fwts_skipped(fw, "Skipping test, GetVariable runtime "
+				"service is not supported on this platform.");
+			return FWTS_SKIP;
+		}
 		fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetVariable",
 			"Failed to get variable with UEFI runtime service.");
 		fwts_uefi_print_status_info(fw, status);
@@ -1021,6 +1080,11 @@  static int setvariable_checkvariable_notfound(
 
 	ioret = ioctl(fd, EFI_RUNTIME_GET_VARIABLE, &getvariable);
 
+	if (status == EFI_UNSUPPORTED) {
+		fwts_skipped(fw, "Skipping test, GetVariable runtime "
+			"service is not supported on this platform.");
+		return FWTS_SKIP;
+	}
 	/* expect the uefi runtime interface return EFI_NOT_FOUND */
 	if (ioret == -1) {
 		if (*getvariable.status == EFI_NOT_FOUND)
@@ -1059,6 +1123,12 @@  static int setvariable_invalidattr(
 
 	ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
 
+	if (status == EFI_UNSUPPORTED) {
+		fwts_skipped(fw, "Skipping test, SetVariable runtime "
+			"service is not supported on this platform.");
+		return FWTS_SKIP;
+	}
+
 	if ((status == EFI_SUCCESS) && (ioret != -1)) {
 		if ((attributes & FWTS_UEFI_VARIABLE_ENHANCED_AUTHENTICATED_ACCESS) &&
 			(attributes & FWTS_UEFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) &&
@@ -1838,6 +1908,11 @@  static void getvariable_test_invalid(
 	*(getvariable->status) = ~0ULL;
 
 	ioret = ioctl(fd, EFI_RUNTIME_GET_VARIABLE, getvariable);
+	if (*(getvariable->status) == EFI_UNSUPPORTED) {
+		fwts_skipped(fw, "Skipping test, GetVariable runtime "
+			"service is not supported on this platform.");
+		return;
+	}
 	if (ioret == -1) {
 		if (*(getvariable->status) == EFI_INVALID_PARAMETER) {
 			fwts_passed(fw, "GetVariable with %s returned error "
@@ -1882,6 +1957,11 @@  static int uefirtvariable_test8(fwts_framework *fw)
 	setvariable.status = &status;
 
 	ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
+	if (status == EFI_UNSUPPORTED) {
+		fwts_skipped(fw, "Skipping test, SetVariable runtime "
+			"service is not supported on this platform.");
+		return FWTS_OK;
+	}
 	if (ioret == -1) {
 		if (status == EFI_OUT_OF_RESOURCES) {
 			fwts_uefi_print_status_info(fw, status);