-
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.
AdvLoggerPkg: Add AdvancedLoggerMmCoreGoogleTest
- Loading branch information
Showing
3 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
163 changes: 163 additions & 0 deletions
163
AdvLoggerPkg/Library/AdvancedLoggerLib/MmCore/GoogleTest/AdvancedLoggerMmCoreGoogleTest.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,163 @@ | ||
/** @file AdvancedLoggerMmCoreGoogleTest.cpp | ||
This file contains the unit tests for the Advanced Logger MM Core Library. | ||
Copyright (c) Microsoft Corporation. | ||
SPDX-License-Identifier: BSD-2-Clause-Patent | ||
**/ | ||
|
||
#include <Library/GoogleTestLib.h> | ||
#include <Library/FunctionMockLib.h> | ||
#include <GoogleTest/Library/MockHobLib.h> | ||
#include <GoogleTest/Library/MockAdvancedLoggerHdwPortLib.h> | ||
|
||
extern "C" { | ||
#include <Uefi.h> | ||
#include <Library/BaseLib.h> | ||
#include <Library/DebugLib.h> | ||
#include <AdvancedLoggerInternal.h> | ||
#include <Protocol/AdvancedLogger.h> | ||
#include <AdvancedLoggerInternalProtocol.h> | ||
#include <Library/SynchronizationLib.h> // to mock (MU_BASECORE MdePkg) | ||
#include "../../AdvancedLoggerCommon.h" | ||
|
||
extern ADVANCED_LOGGER_INFO *mLoggerInfo; | ||
extern UINT32 mBufferSize; | ||
extern EFI_PHYSICAL_ADDRESS mMaxAddress; | ||
extern BOOLEAN mInitialized; | ||
|
||
// Static function declaration | ||
BOOLEAN | ||
ValidateInfoBlock ( | ||
VOID | ||
); | ||
} | ||
|
||
using namespace testing; | ||
|
||
/** | ||
Test class for AdvancedLoggerMmCore | ||
**/ | ||
class AdvancedLoggerMmCoreTest : public Test { | ||
protected: | ||
UINTN DebugLevel; | ||
EFI_HANDLE ImageHandle; | ||
EFI_SYSTEM_TABLE SystemTable; | ||
BOOLEAN Status; | ||
ADVANCED_LOGGER_INFO testLoggerInfo; | ||
// StrictMock<MockHobLib> gHobLib; | ||
// StrictMock<MockAdvancedLoggerHdwPortLib> gALHdwPortLib; | ||
|
||
void | ||
SetUp ( | ||
) override | ||
{ | ||
mLoggerInfo = NULL; | ||
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)); | ||
|
||
} | ||
}; | ||
|
||
// | ||
// Test ValidateInfoBlock | ||
// | ||
TEST_F (AdvancedLoggerMmCoreTest, AdvLoggerGetInfoFail) { | ||
// NULL LoggerInfo | ||
Status = ValidateInfoBlock (); | ||
EXPECT_EQ (Status, FALSE); | ||
|
||
// Invalid Signature | ||
mLoggerInfo = &testLoggerInfo; | ||
mLoggerInfo->Signature = SIGNATURE_32 ('T', 'E', 'S', 'T'); | ||
Status = ValidateInfoBlock (); | ||
EXPECT_EQ (Status, FALSE); | ||
mLoggerInfo->Signature = ADVANCED_LOGGER_SIGNATURE; | ||
|
||
// Mismatched Version is okay? Wouldn't expect mismatched version with valid signature? | ||
|
||
// Invalid Buffer Offset | ||
mLoggerInfo->LogBufferOffset = (UINT32)0; | ||
Status = ValidateInfoBlock (); | ||
EXPECT_EQ (Status, FALSE); | ||
mLoggerInfo->LogBufferOffset = (ALIGN_VALUE (sizeof (testLoggerInfo), 8)); | ||
|
||
// Invalid Current Offset | ||
mLoggerInfo->LogCurrentOffset = (UINT32)0; | ||
Status = ValidateInfoBlock (); | ||
EXPECT_EQ (Status, FALSE); | ||
mLoggerInfo->LogCurrentOffset = (ALIGN_VALUE (sizeof (testLoggerInfo), 8)); | ||
|
||
// Invalid Buffer Size | ||
mLoggerInfo->LogBufferSize = (UINT32)0; | ||
mBufferSize = (UINT32)0x1000; | ||
Status = ValidateInfoBlock (); | ||
EXPECT_EQ (Status, FALSE); | ||
} | ||
|
||
/*/* Commented out, need mock libraries to be implemented. | ||
// Test AdvancedLoggerGetLoggerInfo NULL HOB | ||
TEST_F (AdvancedLoggerMmCoreTest, 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 (AdvancedLoggerMmCoreTest, 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); | ||
// expect mLoggerInfo->Signature to be ADVANCED_LOGGER_SIGNATURE | ||
// expect mMAXAddress to be 0x1000 | ||
} | ||
// Test Advanced Logger constructor | ||
TEST_F (AdvancedLoggerMmCoreTest, AdvLoggerContructorSuccess) { | ||
MmCoreAdvancedLoggerLibConstructor (ImageHandle, SystemTable); | ||
} | ||
*/ | ||
int | ||
main ( | ||
int argc, | ||
char *argv[] | ||
) | ||
{ | ||
InitGoogleTest (&argc, argv); | ||
return RUN_ALL_TESTS (); | ||
} |
46 changes: 46 additions & 0 deletions
46
AdvLoggerPkg/Library/AdvancedLoggerLib/MmCore/GoogleTest/AdvancedLoggerMmCoreGoogleTest.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,46 @@ | ||
## @file AdvancedLoggerMmCoreGoogleTest.inf | ||
# | ||
# MM_CORE instance of the Advanced Logger library. | ||
# | ||
# Copyright (c) Microsoft Corporation. | ||
# SPDX-License-Identifier: BSD-2-Clause-Patent | ||
# | ||
## | ||
|
||
[Defines] | ||
INF_VERSION = 1.29 | ||
BASE_NAME = AdvancedLoggerMmCoreGoogleTest | ||
FILE_GUID = 4161C933-AEFC-43A5-8D5F-F1E9E9586A03 | ||
MODULE_TYPE = HOST_APPLICATION | ||
VERSION_STRING = 1.0 | ||
|
||
# | ||
# VALID_ARCHITECTURES = IA32 X64 | ||
# | ||
|
||
[Sources] | ||
AdvancedLoggerMmCoreGoogleTest.cpp | ||
../AdvancedLoggerLib.c # Resolve function ValidateInfoBlock() | ||
#../../AdvancedLoggerLibCommon.c # Resolve | ||
|
||
[Packages] | ||
MdePkg/MdePkg.dec | ||
AdvLoggerPkg/AdvLoggerPkg.dec | ||
UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec | ||
|
||
[LibraryClasses] | ||
BaseLib | ||
DebugLib | ||
UnitTestLib | ||
AdvancedLoggerHdwPortLib | ||
HobLib | ||
SynchronizationLib | ||
|
||
[Guids] | ||
gAdvancedLoggerHobGuid | ||
|
||
[Pcd] | ||
gAdvLoggerPkgTokenSpaceGuid.PcdAdvancedLoggerHdwPortDebugPrintErrorLevel ## CONSUMES | ||
|
||
[FeaturePcd] | ||
gAdvLoggerPkgTokenSpaceGuid.PcdAdvancedLoggerAutoWrapEnable |
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