Skip to content

Commit 4eb86f0

Browse files
PaddyDengAmimergify[bot]
authored andcommitted
MdePkg: Added several mock libraries for google test
Added several mock libraries for google test so one can make google test drives consuming those libraries: - MockReportStatusCodeLib - MockSerialPortLib Signed-off-by: Paddy Deng <PaddyDeng@ami.com>
1 parent d68752d commit 4eb86f0

File tree

7 files changed

+225
-2
lines changed

7 files changed

+225
-2
lines changed

MdePkg/Test/MdePkgHostTest.dsc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,7 @@
5454
MdePkg/Test/Mock/Library/GoogleTest/MockReportStatusCodeLib/MockReportStatusCodeLib.inf
5555
MdePkg/Test/Mock/Library/GoogleTest/MockSafeIntLib/MockSafeIntLib.inf
5656
MdePkg/Test/Mock/Library/GoogleTest/MockDevicePathLib/MockDevicePathLib.inf
57+
MdePkg/Test/Mock/Library/GoogleTest/MockReportStatusCodeLib/MockReportStatusCodeLib.inf
58+
MdePkg/Test/Mock/Library/GoogleTest/MockSerialPortLib/MockSerialPortLib.inf
5759

5860
MdePkg/Library/StackCheckLibNull/StackCheckLibNullHostApplication.inf

MdePkg/Test/Mock/Include/GoogleTest/Library/MockReportStatusCodeLib.h

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#include <Library/GoogleTestLib.h>
1111
#include <Library/FunctionMockLib.h>
12-
1312
extern "C" {
1413
#include <Uefi.h>
1514
#include <Library/ReportStatusCodeLib.h>
@@ -18,9 +17,93 @@ extern "C" {
1817
struct MockReportStatusCodeLib {
1918
MOCK_INTERFACE_DECLARATION (MockReportStatusCodeLib);
2019

20+
MOCK_FUNCTION_DECLARATION (
21+
EFI_STATUS,
22+
ReportStatusCode,
23+
(
24+
IN EFI_STATUS_CODE_TYPE Type,
25+
IN EFI_STATUS_CODE_VALUE Value
26+
)
27+
);
28+
MOCK_FUNCTION_DECLARATION (
29+
EFI_STATUS,
30+
ReportStatusCodeWithDevicePath,
31+
(
32+
IN EFI_STATUS_CODE_TYPE Type,
33+
IN EFI_STATUS_CODE_VALUE Value,
34+
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
35+
)
36+
);
37+
MOCK_FUNCTION_DECLARATION (
38+
EFI_STATUS,
39+
ReportStatusCodeWithExtendedData,
40+
(
41+
IN EFI_STATUS_CODE_TYPE Type,
42+
IN EFI_STATUS_CODE_VALUE Value,
43+
IN CONST VOID *ExtendedData,
44+
IN UINTN ExtendedDataSize
45+
)
46+
);
47+
MOCK_FUNCTION_DECLARATION (
48+
EFI_STATUS,
49+
ReportStatusCodeEx,
50+
(
51+
IN EFI_STATUS_CODE_TYPE Type,
52+
IN EFI_STATUS_CODE_VALUE Value,
53+
IN UINT32 Instance,
54+
IN CONST EFI_GUID *CallerId OPTIONAL,
55+
IN CONST EFI_GUID *ExtendedDataGuid OPTIONAL,
56+
IN CONST VOID *ExtendedData OPTIONAL,
57+
IN UINTN ExtendedDataSize
58+
)
59+
);
2160
MOCK_FUNCTION_DECLARATION (
2261
BOOLEAN,
2362
ReportProgressCodeEnabled,
24-
()
63+
(
64+
)
65+
);
66+
MOCK_FUNCTION_DECLARATION (
67+
BOOLEAN,
68+
ReportErrorCodeEnabled,
69+
(
70+
)
71+
);
72+
MOCK_FUNCTION_DECLARATION (
73+
BOOLEAN,
74+
ReportDebugCodeEnabled,
75+
(
76+
)
77+
);
78+
MOCK_FUNCTION_DECLARATION (
79+
BOOLEAN,
80+
CodeTypeToPostCode,
81+
(
82+
IN EFI_STATUS_CODE_TYPE CodeType,
83+
IN EFI_STATUS_CODE_VALUE Value,
84+
OUT UINT8 *PostCode
85+
)
86+
);
87+
MOCK_FUNCTION_DECLARATION (
88+
BOOLEAN,
89+
ReportStatusCodeExtractAssertInfo,
90+
(
91+
IN EFI_STATUS_CODE_TYPE CodeType,
92+
IN EFI_STATUS_CODE_VALUE Value,
93+
IN CONST EFI_STATUS_CODE_DATA *Data,
94+
OUT CHAR8 **Filename,
95+
OUT CHAR8 **Description,
96+
OUT UINT32 *LineNumber
97+
)
98+
);
99+
MOCK_FUNCTION_DECLARATION (
100+
BOOLEAN,
101+
ReportStatusCodeExtractDebugInfo,
102+
(
103+
IN CONST EFI_STATUS_CODE_DATA *Data,
104+
OUT UINT32 *ErrorLevel,
105+
OUT BASE_LIST *Marker,
106+
OUT CHAR8 **Format
107+
)
25108
);
26109
};
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/** @file MockSerialPortLib.h
2+
Google Test mocks for SerialPortLib
3+
4+
Copyright (c) Microsoft Corporation.
5+
SPDX-License-Identifier: BSD-2-Clause-Patent
6+
**/
7+
8+
#ifndef MOCK_SERIAL_PORT_LIB_H_
9+
#define MOCK_SERIAL_PORT_LIB_H_
10+
11+
#include <Library/GoogleTestLib.h>
12+
#include <Library/FunctionMockLib.h>
13+
extern "C" {
14+
#include <Uefi.h>
15+
#include <Library/SerialPortLib.h>
16+
}
17+
18+
struct MockSerialPortLib {
19+
MOCK_INTERFACE_DECLARATION (MockSerialPortLib);
20+
21+
MOCK_FUNCTION_DECLARATION (
22+
RETURN_STATUS,
23+
SerialPortInitialize,
24+
(
25+
26+
)
27+
);
28+
MOCK_FUNCTION_DECLARATION (
29+
UINTN,
30+
SerialPortWrite,
31+
(
32+
IN UINT8 *Buffer,
33+
IN UINTN NumberOfBytes
34+
)
35+
);
36+
MOCK_FUNCTION_DECLARATION (
37+
UINTN,
38+
SerialPortRead,
39+
(
40+
OUT UINT8 *Buffer,
41+
IN UINTN NumberOfBytes
42+
)
43+
);
44+
MOCK_FUNCTION_DECLARATION (
45+
BOOLEAN,
46+
SerialPortPoll,
47+
(
48+
49+
)
50+
);
51+
MOCK_FUNCTION_DECLARATION (
52+
RETURN_STATUS,
53+
SerialPortSetControl,
54+
(
55+
IN UINT32 Control
56+
)
57+
);
58+
MOCK_FUNCTION_DECLARATION (
59+
RETURN_STATUS,
60+
SerialPortGetControl,
61+
(
62+
OUT UINT32 *Control
63+
)
64+
);
65+
MOCK_FUNCTION_DECLARATION (
66+
RETURN_STATUS,
67+
SerialPortSetAttributes,
68+
(
69+
IN OUT UINT64 *BaudRate,
70+
IN OUT UINT32 *ReceiveFifoDepth,
71+
IN OUT UINT32 *Timeout,
72+
IN OUT EFI_PARITY_TYPE *Parity,
73+
IN OUT UINT8 *DataBits,
74+
IN OUT EFI_STOP_BITS_TYPE *StopBits
75+
)
76+
);
77+
};
78+
79+
#endif

MdePkg/Test/Mock/Library/GoogleTest/MockReportStatusCodeLib/MockReportStatusCodeLib.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,13 @@
88
#include <GoogleTest/Library/MockReportStatusCodeLib.h>
99

1010
MOCK_INTERFACE_DEFINITION (MockReportStatusCodeLib);
11+
MOCK_FUNCTION_DEFINITION (MockReportStatusCodeLib, ReportStatusCode, 2, EFIAPI);
12+
MOCK_FUNCTION_DEFINITION (MockReportStatusCodeLib, ReportStatusCodeWithDevicePath, 3, EFIAPI);
13+
MOCK_FUNCTION_DEFINITION (MockReportStatusCodeLib, ReportStatusCodeWithExtendedData, 4, EFIAPI);
14+
MOCK_FUNCTION_DEFINITION (MockReportStatusCodeLib, ReportStatusCodeEx, 7, EFIAPI);
1115
MOCK_FUNCTION_DEFINITION (MockReportStatusCodeLib, ReportProgressCodeEnabled, 0, EFIAPI);
16+
MOCK_FUNCTION_DEFINITION (MockReportStatusCodeLib, ReportErrorCodeEnabled, 0, EFIAPI);
17+
MOCK_FUNCTION_DEFINITION (MockReportStatusCodeLib, ReportDebugCodeEnabled, 0, EFIAPI);
18+
MOCK_FUNCTION_DEFINITION (MockReportStatusCodeLib, CodeTypeToPostCode, 3, EFIAPI);
19+
MOCK_FUNCTION_DEFINITION (MockReportStatusCodeLib, ReportStatusCodeExtractAssertInfo, 6, EFIAPI);
20+
MOCK_FUNCTION_DEFINITION (MockReportStatusCodeLib, ReportStatusCodeExtractDebugInfo, 4, EFIAPI);

MdePkg/Test/Mock/Library/GoogleTest/MockReportStatusCodeLib/MockReportStatusCodeLib.inf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
MODULE_TYPE = HOST_APPLICATION
1313
VERSION_STRING = 1.0
1414
LIBRARY_CLASS = ReportStatusCodeLib
15+
PI_SPECIFICATION_VERSION = 0x0001000A
1516

1617
#
1718
# The following information is for reference only and not required by the build tools.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/** @file MockSerialPortLib.cpp
2+
Google Test mocks for SerialPortLib
3+
4+
Copyright (c) Microsoft Corporation.
5+
SPDX-License-Identifier: BSD-2-Clause-Patent
6+
**/
7+
8+
#include <GoogleTest/Library/MockSerialPortLib.h>
9+
10+
MOCK_INTERFACE_DEFINITION (MockSerialPortLib);
11+
MOCK_FUNCTION_DEFINITION (MockSerialPortLib, SerialPortInitialize, 0, EFIAPI);
12+
MOCK_FUNCTION_DEFINITION (MockSerialPortLib, SerialPortWrite, 2, EFIAPI);
13+
MOCK_FUNCTION_DEFINITION (MockSerialPortLib, SerialPortRead, 2, EFIAPI);
14+
MOCK_FUNCTION_DEFINITION (MockSerialPortLib, SerialPortPoll, 0, EFIAPI);
15+
MOCK_FUNCTION_DEFINITION (MockSerialPortLib, SerialPortSetControl, 1, EFIAPI);
16+
MOCK_FUNCTION_DEFINITION (MockSerialPortLib, SerialPortGetControl, 1, EFIAPI);
17+
MOCK_FUNCTION_DEFINITION (MockSerialPortLib, SerialPortSetAttributes, 6, EFIAPI);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
## @file MockSerialPortLib.inf
2+
# Google Test mocks for SerialPortLib
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 = MockSerialPortLib
11+
FILE_GUID = 1E192C74-78D6-4CF1-A8B9-BB2A4BDAF6FD
12+
MODULE_TYPE = HOST_APPLICATION
13+
VERSION_STRING = 1.0
14+
LIBRARY_CLASS = SerialPortLib
15+
PI_SPECIFICATION_VERSION = 0x0001000A
16+
17+
#
18+
# VALID_ARCHITECTURES = IA32 X64
19+
#
20+
21+
[Sources]
22+
MockSerialPortLib.cpp
23+
24+
[Packages]
25+
MdePkg/MdePkg.dec
26+
UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
27+
28+
[LibraryClasses]
29+
GoogleTestLib
30+
31+
[BuildOptions]
32+
MSFT:*_*_*_CC_FLAGS = /EHsc

0 commit comments

Comments
 (0)