Skip to content

Commit 9b19430

Browse files
authored
StandaloneMmPkg: Add Google Mock Library for StandaloneMmMemLib (#1287)
1 parent a46dbcc commit 9b19430

File tree

4 files changed

+138
-0
lines changed

4 files changed

+138
-0
lines changed

StandaloneMmPkg/StandaloneMmPkg.dec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
[Includes]
1818
Include
19+
Test/Mock/Include
1920

2021
[LibraryClasses]
2122

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/** @file MockStandaloneMmMemLib.h
2+
Google Test mocks for StandaloneMmMemLib
3+
4+
Copyright (c) Microsoft Corporation.
5+
SPDX-License-Identifier: BSD-2-Clause-Patent
6+
**/
7+
8+
#ifndef MOCK_MM_MEM_LIB_H_
9+
#define MOCK_MM_MEM_LIB_H_
10+
11+
#include <Library/GoogleTestLib.h>
12+
#include <Library/FunctionMockLib.h>
13+
extern "C" {
14+
#include <Uefi.h>
15+
#include <Library/StandaloneMmMemLib.h>
16+
}
17+
18+
//
19+
// Declarations to handle usage of the MmMemLib by creating mock
20+
//
21+
struct MockMmMemLib {
22+
MOCK_INTERFACE_DECLARATION (MockMmMemLib);
23+
24+
MOCK_FUNCTION_DECLARATION (
25+
BOOLEAN,
26+
MmIsBufferOutsideMmValid,
27+
(
28+
IN EFI_PHYSICAL_ADDRESS Buffer,
29+
IN UINT64 Length
30+
)
31+
);
32+
33+
MOCK_FUNCTION_DECLARATION (
34+
EFI_STATUS,
35+
MmCopyMemToMmram,
36+
(
37+
OUT VOID *DestinationBuffer,
38+
IN CONST VOID *SourceBuffer,
39+
IN UINTN Length
40+
)
41+
);
42+
43+
MOCK_FUNCTION_DECLARATION (
44+
EFI_STATUS,
45+
MmCopyMemFromMmram,
46+
(
47+
OUT VOID *DestinationBuffer,
48+
IN CONST VOID *SourceBuffer,
49+
IN UINTN Length
50+
)
51+
);
52+
53+
MOCK_FUNCTION_DECLARATION (
54+
EFI_STATUS,
55+
MmCopyMem,
56+
(
57+
OUT VOID *DestinationBuffer,
58+
IN CONST VOID *SourceBuffer,
59+
IN UINTN Length
60+
)
61+
);
62+
63+
MOCK_FUNCTION_DECLARATION (
64+
EFI_STATUS,
65+
MmSetMem,
66+
(
67+
OUT VOID *Buffer,
68+
IN UINTN Length,
69+
IN UINT8 Value
70+
)
71+
);
72+
73+
// MU_CHANGE Start: Add Communication Buffer Validation
74+
MOCK_FUNCTION_DECLARATION (
75+
BOOLEAN,
76+
MmCommBufferValid,
77+
(
78+
IN EFI_PHYSICAL_ADDRESS Buffer,
79+
IN UINT64 Length
80+
)
81+
);
82+
// MU_CHANGE End: Add Communication Buffer Validation
83+
};
84+
85+
#endif
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/** @file MockStandaloneMmMemLib.cpp
2+
Google Test mocks for StandaloneMmMemLib
3+
4+
Copyright (c) Microsoft Corporation.
5+
SPDX-License-Identifier: BSD-2-Clause-Patent
6+
**/
7+
#include <GoogleTest/Library/MockStandaloneMmMemLib.h>
8+
9+
MOCK_INTERFACE_DEFINITION (MockMmMemLib);
10+
11+
MOCK_FUNCTION_DEFINITION (MockMmMemLib, MmIsBufferOutsideMmValid, 2, EFIAPI);
12+
MOCK_FUNCTION_DEFINITION (MockMmMemLib, MmCopyMemToMmram, 3, EFIAPI);
13+
MOCK_FUNCTION_DEFINITION (MockMmMemLib, MmCopyMemFromMmram, 3, EFIAPI);
14+
MOCK_FUNCTION_DEFINITION (MockMmMemLib, MmCopyMem, 3, EFIAPI);
15+
MOCK_FUNCTION_DEFINITION (MockMmMemLib, MmSetMem, 3, EFIAPI);
16+
// MU_CHANGE Start: Add Communication Buffer Validation
17+
MOCK_FUNCTION_DEFINITION (MockMmMemLib, MmCommBufferValid, 2, EFIAPI);
18+
// MU_CHANGE End: Add Communication Buffer Validation
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
## @file MockStandaloneMmMemLib.inf
2+
# Google Test mocks for StandaloneMmMemLib
3+
#
4+
# Copyright (c) Microsoft Corporation.
5+
# SPDX-License-Identifier: BSD-2-Clause-Patent
6+
##
7+
8+
[Defines]
9+
INF_VERSION = 0x00010005
10+
BASE_NAME = MockStandaloneMmMemLib
11+
FILE_GUID = 925CFA0C-2B5C-487B-8B93-3031EA16CEB2
12+
MODULE_TYPE = HOST_APPLICATION
13+
VERSION_STRING = 1.0
14+
LIBRARY_CLASS = MemLib
15+
16+
#
17+
# The following information is for reference only and not required by the build tools.
18+
#
19+
# VALID_ARCHITECTURES = IA32 X64
20+
#
21+
22+
[Sources]
23+
MockStandaloneMmMemLib.cpp
24+
25+
[Packages]
26+
MdePkg/MdePkg.dec
27+
StandaloneMmPkg/StandaloneMmPkg.dec
28+
UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
29+
30+
[LibraryClasses]
31+
GoogleTestLib
32+
33+
[BuildOptions]
34+
MSFT:*_*_*_CC_FLAGS = /EHsc

0 commit comments

Comments
 (0)