From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.151; helo=mga17.intel.com; envelope-from=eric.jin@intel.com; receiver=edk2-devel@lists.01.org Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 28B9B21168201 for ; Thu, 11 Oct 2018 22:22:29 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Oct 2018 22:22:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,371,1534834800"; d="scan'208";a="271748113" Received: from shwdeopenpsi175.ccr.corp.intel.com ([10.239.9.140]) by fmsmga006.fm.intel.com with ESMTP; 11 Oct 2018 22:22:28 -0700 From: Eric Jin To: edk2-devel@lists.01.org Cc: Supreeth Venkatesh , Jiaxin Wu Date: Fri, 12 Oct 2018 13:22:24 +0800 Message-Id: <20181012052224.12860-1-eric.jin@intel.com> X-Mailer: git-send-email 2.9.0.windows.1 Subject: [edk2-test][Patch] uefi-sct\SctPkg:Add two checkpoints of GetNextVariable() X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Oct 2018 05:22:30 -0000 If a VariableName buffer on input is not a Null-terminated string, EFI_INVALID_PARAMETER is returned. If input values of VariableName and VendorGuid are not a name and GUID of an existing variable, EFI_INVALID_PARAMETER is returned. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Eric Jin Cc: Supreeth Venkatesh Cc: Jiaxin Wu --- .../VariableServicesBBTestConformance.c | 388 ++++++++++++++++++++- 1 file changed, 387 insertions(+), 1 deletion(-) diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/VariableServices/BlackBoxTest/VariableServicesBBTestConformance.c b/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/VariableServices/BlackBoxTest/VariableServicesBBTestConformance.c index 46dcc72..e2182c5 100644 --- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/VariableServices/BlackBoxTest/VariableServicesBBTestConformance.c +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/RuntimeServices/VariableServices/BlackBoxTest/VariableServicesBBTestConformance.c @@ -1,7 +1,7 @@ /** @file Copyright 2006 - 2016 Unified EFI, Inc.
- Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License @@ -148,6 +148,20 @@ GetNextVariableNameConfTestSub5 ( ); EFI_STATUS +GetNextVariableNameConfTestSub6 ( + IN EFI_RUNTIME_SERVICES *RT, + IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib, + IN EFI_TEST_LOGGING_LIBRARY_PROTOCOL *LoggingLib + ); + +EFI_STATUS +GetNextVariableNameConfTestSub7 ( + IN EFI_RUNTIME_SERVICES *RT, + IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib, + IN EFI_TEST_LOGGING_LIBRARY_PROTOCOL *LoggingLib + ); + +EFI_STATUS SetVariableConfTestSub1 ( IN EFI_RUNTIME_SERVICES *RT, IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib, @@ -393,6 +407,15 @@ GetNextVariableNameConfTest ( Status = GetNextVariableNameConfTestSub5 (RT, StandardLib, LoggingLib); // + // GetNextVariableName when a VariableName buffer on input is not a Null-terminated string + // + Status = GetNextVariableNameConfTestSub6 (RT, StandardLib, LoggingLib); + + // + // GetNextVariableName when input values of VariableName and VendorGuid are not a name and GUID of an existing variable + // + Status = GetNextVariableNameConfTestSub7 (RT, StandardLib, LoggingLib); + // // Done // return EFI_SUCCESS; @@ -2035,6 +2058,369 @@ GetNextVariableNameConfTestSub5 ( /** + * GetNextVariableName when a VariableName buffer on input is not a Null-terminated string. + * @param StandardLib A pointer to EFI_STANDARD_TEST_LIBRARY_PROTOCOL + * instance. + * @param LoggingLib A pointer to EFI_TEST_LOGGING_LIBRARY_PROTOCOL + * instance. + * @return EFI_SUCCESS Successfully. + * @return Other value Something failed. + */ +EFI_STATUS +GetNextVariableNameConfTestSub6 ( + IN EFI_RUNTIME_SERVICES *RT, + IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib, + IN EFI_TEST_LOGGING_LIBRARY_PROTOCOL *LoggingLib + ) +{ + EFI_STATUS Status; + EFI_TEST_ASSERTION Result; + UINTN DataIndex; + UINT8 Data[MAX_BUFFER_SIZE]; + UINTN VariableNameSize; + CHAR16 VariableName[MAX_BUFFER_SIZE]; + EFI_GUID VendorGuid; + + // + // Trace ... + // + if (LoggingLib != NULL) { + LoggingLib->EnterFunction ( + LoggingLib, + L"GetNextVariableNameConfTestSub6", + L"TDS" + ); + } + + // + // Insert a variable + // + for (DataIndex = 0; DataIndex < 10; DataIndex++) { + Data[DataIndex] = (UINT8)DataIndex; + } + + Status = RT->SetVariable ( + L"TestVariable", // VariableName + &gTestVendor1Guid, // VendorGuid + EFI_VARIABLE_BOOTSERVICE_ACCESS, + 10, // DataSize + Data // Data + ); + if (EFI_ERROR(Status)) { + StandardLib->RecordAssertion ( + StandardLib, + EFI_TEST_ASSERTION_WARNING, + gTestGenericFailureGuid, + L"RT.GetNextVariableName - Cannot insert a variable", + L"%a:%d:Status - %r", + __FILE__, + (UINTN)__LINE__, + Status + ); + + if (LoggingLib != NULL) { + LoggingLib->ExitFunction ( + LoggingLib, + L"GetNextVariableNameConfTestSub6", + L"TDS - Cannot insert a variable" + ); + } + + return Status; + } + + // + // Walk through all variables + // + VariableName[0] = L'\0'; + VariableNameSize = MAX_BUFFER_SIZE * sizeof (CHAR16); + Result = EFI_TEST_ASSERTION_PASSED; + + while (TRUE) { + Status = RT->GetNextVariableName ( + &VariableNameSize, // VariableNameSize + VariableName, // VariableName + &VendorGuid // VendorGuid + ); + if (EFI_ERROR(Status)) { + if (Status != EFI_INVALID_PARAMETER) { + Result = EFI_TEST_ASSERTION_FAILED; + } + break; + } + + if ((SctStrCmp (VariableName, L"TestVariable") == 0) && + (SctCompareGuid (&VendorGuid, &gTestVendor1Guid) == 0)) { + VariableNameSize = 8; + } else { + VariableNameSize = MAX_BUFFER_SIZE * sizeof (CHAR16); + } + } + + // + // Record assertion + // + StandardLib->RecordAssertion ( + StandardLib, + Result, + gVariableServicesBbTestConformanceAssertionGuid019, + L"RT.GetNextVariableName - when a VariableName buffer on input is not a Null-terminated string", + L"%a:%d:Status - %r, Expected - %r", + __FILE__, + (UINTN)__LINE__, + Status, EFI_INVALID_PARAMETER + ); + + Status = RT->SetVariable ( + L"TestVariable", // VariableName + &gTestVendor1Guid, // VendorGuid + EFI_VARIABLE_BOOTSERVICE_ACCESS, + 0, // DataSize + Data // Data + ); + + if (EFI_ERROR(Status)) { + StandardLib->RecordAssertion ( + StandardLib, + EFI_TEST_ASSERTION_WARNING, + gTestGenericFailureGuid, + L"RT.GetNextVariableName - Cannot delete a variable", + L"%a:%d:Status - %r", + __FILE__, + (UINTN)__LINE__, + Status + ); + + if (LoggingLib != NULL) { + LoggingLib->ExitFunction ( + LoggingLib, + L"GetNextVariableNameConfTestSub6", + L"TDS - Cannot delete a variable" + ); + } + + return Status; + } + // + // Trace ... + // + if (LoggingLib != NULL) { + LoggingLib->ExitFunction ( + LoggingLib, + L"GetNextVariableNameConfTestSub6", + L"TDS" + ); + } + + // + // Done + // + return EFI_SUCCESS; +} + +/** + * GetNextVariableName when input values of VariableName and VendorGuid are not a name and GUID of an existing variable. + * @param StandardLib A pointer to EFI_STANDARD_TEST_LIBRARY_PROTOCOL + * instance. + * @param LoggingLib A pointer to EFI_TEST_LOGGING_LIBRARY_PROTOCOL + * instance. + * @return EFI_SUCCESS Successfully. + * @return Other value Something failed. + */ +EFI_STATUS +GetNextVariableNameConfTestSub7 ( + IN EFI_RUNTIME_SERVICES *RT, + IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib, + IN EFI_TEST_LOGGING_LIBRARY_PROTOCOL *LoggingLib + ) +{ + EFI_STATUS Status; + EFI_TEST_ASSERTION Result; + UINTN DataIndex; + UINT8 Data[MAX_BUFFER_SIZE]; + UINTN VariableNameSize; + CHAR16 VariableName[MAX_BUFFER_SIZE]; + EFI_GUID VendorGuid; + + // + // Trace ... + // + if (LoggingLib != NULL) { + LoggingLib->EnterFunction ( + LoggingLib, + L"GetNextVariableNameConfTestSub7", + L"TDS" + ); + } + + // + // Insert a variable + // + for (DataIndex = 0; DataIndex < 10; DataIndex++) { + Data[DataIndex] = (UINT8)DataIndex; + } + + Status = RT->SetVariable ( + L"TestVariable", // VariableName + &gTestVendor1Guid, // VendorGuid + EFI_VARIABLE_BOOTSERVICE_ACCESS, + 10, // DataSize + Data // Data + ); + if (EFI_ERROR(Status)) { + StandardLib->RecordAssertion ( + StandardLib, + EFI_TEST_ASSERTION_WARNING, + gTestGenericFailureGuid, + L"RT.GetNextVariableName - Cannot insert a variable", + L"%a:%d:Status - %r", + __FILE__, + (UINTN)__LINE__, + Status + ); + + if (LoggingLib != NULL) { + LoggingLib->ExitFunction ( + LoggingLib, + L"GetNextVariableNameConfTestSub7", + L"TDS - Cannot insert a variable" + ); + } + + return Status; + } + + // + // Walk through all variables + // + VariableName[0] = L'\0'; + + Result = EFI_TEST_ASSERTION_PASSED; + + while (TRUE) { + VariableNameSize = MAX_BUFFER_SIZE * sizeof (CHAR16); + Status = RT->GetNextVariableName ( + &VariableNameSize, // VariableNameSize + VariableName, // VariableName + &VendorGuid // VendorGuid + ); + if (EFI_ERROR(Status)) { + if (Status != EFI_INVALID_PARAMETER) { + Result = EFI_TEST_ASSERTION_FAILED; + } + break; + } + + if ((SctStrCmp (VariableName, L"TestVariable") == 0) && + (SctCompareGuid (&VendorGuid, &gTestVendor1Guid) == 0)) { + VariableName[8] = L'e'; + } + } + + // + // Record assertion + // + StandardLib->RecordAssertion ( + StandardLib, + Result, + gVariableServicesBbTestConformanceAssertionGuid020, + L"RT.GetNextVariableName - when input values of VariableName and VendorGuid are not a name and GUID of an existing variable", + L"%a:%d:Status - %r, Expected - %r", + __FILE__, + (UINTN)__LINE__, + Status, EFI_INVALID_PARAMETER + ); + + // + // Walk through all variables + // + VariableName[0] = L'\0'; + + Result = EFI_TEST_ASSERTION_PASSED; + + while (TRUE) { + VariableNameSize = MAX_BUFFER_SIZE * sizeof (CHAR16); + Status = RT->GetNextVariableName ( + &VariableNameSize, // VariableNameSize + VariableName, // VariableName + &VendorGuid // VendorGuid + ); + if (EFI_ERROR(Status)) { + if (Status != EFI_INVALID_PARAMETER) { + Result = EFI_TEST_ASSERTION_FAILED; + } + break; + } + + if ((SctStrCmp (VariableName, L"TestVariable") == 0) && + (SctCompareGuid (&VendorGuid, &gTestVendor1Guid) == 0)) { + VendorGuid = gTestVendor2Guid; + } + } + + // + // Record assertion + // + StandardLib->RecordAssertion ( + StandardLib, + Result, + gVariableServicesBbTestConformanceAssertionGuid020, + L"RT.GetNextVariableName - when input values of VariableName and VendorGuid are not a name and GUID of an existing variable", + L"%a:%d:Status - %r, Expected - %r", + __FILE__, + (UINTN)__LINE__, + Status, EFI_INVALID_PARAMETER + ); + + Status = RT->SetVariable ( + L"TestVariable", // VariableName + &gTestVendor1Guid, // VendorGuid + EFI_VARIABLE_BOOTSERVICE_ACCESS, + 0, // DataSize + Data // Data + ); + + if (EFI_ERROR(Status)) { + StandardLib->RecordAssertion ( + StandardLib, + EFI_TEST_ASSERTION_WARNING, + gTestGenericFailureGuid, + L"RT.GetNextVariableName - Cannot delete a variable", + L"%a:%d:Status - %r", + __FILE__, + (UINTN)__LINE__, + Status + ); + + if (LoggingLib != NULL) { + LoggingLib->ExitFunction ( + LoggingLib, + L"GetNextVariableNameConfTestSub6", + L"TDS - Cannot delete a variable" + ); + } + + return Status; + } + // + // Trace ... + // + if (LoggingLib != NULL) { + LoggingLib->ExitFunction ( + LoggingLib, + L"GetNextVariableNameConfTestSub6", + L"TDS" + ); + } + + // + // Done + // + return EFI_SUCCESS; +} + + +/** * SetVariable when VariableName is an empty string. * @param StandardLib A pointer to EFI_STANDARD_TEST_LIBRARY_PROTOCOL * instance. -- 2.9.0.windows.1