From patchwork Thu Nov 8 06:11:50 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Hu X-Patchwork-Id: 197778 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from chlorine.canonical.com (chlorine.canonical.com [91.189.94.204]) by ozlabs.org (Postfix) with ESMTP id 8EF8E2C0097 for ; Thu, 8 Nov 2012 17:11:59 +1100 (EST) Received: from localhost ([127.0.0.1] helo=chlorine.canonical.com) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1TWLLK-0007sR-Co; Thu, 08 Nov 2012 06:11:58 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1TWLLI-0007sM-4l for fwts-devel@lists.ubuntu.com; Thu, 08 Nov 2012 06:11:56 +0000 Received: from [175.41.48.77] (helo=canonical.com) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1TWLLH-0002V3-5H; Thu, 08 Nov 2012 06:11:56 +0000 From: Ivan Hu To: fwts-devel@lists.ubuntu.com Subject: [PATCH 2/2] uefirttime: add the fwts test for the UEFI set wakeup time runtime service Date: Thu, 8 Nov 2012 14:11:50 +0800 Message-Id: <1352355110-6971-1-git-send-email-ivan.hu@canonical.com> X-Mailer: git-send-email 1.7.10.4 X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.13 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: fwts-devel-bounces@lists.ubuntu.com Errors-To: fwts-devel-bounces@lists.ubuntu.com Add the fwts test which sets wakeup time using the UEFI runtime service interfaces via efi_runtime driver. Signed-off-by: Ivan Hu Acked-by: Colin Ian King Acked-by: Alex Hung --- src/uefi/uefirttime/uefirttime.c | 130 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/src/uefi/uefirttime/uefirttime.c b/src/uefi/uefirttime/uefirttime.c index 280e48e..e557619 100644 --- a/src/uefi/uefirttime/uefirttime.c +++ b/src/uefi/uefirttime/uefirttime.c @@ -137,6 +137,32 @@ static bool checktimefields(fwts_framework *fw, EFI_TIME *Time) return true; } + +static void addonehour(EFI_TIME *time) +{ + if (time->Hour != 23) { + time->Hour += 1; + return; + } + time->Hour = 0; + + if ((time->Day != dayofmonth[time->Month - 1]) && + (!(time->Month == 2 && (!IS_LEAP(time->Year) + && time->Day == 28)))) { + time->Day += 1; + return; + } + time->Day = 1; + + if (time->Month != 12) { + time->Month += 1; + return; + } + time->Month = 1; + time->Year += 1; + return; +} + static int uefirttime_init(fwts_framework *fw) { if (fwts_firmware_detect() != FWTS_FIRMWARE_UEFI) { @@ -341,10 +367,114 @@ static int uefirttime_test3(fwts_framework *fw) return FWTS_OK; } +static int uefirttime_test4(fwts_framework *fw) +{ + + long ioret; + struct efi_setwakeuptime setwakeuptime; + uint64_t status; + EFI_TIME oldtime; + EFI_TIME newtime; + + struct efi_gettime gettime; + EFI_TIME_CAPABILITIES efi_time_cap; + + struct efi_getwakeuptime getwakeuptime; + uint8_t enabled, pending; + + gettime.Capabilities = &efi_time_cap; + gettime.Time = &oldtime; + gettime.status = &status; + + ioret = ioctl(fd, EFI_RUNTIME_GET_TIME, &gettime); + + if (ioret == -1) { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetTime", + "Failed to get time with UEFI runtime service."); + return FWTS_ERROR; + } + + /* change the hour, add 1 hour*/ + addonehour(&oldtime); + + setwakeuptime.Time = &oldtime; + setwakeuptime.status = &status; + setwakeuptime.Enabled = true; + + ioret = ioctl(fd, EFI_RUNTIME_SET_WAKETIME, &setwakeuptime); + if (ioret == -1) { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetWakeupTime", + "Failed to set wakeup time with UEFI runtime service."); + return FWTS_ERROR; + } + + sleep(1); + + getwakeuptime.Enabled = &enabled; + getwakeuptime.Pending = &pending; + getwakeuptime.Time = &newtime; + getwakeuptime.status = &status; + + ioret = ioctl(fd, EFI_RUNTIME_GET_WAKETIME, &getwakeuptime); + if (ioret == -1) { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetWakeupTime", + "Failed to get wakeup time with UEFI runtime service."); + return FWTS_ERROR; + } + + if (*getwakeuptime.Enabled != true) { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetWakeupTimeEnable", + "Failed to set wakeup alarm clock, wakeup timer should be enabled."); + return FWTS_ERROR; + } + + if (*getwakeuptime.Pending != false) { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetWakeupTimePending", + "Get error alarm signle status."); + return FWTS_ERROR; + } + + if ((oldtime.Year != newtime.Year) || (oldtime.Month != newtime.Month) || + (oldtime.Day != newtime.Day) || (oldtime.Hour != newtime.Hour)) { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetWakeupTimeVerify", + "Failed to verify wakeup time after change."); + return FWTS_ERROR; + } + + setwakeuptime.Enabled = false; + + ioret = ioctl(fd, EFI_RUNTIME_SET_WAKETIME, &setwakeuptime); + if (ioret == -1) { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetWakeupTime", + "Failed to set wakeup time with UEFI runtime service."); + return FWTS_ERROR; + } + + sleep(1); + + ioret = ioctl(fd, EFI_RUNTIME_GET_WAKETIME, &getwakeuptime); + if (ioret == -1) { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetWakeupTime", + "Failed to get wakeup time with UEFI runtime service."); + return FWTS_ERROR; + } + + if (*getwakeuptime.Enabled != false) { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetWakeupTimeEnable", + "Failed to set wakeup alarm clock, wakeup timer should be disabled."); + return FWTS_ERROR; + } + + fwts_passed(fw, "UEFI runtime service SetWakeupTime interface test passed."); + + return FWTS_OK; +} + static fwts_framework_minor_test uefirttime_tests[] = { { uefirttime_test1, "Test UEFI RT service get time interface." }, { uefirttime_test2, "Test UEFI RT service set time interface." }, { uefirttime_test3, "Test UEFI RT service get wakeup time interface." }, + { uefirttime_test4, "Test UEFI RT service set wakeup time interface." }, { NULL, NULL } };