-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/dev/202405' into adv_logger
- Loading branch information
Showing
3 changed files
with
251 additions
and
9 deletions.
There are no files selected for viewing
177 changes: 177 additions & 0 deletions
177
...oggerPkg/Library/AdvancedLoggerLib/PeiCore/GoogleTest/AdvancedLoggerPeiCoreGoogleTest.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,177 @@ | ||
/** @file AdvancedLoggerPeiCoreGoogleTest.cpp | ||
This file contains the unit tests for the Advanced Logger PEI Core Library. | ||
Copyright (c) Microsoft Corporation. | ||
SPDX-License-Identifier: BSD-2-Clause-Patent | ||
**/ | ||
|
||
#include <Library/GoogleTestLib.h> | ||
#include <Library/FunctionMockLib.h> | ||
#include <GoogleTest/Library/MockPeiServicesLib.h> | ||
#include <GoogleTest/Library/MockMemoryAllocationLib.h> | ||
#include <GoogleTest/Library/MockHobLib.h> | ||
#include <GoogleTest/Library/MockAdvancedLoggerHdwPortLib.h> | ||
#include <GoogleTest/Ppi/MockAdvancedLogger.h> | ||
|
||
extern "C" { | ||
#include <Uefi.h> | ||
#include <Library/BaseLib.h> | ||
#include <Library/DebugLib.h> | ||
#include <AdvancedLoggerInternal.h> | ||
#include <Protocol/AdvancedLogger.h> | ||
#include <Protocol/VariablePolicy.h> // to mock (MU_BASECORE MdeModulePkg) | ||
#include <AdvancedLoggerInternalProtocol.h> | ||
#include <Library/BaseMemoryLib.h> // to mock (MU_BASECORE MdePkg) | ||
#include <Library/PcdLib.h> // to mock (MU_BASECORE MdePkg) | ||
#include <Library/SynchronizationLib.h> // to mock (MU_BASECORE MdePkg) | ||
#include <Library/TimerLib.h> // to mock (MU_BASECORE MdePkg) | ||
#include <Library/VariablePolicyHelperLib.h> // to mock (MU_BASECORE MdeModulePkg) | ||
#include "../../AdvancedLoggerCommon.h" | ||
|
||
#include <Core/Pei/PeiMain.h> | ||
#include <Library/MmUnblockMemoryLib.h> | ||
#include <Library/PeiServicesTablePointerLib.h> // to mock (MU_BASECORE MdePkg) | ||
#include <Library/PrintLib.h> | ||
|
||
// Static function declaration | ||
BOOLEAN | ||
ValidateInfoBlock ( | ||
IN ADVANCED_LOGGER_INFO *LoggerInfo | ||
); | ||
} | ||
|
||
using namespace testing; | ||
|
||
/** | ||
Test class for AdvancedLoggerPeiCore | ||
**/ | ||
class AdvancedLoggerPeiCoreTest : public Test { | ||
protected: | ||
ADVANCED_LOGGER_INFO *mLoggerInfo; | ||
CHAR8 SourceBuf[4096]; | ||
UINTN DebugLevel; | ||
UINTN NumberOfBytes; | ||
EFI_HANDLE ImageHandle; | ||
EFI_SYSTEM_TABLE SystemTable; | ||
BOOLEAN status; | ||
ADVANCED_LOGGER_INFO testLoggerInfo; | ||
// StrictMock<MockHobLib> gHobLib; | ||
// StrictMock<MockAdvancedLoggerHdwPortLib> gALHdwPortLib; | ||
|
||
void | ||
SetUp ( | ||
) override | ||
{ | ||
mLoggerInfo = NULL; | ||
NumberOfBytes = sizeof (SourceBuf); | ||
DebugLevel = DEBUG_ERROR; | ||
ImageHandle = (EFI_HANDLE)0x12345678; | ||
testLoggerInfo.Signature = ADVANCED_LOGGER_SIGNATURE; | ||
testLoggerInfo.Version = ADVANCED_LOGGER_VERSION; | ||
testLoggerInfo.LogBufferOffset = (ALIGN_VALUE (sizeof (testLoggerInfo), 8)); | ||
testLoggerInfo.LogCurrentOffset = (ALIGN_VALUE (sizeof (testLoggerInfo), 8)); | ||
ZeroMem (SourceBuf, NumberOfBytes); | ||
CopyMem (SourceBuf, "MyUnitTest", 11); | ||
} | ||
}; | ||
|
||
// | ||
// Test ValidateInfoBlock | ||
// | ||
TEST_F (AdvancedLoggerPeiCoreTest, AdvLoggerValidateInfoBlock) { | ||
// NULL LoggerInfo | ||
status = ValidateInfoBlock (mLoggerInfo); | ||
EXPECT_EQ (status, FALSE); | ||
|
||
mLoggerInfo = &testLoggerInfo; | ||
|
||
// Success | ||
status = ValidateInfoBlock (mLoggerInfo); | ||
EXPECT_EQ (status, TRUE); | ||
|
||
// Invalid Signature | ||
mLoggerInfo->Signature = SIGNATURE_32 ('T', 'E', 'S', 'T'); | ||
status = ValidateInfoBlock (mLoggerInfo); | ||
EXPECT_EQ (status, FALSE); | ||
mLoggerInfo->Signature = ADVANCED_LOGGER_SIGNATURE; | ||
|
||
// Invalid Buffer Offset | ||
mLoggerInfo->LogBufferOffset = (UINT32)0; | ||
status = ValidateInfoBlock (mLoggerInfo); | ||
EXPECT_EQ (status, FALSE); | ||
mLoggerInfo->LogBufferOffset = (ALIGN_VALUE (sizeof (testLoggerInfo), 8)); | ||
|
||
// Invalid Current Offset | ||
mLoggerInfo->LogCurrentOffset = (UINT32)0; | ||
status = ValidateInfoBlock (mLoggerInfo); | ||
EXPECT_EQ (status, FALSE); | ||
} | ||
|
||
/*/* Commented out, need mock libraries to be implemented. | ||
// Test AdvancedLoggerGetLoggerInfo when PEI Services is null | ||
TEST_F (AdvancedLoggerPeiCoreTest, AdvLoggerGetInfoAlreadyInitializedValid) { | ||
ADVANCED_LOGGER_INFO *LocalLoggerInfo = AdvancedLoggerGetLoggerInfo (); | ||
} | ||
// Test AdvancedLoggerGetLoggerInfo when PEI Services is returned | ||
// | ||
TEST_F (AdvancedLoggerPeiCoreTest, AdvLoggerGetInfoAlreadyInitializedValid) { | ||
ADVANCED_LOGGER_INFO *LocalLoggerInfo = AdvancedLoggerGetLoggerInfo (); | ||
} | ||
// Test AdvancedLoggerGetLoggerInfo NULL HOB | ||
TEST_F (AdvancedLoggerPeiCoreTest, AdvLoggerGetInfoNullHob) { | ||
// PcdAdvancedLoggerFixedInRAM is FALSE, so expect to get the logger info from the HOB | ||
// GetFirstGuidHob and GetNextGuidHob are not mocked | ||
EXPECT_CALL ( | ||
gHobLib, | ||
GetFirstGuidHob ( | ||
BufferEq (&gAdvancedLoggerHobGuid, sizeof (EFI_GUID)) | ||
) | ||
) | ||
.WillOnce ( | ||
Return (NULL) | ||
); | ||
mLoggerInfo = AdvancedLoggerGetLoggerInfo (); | ||
EXPECT_EQ (mLoggerInfo, nullptr); | ||
} | ||
// Test AdvancedLoggerGetLoggerInfo Success | ||
TEST_F (AdvancedLoggerPeiCoreTest, AdvLoggerGetInfoSuccess) { | ||
EXPECT_CALL ( | ||
gHobLib, | ||
GetFirstGuidHob ( | ||
BufferEq (&gAdvancedLoggerHobGuid, sizeof (EFI_GUID)) | ||
) | ||
) | ||
.WillOnce ( | ||
Return (NULL) // Need to mock the HOB to return a valid logger info | ||
); | ||
EXPECT_CALL ( | ||
gALHdwPortLib, | ||
AdvancedLoggerHdwPortInitialize () | ||
) | ||
.WillOnce ( | ||
Return (EFI_SUCCESS) | ||
); | ||
mLoggerInfo = AdvancedLoggerGetLoggerInfo (); | ||
EXPECT_NE (mLoggerInfo, nullptr); | ||
} | ||
*/ | ||
int | ||
main ( | ||
int argc, | ||
char *argv[] | ||
) | ||
{ | ||
InitGoogleTest (&argc, argv); | ||
return RUN_ALL_TESTS (); | ||
} |
64 changes: 64 additions & 0 deletions
64
...oggerPkg/Library/AdvancedLoggerLib/PeiCore/GoogleTest/AdvancedLoggerPeiCoreGoogleTest.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,64 @@ | ||
## @file AdvancedLoggerPeiCoreGoogleTest.inf | ||
# | ||
# Unit test for PEI_CORE instance of the Advanced Logger library. | ||
# | ||
## | ||
|
||
[Defines] | ||
INF_VERSION = 1.26 | ||
BASE_NAME = AdvancedLoggerPeiCoreGoogleTest | ||
FILE_GUID = 93D8CDB3-9ADA-47A1-BE2C-C449E68D205E | ||
MODULE_TYPE = HOST_APPLICATION | ||
VERSION_STRING = 1.0 | ||
|
||
# | ||
# The following information is for reference only and not required by the build tools. | ||
# | ||
# VALID_ARCHITECTURES = IA32 X64 | ||
# | ||
|
||
[Sources] | ||
AdvancedLoggerPeiCoreGoogleTest.cpp | ||
../AdvancedLoggerLib.c # Resolve static function ValidateInfoBlock() | ||
../../AdvancedLoggerCommon.c # Resolve AdvancedLoggerWrite | ||
|
||
[Packages] | ||
MdePkg/MdePkg.dec | ||
MdeModulePkg/MdeModulePkg.dec | ||
AdvLoggerPkg/AdvLoggerPkg.dec | ||
UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec | ||
|
||
[LibraryClasses] | ||
BaseLib | ||
DebugLib | ||
UnitTestLib | ||
AdvancedLoggerHdwPortLib | ||
BaseMemoryLib | ||
HobLib | ||
MemoryAllocationLib | ||
MmUnblockMemoryLib | ||
PcdLib | ||
PeiServicesLib | ||
PeiServicesTablePointerLib | ||
SynchronizationLib | ||
TimerLib | ||
|
||
[Guids] | ||
gAdvancedLoggerHobGuid | ||
gEfiFirmwareFileSystem2Guid | ||
gAdvancedLoggerInterimHobGuid | ||
gAdvancedLoggerInterimBufHobGuid | ||
|
||
[Ppis] | ||
gAdvancedLoggerPpiGuid ## CONSUMES | ||
gEfiPeiMemoryDiscoveredPpiGuid ## CONSUMES | ||
|
||
[FeaturePcd] | ||
gAdvLoggerPkgTokenSpaceGuid.PcdAdvancedLoggerFixedInRAM ## CONSUMES | ||
gAdvLoggerPkgTokenSpaceGuid.PcdAdvancedLoggerAutoWrapEnable | ||
|
||
[FixedPcd] | ||
gAdvLoggerPkgTokenSpaceGuid.PcdAdvancedLoggerBase ## CONSUMES | ||
gAdvLoggerPkgTokenSpaceGuid.PcdAdvancedLoggerPreMemPages ## CONSUMES | ||
gAdvLoggerPkgTokenSpaceGuid.PcdAdvancedLoggerPages ## CONSUMES | ||
gAdvLoggerPkgTokenSpaceGuid.PcdAdvancedLoggerHdwPortDebugPrintErrorLevel ## CONSUMES |
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