diff --git a/AdvLoggerPkg/Library/AdvancedLoggerLib/DxeCore/GoogleTest/AdvancedLoggerDxeCoreGoogleTest.cpp b/AdvLoggerPkg/Library/AdvancedLoggerLib/DxeCore/GoogleTest/AdvancedLoggerDxeCoreGoogleTest.cpp new file mode 100644 index 0000000000..b28584117f --- /dev/null +++ b/AdvLoggerPkg/Library/AdvancedLoggerLib/DxeCore/GoogleTest/AdvancedLoggerDxeCoreGoogleTest.cpp @@ -0,0 +1,112 @@ +/** @file AdvancedLoggerDxeCoreGoogleTest.cpp + + This file contains the unit tests for the Advanced Logger DXE Core Library. + + Copyright (c) Microsoft Corporation. + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +// #include + +extern "C" { + #include + #include + #include + #include + #include + #include + #include // to mock? + #include + #include // to mock? + #include // to mock? + #include // to mock? + #include // to mock? + #include // to mock? + #include // to mock? + #include // to mock? + #include // to mock? + #include "../../AdvancedLoggerCommon.h" + + // extern ADVANCED_LOGGER_PROTOCOL *mLoggerProtocol; + extern ADVANCED_LOGGER_INFO *mLoggerInfo; + extern UINT32 mBufferSize; + extern EFI_PHYSICAL_ADDRESS mMaxAddress; + extern BOOLEAN mInitialized; +} + +using namespace testing; + +/** + Test class for AdvancedLoggerDxeCore +**/ +class AdvancedLoggerDxeCoreTest : public Test { +protected: + // StrictMock AdvLoggerProtocolMock; + UINTN DebugLevel; + CHAR8 *Buffer; + UINTN NumberOfBytes; + EFI_HANDLE ImageHandle; + EFI_SYSTEM_TABLE *SystemTable; + ADVANCED_LOGGER_INFO *loggerInfo; + BOOLEAN status; + + void + SetUp ( + ) override + { + CHAR8 OutputBuf[] = "MyUnitTestLog"; + + NumberOfBytes = sizeof (OutputBuf); + Buffer = OutputBuf; + DebugLevel = DEBUG_ERROR; + mInitialized = FALSE; + // gALProtocol->Signature = ADVANCED_LOGGER_PROTOCOL_SIGNATURE; + // gALProtocol->Version = ADVANCED_LOGGER_PROTOCOL_VERSION; + ImageHandle = (EFI_HANDLE)0x12345678; + SystemTable = (EFI_SYSTEM_TABLE *)0x87654321; + } +}; + +// +// Test ValidateInfoBlock +// +TEST_F (AdvancedLoggerDxeCoreTest, AdvLoggerGetInfoFail) { + // mLoggerInfo NULL + mLoggerInfo = NULL; + status = ValidateInfoBlock (); + EXPECT_EQ (status, FALSE); + + // Invalid Signature + mLoggerInfo = (ADVANCED_LOGGER_INFO *)AllocatePool (sizeof (ADVANCED_LOGGER_INFO)); + mLoggerInfo->Signature = SIGNATURE_32('T','E','S','T'); + status = ValidateInfoBlock (); + EXPECT_EQ (status, FALSE); + + // TODO Test offset and size +} + + +/* TODO need to mock PCD library, and more +// Test AdvancedLoggerGetLoggerInfo +TEST_F (AdvancedLoggerDxeCoreTest, AdvLoggerGetInfoSuccess) { + loggerInfo = AdvancedLoggerGetLoggerInfo (); +} +*/ + +/* TODO need to test AdvancedLoggerGetLoggerInfo +// Test DxeCore Advanced Logger initialization +TEST_F (AdvancedLoggerDxeCoreTest, AdvLoggerContructorSuccess) { + DxeCoreAdvancedLoggerLibConstructor (ImageHandle, SystemTable); +} +*/ + +int +main ( + int argc, + char *argv[] + ) +{ + InitGoogleTest (&argc, argv); + return RUN_ALL_TESTS (); +} diff --git a/AdvLoggerPkg/Library/AdvancedLoggerLib/DxeCore/GoogleTest/AdvancedLoggerDxeCoreGoogleTest.inf b/AdvLoggerPkg/Library/AdvancedLoggerLib/DxeCore/GoogleTest/AdvancedLoggerDxeCoreGoogleTest.inf new file mode 100644 index 0000000000..55ad3c2933 --- /dev/null +++ b/AdvLoggerPkg/Library/AdvancedLoggerLib/DxeCore/GoogleTest/AdvancedLoggerDxeCoreGoogleTest.inf @@ -0,0 +1,53 @@ +## @file AdvancedLoggerDxeCoreGoogleTest.inf +# +# DXE_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 = DxeCoreAdvancedLoggerLib + FILE_GUID = 01D768B5-B788-4253-86AD-B0524563BABC + MODULE_TYPE = HOST_APPLICATION + VERSION_STRING = 1.0 + +# +# VALID_ARCHITECTURES = IA32 X64 +# + +[Sources] + AdvancedLoggerDxeCoreGoogleTest.cpp + +[Packages] + MdePkg/MdePkg.dec + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec + MdeModulePkg/MdeModulePkg.dec + AdvLoggerPkg/AdvLoggerPkg.dec + +[LibraryClasses] + AdvancedLoggerLib + UnitTestLib + +[Guids] + gAdvancedLoggerHobGuid + gEfiEndOfDxeEventGroupGuid + gAdvancedLoggerPreDxeLogsGuid + +[Protocols] + gAdvancedLoggerProtocolGuid ## CONSUMES + gEdkiiVariablePolicyProtocolGuid ## CONSUMES + gEfiRealTimeClockArchProtocolGuid ## CONSUMES + gEfiVariableWriteArchProtocolGuid ## CONSUMES + +[FixedPcd] + gAdvLoggerPkgTokenSpaceGuid.PcdAdvancedLoggerPages + gAdvLoggerPkgTokenSpaceGuid.PcdAdvancedLoggerBase + gAdvLoggerPkgTokenSpaceGuid.PcdAdvancedLoggerHdwPortDebugPrintErrorLevel + +[FeaturePcd] + gAdvLoggerPkgTokenSpaceGuid.PcdAdvancedLoggerLocator + gAdvLoggerPkgTokenSpaceGuid.PcdAdvancedLoggerFixedInRAM + gAdvLoggerPkgTokenSpaceGuid.PcdAdvancedLoggerAutoWrapEnable diff --git a/AdvLoggerPkg/Test/AdvLoggerHostTest.dsc b/AdvLoggerPkg/Test/AdvLoggerHostTest.dsc index ebe57dc610..3e1b95040f 100644 --- a/AdvLoggerPkg/Test/AdvLoggerHostTest.dsc +++ b/AdvLoggerPkg/Test/AdvLoggerHostTest.dsc @@ -50,3 +50,4 @@ AdvLoggerPkg/AdvLoggerOsConnectorPrm/Library/AdvLoggerOsConnectorPrmConfigLib/GoogleTest/AdvLoggerPrmConfigLibGoogleTest.inf AdvLoggerPkg/AdvLoggerOsConnectorPrm/GoogleTest/AdvLoggerOsConnectorPrmGoogleTest.inf AdvLoggerPkg/Library/AdvancedLoggerLib/Dxe/GoogleTest/AdvancedLoggerDxeLibGoogleTest.inf + AdvLoggerPkg/Library/AdvancedLoggerLib/DxeCore/GoogleTest/AdvancedLoggerDxeCoreGoogleTest.inf