From patchwork Fri Nov 30 08:40:44 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Hu X-Patchwork-Id: 202889 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 8FFB82C0093 for ; Fri, 30 Nov 2012 19:40:54 +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 1TeM9U-0002Hp-DA; Fri, 30 Nov 2012 08:40:52 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1TeM9R-0002Gf-Qg for fwts-devel@lists.ubuntu.com; Fri, 30 Nov 2012 08:40:49 +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 1TeM9Q-00020R-Ir; Fri, 30 Nov 2012 08:40:49 +0000 From: Ivan Hu To: fwts-devel@lists.ubuntu.com Subject: [PATCH] uefirtvariable: Add new test for UEFI runtime GetNextVariableName Date: Fri, 30 Nov 2012 16:40:44 +0800 Message-Id: <1354264844-3897-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 This tests the UEFI runtime service GetNextVariableName interface by checking the variable name and GUID. Signed-off-by: Ivan Hu --- src/uefi/uefirtvariable/uefirtvariable.c | 139 +++++++++++++++++++++++++++++- 1 file changed, 138 insertions(+), 1 deletion(-) diff --git a/src/uefi/uefirtvariable/uefirtvariable.c b/src/uefi/uefirtvariable/uefirtvariable.c index 659c1d2..71346ee 100644 --- a/src/uefi/uefirtvariable/uefirtvariable.c +++ b/src/uefi/uefirtvariable/uefirtvariable.c @@ -35,6 +35,7 @@ } #define EFI_SUCCESS 0 +#define EFI_NOT_FOUND (14 | (1UL << 63)) #define MAX_DATA_LEMGTH 1024 @@ -133,7 +134,7 @@ static int getvariable_test(fwts_framework *fw, uint32_t attributes, uint64_t da fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetVariableAttributes", "Failed to get variable with right attributes, " "attributes we got is %" PRIu32 - ", but it should be %" PRIu32".", + ", but it should be %" PRIu32 ".", *getvariable.Attributes, attributes); return FWTS_ERROR; } else if (*getvariable.DataSize != datasize) { @@ -164,6 +165,127 @@ static int getvariable_test(fwts_framework *fw, uint32_t attributes, uint64_t da return FWTS_OK; } + +static bool compare_guid(EFI_GUID *guid1, EFI_GUID *guid2) +{ + bool ident = true; + int i; + + if ((guid1->Data1 != guid2->Data1) || (guid1->Data2 != guid2->Data2) || (guid1->Data3 != guid2->Data3)) + ident = false; + else { + for (i = 0; i < 8; i++) { + if (guid1->Data4[i] != guid2->Data4[i]) + ident = false; + } + } + return ident; +} + +static bool compare_name(uint16_t *name1, uint16_t *name2) +{ + bool ident = true; + int i = 0; + + while (true) { + if ((name1[i] != name2[i])) { + ident = false; + break; + } else if (name1[i] == '\0') + break; + i++; + } + return ident; +} + +static int getnextvariable_test(fwts_framework *fw, uint32_t attributes) +{ + long ioret; + uint64_t status; + + struct efi_setvariable setvariable; + + uint64_t dataindex, datasize = 10; + uint8_t data[MAX_DATA_LEMGTH]; + + struct efi_getnextvariablename getnextvariablename; + uint64_t variablenamesize = MAX_DATA_LEMGTH; + uint16_t variablename[MAX_DATA_LEMGTH]; + EFI_GUID vendorguid; + bool found_name = false, found_guid = false; + + for (dataindex = 0; dataindex < datasize; dataindex++) + data[dataindex] = (uint8_t)dataindex; + + setvariable.VariableName = variablenametest; + setvariable.VendorGuid = >estguid1; + setvariable.Attributes = attributes; + setvariable.DataSize = datasize; + setvariable.Data = data; + setvariable.status = &status; + + ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable); + + if (ioret == -1) { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetVariable", + "Failed to set variable with UEFI runtime service."); + return FWTS_ERROR; + } + + getnextvariablename.VariableNameSize = &variablenamesize; + getnextvariablename.VariableName = variablename; + getnextvariablename.VendorGuid = &vendorguid; + getnextvariablename.status = &status; + + /* To start the search, need to pass a Null-terminated string in VariableName */ + variablename[0] = '\0'; + while (true) { + variablenamesize = MAX_DATA_LEMGTH; + ioret = ioctl(fd, EFI_RUNTIME_GET_NEXTVARIABLENAME, &getnextvariablename); + + if (ioret == -1) { + + /* no next variable was found*/ + if (*getnextvariablename.status == EFI_NOT_FOUND) + break; + + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetNextVariableName", + "Failed to get next variable name with UEFI runtime service."); + return FWTS_ERROR; + } + if (compare_name(getnextvariablename.VariableName, variablenametest)) + found_name = true; + if (compare_guid(getnextvariablename.VendorGuid, >estguid1)) + found_guid = true; + if (found_name && found_guid) + break; + }; + + if (!found_name) { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetNextVariableNameName", + "Failed to get next variable name with right name."); + return FWTS_ERROR; + } + if (!found_guid) { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetNextVariableNameGuid", + "Failed to get next variable name correct guid."); + return FWTS_ERROR; + } + + /* delete the variable */ + setvariable.DataSize = 0; + + ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable); + + if (ioret == -1) { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetVariable", + "Failed to set variable with UEFI runtime service."); + return FWTS_ERROR; + } + + return FWTS_OK; +} + static int uefirtvariable_test1(fwts_framework *fw) { uint64_t index; @@ -179,8 +301,23 @@ static int uefirtvariable_test1(fwts_framework *fw) return FWTS_OK; } +static int uefirtvariable_test2(fwts_framework *fw) +{ + uint64_t index; + + for (index = 0; index < (sizeof(attributesarray)/(sizeof attributesarray[0])); index++) { + if (getnextvariable_test(fw, attributesarray[index]) == FWTS_ERROR) + return FWTS_ERROR; + } + + fwts_passed(fw, "UEFI runtime service GetNextVariableName interface test passed."); + + return FWTS_OK; +} + static fwts_framework_minor_test uefirtvariable_tests[] = { { uefirtvariable_test1, "Test UEFI RT service get variable interface." }, + { uefirtvariable_test2, "Test UEFI RT service get next variable name interface." }, { NULL, NULL } };