Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
VivianNK committed Aug 29, 2024
1 parent 60a5f10 commit 0ae130b
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 29 deletions.
4 changes: 3 additions & 1 deletion AdvLoggerPkg/AdvLoggerPkg.ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@
DEBUGAGENT,
POSTMEM,
MMARM,
BLKIO
BLKIO,
dlink,
uintn
]
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,42 @@
**/

#include <Library/GoogleTestLib.h>
#include <Library/FunctionMockLib.h>
#include <GoogleTest/Library/MockMemoryAllocationLib.h>
// #include <GoogleTest/Protocol/MockAdvancedLogger.h>

extern "C" {
#include <Uefi.h>
#include <Uefi.h> // should include basetype and base
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>

#include <AdvancedLoggerInternal.h>
#include <Protocol/AdvancedLogger.h>
#include <Guid/AdvancedLoggerPreDxeLogs.h>
#include <Protocol/VariablePolicy.h> // to mock?
// #include <Protocol/VariablePolicy.h> // to mock
#include <AdvancedLoggerInternalProtocol.h>
#include <Library/AdvancedLoggerHdwPortLib.h> // to mock?
#include <Library/BaseMemoryLib.h> // to mock?
#include <Library/HobLib.h> // to mock?
#include <Library/MemoryAllocationLib.h> // to mock?
#include <Library/PcdLib.h> // to mock?
#include <Library/SynchronizationLib.h> // to mock?
#include <Library/TimerLib.h> // to mock?
#include <Library/VariablePolicyHelperLib.h> // to mock?

// #include <Library/AdvancedLoggerHdwPortLib.h> // to mock
#include <Library/BaseMemoryLib.h> // to mock
// #include <Library/HobLib.h> // to mock
#include <Library/PcdLib.h> // to mock
#include <Library/SynchronizationLib.h> // to mock
#include <Library/TimerLib.h> // to mock
// #include <Library/VariablePolicyHelperLib.h> // 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;

// Static function declaration
BOOLEAN
ValidateInfoBlock (
VOID
);
}

using namespace testing;
Expand All @@ -47,45 +57,66 @@ class AdvancedLoggerDxeCoreTest : public Test {
CHAR8 *Buffer;
UINTN NumberOfBytes;
EFI_HANDLE ImageHandle;
EFI_SYSTEM_TABLE *SystemTable;
ADVANCED_LOGGER_INFO *loggerInfo;
EFI_SYSTEM_TABLE SystemTable;
BOOLEAN status;
ADVANCED_LOGGER_INFO testLoggerInfo;

void
SetUp (
) override
{
CHAR8 OutputBuf[] = "MyUnitTestLog";

NumberOfBytes = sizeof (OutputBuf);
Buffer = OutputBuf;
DebugLevel = DEBUG_ERROR;
mInitialized = FALSE;
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;
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 (AdvancedLoggerDxeCoreTest, AdvLoggerGetInfoFail) {
// mLoggerInfo NULL
// NULL Info block
mLoggerInfo = NULL;
status = ValidateInfoBlock ();
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 ();
mLoggerInfo = &testLoggerInfo;
mLoggerInfo->Signature = SIGNATURE_32 ('T', 'E', 'S', 'T');
status = ValidateInfoBlock ();
EXPECT_EQ (status, FALSE);
mLoggerInfo->Signature = ADVANCED_LOGGER_SIGNATURE;

// TODO Test offset and size
}
// TODO Mismatched Version is okay?

// 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);
}

/* TODO need to mock PCD library, and more
// Test AdvancedLoggerGetLoggerInfo
Expand All @@ -100,7 +131,6 @@ TEST_F (AdvancedLoggerDxeCoreTest, AdvLoggerContructorSuccess) {
DxeCoreAdvancedLoggerLibConstructor (ImageHandle, SystemTable);
}
*/

int
main (
int argc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,20 @@
#

[Sources]
../AdvancedLoggerLib.c # Source for externs
AdvancedLoggerDxeCoreGoogleTest.cpp

[Packages]
MdePkg/MdePkg.dec
UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
MdeModulePkg/MdeModulePkg.dec
AdvLoggerPkg/AdvLoggerPkg.dec
UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec

[LibraryClasses]
AdvancedLoggerLib
BaseLib
DebugLib
UnitTestLib
GoogleTestLib

[Guids]
gAdvancedLoggerHobGuid
Expand All @@ -51,3 +54,7 @@
gAdvLoggerPkgTokenSpaceGuid.PcdAdvancedLoggerLocator
gAdvLoggerPkgTokenSpaceGuid.PcdAdvancedLoggerFixedInRAM
gAdvLoggerPkgTokenSpaceGuid.PcdAdvancedLoggerAutoWrapEnable

[BuildOptions]
# MSFT:*_*_*_CC_FLAGS = /std:c++latest
# MSFT:*_*_*_CC_FLAGS = /EHsc
12 changes: 12 additions & 0 deletions AdvLoggerPkg/Test/AdvLoggerHostTest.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf
# TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf
# SerialPortLib|MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.inf

#
# Mocked Libs
Expand All @@ -38,6 +40,16 @@
MemoryAllocationLib|MdePkg/Test/Mock/Library/GoogleTest/MockMemoryAllocationLib/MockMemoryAllocationLib.inf
UefiBootServicesTableLib|MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.inf

#
# To mock
#
# HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf # TODO mock
# VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf # TODO mock

# [LibraryClasses.X64]
# SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf # TODO mock
# AdvancedLoggerHdwPortLib|AdvLoggerPkg/Library/AdvancedLoggerHdwPortLib/AdvancedLoggerHdwPortLib.inf

################################################################################
#
# Components section - list of all Components needed by this Platform.
Expand Down

0 comments on commit 0ae130b

Please sign in to comment.