diff mbox series

[1/4] uefirttime: only test the unsupported status with RuntimeServicesSupported

Message ID 20210507095623.34254-1-ivan.hu@canonical.com
State Accepted
Headers show
Series [1/4] uefirttime: only test the unsupported status with RuntimeServicesSupported | expand

Commit Message

Ivan Hu May 7, 2021, 9:56 a.m. UTC
Currently, kernel efi driver will set the RuntimeServicesSupported mask
all supported as default when RTPROT table not found.
And from the UEFI spec., RTPROT table should be published by a platform
if it no longer supports all EFI runtime services once ExitBootServices()
has been called by the OS. And the platform is still required to provide
callable implementations of unsupported runtime services that simply
return EFI_UNSUPPORTED.

So do not test the supported status which might get RuntimeServicesSupported
mask from kernel default value in case we get false alarm, only test the
upsupported status which can make sure is from RTPROT table for the
GetTime, SetTime, GetWakeupTime and SetWakeupTime runtime services.

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

Comments

Colin Ian King May 7, 2021, 10:39 a.m. UTC | #1
On 07/05/2021 10:56, Ivan Hu wrote:
> Currently, kernel efi driver will set the RuntimeServicesSupported mask
> all supported as default when RTPROT table not found.
> And from the UEFI spec., RTPROT table should be published by a platform
> if it no longer supports all EFI runtime services once ExitBootServices()
> has been called by the OS. And the platform is still required to provide
> callable implementations of unsupported runtime services that simply
> return EFI_UNSUPPORTED.
> 
> So do not test the supported status which might get RuntimeServicesSupported
> mask from kernel default value in case we get false alarm, only test the
> upsupported status which can make sure is from RTPROT table for the
> GetTime, SetTime, GetWakeupTime and SetWakeupTime runtime services.
> 
> Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
> ---
>  src/uefi/uefirttime/uefirttime.c | 250 +++++++++++--------------------
>  1 file changed, 90 insertions(+), 160 deletions(-)
> 
> diff --git a/src/uefi/uefirttime/uefirttime.c b/src/uefi/uefirttime/uefirttime.c
> index fa157736..00326139 100644
> --- a/src/uefi/uefirttime/uefirttime.c
> +++ b/src/uefi/uefirttime/uefirttime.c
> @@ -1159,202 +1159,132 @@ static int uefirttime_test38(fwts_framework *fw)
>  	EFI_TIME efi_time;
>  	EFI_TIME_CAPABILITIES efi_time_cap;
>  
> -	if (!have_rtsupported) {
> -		fwts_skipped(fw, "Cannot get the RuntimeServicesSupported "
> -				 "mask from the kernel. This IOCTL was "
> -				 "introduced in Linux v5.11.");
> -		return FWTS_SKIP;
> -	}
> -
> -	gettime.Capabilities = &efi_time_cap;
> -	gettime.Time = &efi_time;
> -	gettime.status = &status;
> -	ioret = ioctl(fd, EFI_RUNTIME_GET_TIME, &gettime);
> -	if (ioret == -1) {
> -		if (status == EFI_UNSUPPORTED) {
> -			if (runtimeservicessupported & EFI_RT_SUPPORTED_GET_TIME) {
> -				fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetTime",
> -					"Get the GetTime runtime service supported "
> -					"via RuntimeServicesSupported mask. "
> -					"But actually is not supported by firmware.");
> -			} else {
> +	if (!(runtimeservicessupported & EFI_RT_SUPPORTED_GET_TIME)) {
> +		gettime.Capabilities = &efi_time_cap;
> +		gettime.Time = &efi_time;
> +		gettime.status = &status;
> +
> +		ioret = ioctl(fd, EFI_RUNTIME_GET_TIME, &gettime);
> +		if (ioret == -1) {
> +			if (status == EFI_UNSUPPORTED)
>  				fwts_passed(fw, "UEFI GetTime runtime service "
> -					"supported status test passed.");
> +					"unsupported status test passed.");
> +			else {
> +				if (status == ~0ULL)
> +					fwts_skipped(fw, "Unknown error occurred, skip test.");
> +				else
> +					fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetTime",
> +						"Get the GetTime runtime service unsupported "
> +						"via RuntimeServicesSupported mask. "
> +						"But actually is supported by firmware.");
>  			}
>  		} else {
> -			if (status == ~0ULL) {
> +			if (status != EFI_SUCCESS )
>  				fwts_skipped(fw, "Unknown error occurred, skip test.");
> -				return FWTS_SKIP;
> -			}
> -			if (runtimeservicessupported & EFI_RT_SUPPORTED_GET_TIME) {
> -				fwts_passed(fw, "UEFI GetTime runtime service "
> -					"supported status test passed.");
> -			} else {
> +			else
>  				fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetTime",
>  					"Get the GetTime runtime service unsupported "
>  					"via RuntimeServicesSupported mask. "
>  					"But actually is supported by firmware.");
> -			}
> -		}
> -	} else {
> -		if (status != EFI_SUCCESS ) {
> -			fwts_skipped(fw, "Unknown error occurred, skip test.");
> -			return FWTS_SKIP;
>  		}
> -		if (runtimeservicessupported & EFI_RT_SUPPORTED_GET_TIME) {
> -			fwts_passed(fw, "UEFI GetTime runtime service "
> -				"supported status test passed.");
> -		} else {
> -			fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetTime",
> -				"Get the GetTime runtime service unsupported "
> -				"via RuntimeServicesSupported mask. "
> -				"But actually is supported by firmware.");
> -		}
> -	}
> +	} else
> +		fwts_skipped(fw, "GetTime runtime service supported, skip test.");
>  
> -	settime.Time = &efi_time;
> -	status = ~0ULL;
> -	settime.status = &status;
> +	if (!(runtimeservicessupported & EFI_RT_SUPPORTED_SET_TIME)) {
> +		settime.Time = &efi_time;
> +		status = ~0ULL;
> +		settime.status = &status;
>  
> -	ioret = ioctl(fd, EFI_RUNTIME_SET_TIME, &settime);
> -	if (ioret == -1) {
> -		if (status == EFI_UNSUPPORTED) {
> -			if (runtimeservicessupported & EFI_RT_SUPPORTED_SET_TIME) {
> -				fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetTime",
> -					"Get the SetTime runtime service supported "
> -					"via RuntimeServicesSupported mask. "
> -					"But actually is not supported by firmware.");
> -			} else {
> +		ioret = ioctl(fd, EFI_RUNTIME_SET_TIME, &settime);
> +		if (ioret == -1) {
> +			if (status == EFI_UNSUPPORTED) {
>  				fwts_passed(fw, "UEFI SetTime runtime service "
> -					"supported status test passed.");
> +					"unsupported status test passed.");
> +			} else {
> +				if (status == ~0ULL)
> +					fwts_skipped(fw, "Unknown error occurred, skip test.");
> +				else
> +					fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetTime",
> +						"Get the SetTime runtime service unsupported "
> +						"via RuntimeServicesSupported mask. "
> +						"But actually is supported by firmware.");
>  			}
>  		} else {
> -			if (status == ~0ULL) {
> +			if (status != EFI_SUCCESS )
>  				fwts_skipped(fw, "Unknown error occurred, skip test.");
> -				return FWTS_SKIP;
> -			}
> -			if (runtimeservicessupported & EFI_RT_SUPPORTED_SET_TIME) {
> -				fwts_passed(fw, "UEFI SetTime runtime service "
> -					"supported status test passed.");
> -			} else {
> +			else
>  				fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetTime",
>  					"Get the SetTime runtime service unsupported "
>  					"via RuntimeServicesSupported mask. "
>  					"But actually is supported by firmware.");
> -			}
> -		}
> -	} else {
> -		if (status != EFI_SUCCESS ) {
> -			fwts_skipped(fw, "Unknown error occurred, skip test.");
> -			return FWTS_SKIP;
>  		}
> -		if (runtimeservicessupported & EFI_RT_SUPPORTED_SET_TIME) {
> -			fwts_passed(fw, "UEFI SetTime runtime service "
> -				"supported status test passed.");
> -		} else {
> -			fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetTime",
> -				"Get the SetTime runtime service unsupported "
> -				"via RuntimeServicesSupported mask. "
> -				"But actually is supported by firmware.");
> -		}
> -	}
> -
> -	setwakeuptime.Time = &efi_time;
> -	status = ~0ULL;
> -	setwakeuptime.status = &status;
> -	setwakeuptime.Enabled = false;
> -
> -	ioret = ioctl(fd, EFI_RUNTIME_SET_WAKETIME, &setwakeuptime);
> -	if (ioret == -1) {
> -		if (status == EFI_UNSUPPORTED) {
> -			if (runtimeservicessupported & EFI_RT_SUPPORTED_SET_WAKEUP_TIME) {
> -				fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetWakeupTime",
> -					"Get the SetWakeupTime runtime service supported "
> -					"via RuntimeServicesSupported mask. "
> -					"But actually is not supported by firmware");
> -
> -			} else {
> -					fwts_passed(fw, "UEFI SetWakeupTime runtime service "
> -						"supported status test passed.");
> +	} else
> +		fwts_skipped(fw, "SetTime runtime service supported, skip test.");
> +
> +	if (!(runtimeservicessupported & EFI_RT_SUPPORTED_SET_WAKEUP_TIME)) {
> +		setwakeuptime.Time = &efi_time;
> +		status = ~0ULL;
> +		setwakeuptime.status = &status;
> +		setwakeuptime.Enabled = false;
> +
> +		ioret = ioctl(fd, EFI_RUNTIME_SET_WAKETIME, &setwakeuptime);
> +		if (ioret == -1) {
> +			if (status == EFI_UNSUPPORTED)
> +						fwts_passed(fw, "UEFI SetWakeupTime runtime service "
> +							"unsupported status test passed.");
> +			else {
> +				if (status == ~0ULL)
> +					fwts_skipped(fw, "Unknown error occurred, skip test.");
> +				else
> +					fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetWakeupTime",
> +						"Get the SetWakeupTime runtime service unsupported "
> +						"via RuntimeServicesSupported mask. "
> +						"But actually is supported by firmware.");
>  			}
>  		} else {
> -			if (status == ~0ULL) {
> +			if (status != EFI_SUCCESS )
>  				fwts_skipped(fw, "Unknown error occurred, skip test.");
> -				return FWTS_SKIP;
> -			}
> -			if (runtimeservicessupported & EFI_RT_SUPPORTED_SET_WAKEUP_TIME) {
> -				fwts_passed(fw, "UEFI SetWakeupTime runtime service "
> -					"supported status test passed.");
> -			} else {
> +			else
>  				fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetWakeupTime",
>  					"Get the SetWakeupTime runtime service unsupported "
>  					"via RuntimeServicesSupported mask. "
>  					"But actually is supported by firmware.");
> -			}
> -		}
> -	} else {
> -		if (status != EFI_SUCCESS ) {
> -			fwts_skipped(fw, "Unknown error occurred, skip test.");
> -			return FWTS_SKIP;
> -		}
> -		if (runtimeservicessupported & EFI_RT_SUPPORTED_SET_WAKEUP_TIME) {
> -			fwts_passed(fw, "UEFI SetWakeupTime runtime service "
> -				"supported status test passed.");
> -		} else {
> -			fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetWakeupTime",
> -				"Get the SetWakeupTime runtime service unsupported "
> -				"via RuntimeServicesSupported mask. "
> -				"But actually is supported by firmware.");
>  		}
>  	}
> -
> -	getwakeuptime.Enabled = &enabled;
> -	getwakeuptime.Pending = &pending;
> -	getwakeuptime.Time = &efi_time;
> -	getwakeuptime.status = &status;
> -
> -	ioret = ioctl(fd, EFI_RUNTIME_GET_WAKETIME, &getwakeuptime);
> -	if (ioret == -1) {
> -		if (status == EFI_UNSUPPORTED) {
> -			if (runtimeservicessupported & EFI_RT_SUPPORTED_GET_WAKEUP_TIME) {
> -				fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetWakeupTime",
> -					"Get the GetWakeupTime runtime service supported "
> -					"via RuntimeServicesSupported mask. "
> -					"But actually is not supported by firmware");
> -			} else {
> -				fwts_passed(fw, "UEFI GetWakeupTime runtime service "
> -					"supported status test passed.");
> +	else
> +		fwts_skipped(fw, "SetWakeupTime runtime service supported, skip test.");
> +
> +	if (!(runtimeservicessupported & EFI_RT_SUPPORTED_GET_WAKEUP_TIME)) {
> +		getwakeuptime.Enabled = &enabled;
> +		getwakeuptime.Pending = &pending;
> +		getwakeuptime.Time = &efi_time;
> +		getwakeuptime.status = &status;
> +
> +		ioret = ioctl(fd, EFI_RUNTIME_GET_WAKETIME, &getwakeuptime);
> +		if (ioret == -1) {
> +			if (status == EFI_UNSUPPORTED)
> +					fwts_passed(fw, "UEFI GetWakeupTime runtime service "
> +						"unsupported status test passed.");
> +			else {
> +				if (status == ~0ULL)
> +					fwts_skipped(fw, "Unknown error occurred, skip test.");
> +				else
> +					fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetWakeupTime",
> +						"Get the GetWakeupTime runtime service unsupported "
> +						"via RuntimeServicesSupported mask. "
> +						"But actually is supported by firmware");
>  			}
>  		} else {
> -			if (status == ~0ULL) {
> +			if (status != EFI_SUCCESS )
>  				fwts_skipped(fw, "Unknown error occurred, skip test.");
> -				return FWTS_SKIP;
> -			}
> -			if (runtimeservicessupported & EFI_RT_SUPPORTED_GET_WAKEUP_TIME) {
> -				fwts_passed(fw, "UEFI GetWakeupTime runtime service "
> -					"supported status test passed.");
> -			} else {
> +			else
>  				fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetWakeupTime",
>  					"Get the GetWakeupTime runtime service unsupported "
>  					"via RuntimeServicesSupported mask. "
>  					"But actually is supported by firmware");
> -			}
> -		}
> -	} else {
> -		if (status != EFI_SUCCESS ){
> -			fwts_skipped(fw, "Unknown error occurred, skip test.");
> -			return FWTS_SKIP;
>  		}
> -		if (runtimeservicessupported & EFI_RT_SUPPORTED_GET_WAKEUP_TIME) {
> -			fwts_passed(fw, "UEFI GetWakeupTime runtime service "
> -				"supported status test passed.");
> -		} else {
> -			fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetWakeupTime",
> -				"Get the GetWakeupTime runtime service unsupported "
> -				"via RuntimeServicesSupported mask. "
> -				"But actually is supported by firmware");
> -		}
> -	}
> +	} else
> +		fwts_skipped(fw, "GetWakeupTime runtime service supported, skip test.");
>  
>  	return FWTS_OK;
>  }
> @@ -1404,7 +1334,7 @@ static fwts_framework_minor_test uefirttime_tests[] = {
>  #if UEFI_IGNORE_UNSET_BITS
>  	{ uefirttime_test37, "Test UEFI RT service set wakeup time interface, invalid daylight 0xfc." },
>  #endif
> -	{ uefirttime_test38, "Test UEFI RT time services supported status." },
> +	{ uefirttime_test38, "Test UEFI RT time services unsupported status." },
>  	{ NULL, NULL }
>  };
>  
> 
Looks good to me. Thanks Ivan

Acked-by: Colin Ian King <colin.king@canonical.com>
Alex Hung May 7, 2021, 5:58 p.m. UTC | #2
On 2021-05-07 3:56 a.m., Ivan Hu wrote:
> Currently, kernel efi driver will set the RuntimeServicesSupported mask
> all supported as default when RTPROT table not found.
> And from the UEFI spec., RTPROT table should be published by a platform
> if it no longer supports all EFI runtime services once ExitBootServices()
> has been called by the OS. And the platform is still required to provide
> callable implementations of unsupported runtime services that simply
> return EFI_UNSUPPORTED.
> 
> So do not test the supported status which might get RuntimeServicesSupported
> mask from kernel default value in case we get false alarm, only test the
> upsupported status which can make sure is from RTPROT table for the
> GetTime, SetTime, GetWakeupTime and SetWakeupTime runtime services.
> 
> Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
> ---
>  src/uefi/uefirttime/uefirttime.c | 250 +++++++++++--------------------
>  1 file changed, 90 insertions(+), 160 deletions(-)
> 
> diff --git a/src/uefi/uefirttime/uefirttime.c b/src/uefi/uefirttime/uefirttime.c
> index fa157736..00326139 100644
> --- a/src/uefi/uefirttime/uefirttime.c
> +++ b/src/uefi/uefirttime/uefirttime.c
> @@ -1159,202 +1159,132 @@ static int uefirttime_test38(fwts_framework *fw)
>  	EFI_TIME efi_time;
>  	EFI_TIME_CAPABILITIES efi_time_cap;
>  
> -	if (!have_rtsupported) {
> -		fwts_skipped(fw, "Cannot get the RuntimeServicesSupported "
> -				 "mask from the kernel. This IOCTL was "
> -				 "introduced in Linux v5.11.");
> -		return FWTS_SKIP;
> -	}
> -
> -	gettime.Capabilities = &efi_time_cap;
> -	gettime.Time = &efi_time;
> -	gettime.status = &status;
> -	ioret = ioctl(fd, EFI_RUNTIME_GET_TIME, &gettime);
> -	if (ioret == -1) {
> -		if (status == EFI_UNSUPPORTED) {
> -			if (runtimeservicessupported & EFI_RT_SUPPORTED_GET_TIME) {
> -				fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetTime",
> -					"Get the GetTime runtime service supported "
> -					"via RuntimeServicesSupported mask. "
> -					"But actually is not supported by firmware.");
> -			} else {
> +	if (!(runtimeservicessupported & EFI_RT_SUPPORTED_GET_TIME)) {
> +		gettime.Capabilities = &efi_time_cap;
> +		gettime.Time = &efi_time;
> +		gettime.status = &status;
> +
> +		ioret = ioctl(fd, EFI_RUNTIME_GET_TIME, &gettime);
> +		if (ioret == -1) {
> +			if (status == EFI_UNSUPPORTED)
>  				fwts_passed(fw, "UEFI GetTime runtime service "
> -					"supported status test passed.");
> +					"unsupported status test passed.");
> +			else {
> +				if (status == ~0ULL)
> +					fwts_skipped(fw, "Unknown error occurred, skip test.");
> +				else
> +					fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetTime",
> +						"Get the GetTime runtime service unsupported "
> +						"via RuntimeServicesSupported mask. "
> +						"But actually is supported by firmware.");
>  			}
>  		} else {
> -			if (status == ~0ULL) {
> +			if (status != EFI_SUCCESS )
>  				fwts_skipped(fw, "Unknown error occurred, skip test.");
> -				return FWTS_SKIP;
> -			}
> -			if (runtimeservicessupported & EFI_RT_SUPPORTED_GET_TIME) {
> -				fwts_passed(fw, "UEFI GetTime runtime service "
> -					"supported status test passed.");
> -			} else {
> +			else
>  				fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetTime",
>  					"Get the GetTime runtime service unsupported "
>  					"via RuntimeServicesSupported mask. "
>  					"But actually is supported by firmware.");
> -			}
> -		}
> -	} else {
> -		if (status != EFI_SUCCESS ) {
> -			fwts_skipped(fw, "Unknown error occurred, skip test.");
> -			return FWTS_SKIP;
>  		}
> -		if (runtimeservicessupported & EFI_RT_SUPPORTED_GET_TIME) {
> -			fwts_passed(fw, "UEFI GetTime runtime service "
> -				"supported status test passed.");
> -		} else {
> -			fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetTime",
> -				"Get the GetTime runtime service unsupported "
> -				"via RuntimeServicesSupported mask. "
> -				"But actually is supported by firmware.");
> -		}
> -	}
> +	} else
> +		fwts_skipped(fw, "GetTime runtime service supported, skip test.");
>  
> -	settime.Time = &efi_time;
> -	status = ~0ULL;
> -	settime.status = &status;
> +	if (!(runtimeservicessupported & EFI_RT_SUPPORTED_SET_TIME)) {
> +		settime.Time = &efi_time;
> +		status = ~0ULL;
> +		settime.status = &status;
>  
> -	ioret = ioctl(fd, EFI_RUNTIME_SET_TIME, &settime);
> -	if (ioret == -1) {
> -		if (status == EFI_UNSUPPORTED) {
> -			if (runtimeservicessupported & EFI_RT_SUPPORTED_SET_TIME) {
> -				fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetTime",
> -					"Get the SetTime runtime service supported "
> -					"via RuntimeServicesSupported mask. "
> -					"But actually is not supported by firmware.");
> -			} else {
> +		ioret = ioctl(fd, EFI_RUNTIME_SET_TIME, &settime);
> +		if (ioret == -1) {
> +			if (status == EFI_UNSUPPORTED) {
>  				fwts_passed(fw, "UEFI SetTime runtime service "
> -					"supported status test passed.");
> +					"unsupported status test passed.");
> +			} else {
> +				if (status == ~0ULL)
> +					fwts_skipped(fw, "Unknown error occurred, skip test.");
> +				else
> +					fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetTime",
> +						"Get the SetTime runtime service unsupported "
> +						"via RuntimeServicesSupported mask. "
> +						"But actually is supported by firmware.");
>  			}
>  		} else {
> -			if (status == ~0ULL) {
> +			if (status != EFI_SUCCESS )
>  				fwts_skipped(fw, "Unknown error occurred, skip test.");
> -				return FWTS_SKIP;
> -			}
> -			if (runtimeservicessupported & EFI_RT_SUPPORTED_SET_TIME) {
> -				fwts_passed(fw, "UEFI SetTime runtime service "
> -					"supported status test passed.");
> -			} else {
> +			else
>  				fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetTime",
>  					"Get the SetTime runtime service unsupported "
>  					"via RuntimeServicesSupported mask. "
>  					"But actually is supported by firmware.");
> -			}
> -		}
> -	} else {
> -		if (status != EFI_SUCCESS ) {
> -			fwts_skipped(fw, "Unknown error occurred, skip test.");
> -			return FWTS_SKIP;
>  		}
> -		if (runtimeservicessupported & EFI_RT_SUPPORTED_SET_TIME) {
> -			fwts_passed(fw, "UEFI SetTime runtime service "
> -				"supported status test passed.");
> -		} else {
> -			fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetTime",
> -				"Get the SetTime runtime service unsupported "
> -				"via RuntimeServicesSupported mask. "
> -				"But actually is supported by firmware.");
> -		}
> -	}
> -
> -	setwakeuptime.Time = &efi_time;
> -	status = ~0ULL;
> -	setwakeuptime.status = &status;
> -	setwakeuptime.Enabled = false;
> -
> -	ioret = ioctl(fd, EFI_RUNTIME_SET_WAKETIME, &setwakeuptime);
> -	if (ioret == -1) {
> -		if (status == EFI_UNSUPPORTED) {
> -			if (runtimeservicessupported & EFI_RT_SUPPORTED_SET_WAKEUP_TIME) {
> -				fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetWakeupTime",
> -					"Get the SetWakeupTime runtime service supported "
> -					"via RuntimeServicesSupported mask. "
> -					"But actually is not supported by firmware");
> -
> -			} else {
> -					fwts_passed(fw, "UEFI SetWakeupTime runtime service "
> -						"supported status test passed.");
> +	} else
> +		fwts_skipped(fw, "SetTime runtime service supported, skip test.");
> +
> +	if (!(runtimeservicessupported & EFI_RT_SUPPORTED_SET_WAKEUP_TIME)) {
> +		setwakeuptime.Time = &efi_time;
> +		status = ~0ULL;
> +		setwakeuptime.status = &status;
> +		setwakeuptime.Enabled = false;
> +
> +		ioret = ioctl(fd, EFI_RUNTIME_SET_WAKETIME, &setwakeuptime);
> +		if (ioret == -1) {
> +			if (status == EFI_UNSUPPORTED)
> +						fwts_passed(fw, "UEFI SetWakeupTime runtime service "
> +							"unsupported status test passed.");
> +			else {
> +				if (status == ~0ULL)
> +					fwts_skipped(fw, "Unknown error occurred, skip test.");
> +				else
> +					fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetWakeupTime",
> +						"Get the SetWakeupTime runtime service unsupported "
> +						"via RuntimeServicesSupported mask. "
> +						"But actually is supported by firmware.");
>  			}
>  		} else {
> -			if (status == ~0ULL) {
> +			if (status != EFI_SUCCESS )
>  				fwts_skipped(fw, "Unknown error occurred, skip test.");
> -				return FWTS_SKIP;
> -			}
> -			if (runtimeservicessupported & EFI_RT_SUPPORTED_SET_WAKEUP_TIME) {
> -				fwts_passed(fw, "UEFI SetWakeupTime runtime service "
> -					"supported status test passed.");
> -			} else {
> +			else
>  				fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetWakeupTime",
>  					"Get the SetWakeupTime runtime service unsupported "
>  					"via RuntimeServicesSupported mask. "
>  					"But actually is supported by firmware.");
> -			}
> -		}
> -	} else {
> -		if (status != EFI_SUCCESS ) {
> -			fwts_skipped(fw, "Unknown error occurred, skip test.");
> -			return FWTS_SKIP;
> -		}
> -		if (runtimeservicessupported & EFI_RT_SUPPORTED_SET_WAKEUP_TIME) {
> -			fwts_passed(fw, "UEFI SetWakeupTime runtime service "
> -				"supported status test passed.");
> -		} else {
> -			fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetWakeupTime",
> -				"Get the SetWakeupTime runtime service unsupported "
> -				"via RuntimeServicesSupported mask. "
> -				"But actually is supported by firmware.");
>  		}
>  	}
> -
> -	getwakeuptime.Enabled = &enabled;
> -	getwakeuptime.Pending = &pending;
> -	getwakeuptime.Time = &efi_time;
> -	getwakeuptime.status = &status;
> -
> -	ioret = ioctl(fd, EFI_RUNTIME_GET_WAKETIME, &getwakeuptime);
> -	if (ioret == -1) {
> -		if (status == EFI_UNSUPPORTED) {
> -			if (runtimeservicessupported & EFI_RT_SUPPORTED_GET_WAKEUP_TIME) {
> -				fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetWakeupTime",
> -					"Get the GetWakeupTime runtime service supported "
> -					"via RuntimeServicesSupported mask. "
> -					"But actually is not supported by firmware");
> -			} else {
> -				fwts_passed(fw, "UEFI GetWakeupTime runtime service "
> -					"supported status test passed.");
> +	else
> +		fwts_skipped(fw, "SetWakeupTime runtime service supported, skip test.");
> +
> +	if (!(runtimeservicessupported & EFI_RT_SUPPORTED_GET_WAKEUP_TIME)) {
> +		getwakeuptime.Enabled = &enabled;
> +		getwakeuptime.Pending = &pending;
> +		getwakeuptime.Time = &efi_time;
> +		getwakeuptime.status = &status;
> +
> +		ioret = ioctl(fd, EFI_RUNTIME_GET_WAKETIME, &getwakeuptime);
> +		if (ioret == -1) {
> +			if (status == EFI_UNSUPPORTED)
> +					fwts_passed(fw, "UEFI GetWakeupTime runtime service "
> +						"unsupported status test passed.");
> +			else {
> +				if (status == ~0ULL)
> +					fwts_skipped(fw, "Unknown error occurred, skip test.");
> +				else
> +					fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetWakeupTime",
> +						"Get the GetWakeupTime runtime service unsupported "
> +						"via RuntimeServicesSupported mask. "
> +						"But actually is supported by firmware");
>  			}
>  		} else {
> -			if (status == ~0ULL) {
> +			if (status != EFI_SUCCESS )
>  				fwts_skipped(fw, "Unknown error occurred, skip test.");
> -				return FWTS_SKIP;
> -			}
> -			if (runtimeservicessupported & EFI_RT_SUPPORTED_GET_WAKEUP_TIME) {
> -				fwts_passed(fw, "UEFI GetWakeupTime runtime service "
> -					"supported status test passed.");
> -			} else {
> +			else
>  				fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetWakeupTime",
>  					"Get the GetWakeupTime runtime service unsupported "
>  					"via RuntimeServicesSupported mask. "
>  					"But actually is supported by firmware");
> -			}
> -		}
> -	} else {
> -		if (status != EFI_SUCCESS ){
> -			fwts_skipped(fw, "Unknown error occurred, skip test.");
> -			return FWTS_SKIP;
>  		}
> -		if (runtimeservicessupported & EFI_RT_SUPPORTED_GET_WAKEUP_TIME) {
> -			fwts_passed(fw, "UEFI GetWakeupTime runtime service "
> -				"supported status test passed.");
> -		} else {
> -			fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetWakeupTime",
> -				"Get the GetWakeupTime runtime service unsupported "
> -				"via RuntimeServicesSupported mask. "
> -				"But actually is supported by firmware");
> -		}
> -	}
> +	} else
> +		fwts_skipped(fw, "GetWakeupTime runtime service supported, skip test.");
>  
>  	return FWTS_OK;
>  }
> @@ -1404,7 +1334,7 @@ static fwts_framework_minor_test uefirttime_tests[] = {
>  #if UEFI_IGNORE_UNSET_BITS
>  	{ uefirttime_test37, "Test UEFI RT service set wakeup time interface, invalid daylight 0xfc." },
>  #endif
> -	{ uefirttime_test38, "Test UEFI RT time services supported status." },
> +	{ uefirttime_test38, "Test UEFI RT time services unsupported status." },
>  	{ NULL, NULL }
>  };
>  
>
Alex Hung May 7, 2021, 6 p.m. UTC | #3
On 2021-05-07 3:56 a.m., Ivan Hu wrote:
> Currently, kernel efi driver will set the RuntimeServicesSupported mask
> all supported as default when RTPROT table not found.
> And from the UEFI spec., RTPROT table should be published by a platform
> if it no longer supports all EFI runtime services once ExitBootServices()
> has been called by the OS. And the platform is still required to provide
> callable implementations of unsupported runtime services that simply
> return EFI_UNSUPPORTED.
> 
> So do not test the supported status which might get RuntimeServicesSupported
> mask from kernel default value in case we get false alarm, only test the
> upsupported status which can make sure is from RTPROT table for the
> GetTime, SetTime, GetWakeupTime and SetWakeupTime runtime services.
> 
> Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
> ---
>  src/uefi/uefirttime/uefirttime.c | 250 +++++++++++--------------------
>  1 file changed, 90 insertions(+), 160 deletions(-)
> 
> diff --git a/src/uefi/uefirttime/uefirttime.c b/src/uefi/uefirttime/uefirttime.c
> index fa157736..00326139 100644
> --- a/src/uefi/uefirttime/uefirttime.c
> +++ b/src/uefi/uefirttime/uefirttime.c
> @@ -1159,202 +1159,132 @@ static int uefirttime_test38(fwts_framework *fw)
>  	EFI_TIME efi_time;
>  	EFI_TIME_CAPABILITIES efi_time_cap;
>  
> -	if (!have_rtsupported) {
> -		fwts_skipped(fw, "Cannot get the RuntimeServicesSupported "
> -				 "mask from the kernel. This IOCTL was "
> -				 "introduced in Linux v5.11.");
> -		return FWTS_SKIP;
> -	}
> -
> -	gettime.Capabilities = &efi_time_cap;
> -	gettime.Time = &efi_time;
> -	gettime.status = &status;
> -	ioret = ioctl(fd, EFI_RUNTIME_GET_TIME, &gettime);
> -	if (ioret == -1) {
> -		if (status == EFI_UNSUPPORTED) {
> -			if (runtimeservicessupported & EFI_RT_SUPPORTED_GET_TIME) {
> -				fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetTime",
> -					"Get the GetTime runtime service supported "
> -					"via RuntimeServicesSupported mask. "
> -					"But actually is not supported by firmware.");
> -			} else {
> +	if (!(runtimeservicessupported & EFI_RT_SUPPORTED_GET_TIME)) {
> +		gettime.Capabilities = &efi_time_cap;
> +		gettime.Time = &efi_time;
> +		gettime.status = &status;
> +
> +		ioret = ioctl(fd, EFI_RUNTIME_GET_TIME, &gettime);
> +		if (ioret == -1) {
> +			if (status == EFI_UNSUPPORTED)
>  				fwts_passed(fw, "UEFI GetTime runtime service "
> -					"supported status test passed.");
> +					"unsupported status test passed.");
> +			else {
> +				if (status == ~0ULL)
> +					fwts_skipped(fw, "Unknown error occurred, skip test.");
> +				else
> +					fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetTime",
> +						"Get the GetTime runtime service unsupported "
> +						"via RuntimeServicesSupported mask. "
> +						"But actually is supported by firmware.");
>  			}
>  		} else {
> -			if (status == ~0ULL) {
> +			if (status != EFI_SUCCESS )
>  				fwts_skipped(fw, "Unknown error occurred, skip test.");
> -				return FWTS_SKIP;
> -			}
> -			if (runtimeservicessupported & EFI_RT_SUPPORTED_GET_TIME) {
> -				fwts_passed(fw, "UEFI GetTime runtime service "
> -					"supported status test passed.");
> -			} else {
> +			else
>  				fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetTime",
>  					"Get the GetTime runtime service unsupported "
>  					"via RuntimeServicesSupported mask. "
>  					"But actually is supported by firmware.");
> -			}
> -		}
> -	} else {
> -		if (status != EFI_SUCCESS ) {
> -			fwts_skipped(fw, "Unknown error occurred, skip test.");
> -			return FWTS_SKIP;
>  		}
> -		if (runtimeservicessupported & EFI_RT_SUPPORTED_GET_TIME) {
> -			fwts_passed(fw, "UEFI GetTime runtime service "
> -				"supported status test passed.");
> -		} else {
> -			fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetTime",
> -				"Get the GetTime runtime service unsupported "
> -				"via RuntimeServicesSupported mask. "
> -				"But actually is supported by firmware.");
> -		}
> -	}
> +	} else
> +		fwts_skipped(fw, "GetTime runtime service supported, skip test.");
>  
> -	settime.Time = &efi_time;
> -	status = ~0ULL;
> -	settime.status = &status;
> +	if (!(runtimeservicessupported & EFI_RT_SUPPORTED_SET_TIME)) {
> +		settime.Time = &efi_time;
> +		status = ~0ULL;
> +		settime.status = &status;
>  
> -	ioret = ioctl(fd, EFI_RUNTIME_SET_TIME, &settime);
> -	if (ioret == -1) {
> -		if (status == EFI_UNSUPPORTED) {
> -			if (runtimeservicessupported & EFI_RT_SUPPORTED_SET_TIME) {
> -				fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetTime",
> -					"Get the SetTime runtime service supported "
> -					"via RuntimeServicesSupported mask. "
> -					"But actually is not supported by firmware.");
> -			} else {
> +		ioret = ioctl(fd, EFI_RUNTIME_SET_TIME, &settime);
> +		if (ioret == -1) {
> +			if (status == EFI_UNSUPPORTED) {
>  				fwts_passed(fw, "UEFI SetTime runtime service "
> -					"supported status test passed.");
> +					"unsupported status test passed.");
> +			} else {
> +				if (status == ~0ULL)
> +					fwts_skipped(fw, "Unknown error occurred, skip test.");
> +				else
> +					fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetTime",
> +						"Get the SetTime runtime service unsupported "
> +						"via RuntimeServicesSupported mask. "
> +						"But actually is supported by firmware.");
>  			}
>  		} else {
> -			if (status == ~0ULL) {
> +			if (status != EFI_SUCCESS )
>  				fwts_skipped(fw, "Unknown error occurred, skip test.");
> -				return FWTS_SKIP;
> -			}
> -			if (runtimeservicessupported & EFI_RT_SUPPORTED_SET_TIME) {
> -				fwts_passed(fw, "UEFI SetTime runtime service "
> -					"supported status test passed.");
> -			} else {
> +			else
>  				fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetTime",
>  					"Get the SetTime runtime service unsupported "
>  					"via RuntimeServicesSupported mask. "
>  					"But actually is supported by firmware.");
> -			}
> -		}
> -	} else {
> -		if (status != EFI_SUCCESS ) {
> -			fwts_skipped(fw, "Unknown error occurred, skip test.");
> -			return FWTS_SKIP;
>  		}
> -		if (runtimeservicessupported & EFI_RT_SUPPORTED_SET_TIME) {
> -			fwts_passed(fw, "UEFI SetTime runtime service "
> -				"supported status test passed.");
> -		} else {
> -			fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetTime",
> -				"Get the SetTime runtime service unsupported "
> -				"via RuntimeServicesSupported mask. "
> -				"But actually is supported by firmware.");
> -		}
> -	}
> -
> -	setwakeuptime.Time = &efi_time;
> -	status = ~0ULL;
> -	setwakeuptime.status = &status;
> -	setwakeuptime.Enabled = false;
> -
> -	ioret = ioctl(fd, EFI_RUNTIME_SET_WAKETIME, &setwakeuptime);
> -	if (ioret == -1) {
> -		if (status == EFI_UNSUPPORTED) {
> -			if (runtimeservicessupported & EFI_RT_SUPPORTED_SET_WAKEUP_TIME) {
> -				fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetWakeupTime",
> -					"Get the SetWakeupTime runtime service supported "
> -					"via RuntimeServicesSupported mask. "
> -					"But actually is not supported by firmware");
> -
> -			} else {
> -					fwts_passed(fw, "UEFI SetWakeupTime runtime service "
> -						"supported status test passed.");
> +	} else
> +		fwts_skipped(fw, "SetTime runtime service supported, skip test.");
> +
> +	if (!(runtimeservicessupported & EFI_RT_SUPPORTED_SET_WAKEUP_TIME)) {
> +		setwakeuptime.Time = &efi_time;
> +		status = ~0ULL;
> +		setwakeuptime.status = &status;
> +		setwakeuptime.Enabled = false;
> +
> +		ioret = ioctl(fd, EFI_RUNTIME_SET_WAKETIME, &setwakeuptime);
> +		if (ioret == -1) {
> +			if (status == EFI_UNSUPPORTED)
> +						fwts_passed(fw, "UEFI SetWakeupTime runtime service "
> +							"unsupported status test passed.");
> +			else {
> +				if (status == ~0ULL)
> +					fwts_skipped(fw, "Unknown error occurred, skip test.");
> +				else
> +					fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetWakeupTime",
> +						"Get the SetWakeupTime runtime service unsupported "
> +						"via RuntimeServicesSupported mask. "
> +						"But actually is supported by firmware.");
>  			}
>  		} else {
> -			if (status == ~0ULL) {
> +			if (status != EFI_SUCCESS )
>  				fwts_skipped(fw, "Unknown error occurred, skip test.");
> -				return FWTS_SKIP;
> -			}
> -			if (runtimeservicessupported & EFI_RT_SUPPORTED_SET_WAKEUP_TIME) {
> -				fwts_passed(fw, "UEFI SetWakeupTime runtime service "
> -					"supported status test passed.");
> -			} else {
> +			else
>  				fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetWakeupTime",
>  					"Get the SetWakeupTime runtime service unsupported "
>  					"via RuntimeServicesSupported mask. "
>  					"But actually is supported by firmware.");
> -			}
> -		}
> -	} else {
> -		if (status != EFI_SUCCESS ) {
> -			fwts_skipped(fw, "Unknown error occurred, skip test.");
> -			return FWTS_SKIP;
> -		}
> -		if (runtimeservicessupported & EFI_RT_SUPPORTED_SET_WAKEUP_TIME) {
> -			fwts_passed(fw, "UEFI SetWakeupTime runtime service "
> -				"supported status test passed.");
> -		} else {
> -			fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetWakeupTime",
> -				"Get the SetWakeupTime runtime service unsupported "
> -				"via RuntimeServicesSupported mask. "
> -				"But actually is supported by firmware.");
>  		}
>  	}
> -
> -	getwakeuptime.Enabled = &enabled;
> -	getwakeuptime.Pending = &pending;
> -	getwakeuptime.Time = &efi_time;
> -	getwakeuptime.status = &status;
> -
> -	ioret = ioctl(fd, EFI_RUNTIME_GET_WAKETIME, &getwakeuptime);
> -	if (ioret == -1) {
> -		if (status == EFI_UNSUPPORTED) {
> -			if (runtimeservicessupported & EFI_RT_SUPPORTED_GET_WAKEUP_TIME) {
> -				fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetWakeupTime",
> -					"Get the GetWakeupTime runtime service supported "
> -					"via RuntimeServicesSupported mask. "
> -					"But actually is not supported by firmware");
> -			} else {
> -				fwts_passed(fw, "UEFI GetWakeupTime runtime service "
> -					"supported status test passed.");
> +	else
> +		fwts_skipped(fw, "SetWakeupTime runtime service supported, skip test.");
> +
> +	if (!(runtimeservicessupported & EFI_RT_SUPPORTED_GET_WAKEUP_TIME)) {
> +		getwakeuptime.Enabled = &enabled;
> +		getwakeuptime.Pending = &pending;
> +		getwakeuptime.Time = &efi_time;
> +		getwakeuptime.status = &status;
> +
> +		ioret = ioctl(fd, EFI_RUNTIME_GET_WAKETIME, &getwakeuptime);
> +		if (ioret == -1) {
> +			if (status == EFI_UNSUPPORTED)
> +					fwts_passed(fw, "UEFI GetWakeupTime runtime service "
> +						"unsupported status test passed.");
> +			else {
> +				if (status == ~0ULL)
> +					fwts_skipped(fw, "Unknown error occurred, skip test.");
> +				else
> +					fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetWakeupTime",
> +						"Get the GetWakeupTime runtime service unsupported "
> +						"via RuntimeServicesSupported mask. "
> +						"But actually is supported by firmware");
>  			}
>  		} else {
> -			if (status == ~0ULL) {
> +			if (status != EFI_SUCCESS )
>  				fwts_skipped(fw, "Unknown error occurred, skip test.");
> -				return FWTS_SKIP;
> -			}
> -			if (runtimeservicessupported & EFI_RT_SUPPORTED_GET_WAKEUP_TIME) {
> -				fwts_passed(fw, "UEFI GetWakeupTime runtime service "
> -					"supported status test passed.");
> -			} else {
> +			else
>  				fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetWakeupTime",
>  					"Get the GetWakeupTime runtime service unsupported "
>  					"via RuntimeServicesSupported mask. "
>  					"But actually is supported by firmware");
> -			}
> -		}
> -	} else {
> -		if (status != EFI_SUCCESS ){
> -			fwts_skipped(fw, "Unknown error occurred, skip test.");
> -			return FWTS_SKIP;
>  		}
> -		if (runtimeservicessupported & EFI_RT_SUPPORTED_GET_WAKEUP_TIME) {
> -			fwts_passed(fw, "UEFI GetWakeupTime runtime service "
> -				"supported status test passed.");
> -		} else {
> -			fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetWakeupTime",
> -				"Get the GetWakeupTime runtime service unsupported "
> -				"via RuntimeServicesSupported mask. "
> -				"But actually is supported by firmware");
> -		}
> -	}
> +	} else
> +		fwts_skipped(fw, "GetWakeupTime runtime service supported, skip test.");
>  
>  	return FWTS_OK;
>  }
> @@ -1404,7 +1334,7 @@ static fwts_framework_minor_test uefirttime_tests[] = {
>  #if UEFI_IGNORE_UNSET_BITS
>  	{ uefirttime_test37, "Test UEFI RT service set wakeup time interface, invalid daylight 0xfc." },
>  #endif
> -	{ uefirttime_test38, "Test UEFI RT time services supported status." },
> +	{ uefirttime_test38, "Test UEFI RT time services unsupported status." },
>  	{ NULL, NULL }
>  };
>  
> 


Acked-by: Alex Hung <alex.hung@canonical.com>
diff mbox series

Patch

diff --git a/src/uefi/uefirttime/uefirttime.c b/src/uefi/uefirttime/uefirttime.c
index fa157736..00326139 100644
--- a/src/uefi/uefirttime/uefirttime.c
+++ b/src/uefi/uefirttime/uefirttime.c
@@ -1159,202 +1159,132 @@  static int uefirttime_test38(fwts_framework *fw)
 	EFI_TIME efi_time;
 	EFI_TIME_CAPABILITIES efi_time_cap;
 
-	if (!have_rtsupported) {
-		fwts_skipped(fw, "Cannot get the RuntimeServicesSupported "
-				 "mask from the kernel. This IOCTL was "
-				 "introduced in Linux v5.11.");
-		return FWTS_SKIP;
-	}
-
-	gettime.Capabilities = &efi_time_cap;
-	gettime.Time = &efi_time;
-	gettime.status = &status;
-	ioret = ioctl(fd, EFI_RUNTIME_GET_TIME, &gettime);
-	if (ioret == -1) {
-		if (status == EFI_UNSUPPORTED) {
-			if (runtimeservicessupported & EFI_RT_SUPPORTED_GET_TIME) {
-				fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetTime",
-					"Get the GetTime runtime service supported "
-					"via RuntimeServicesSupported mask. "
-					"But actually is not supported by firmware.");
-			} else {
+	if (!(runtimeservicessupported & EFI_RT_SUPPORTED_GET_TIME)) {
+		gettime.Capabilities = &efi_time_cap;
+		gettime.Time = &efi_time;
+		gettime.status = &status;
+
+		ioret = ioctl(fd, EFI_RUNTIME_GET_TIME, &gettime);
+		if (ioret == -1) {
+			if (status == EFI_UNSUPPORTED)
 				fwts_passed(fw, "UEFI GetTime runtime service "
-					"supported status test passed.");
+					"unsupported status test passed.");
+			else {
+				if (status == ~0ULL)
+					fwts_skipped(fw, "Unknown error occurred, skip test.");
+				else
+					fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetTime",
+						"Get the GetTime runtime service unsupported "
+						"via RuntimeServicesSupported mask. "
+						"But actually is supported by firmware.");
 			}
 		} else {
-			if (status == ~0ULL) {
+			if (status != EFI_SUCCESS )
 				fwts_skipped(fw, "Unknown error occurred, skip test.");
-				return FWTS_SKIP;
-			}
-			if (runtimeservicessupported & EFI_RT_SUPPORTED_GET_TIME) {
-				fwts_passed(fw, "UEFI GetTime runtime service "
-					"supported status test passed.");
-			} else {
+			else
 				fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetTime",
 					"Get the GetTime runtime service unsupported "
 					"via RuntimeServicesSupported mask. "
 					"But actually is supported by firmware.");
-			}
-		}
-	} else {
-		if (status != EFI_SUCCESS ) {
-			fwts_skipped(fw, "Unknown error occurred, skip test.");
-			return FWTS_SKIP;
 		}
-		if (runtimeservicessupported & EFI_RT_SUPPORTED_GET_TIME) {
-			fwts_passed(fw, "UEFI GetTime runtime service "
-				"supported status test passed.");
-		} else {
-			fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetTime",
-				"Get the GetTime runtime service unsupported "
-				"via RuntimeServicesSupported mask. "
-				"But actually is supported by firmware.");
-		}
-	}
+	} else
+		fwts_skipped(fw, "GetTime runtime service supported, skip test.");
 
-	settime.Time = &efi_time;
-	status = ~0ULL;
-	settime.status = &status;
+	if (!(runtimeservicessupported & EFI_RT_SUPPORTED_SET_TIME)) {
+		settime.Time = &efi_time;
+		status = ~0ULL;
+		settime.status = &status;
 
-	ioret = ioctl(fd, EFI_RUNTIME_SET_TIME, &settime);
-	if (ioret == -1) {
-		if (status == EFI_UNSUPPORTED) {
-			if (runtimeservicessupported & EFI_RT_SUPPORTED_SET_TIME) {
-				fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetTime",
-					"Get the SetTime runtime service supported "
-					"via RuntimeServicesSupported mask. "
-					"But actually is not supported by firmware.");
-			} else {
+		ioret = ioctl(fd, EFI_RUNTIME_SET_TIME, &settime);
+		if (ioret == -1) {
+			if (status == EFI_UNSUPPORTED) {
 				fwts_passed(fw, "UEFI SetTime runtime service "
-					"supported status test passed.");
+					"unsupported status test passed.");
+			} else {
+				if (status == ~0ULL)
+					fwts_skipped(fw, "Unknown error occurred, skip test.");
+				else
+					fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetTime",
+						"Get the SetTime runtime service unsupported "
+						"via RuntimeServicesSupported mask. "
+						"But actually is supported by firmware.");
 			}
 		} else {
-			if (status == ~0ULL) {
+			if (status != EFI_SUCCESS )
 				fwts_skipped(fw, "Unknown error occurred, skip test.");
-				return FWTS_SKIP;
-			}
-			if (runtimeservicessupported & EFI_RT_SUPPORTED_SET_TIME) {
-				fwts_passed(fw, "UEFI SetTime runtime service "
-					"supported status test passed.");
-			} else {
+			else
 				fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetTime",
 					"Get the SetTime runtime service unsupported "
 					"via RuntimeServicesSupported mask. "
 					"But actually is supported by firmware.");
-			}
-		}
-	} else {
-		if (status != EFI_SUCCESS ) {
-			fwts_skipped(fw, "Unknown error occurred, skip test.");
-			return FWTS_SKIP;
 		}
-		if (runtimeservicessupported & EFI_RT_SUPPORTED_SET_TIME) {
-			fwts_passed(fw, "UEFI SetTime runtime service "
-				"supported status test passed.");
-		} else {
-			fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetTime",
-				"Get the SetTime runtime service unsupported "
-				"via RuntimeServicesSupported mask. "
-				"But actually is supported by firmware.");
-		}
-	}
-
-	setwakeuptime.Time = &efi_time;
-	status = ~0ULL;
-	setwakeuptime.status = &status;
-	setwakeuptime.Enabled = false;
-
-	ioret = ioctl(fd, EFI_RUNTIME_SET_WAKETIME, &setwakeuptime);
-	if (ioret == -1) {
-		if (status == EFI_UNSUPPORTED) {
-			if (runtimeservicessupported & EFI_RT_SUPPORTED_SET_WAKEUP_TIME) {
-				fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetWakeupTime",
-					"Get the SetWakeupTime runtime service supported "
-					"via RuntimeServicesSupported mask. "
-					"But actually is not supported by firmware");
-
-			} else {
-					fwts_passed(fw, "UEFI SetWakeupTime runtime service "
-						"supported status test passed.");
+	} else
+		fwts_skipped(fw, "SetTime runtime service supported, skip test.");
+
+	if (!(runtimeservicessupported & EFI_RT_SUPPORTED_SET_WAKEUP_TIME)) {
+		setwakeuptime.Time = &efi_time;
+		status = ~0ULL;
+		setwakeuptime.status = &status;
+		setwakeuptime.Enabled = false;
+
+		ioret = ioctl(fd, EFI_RUNTIME_SET_WAKETIME, &setwakeuptime);
+		if (ioret == -1) {
+			if (status == EFI_UNSUPPORTED)
+						fwts_passed(fw, "UEFI SetWakeupTime runtime service "
+							"unsupported status test passed.");
+			else {
+				if (status == ~0ULL)
+					fwts_skipped(fw, "Unknown error occurred, skip test.");
+				else
+					fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetWakeupTime",
+						"Get the SetWakeupTime runtime service unsupported "
+						"via RuntimeServicesSupported mask. "
+						"But actually is supported by firmware.");
 			}
 		} else {
-			if (status == ~0ULL) {
+			if (status != EFI_SUCCESS )
 				fwts_skipped(fw, "Unknown error occurred, skip test.");
-				return FWTS_SKIP;
-			}
-			if (runtimeservicessupported & EFI_RT_SUPPORTED_SET_WAKEUP_TIME) {
-				fwts_passed(fw, "UEFI SetWakeupTime runtime service "
-					"supported status test passed.");
-			} else {
+			else
 				fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetWakeupTime",
 					"Get the SetWakeupTime runtime service unsupported "
 					"via RuntimeServicesSupported mask. "
 					"But actually is supported by firmware.");
-			}
-		}
-	} else {
-		if (status != EFI_SUCCESS ) {
-			fwts_skipped(fw, "Unknown error occurred, skip test.");
-			return FWTS_SKIP;
-		}
-		if (runtimeservicessupported & EFI_RT_SUPPORTED_SET_WAKEUP_TIME) {
-			fwts_passed(fw, "UEFI SetWakeupTime runtime service "
-				"supported status test passed.");
-		} else {
-			fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetWakeupTime",
-				"Get the SetWakeupTime runtime service unsupported "
-				"via RuntimeServicesSupported mask. "
-				"But actually is supported by firmware.");
 		}
 	}
-
-	getwakeuptime.Enabled = &enabled;
-	getwakeuptime.Pending = &pending;
-	getwakeuptime.Time = &efi_time;
-	getwakeuptime.status = &status;
-
-	ioret = ioctl(fd, EFI_RUNTIME_GET_WAKETIME, &getwakeuptime);
-	if (ioret == -1) {
-		if (status == EFI_UNSUPPORTED) {
-			if (runtimeservicessupported & EFI_RT_SUPPORTED_GET_WAKEUP_TIME) {
-				fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetWakeupTime",
-					"Get the GetWakeupTime runtime service supported "
-					"via RuntimeServicesSupported mask. "
-					"But actually is not supported by firmware");
-			} else {
-				fwts_passed(fw, "UEFI GetWakeupTime runtime service "
-					"supported status test passed.");
+	else
+		fwts_skipped(fw, "SetWakeupTime runtime service supported, skip test.");
+
+	if (!(runtimeservicessupported & EFI_RT_SUPPORTED_GET_WAKEUP_TIME)) {
+		getwakeuptime.Enabled = &enabled;
+		getwakeuptime.Pending = &pending;
+		getwakeuptime.Time = &efi_time;
+		getwakeuptime.status = &status;
+
+		ioret = ioctl(fd, EFI_RUNTIME_GET_WAKETIME, &getwakeuptime);
+		if (ioret == -1) {
+			if (status == EFI_UNSUPPORTED)
+					fwts_passed(fw, "UEFI GetWakeupTime runtime service "
+						"unsupported status test passed.");
+			else {
+				if (status == ~0ULL)
+					fwts_skipped(fw, "Unknown error occurred, skip test.");
+				else
+					fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetWakeupTime",
+						"Get the GetWakeupTime runtime service unsupported "
+						"via RuntimeServicesSupported mask. "
+						"But actually is supported by firmware");
 			}
 		} else {
-			if (status == ~0ULL) {
+			if (status != EFI_SUCCESS )
 				fwts_skipped(fw, "Unknown error occurred, skip test.");
-				return FWTS_SKIP;
-			}
-			if (runtimeservicessupported & EFI_RT_SUPPORTED_GET_WAKEUP_TIME) {
-				fwts_passed(fw, "UEFI GetWakeupTime runtime service "
-					"supported status test passed.");
-			} else {
+			else
 				fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetWakeupTime",
 					"Get the GetWakeupTime runtime service unsupported "
 					"via RuntimeServicesSupported mask. "
 					"But actually is supported by firmware");
-			}
-		}
-	} else {
-		if (status != EFI_SUCCESS ){
-			fwts_skipped(fw, "Unknown error occurred, skip test.");
-			return FWTS_SKIP;
 		}
-		if (runtimeservicessupported & EFI_RT_SUPPORTED_GET_WAKEUP_TIME) {
-			fwts_passed(fw, "UEFI GetWakeupTime runtime service "
-				"supported status test passed.");
-		} else {
-			fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetWakeupTime",
-				"Get the GetWakeupTime runtime service unsupported "
-				"via RuntimeServicesSupported mask. "
-				"But actually is supported by firmware");
-		}
-	}
+	} else
+		fwts_skipped(fw, "GetWakeupTime runtime service supported, skip test.");
 
 	return FWTS_OK;
 }
@@ -1404,7 +1334,7 @@  static fwts_framework_minor_test uefirttime_tests[] = {
 #if UEFI_IGNORE_UNSET_BITS
 	{ uefirttime_test37, "Test UEFI RT service set wakeup time interface, invalid daylight 0xfc." },
 #endif
-	{ uefirttime_test38, "Test UEFI RT time services supported status." },
+	{ uefirttime_test38, "Test UEFI RT time services unsupported status." },
 	{ NULL, NULL }
 };