From 5b64a0847aea2f0b49464bf330ce2886650e4945 Mon Sep 17 00:00:00 2001 From: Vivian Nowka-Keane Date: Thu, 19 Sep 2024 13:14:09 -0700 Subject: [PATCH] Fix dsc --- AdvLoggerPkg/AdvLoggerPkg.ci.yaml | 2 +- ...pp => AdvancedLoggerPeiCoreGoogleTest.cpp} | 56 ++++++++++--------- ...nf => AdvancedLoggerPeiCoreGoogleTest.inf} | 13 +++-- AdvLoggerPkg/Test/AdvLoggerHostTest.dsc | 13 +++-- 4 files changed, 46 insertions(+), 38 deletions(-) rename AdvLoggerPkg/Library/AdvancedLoggerLib/PeiCore/GoogleTest/{AdvancedLoggerPeiCoreLib.cpp => AdvancedLoggerPeiCoreGoogleTest.cpp} (72%) rename AdvLoggerPkg/Library/AdvancedLoggerLib/PeiCore/GoogleTest/{AdvancedLoggerPeiCoreLib.inf => AdvancedLoggerPeiCoreGoogleTest.inf} (76%) diff --git a/AdvLoggerPkg/AdvLoggerPkg.ci.yaml b/AdvLoggerPkg/AdvLoggerPkg.ci.yaml index 9b5669e548..daf14b97f3 100644 --- a/AdvLoggerPkg/AdvLoggerPkg.ci.yaml +++ b/AdvLoggerPkg/AdvLoggerPkg.ci.yaml @@ -31,7 +31,7 @@ "PrmPkg/PrmPkg.dec" ], "AcceptableDependencies-HOST_APPLICATION":[ # for host based unit tests - "UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec" + "UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec", ], "AcceptableDependencies-UEFI_APPLICATION": [ ], diff --git a/AdvLoggerPkg/Library/AdvancedLoggerLib/PeiCore/GoogleTest/AdvancedLoggerPeiCoreLib.cpp b/AdvLoggerPkg/Library/AdvancedLoggerLib/PeiCore/GoogleTest/AdvancedLoggerPeiCoreGoogleTest.cpp similarity index 72% rename from AdvLoggerPkg/Library/AdvancedLoggerLib/PeiCore/GoogleTest/AdvancedLoggerPeiCoreLib.cpp rename to AdvLoggerPkg/Library/AdvancedLoggerLib/PeiCore/GoogleTest/AdvancedLoggerPeiCoreGoogleTest.cpp index 2b06d0f2ca..1005993e47 100644 --- a/AdvLoggerPkg/Library/AdvancedLoggerLib/PeiCore/GoogleTest/AdvancedLoggerPeiCoreLib.cpp +++ b/AdvLoggerPkg/Library/AdvancedLoggerLib/PeiCore/GoogleTest/AdvancedLoggerPeiCoreGoogleTest.cpp @@ -1,4 +1,4 @@ -/** @file AdvancedLoggerPeiCoreLib.cpp +/** @file AdvancedLoggerPeiCoreGoogleTest.cpp This file contains the unit tests for the Advanced Logger PEI Core Library. @@ -20,19 +20,25 @@ extern "C" { #include #include #include - #include // to mock (MU_BASECORE MdeModulePkg) + #include // to mock (MU_BASECORE MdeModulePkg) #include - #include // to mock (MU_BASECORE MdePkg) - #include // to mock OR NULL lib? (MU_BASECORE MdePkg) - #include // to mock (MU_BASECORE MdePkg) - #include // to mock (MU_BASECORE MdePkg) - #include // to mock (MU_BASECORE MdeModulePkg) + #include // to mock (MU_BASECORE MdePkg) + #include // to mock (MU_BASECORE MdePkg) + #include // to mock (MU_BASECORE MdePkg) + #include // to mock (MU_BASECORE MdePkg) + #include // to mock (MU_BASECORE MdeModulePkg) #include "../../AdvancedLoggerCommon.h" #include #include #include // to mock (MU_BASECORE MdePkg) #include + + // Static function declaration + BOOLEAN + ValidateInfoBlock ( + IN ADVANCED_LOGGER_INFO *LoggerInfo + ); } using namespace testing; @@ -42,8 +48,9 @@ using namespace testing; **/ class AdvancedLoggerPeiCoreTest : public Test { protected: + ADVANCED_LOGGER_INFO *mLoggerInfo; + CHAR8 SourceBuf[4096]; UINTN DebugLevel; - CHAR8 *Buffer; UINTN NumberOfBytes; EFI_HANDLE ImageHandle; EFI_SYSTEM_TABLE SystemTable; @@ -56,51 +63,48 @@ class AdvancedLoggerPeiCoreTest : public Test { SetUp ( ) override { - CHAR8 OutputBuf[] = "MyUnitTestLog"; - - NumberOfBytes = sizeof (OutputBuf); - Buffer = OutputBuf; + 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, AdvLoggerGetInfoFail) { +TEST_F (AdvancedLoggerPeiCoreTest, AdvLoggerValidateInfoBlock) { // NULL LoggerInfo - status = ValidateInfoBlock (); + status = ValidateInfoBlock (mLoggerInfo); EXPECT_EQ (status, FALSE); + mLoggerInfo = &testLoggerInfo; + + // Success + status = ValidateInfoBlock (mLoggerInfo); + EXPECT_EQ (status, TRUE); + // Invalid Signature - mLoggerInfo = &testLoggerInfo; mLoggerInfo->Signature = SIGNATURE_32 ('T', 'E', 'S', 'T'); - status = ValidateInfoBlock (); + status = ValidateInfoBlock (mLoggerInfo); 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 (); + status = ValidateInfoBlock (mLoggerInfo); 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 Offset - mLoggerInfo->LogBufferOffset = (UINT32)0; - status = ValidateInfoBlock (); + status = ValidateInfoBlock (mLoggerInfo); EXPECT_EQ (status, FALSE); } diff --git a/AdvLoggerPkg/Library/AdvancedLoggerLib/PeiCore/GoogleTest/AdvancedLoggerPeiCoreLib.inf b/AdvLoggerPkg/Library/AdvancedLoggerLib/PeiCore/GoogleTest/AdvancedLoggerPeiCoreGoogleTest.inf similarity index 76% rename from AdvLoggerPkg/Library/AdvancedLoggerLib/PeiCore/GoogleTest/AdvancedLoggerPeiCoreLib.inf rename to AdvLoggerPkg/Library/AdvancedLoggerLib/PeiCore/GoogleTest/AdvancedLoggerPeiCoreGoogleTest.inf index 947a088928..8ecd77ca06 100644 --- a/AdvLoggerPkg/Library/AdvancedLoggerLib/PeiCore/GoogleTest/AdvancedLoggerPeiCoreLib.inf +++ b/AdvLoggerPkg/Library/AdvancedLoggerLib/PeiCore/GoogleTest/AdvancedLoggerPeiCoreGoogleTest.inf @@ -1,12 +1,12 @@ -## @file AdvancedLoggerPeiCoreLib.inf +## @file AdvancedLoggerPeiCoreGoogleTest.inf # -# Description +# Unit test for PEI_CORE instance of the Advanced Logger library. # ## [Defines] INF_VERSION = 1.26 -BASE_NAME = AdvancedLoggerPeiCoreLibGoogleTest +BASE_NAME = AdvancedLoggerPeiCoreGoogleTest FILE_GUID = 93D8CDB3-9ADA-47A1-BE2C-C449E68D205E MODULE_TYPE = HOST_APPLICATION VERSION_STRING = 1.0 @@ -18,12 +18,15 @@ VERSION_STRING = 1.0 # [Sources] - AdvancedLoggerPeiCoreLibGoogleTest.cpp + 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 - AdvancedLoggerPkg/AdvancedLoggerPkg.dec [LibraryClasses] BaseLib diff --git a/AdvLoggerPkg/Test/AdvLoggerHostTest.dsc b/AdvLoggerPkg/Test/AdvLoggerHostTest.dsc index 2dd1ac076c..384a38e4e1 100644 --- a/AdvLoggerPkg/Test/AdvLoggerHostTest.dsc +++ b/AdvLoggerPkg/Test/AdvLoggerHostTest.dsc @@ -34,6 +34,7 @@ TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf SerialPortLib|MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.inf VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf # To mock + MmUnblockMemoryLib|MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf # # Mocked Libs @@ -52,10 +53,6 @@ # ################################################################################ [Components] - # - # Build AdvancedLoggerPkg mock libraries - # - # # Build HOST_APPLICATIONs that test AdvLoggerPkg # @@ -68,8 +65,12 @@ AdvancedLoggerLib|AdvLoggerPkg/Library/AdvancedLoggerLib/Pei/AdvancedLoggerLib.inf PeiServicesLib|MdePkg/Test/Mock/Library/GoogleTest/MockPeiServicesLib/MockPeiServicesLib.inf } - AdvLoggerPkg/Library/AdvancedLoggerLib/PeiCore/GoogleTest/AdvancedLoggerPeiCoreLibGoogleTest.inf { + AdvLoggerPkg/Library/AdvancedLoggerLib/PeiCore/GoogleTest/AdvancedLoggerPeiCoreGoogleTest.inf { - AdvancedLoggerLib|AdvLoggerPkg/Library/AdvancedLoggerLib/Pei/AdvancedLoggerLib.inf PeiServicesLib|MdePkg/Test/Mock/Library/GoogleTest/MockPeiServicesLib/MockPeiServicesLib.inf } + + # + # Build AdvancedLoggerPkg mock libraries + # + AdvLoggerPkg/Test/Mock/Library/GoogleTest/MockAdvancedLoggerHdwPortLib/MockAdvancedLoggerHdwPortLib.inf