ACK: [PATCH 1/2] fwts: wakealarm: reset wakealarm timer at end of test (LP: #1534003)

Alex Hung alex.hung at canonical.com
Mon Jan 18 07:02:11 UTC 2016


On 2016-01-14 07:15 PM, Colin King wrote:
> From: Colin Ian King <colin.king at canonical.com>
>
> The wakealarm test is setting the wakealarm timer but does not
> restore it to the original state once the test is complete. This
> fix saves the RTC wakealarm state and restores it again. I've added
> a 5th test that does the restore and sanity checks this just to do
> the job properly.
>
> Signed-off-by: Colin Ian King <colin.king at canonical.com>
> ---
>   src/acpi/wakealarm/wakealarm.c   | 49 +++++++++++++++++++++++++++++++++++++---
>   src/lib/include/fwts_wakealarm.h |  4 ++++
>   src/lib/src/fwts_wakealarm.c     | 49 +++++++++++++++++++++++++++++++++-------
>   3 files changed, 91 insertions(+), 11 deletions(-)
>
> diff --git a/src/acpi/wakealarm/wakealarm.c b/src/acpi/wakealarm/wakealarm.c
> index 3dd656c..32bf3c4 100644
> --- a/src/acpi/wakealarm/wakealarm.c
> +++ b/src/acpi/wakealarm/wakealarm.c
> @@ -24,12 +24,15 @@
>   #include <sys/stat.h>
>   #include <unistd.h>
>   #include <string.h>
> +#include <linux/rtc.h>
> +
> +static struct rtc_time rtc_tm;
>
>   static int wakealarm_test1(fwts_framework *fw)
>   {
> -	if (fwts_wakealarm_exits(fw) == FWTS_OK)
> +	if (fwts_wakealarm_get(fw, &rtc_tm) == FWTS_OK) {
>   		fwts_passed(fw, "RTC with a RTC alarm ioctl() interface found.");
> -	else {
> +	} else {
>   		fwts_failed(fw, LOG_LEVEL_MEDIUM, "NoWakeAlarmTest1",
>   			"Could not find an RTC with an alarm ioctl() interface.");
>   #ifdef FWTS_ARCH_INTEL
> @@ -46,7 +49,6 @@ static int wakealarm_test1(fwts_framework *fw)
>   #endif
>   		return FWTS_ABORTED;
>   	}
> -
>   	return FWTS_OK;
>   }
>
> @@ -114,11 +116,52 @@ static int wakealarm_test4(fwts_framework *fw)
>   	return FWTS_OK;
>   }
>
> +static int wakealarm_test5(fwts_framework *fw)
> +{
> +	struct rtc_time rtc_now;
> +
> +	if (fwts_wakealarm_set(fw, &rtc_tm) == FWTS_OK) {
> +		fwts_passed(fw, "RTC wakealarm set.");
> +	} else {
> +		fwts_failed(fw, LOG_LEVEL_MEDIUM,
> +			"WakeAlarmNotResetTest5",
> +			"RTC wakealarm failed to be reset back to original state.");
> +		return FWTS_ERROR;
> +	}
> +
> +	if (fwts_wakealarm_get(fw, &rtc_now) == FWTS_OK) {
> +		if (rtc_now.tm_year == rtc_tm.tm_year &&
> +		    rtc_now.tm_mon  == rtc_tm.tm_mon &&
> +		    rtc_now.tm_mday == rtc_tm.tm_mday &&
> +		    rtc_now.tm_hour == rtc_tm.tm_hour &&
> +		    rtc_now.tm_min  == rtc_tm.tm_min &&
> +		    rtc_now.tm_sec  == rtc_tm.tm_sec) {
> +			fwts_passed(fw, "RTC wakealarm reset correctly back to "
> +				"%d/%d/%d %2.2d:%2.2d:%2.2d.",
> +					rtc_tm.tm_mday, rtc_tm.tm_mon + 1,
> +					rtc_tm.tm_year + 1900, rtc_tm.tm_hour,
> +					rtc_tm.tm_min, rtc_tm.tm_sec);
> +		} else {
> +			fwts_failed(fw, LOG_LEVEL_MEDIUM,
> +				"WakeAlarmNotResetTest5",
> +				"RTC wakealarm failed to be reset back to original time.");
> +			return FWTS_ERROR;
> +		}
> +	} else {
> +		fwts_failed(fw, LOG_LEVEL_MEDIUM,
> +			"WakeAlarmNotReadTest5",
> +			"RTC wakealarm failed to be read to verify original time.");
> +		return FWTS_ERROR;
> +	}
> +	return FWTS_OK;
> +}
> +
>   static fwts_framework_minor_test wakealarm_tests[] = {
>   	{ wakealarm_test1, "Test existence of RTC with alarm interface." },
>   	{ wakealarm_test2, "Trigger wakealarm for 1 seconds in the future." },
>   	{ wakealarm_test3, "Test if wakealarm is fired." },
>   	{ wakealarm_test4, "Multiple wakealarm firing tests." },
> +	{ wakealarm_test5, "Reset wakealarm time." },
>   	{ NULL, NULL }
>   };
>
> diff --git a/src/lib/include/fwts_wakealarm.h b/src/lib/include/fwts_wakealarm.h
> index 149aa89..f4cd20a 100644
> --- a/src/lib/include/fwts_wakealarm.h
> +++ b/src/lib/include/fwts_wakealarm.h
> @@ -20,11 +20,15 @@
>   #ifndef __FWTS_WAKEALARM_H__
>   #define __FWTS_WAKEALARM_H__
>
> +#include <linux/rtc.h>
> +
>   #include "fwts_framework.h"
>
>   int fwts_wakealarm_exits(fwts_framework *fw);
>   int fwts_wakealarm_test_firing(fwts_framework *fw, const int sleep);
>   int fwts_wakealarm_trigger(fwts_framework *fw, const int seconds);
>   int fwts_wakealarm_cancel(fwts_framework *fw);
> +int fwts_wakealarm_get(fwts_framework *fw, struct rtc_time *rtc_tm);
> +int fwts_wakealarm_set(fwts_framework *fw, struct rtc_time *rtc_tm);
>
>   #endif
> diff --git a/src/lib/src/fwts_wakealarm.c b/src/lib/src/fwts_wakealarm.c
> index 002293e..13f998a 100644
> --- a/src/lib/src/fwts_wakealarm.c
> +++ b/src/lib/src/fwts_wakealarm.c
> @@ -30,25 +30,47 @@
>
>   #include "fwts.h"
>
> -static char *fwts_rtc = "/dev/rtc0";
> +static const char *fwts_rtc = "/dev/rtc0";
>
>   /*
> - *  fwts_wakealarm_exits()
> - *	check that a RTC exists that supports minimal RTC alarm ioctl
> + *  fwts_wakealarm_get()
> + *	get wakealarm
>    */
> -int fwts_wakealarm_exits(fwts_framework *fw)
> +int fwts_wakealarm_get(fwts_framework *fw, struct rtc_time *rtc_tm)
>   {
>   	int fd;
>   	int ret = FWTS_OK;
> -	struct rtc_time rtc_tm;
>
>   	if ((fd = open(fwts_rtc, O_RDWR)) < 0) {
>   		fwts_log_error(fw, "Cannot access Real Time Clock device %s.", fwts_rtc);
>   		return FWTS_ERROR;
>   	}
>
> -	if (ioctl(fd, RTC_ALM_READ, &rtc_tm) < 0) {
> -		fwts_log_error(fw, "Cannot read Real Time Clock with ioctl RTC_RD_TIME %s.", fwts_rtc);
> +	if (ioctl(fd, RTC_ALM_READ, rtc_tm) < 0) {
> +		fwts_log_error(fw, "Cannot read Real Time Clock Alarm with ioctl RTC_ALM_READ %s.", fwts_rtc);
> +		ret = FWTS_ERROR;
> +	}
> +	(void)close(fd);
> +
> +	return ret;
> +}
> +
> +/*
> + *  fwts_wakealarm_set()
> + *	set wakealarm
> + */
> +int fwts_wakealarm_set(fwts_framework *fw, struct rtc_time *rtc_tm)
> +{
> +	int fd;
> +	int ret = FWTS_OK;
> +
> +	if ((fd = open(fwts_rtc, O_RDWR)) < 0) {
> +		fwts_log_error(fw, "Cannot access Real Time Clock device %s.", fwts_rtc);
> +		return FWTS_ERROR;
> +	}
> +
> +	if (ioctl(fd, RTC_ALM_SET, rtc_tm) < 0) {
> +		fwts_log_error(fw, "Cannot set Real Time Clock Alarm with ioctl RTC_ALM_SET %s.", fwts_rtc);
>   		ret = FWTS_ERROR;
>   	}
>   	(void)close(fd);
> @@ -57,6 +79,17 @@ int fwts_wakealarm_exits(fwts_framework *fw)
>   }
>
>   /*
> + *  fwts_wakealarm_exits()
> + *	check that a RTC exists that supports minimal RTC alarm ioctl
> + */
> +int fwts_wakealarm_exits(fwts_framework *fw)
> +{
> +	struct rtc_time rtc_tm;
> +
> +	return fwts_wakealarm_get(fw, &rtc_tm);
> +}
> +
> +/*
>    *  fwts_wakealarm_trigger()
>    *	trigger the RTC wakealarm to fire in 'seconds' seconds from now.
>    */
> @@ -116,7 +149,7 @@ int fwts_wakealarm_cancel(fwts_framework *fw)
>   	}
>
>   	if (ioctl(fd, RTC_AIE_OFF, 0) < 0) {
> -		fwts_log_error(fw, "Cannot read Real Time Clock with ioctl RTC_RD_TIME %s.", fwts_rtc);
> +		fwts_log_error(fw, "Cannot cancel Real Time Clock Alarm with ioctl RTC_AIE_OFF %s.", fwts_rtc);
>   		ret = FWTS_ERROR;
>   	}
>   	(void)close(fd);
>

Acked-by: Alex Hung <alex.hung at canonical.com>



More information about the fwts-devel mailing list