public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-test][Patch] uefi-sct\SctPkg:Add two checkpoints of GetNextVariable()
@ 2018-10-12  5:22 Eric Jin
  2018-10-12  8:48 ` Supreeth Venkatesh
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Jin @ 2018-10-12  5:22 UTC (permalink / raw)
  To: edk2-devel; +Cc: Supreeth Venkatesh, Jiaxin Wu

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 <eric.jin@intel.com>
Cc: Supreeth Venkatesh <supreeth.venkatesh@arm.com>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
---
 .../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.<BR>
-  Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
 
   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



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-10-12  8:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-10-12  5:22 [edk2-test][Patch] uefi-sct\SctPkg:Add two checkpoints of GetNextVariable() Eric Jin
2018-10-12  8:48 ` Supreeth Venkatesh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox