-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
221 additions
and
0 deletions.
There are no files selected for viewing
187 changes: 187 additions & 0 deletions
187
...rary/ConfigKnobShimLib/ConfigKnobShimPeiLib/GoogleTest/ConfigKnobShimPeiLibGoogleTest.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
/** @file ConfigKnobShimPeiLibGoogleTest.cpp | ||
This is a sample to demonstrates the use of GoogleTest that supports host | ||
execution environments. | ||
Copyright (c) Microsoft Corporation. | ||
SPDX-License-Identifier: BSD-2-Clause-Patent | ||
**/ | ||
|
||
#include <Library/GoogleTestLib.h> | ||
#include <GoogleTest/Library/MockUefiRuntimeServicesTableLib.h> | ||
extern "C" { | ||
#include <Uefi.h> | ||
#include <Library/BaseLib.h> | ||
#include <Library/DebugLib.h> | ||
|
||
#include "../../ConfigKnobShimLibCommon.c" // include the c file to be able to unit test static function | ||
} | ||
|
||
#define CONFIG_KNOB_GUID {0x52d39693, 0x4f64, 0x4ee6, {0x81, 0xde, 0x45, 0x89, 0x37, 0x72, 0x78, 0x55}} | ||
|
||
using namespace testing; | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
class GetConfigKnobOverrideFromVariableStorageTest : public Test | ||
{ | ||
protected: | ||
MockPeiServicesLib PeiServicesMock; | ||
MockReadOnlyVariable2 PpiVariableServicesMock; // mock of EFI_PEI_READ_ONLY_VARIABLE2_PPI | ||
PPI_STATUS PpiStatus; | ||
EFI_STATUS Status; | ||
EFI_GUID ConfigKnobGuid; | ||
CHAR16 *ConfigKnobName; | ||
UINT64 ProfileDefaultValue; | ||
UINTN ProfileDefaultSize; | ||
UINT64 VariableData; | ||
UINT64 ConfigKnobData; | ||
|
||
// | ||
// Redefining the Test class's SetUp function for test fixtures. | ||
// | ||
void | ||
SetUp ( | ||
) override | ||
{ | ||
ConfigKnobGuid = CONFIG_KNOB_GUID; | ||
ConfigKnobName = (CHAR16 *)L"MyDeadBeefDelivery"; | ||
ProfileDefaultValue = 0xDEADBEEFDEADBEEF; | ||
ProfileDefaultSize = sizeof (ProfileDefaultValue); | ||
VariableData = 0xBEEF7777BEEF7777; | ||
ConfigKnobData = ProfileDefaultValue; | ||
PpiStatus = { .Ppi = &peiReadOnlyVariablePpi, .Status = EFI_SUCCESS }; | ||
PPIActual = (VOID **)&PPIVariableServices; | ||
|
||
} | ||
}; | ||
|
||
// | ||
// Fail to find a cached config knob policy and fail to fetch config knob from | ||
// variable storage. Then, set the profile default value. | ||
// | ||
TEST_F (GetConfigKnobOverrideFromVariableStorageTest, VariableStorageSmallBufferFailure) { | ||
// | ||
// expect the call to locate PPI to return success, "found" PPIVariableServices | ||
// | ||
EXPECT_CALL ( | ||
PeiServicesMock, | ||
PeiServicesLocatePpi () | ||
) | ||
.WillByDefault ( | ||
Return (EFI_SUCCESS) | ||
); | ||
|
||
// | ||
// expect the call to GetVariable | ||
// | ||
EXPECT_CALL( | ||
PpiVariableServicesMock, | ||
pei_GetVariable () | ||
) | ||
.WillOnce( | ||
DoAll ( | ||
SetArgPointee<4>(sizeof (VariableData)), | ||
SetArgBuffer<5>(&VariableData, sizeof (VariableData)), | ||
Return (EFI_SUCCESS) | ||
) | ||
); | ||
|
||
Status = GetConfigKnobOverride (&ConfigKnobGuid, ConfigKnobName, (VOID *)&ConfigKnobData, ProfileDefaultSize); | ||
|
||
ASSERT_EQ (Status, EFI_NOT_FOUND); | ||
ASSERT_EQ (ConfigKnobData, ProfileDefaultValue); | ||
} | ||
|
||
// | ||
// With no cached config knob policy, successfully fetch config knob from | ||
// variable storage. Then, create cached policy. | ||
// | ||
TEST_F (GetConfigKnobOverrideFromVariableStorageTest, VariableStorageSuccess) { | ||
// | ||
// expect the call to locate PPI to return success, "found" PPIVariableServices | ||
// | ||
EXPECT_CALL ( | ||
PeiServicesMock, | ||
PeiServicesLocatePpi () | ||
) | ||
.WillByDefault ( | ||
DoAll( | ||
Return (EFI_SUCCESS) | ||
) | ||
); | ||
|
||
// | ||
// expect the call to GetVaraible | ||
// | ||
EXPECT_CALL( | ||
PpiVariableServicesMock, | ||
pei_GetVariable () | ||
) | ||
.WillOnce( | ||
DoAll ( | ||
SetArgPointee<4>(sizeof (VariableData)), | ||
SetArgBuffer<5>(&VariableData, sizeof (VariableData)), | ||
Return (EFI_SUCCESS) | ||
) | ||
); | ||
Status = GetConfigKnobOverride (&ConfigKnobGuid, ConfigKnobName, (VOID *)&ConfigKnobData, ProfileDefaultSize); | ||
|
||
ASSERT_EQ (Status, EFI_SUCCESS); | ||
ASSERT_EQ (VariableData, ConfigKnobData); | ||
} | ||
|
||
// | ||
// Fail to find a cached config knob policy and fail to fetch config knob from | ||
// variable storage. Then, set the profile default value. | ||
// | ||
TEST_F (GetConfigKnobOverrideFromVariableStorageTest, VariableStorageNotFoundFailure) { | ||
// | ||
// Expect the first GetVariable call to get size to fail | ||
// | ||
EXPECT_CALL ( | ||
PeiServicesMock, | ||
PeiServicesLocatePpi | ||
) | ||
.WillOnce ( | ||
Return (EFI_NOT_FOUND) | ||
); | ||
|
||
Status = GetConfigKnobOverride (&ConfigKnobGuid, ConfigKnobName, (VOID *)&ConfigKnobData, ProfileDefaultSize); | ||
|
||
ASSERT_EQ (Status, EFI_NOT_FOUND); | ||
ASSERT_EQ (ConfigKnobData, ProfileDefaultValue); | ||
} | ||
|
||
/* | ||
Fail to find a cached config knob policy and succeed to fetch config knob from | ||
variable storage. Fail to match variable size with profile default size. Then, set the profile default value. | ||
*/ | ||
TEST_F (GetConfigKnobOverrideFromVariableStorageTest, VariableStorageSizeFailure) { | ||
// | ||
// Expect the first GetVariable call to get (non-matching) size | ||
// | ||
EXPECT_CALL ( | ||
PeiServicesMock, | ||
PeiServicesLocatePpi | ||
) | ||
.WillOnce ( | ||
DoAll ( | ||
SetArgPointee<3>(sizeof (UINT32)), | ||
Return (EFI_BUFFER_TOO_SMALL) | ||
) | ||
); | ||
|
||
Status = GetConfigKnobOverride (&ConfigKnobGuid, ConfigKnobName, (VOID *)&ConfigKnobData, ProfileDefaultSize); | ||
ASSERT_EQ (Status, EFI_BAD_BUFFER_SIZE); | ||
ASSERT_EQ (ConfigKnobData, ProfileDefaultValue); | ||
} | ||
|
||
int | ||
main ( | ||
int argc, | ||
char *argv[] | ||
) | ||
{ | ||
InitGoogleTest (&argc, argv); | ||
return RUN_ALL_TESTS (); | ||
} |
34 changes: 34 additions & 0 deletions
34
...rary/ConfigKnobShimLib/ConfigKnobShimPeiLib/GoogleTest/ConfigKnobShimPeiLibGoogleTest.inf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
## @file | ||
# Unit test suite for the ConfigKnobShimPeiLib using Google Test | ||
# | ||
# Copyright (c) 2022, Intel Corporation. All rights reserved. | ||
# SPDX-License-Identifier: BSD-2-Clause-Patent | ||
## | ||
|
||
[Defines] | ||
INF_VERSION = 0x00010017 | ||
BASE_NAME = ConfigKnobShimPeiLibGoogleTest | ||
FILE_GUID = 3A2B1C8E-FFE2-4EA2-A003-BABCBCB85940 | ||
VERSION_STRING = 1.0 | ||
MODULE_TYPE = HOST_APPLICATION | ||
|
||
# | ||
# The following information is for reference only and not required by the build tools. | ||
# | ||
# VALID_ARCHITECTURES = IA32 X64 | ||
# | ||
|
||
[Sources] | ||
ConfigKnobShimPeiLibGoogleTest.cpp | ||
|
||
[Packages] | ||
MdePkg/MdePkg.dec | ||
SetupDataPkg/SetupDataPkg.dec | ||
UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec | ||
|
||
[LibraryClasses] | ||
GoogleTestLib | ||
BaseLib | ||
DebugLib | ||
ConfigKnobShimLib | ||
|