Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REBASE & FF] Add GoogleTest Mocks and STATIC Testing Ability #830

Merged
merged 5 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
Original file line number Diff line number Diff line change
Expand Up @@ -3364,7 +3364,7 @@ ReclaimForOS (
UINTN RemainingCommonRuntimeVariableSpace;
// MS_CHANGE Starts: HwError record quota state should not trigger variable store reclaim
// UINTN RemainingHwErrVariableSpace;
STATIC BOOLEAN Reclaimed;
static BOOLEAN Reclaimed; // MU_CHANGE: Use lowercase static for static lifetime

//
// This function will be called only once at EndOfDxe or ReadyToBoot event.
Expand Down
5 changes: 5 additions & 0 deletions MdePkg/Include/Base.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,13 @@ struct _LIST_ENTRY {

///
/// Datum is scoped to the current file or function.
/// To support GoogleTest compiling static functions, do away with static in that case
///
#ifndef GOOGLETEST_HOST_UNIT_TEST_BUILD
#define STATIC static
#else
#define STATIC
#endif

///
/// Undeclared type.
Expand Down
3 changes: 2 additions & 1 deletion MdePkg/Test/MdePkgHostTest.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@
MdePkg/Test/Mock/Library/GoogleTest/MockIoLib/MockIoLib.inf
MdePkg/Test/Mock/Library/GoogleTest/MockSmmServicesTableLib/MockSmmServicesTableLib.inf
MdePkg/Test/Mock/Library/GoogleTest/MockMmServicesTableLib/MockMmServicesTableLib.inf

MdePkg/Test/Mock/Library/GoogleTest/MockUefiRuntimeLib/MockUefiRuntimeLib.inf
MdePkg/Test/Mock/Library/GoogleTest/MockMemoryAllocationLib/MockMemoryAllocationLib.inf
166 changes: 166 additions & 0 deletions MdePkg/Test/Mock/Include/GoogleTest/Library/MockMemoryAllocationLib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/** @file
Google Test mocks for MemoryAllocationLib

Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#ifndef MOCK_MEMORY_ALLOCATION_LIB_H_
#define MOCK_MEMORY_ALLOCATION_LIB_H_

#include <Library/GoogleTestLib.h>
#include <Library/FunctionMockLib.h>
extern "C" {
#include <PiPei.h>
#include <PiDxe.h>
#include <PiSmm.h>
#include <PiMm.h>
#include <Uefi.h>
#include <Library/MemoryAllocationLib.h>
}

struct MockMemoryAllocationLib {
MOCK_INTERFACE_DECLARATION (MockMemoryAllocationLib);

MOCK_FUNCTION_DECLARATION (
VOID *,
AllocatePages,
(IN UINTN Pages)
);

MOCK_FUNCTION_DECLARATION (
VOID *,
AllocateRuntimePages,
(IN UINTN Pages)
);

MOCK_FUNCTION_DECLARATION (
VOID *,
AllocateReservedPages,
(IN UINTN Pages)
);

MOCK_FUNCTION_DECLARATION (
VOID,
FreePages,
(IN VOID *Buffer,
IN UINTN Pages)
);

MOCK_FUNCTION_DECLARATION (
VOID *,
AllocateAlignedPages,
(IN UINTN Pages,
IN UINTN Alignment)
);

MOCK_FUNCTION_DECLARATION (
VOID *,
AllocateAlignedRuntimePages,
(IN UINTN Pages,
IN UINTN Alignment)
);

MOCK_FUNCTION_DECLARATION (
VOID *,
AllocateAlignedReservedPages,
(IN UINTN Pages,
IN UINTN Alignment)
);

MOCK_FUNCTION_DECLARATION (
VOID,
FreeAlignedPages,
(IN VOID *Buffer,
IN UINTN Pages)
);

MOCK_FUNCTION_DECLARATION (
VOID *,
AllocatePool,
(IN UINTN AllocationSize)
);

MOCK_FUNCTION_DECLARATION (
VOID *,
AllocateRuntimePool,
(IN UINTN AllocationSize)
);

MOCK_FUNCTION_DECLARATION (
VOID *,
AllocateReservedPool,
(IN UINTN AllocationSize)
);

MOCK_FUNCTION_DECLARATION (
VOID *,
AllocateZeroPool,
(IN UINTN AllocationSize)
);

MOCK_FUNCTION_DECLARATION (
VOID *,
AllocateRuntimeZeroPool,
(IN UINTN AllocationSize)
);

MOCK_FUNCTION_DECLARATION (
VOID *,
AllocateReservedZeroPool,
(IN UINTN AllocationSize)
);

MOCK_FUNCTION_DECLARATION (
VOID *,
AllocateCopyPool,
(IN UINTN AllocationSize,
IN CONST VOID *Buffer)
);

MOCK_FUNCTION_DECLARATION (
VOID *,
AllocateRuntimeCopyPool,
(IN UINTN AllocationSize,
IN CONST VOID *Buffer)
);

MOCK_FUNCTION_DECLARATION (
VOID *,
AllocateReservedCopyPool,
(IN UINTN AllocationSize,
IN CONST VOID *Buffer)
);

MOCK_FUNCTION_DECLARATION (
VOID *,
ReallocatePool,
(IN UINTN OldSize,
IN UINTN NewSize,
IN VOID *OldBuffer OPTIONAL)
);

MOCK_FUNCTION_DECLARATION (
VOID *,
ReallocateRuntimePool,
(IN UINTN OldSize,
IN UINTN NewSize,
IN VOID *OldBuffer OPTIONAL)
);

MOCK_FUNCTION_DECLARATION (
VOID *,
ReallocateReservedPool,
(IN UINTN OldSize,
IN UINTN NewSize,
IN VOID *OldBuffer OPTIONAL)
);

MOCK_FUNCTION_DECLARATION (
VOID,
FreePool,
(IN VOID *Buffer)
);
};

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ struct MockUefiBootServicesTableLib {
(IN EFI_EVENT Event)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
gBS_InstallProtocolInterface,
(IN OUT EFI_HANDLE *UserHandle,
IN EFI_GUID *Protocol,
IN EFI_INTERFACE_TYPE InterfaceType,
IN VOID *Interface)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
gBS_HandleProtocol,
Expand Down
156 changes: 156 additions & 0 deletions MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiRuntimeLib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/** @file
Google Test mocks for UefiRuntimeLib

Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#ifndef MOCK_UEFI_RUNTIME_LIB_H_
#define MOCK_UEFI_RUNTIME_LIB_H_

#include <Library/GoogleTestLib.h>
#include <Library/FunctionMockLib.h>
extern "C" {
#include <PiPei.h>
#include <PiDxe.h>
#include <PiSmm.h>
#include <PiMm.h>
#include <Uefi.h>
#include <Library/UefiRuntimeLib.h>
}

struct MockUefiRuntimeLib {
MOCK_INTERFACE_DECLARATION (MockUefiRuntimeLib);

MOCK_FUNCTION_DECLARATION (
BOOLEAN,
EfiAtRuntime,
()
);

MOCK_FUNCTION_DECLARATION (
BOOLEAN,
EfiGoneVirtual,
()
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
EfiGetTime,
(OUT EFI_TIME *Time,
OUT EFI_TIME_CAPABILITIES *Capabilities OPTIONAL)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
EfiSetTime,
(IN EFI_TIME *Time)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
EfiGetWakeupTime,
(OUT BOOLEAN *Enabled,
OUT BOOLEAN *Pending,
OUT EFI_TIME *Time)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
EfiSetWakeupTime,
(IN BOOLEAN Enable,
IN EFI_TIME *Time OPTIONAL)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
EfiGetVariable,
(IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
OUT UINT32 *Attributes OPTIONAL,
IN OUT UINTN *DataSize,
OUT VOID *Data)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
EfiGetNextVariableName,
(IN OUT UINTN *VariableNameSize,
IN OUT CHAR16 *VariableName,
IN OUT EFI_GUID *VendorGuid)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
EfiSetVariable,
(IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
IN UINT32 Attributes,
IN UINTN DataSize,
IN VOID *Data)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
EfiGetNextHighMonotonicCount,
(OUT UINT32 *HighCount)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
EfiConvertPointer,
(IN UINTN DebugDisposition,
IN OUT VOID **Address)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
EfiConvertFunctionPointer,
(IN UINTN DebugDisposition,
IN OUT VOID **Address)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
EfiSetVirtualAddressMap,
(IN UINTN MemoryMapSize,
IN UINTN DescriptorSize,
IN UINT32 DescriptorVersion,
IN CONST EFI_MEMORY_DESCRIPTOR *VirtualMap)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
EfiConvertList,
(IN UINTN DebugDisposition,
IN OUT LIST_ENTRY *ListHead)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
EfiUpdateCapsule,
(IN EFI_CAPSULE_HEADER **CapsuleHeaderArray,
IN UINTN CapsuleCount,
IN EFI_PHYSICAL_ADDRESS ScatterGatherList OPTIONAL)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
EfiQueryCapsuleCapabilities,
(IN EFI_CAPSULE_HEADER **CapsuleHeaderArray,
IN UINTN CapsuleCount,
OUT UINT64 *MaximumCapsuleSize,
OUT EFI_RESET_TYPE *ResetType)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
EfiQueryVariableInfo,
(IN UINT32 Attributes,
OUT UINT64 *MaximumVariableStorageSize,
OUT UINT64 *RemainingVariableStorageSize,
OUT UINT64 *MaximumVariableSize)
);
};

#endif