Skip to content

Commit

Permalink
Fix dsc
Browse files Browse the repository at this point in the history
  • Loading branch information
VivianNK committed Sep 19, 2024
1 parent 53587cd commit 5b64a08
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 38 deletions.
2 changes: 1 addition & 1 deletion AdvLoggerPkg/AdvLoggerPkg.ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"PrmPkg/PrmPkg.dec"
],
"AcceptableDependencies-HOST_APPLICATION":[ # for host based unit tests
"UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec"
"UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec",
],
"AcceptableDependencies-UEFI_APPLICATION": [
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @file AdvancedLoggerPeiCoreLib.cpp
/** @file AdvancedLoggerPeiCoreGoogleTest.cpp
This file contains the unit tests for the Advanced Logger PEI Core Library.
Expand All @@ -20,19 +20,25 @@ extern "C" {
#include <Library/DebugLib.h>
#include <AdvancedLoggerInternal.h>
#include <Protocol/AdvancedLogger.h>
#include <Protocol/VariablePolicy.h> // to mock (MU_BASECORE MdeModulePkg)
#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 OR NULL lib? (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 <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;
Expand All @@ -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;
Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
13 changes: 7 additions & 6 deletions AdvLoggerPkg/Test/AdvLoggerHostTest.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -52,10 +53,6 @@
#
################################################################################
[Components]
#
# Build AdvancedLoggerPkg mock libraries
#

#
# Build HOST_APPLICATIONs that test AdvLoggerPkg
#
Expand All @@ -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 {
<LibraryClasses>
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

0 comments on commit 5b64a08

Please sign in to comment.