Skip to content

Commit

Permalink
MdePkg: Add Gmock for PcdLib (#1178)
Browse files Browse the repository at this point in the history
## Description

Create gmock for PcdLib

Upstream to edk2: tianocore/edk2#5950

For details on how to complete these options and their meaning refer to
[CONTRIBUTING.md](https://github.com/microsoft/mu/blob/HEAD/CONTRIBUTING.md).

- [ ] Impacts functionality?
- [ ] Impacts security?
- [ ] Breaking change?
- [ ] Includes tests?
- [ ] Includes documentation?

## How This Was Tested

A GoogleTest can mock this library successfully.

## Integration Instructions

N/A
  • Loading branch information
VivianNK committed Oct 12, 2024
1 parent e076855 commit 3fe04e6
Show file tree
Hide file tree
Showing 4 changed files with 389 additions and 0 deletions.
1 change: 1 addition & 0 deletions MdePkg/Test/MdePkgHostTest.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,5 @@
MdePkg/Test/Mock/Library/GoogleTest/MockUefiDevicePathLib/MockUefiDevicePathLib.inf
MdePkg/Test/Mock/Library/GoogleTest/MockDxeServicesTableLib/MockDxeServicesTableLib.inf
MdePkg/Test/Mock/Library/GoogleTest/MockPciLib/MockPciLib.inf
MdePkg/Test/Mock/Library/GoogleTest/MockPcdLib/MockPcdLib.inf
# MU_CHANGE [END]
300 changes: 300 additions & 0 deletions MdePkg/Test/Mock/Include/GoogleTest/Library/MockPcdLib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,300 @@
/** @file MockPcdLib.h
Google Test mocks for PcdLib
Copyright (c) 2024, Intel Corporation. All rights reserved.
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#ifndef MOCK_PCD_LIB_H_
#define MOCK_PCD_LIB_H_

#include <Library/GoogleTestLib.h>
#include <Library/FunctionMockLib.h>
extern "C" {
#include <Uefi.h>
#include <Library/PcdLib.h>
}

struct MockPcdLib {
MOCK_INTERFACE_DECLARATION (MockPcdLib);

MOCK_FUNCTION_DECLARATION (
UINTN,
LibPcdSetSku,
(IN UINTN SkuId)
);

MOCK_FUNCTION_DECLARATION (
UINT8,
LibPcdGet8,
(IN UINTN TokenNumber)
);

MOCK_FUNCTION_DECLARATION (
UINT16,
LibPcdGet16,
(IN UINTN TokenNumber)
);

MOCK_FUNCTION_DECLARATION (
UINT32,
LibPcdGet32,
(IN UINTN TokenNumber)
);

MOCK_FUNCTION_DECLARATION (
UINT64,
LibPcdGet64,
(IN UINTN TokenNumber)
);

MOCK_FUNCTION_DECLARATION (
VOID *,
LibPcdGetPtr,
(IN UINTN TokenNumber)
);

MOCK_FUNCTION_DECLARATION (
BOOLEAN,
LibPcdGetBool,
(IN UINTN TokenNumber)
);

MOCK_FUNCTION_DECLARATION (
UINTN,
LibPcdGetSize,
(IN UINTN TokenNumber)
);

MOCK_FUNCTION_DECLARATION (
UINT8,
LibPcdGetEx8,
(IN CONST GUID *Guid,
IN UINTN TokenNumber)
);

MOCK_FUNCTION_DECLARATION (
UINT16,
LibPcdGetEx16,
(IN CONST GUID *Guid,
IN UINTN TokenNumber)
);

MOCK_FUNCTION_DECLARATION (
UINT32,
LibPcdGetEx32,
(IN CONST GUID *Guid,
IN UINTN TokenNumber)
);

MOCK_FUNCTION_DECLARATION (
UINT64,
LibPcdGetEx64,
(IN CONST GUID *Guid,
IN UINTN TokenNumber)
);

MOCK_FUNCTION_DECLARATION (
VOID *,
LibPcdGetExPtr,
(IN CONST GUID *Guid,
IN UINTN TokenNumber)
);

MOCK_FUNCTION_DECLARATION (
BOOLEAN,
LibPcdGetExBool,
(IN CONST GUID *Guid,
IN UINTN TokenNumber)
);

MOCK_FUNCTION_DECLARATION (
UINTN,
LibPcdGetExSize,
(IN CONST GUID *Guid,
IN UINTN TokenNumber)
);

MOCK_FUNCTION_DECLARATION (
RETURN_STATUS,
LibPcdSet8S,
(IN UINTN TokenNumber,
IN UINT8 Value)
);

MOCK_FUNCTION_DECLARATION (
RETURN_STATUS,
LibPcdSet16S,
(IN UINTN TokenNumber,
IN UINT16 Value)
);

MOCK_FUNCTION_DECLARATION (
RETURN_STATUS,
LibPcdSet32S,
(IN UINTN TokenNumber,
IN UINT32 Value)
);

MOCK_FUNCTION_DECLARATION (
RETURN_STATUS,
LibPcdSet64S,
(IN UINTN TokenNumber,
IN UINT64 Value)
);

MOCK_FUNCTION_DECLARATION (
RETURN_STATUS,
LibPcdSetPtrS,
(IN UINTN TokenNumber,
IN OUT UINTN *SizeOfBuffer,
IN CONST VOID *Buffer)
);

MOCK_FUNCTION_DECLARATION (
RETURN_STATUS,
LibPcdSetBoolS,
(IN UINTN TokenNumber,
IN BOOLEAN Value)
);

MOCK_FUNCTION_DECLARATION (
RETURN_STATUS,
LibPcdSetEx8S,
(IN CONST GUID *Guid,
IN UINTN TokenNumber,
IN UINT8 Value)
);

MOCK_FUNCTION_DECLARATION (
RETURN_STATUS,
LibPcdSetEx16S,
(IN CONST GUID *Guid,
IN UINTN TokenNumber,
IN UINT16 Value)
);

MOCK_FUNCTION_DECLARATION (
RETURN_STATUS,
LibPcdSetEx32S,
(IN CONST GUID *Guid,
IN UINTN TokenNumber,
IN UINT32 Value)
);

MOCK_FUNCTION_DECLARATION (
RETURN_STATUS,
LibPcdSetEx64S,
(IN CONST GUID *Guid,
IN UINTN TokenNumber,
IN UINT64 Value)
);

MOCK_FUNCTION_DECLARATION (
RETURN_STATUS,
LibPcdSetExPtrS,
(IN CONST GUID *Guid,
IN UINTN TokenNumber,
IN OUT UINTN *SizeOfBuffer,
IN VOID *Buffer)
);

MOCK_FUNCTION_DECLARATION (
RETURN_STATUS,
LibPcdSetExBoolS,
(IN CONST GUID *Guid,
IN UINTN TokenNumber,
IN BOOLEAN Value)
);

MOCK_FUNCTION_DECLARATION (
VOID,
LibPcdCallbackOnSet,
(IN CONST GUID *Guid OPTIONAL,
IN UINTN TokenNumber,
IN PCD_CALLBACK NotificationFunction)
);

MOCK_FUNCTION_DECLARATION (
VOID,
LibPcdCancelCallback,
(IN CONST GUID *Guid OPTIONAL,
IN UINTN TokenNumber,
IN PCD_CALLBACK NotificationFunction)
);

MOCK_FUNCTION_DECLARATION (
UINTN,
LibPcdGetNextToken,
(IN CONST GUID *Guid OPTIONAL,
IN UINTN TokenNumber)
);

MOCK_FUNCTION_DECLARATION (
GUID *,
LibPcdGetNextTokenSpace,
(IN CONST GUID *TokenSpaceGuid)
);

MOCK_FUNCTION_DECLARATION (
VOID *,
LibPatchPcdSetPtr,
(OUT VOID *PatchVariable,
IN UINTN MaximumDatumSize,
IN OUT UINTN *SizeOfBuffer,
IN CONST VOID *Buffer)
);

MOCK_FUNCTION_DECLARATION (
RETURN_STATUS,
LibPatchPcdSetPtrS,
(OUT VOID *PatchVariable,
IN UINTN MaximumDatumSize,
IN OUT UINTN *SizeOfBuffer,
IN CONST VOID *Buffer)
);

MOCK_FUNCTION_DECLARATION (
VOID *,
LibPatchPcdSetPtrAndSize,
(OUT VOID *PatchVariable,
OUT UINTN *SizeOfPatchVariable,
IN UINTN MaximumDatumSize,
IN OUT UINTN *SizeOfBuffer,
IN CONST VOID *Buffer)
);

MOCK_FUNCTION_DECLARATION (
RETURN_STATUS,
LibPatchPcdSetPtrAndSizeS,
(OUT VOID *PatchVariable,
OUT UINTN *SizeOfPatchVariable,
IN UINTN MaximumDatumSize,
IN OUT UINTN *SizeOfBuffer,
IN CONST VOID *Buffer)
);

MOCK_FUNCTION_DECLARATION (
VOID,
LibPcdGetInfo,
(IN UINTN TokenNumber,
OUT PCD_INFO *PcdInfo)
);

MOCK_FUNCTION_DECLARATION (
VOID,
LibPcdGetInfoEx,
(IN CONST GUID *Guid,
IN UINTN TokenNumber,
OUT PCD_INFO *PcdInfo)
);

MOCK_FUNCTION_DECLARATION (
UINTN,
LibPcdGetSku,
()
);
};

#endif
54 changes: 54 additions & 0 deletions MdePkg/Test/Mock/Library/GoogleTest/MockPcdLib/MockPcdLib.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/** @file MockPcdLib.cpp
Google Test mocks for PcdLib
Copyright (c) 2024, Intel Corporation. All rights reserved.
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#include <GoogleTest/Library/MockPcdLib.h>

//
// Global Variables that are not const
//

MOCK_INTERFACE_DEFINITION (MockPcdLib);

MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPcdSetSku, 1, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPcdGet8, 1, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPcdGet16, 1, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPcdGet32, 1, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPcdGet64, 1, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPcdGetPtr, 1, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPcdGetBool, 1, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPcdGetSize, 1, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPcdGetEx8, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPcdGetEx16, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPcdGetEx32, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPcdGetEx64, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPcdGetExPtr, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPcdGetExBool, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPcdGetExSize, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPcdSet8S, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPcdSet16S, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPcdSet32S, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPcdSet64S, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPcdSetPtrS, 3, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPcdSetBoolS, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPcdSetEx8S, 3, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPcdSetEx16S, 3, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPcdSetEx32S, 3, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPcdSetEx64S, 3, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPcdSetExPtrS, 4, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPcdSetExBoolS, 3, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPcdCallbackOnSet, 3, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPcdCancelCallback, 3, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPcdGetNextToken, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPcdGetNextTokenSpace, 1, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPatchPcdSetPtr, 4, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPatchPcdSetPtrS, 4, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPatchPcdSetPtrAndSize, 5, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPatchPcdSetPtrAndSizeS, 5, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPcdGetInfo, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPcdGetInfoEx, 3, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPcdLib, LibPcdGetSku, 0, EFIAPI);
34 changes: 34 additions & 0 deletions MdePkg/Test/Mock/Library/GoogleTest/MockPcdLib/MockPcdLib.inf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## @file MockPcdLib.inf
# Google Test mocks for PcdLib
#
# Copyright (c) 2024, Intel Corporation. All rights reserved.
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: BSD-2-Clause-Patent
##

[Defines]
INF_VERSION = 0x00010005
BASE_NAME = MockPcdLib
FILE_GUID = a0d612cd-0b33-5691-b282-02d7f46b93d9
MODULE_TYPE = HOST_APPLICATION
VERSION_STRING = 1.0
LIBRARY_CLASS = PcdLib

#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64
#

[Sources]
MockPcdLib.cpp

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

[LibraryClasses]
GoogleTestLib

[BuildOptions]
MSFT:*_*_*_CC_FLAGS = /EHs /bigobj

0 comments on commit 3fe04e6

Please sign in to comment.