diff mbox series

[5/5] uefirtmisc: add unsupported checking with RuntimeServicesSupported variable

Message ID 20191106094516.15762-6-ivan.hu@canonical.com
State Superseded
Headers show
Series Add tests for runtime services unsupported check | expand

Commit Message

Ivan Hu Nov. 6, 2019, 9:45 a.m. UTC
UEFI spec 2.8 introduced the variable RuntimeServicesSupported, which is
Bitmask of which calls are implemented by the firmware during runtime services.
Add tests for checking GetNextHighMonotonicCount services with
RuntimeServicesSupported variable. Currently, won't test with
QueryCapsuleCapabilities becasue QueryCapsuleCapabilities may return
unsupported due to the update flag of firmware behavior unsupported, not
runtime service unsupported.

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

Comments

Colin Ian King Nov. 6, 2019, 10:38 a.m. UTC | #1
On 06/11/2019 09:45, Ivan Hu wrote:
> UEFI spec 2.8 introduced the variable RuntimeServicesSupported, which is
> Bitmask of which calls are implemented by the firmware during runtime services.
> Add tests for checking GetNextHighMonotonicCount services with
> RuntimeServicesSupported variable. Currently, won't test with
> QueryCapsuleCapabilities becasue QueryCapsuleCapabilities may return
> unsupported due to the update flag of firmware behavior unsupported, not
> runtime service unsupported.
> 
> Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
> ---
>  src/uefi/uefirtmisc/uefirtmisc.c | 55 ++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 55 insertions(+)
> 
> diff --git a/src/uefi/uefirtmisc/uefirtmisc.c b/src/uefi/uefirtmisc/uefirtmisc.c
> index b3fdf5f..4cda778 100644
> --- a/src/uefi/uefirtmisc/uefirtmisc.c
> +++ b/src/uefi/uefirtmisc/uefirtmisc.c
> @@ -254,11 +254,66 @@ static int uefirtmisc_test3(fwts_framework *fw)
>  	return FWTS_ERROR;
>  }
>  
> +static int uefirtmisc_test4(fwts_framework *fw)
> +{
> +	uint64_t status;
> +	bool getvar_supported;
> +	uint32_t var_runtimeservicessupported;
> +
> +	struct efi_getnexthighmonotoniccount getnexthighmonotoniccount;
> +	uint32_t highcount;
> +
> +	fwts_uefi_rt_support_status_get(fd, &getvar_supported,
> +			&var_runtimeservicessupported);
> +	if (!getvar_supported || (var_runtimeservicessupported == 0xFFFF)) {
> +		fwts_skipped(fw, "Cannot get the RuntimeServicesSupported "
> +				"variable, maybe the runtime service "
> +				"GetVariable is not supported or "
> +				"RuntimeServicesSupported not provided by "
> +				"firmware.");
> +		return FWTS_SKIP;
> +	}
> +
> +	getnexthighmonotoniccount.HighCount = &highcount;
> +	getnexthighmonotoniccount.status = &status;
> +	status = ~0ULL;
> +	ioctl(fd, EFI_RUNTIME_GET_NEXTHIGHMONOTONICCOUNT, &getnexthighmonotoniccount);

Please check for ioctl < 0 error returns

> +	if (status == EFI_UNSUPPORTED) {
> +		if ((var_runtimeservicessupported & EFI_RT_SUPPORTED_GET_NEXT_HIGH_MONOTONIC_COUNT)
> +			|| (var_runtimeservicessupported == 0)) {
> +			fwts_failed(fw, LOG_LEVEL_HIGH,
> +				"UEFIRuntimeGetNextHighMonotonicCount",
> +				"Get the GetNextHighMonotonicCount runtime "
> +				"service supported via RuntimeServicesSupported "
> +				"variable. But actually is not supported by "
> +				"firmware.");
> +		} else {
> +			fwts_passed(fw, "UEFI GetNextHighMonotonicCount runtime "
> +				"service supported status test passed.");
> +		}
> +	} else {
> +		if ((var_runtimeservicessupported & EFI_RT_SUPPORTED_GET_NEXT_HIGH_MONOTONIC_COUNT)
> +			|| (var_runtimeservicessupported == 0)) {
> +			fwts_passed(fw, "UEFI GetNextHighMonotonicCount runtime "
> +				"service supported status test passed.");
> +		} else {
> +			fwts_failed(fw, LOG_LEVEL_HIGH,
> +				"UEFIRuntimeGetNextHighMonotonicCount",
> +				"Get the GetNextHighMonotonicCount runtime "
> +				"service unsupported via RuntimeServicesSupported "
> +				"variable. But actually is supported by firmware.");
> +		}
> +	}
> +
> +	return FWTS_OK;
> +}
> +
>  
>  static fwts_framework_minor_test uefirtmisc_tests[] = {
>  	{ uefirtmisc_test1, "Test for UEFI miscellaneous runtime service interfaces." },
>  	{ uefirtmisc_test2, "Stress test for UEFI miscellaneous runtime service interfaces." },
>  	{ uefirtmisc_test3, "Test GetNextHighMonotonicCount with invalid NULL parameter." },
> +	{ uefirtmisc_test4, "Test UEFI miscellaneous runtime services supported status." },
>  	{ NULL, NULL }
>  };
>  
>
diff mbox series

Patch

diff --git a/src/uefi/uefirtmisc/uefirtmisc.c b/src/uefi/uefirtmisc/uefirtmisc.c
index b3fdf5f..4cda778 100644
--- a/src/uefi/uefirtmisc/uefirtmisc.c
+++ b/src/uefi/uefirtmisc/uefirtmisc.c
@@ -254,11 +254,66 @@  static int uefirtmisc_test3(fwts_framework *fw)
 	return FWTS_ERROR;
 }
 
+static int uefirtmisc_test4(fwts_framework *fw)
+{
+	uint64_t status;
+	bool getvar_supported;
+	uint32_t var_runtimeservicessupported;
+
+	struct efi_getnexthighmonotoniccount getnexthighmonotoniccount;
+	uint32_t highcount;
+
+	fwts_uefi_rt_support_status_get(fd, &getvar_supported,
+			&var_runtimeservicessupported);
+	if (!getvar_supported || (var_runtimeservicessupported == 0xFFFF)) {
+		fwts_skipped(fw, "Cannot get the RuntimeServicesSupported "
+				"variable, maybe the runtime service "
+				"GetVariable is not supported or "
+				"RuntimeServicesSupported not provided by "
+				"firmware.");
+		return FWTS_SKIP;
+	}
+
+	getnexthighmonotoniccount.HighCount = &highcount;
+	getnexthighmonotoniccount.status = &status;
+	status = ~0ULL;
+	ioctl(fd, EFI_RUNTIME_GET_NEXTHIGHMONOTONICCOUNT, &getnexthighmonotoniccount);
+	if (status == EFI_UNSUPPORTED) {
+		if ((var_runtimeservicessupported & EFI_RT_SUPPORTED_GET_NEXT_HIGH_MONOTONIC_COUNT)
+			|| (var_runtimeservicessupported == 0)) {
+			fwts_failed(fw, LOG_LEVEL_HIGH,
+				"UEFIRuntimeGetNextHighMonotonicCount",
+				"Get the GetNextHighMonotonicCount runtime "
+				"service supported via RuntimeServicesSupported "
+				"variable. But actually is not supported by "
+				"firmware.");
+		} else {
+			fwts_passed(fw, "UEFI GetNextHighMonotonicCount runtime "
+				"service supported status test passed.");
+		}
+	} else {
+		if ((var_runtimeservicessupported & EFI_RT_SUPPORTED_GET_NEXT_HIGH_MONOTONIC_COUNT)
+			|| (var_runtimeservicessupported == 0)) {
+			fwts_passed(fw, "UEFI GetNextHighMonotonicCount runtime "
+				"service supported status test passed.");
+		} else {
+			fwts_failed(fw, LOG_LEVEL_HIGH,
+				"UEFIRuntimeGetNextHighMonotonicCount",
+				"Get the GetNextHighMonotonicCount runtime "
+				"service unsupported via RuntimeServicesSupported "
+				"variable. But actually is supported by firmware.");
+		}
+	}
+
+	return FWTS_OK;
+}
+
 
 static fwts_framework_minor_test uefirtmisc_tests[] = {
 	{ uefirtmisc_test1, "Test for UEFI miscellaneous runtime service interfaces." },
 	{ uefirtmisc_test2, "Stress test for UEFI miscellaneous runtime service interfaces." },
 	{ uefirtmisc_test3, "Test GetNextHighMonotonicCount with invalid NULL parameter." },
+	{ uefirtmisc_test4, "Test UEFI miscellaneous runtime services supported status." },
 	{ NULL, NULL }
 };