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

AdvLoggerPkg: Generated Mock Libraries using external tool #461

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the mocks can largely be auto generated by a tool now (I presume, haven't tried it yet), do you think there's much value to checking in the files until there's accompanying tests?

Main concern being that doing this at scale might invite dead code into the codebase which comes with those cons - bloat, prone to go stale, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the advanced logger case, waiting is fine because the package isn't really consumed by other packages.

In the case of packages that are externally consumed, it would be useful to get the mocked libraries/protocols created even before there are unit tests that consume them.

I will mark this as draft until some unit tests are created.

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/** @file
Google Test mocks for AdvancedLoggerAccessLib

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

#ifndef MOCK_ADVANCED_LOGGER_ACCESS_LIB_H_
#define MOCK_ADVANCED_LOGGER_ACCESS_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/AdvancedLoggerAccessLib.h>
}

struct MockAdvancedLoggerAccessLib {
MOCK_INTERFACE_DECLARATION (MockAdvancedLoggerAccessLib);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
AdvancedLoggerAccessLibGetNextMessageBlock,
(IN ADVANCED_LOGGER_ACCESS_MESSAGE_BLOCK_ENTRY *BlockEntry)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
AdvancedLoggerAccessLibGetNextFormattedLine,
(IN ADVANCED_LOGGER_ACCESS_MESSAGE_LINE_ENTRY *LineEntry)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
AdvancedLoggerAccessLibReset,
(IN ADVANCED_LOGGER_ACCESS_MESSAGE_LINE_ENTRY *AccessEntry)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
AdvancedLoggerAccessLibUnitTestInitialize,
(IN ADVANCED_LOGGER_PROTOCOL *TestProtocol OPTIONAL,
IN UINT16 MaxMessageSize)
);
};

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/** @file
Google Test mocks for AdvancedLoggerHdwPortLib

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

#ifndef MOCK_ADVANCED_LOGGER_HDW_PORT_LIB_H_
#define MOCK_ADVANCED_LOGGER_HDW_PORT_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/AdvancedLoggerHdwPortLib.h>
}

struct MockAdvancedLoggerHdwPortLib {
MOCK_INTERFACE_DECLARATION (MockAdvancedLoggerHdwPortLib);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
AdvancedLoggerHdwPortInitialize,
()
);

MOCK_FUNCTION_DECLARATION (
UINTN,
AdvancedLoggerHdwPortWrite,
(IN UINTN DebugLevel,
IN UINT8 *Buffer,
IN UINTN NumberOfBytes)
);
};

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/** @file
Google Test mocks for AdvancedLoggerLib

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

#ifndef MOCK_ADVANCED_LOGGER_LIB_H_
#define MOCK_ADVANCED_LOGGER_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/AdvancedLoggerLib.h>
}

struct MockAdvancedLoggerLib {
MOCK_INTERFACE_DECLARATION (MockAdvancedLoggerLib);

MOCK_FUNCTION_DECLARATION (
VOID,
AdvancedLoggerWrite,
(IN UINTN ErrorLevel,
IN CONST CHAR8 *Buffer,
IN UINTN NumberOfBytes)
);
};

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/** @file
Google Test mocks for AdvancedLoggerAccessLib

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

#include <GoogleTest/Library/MockAdvancedLoggerAccessLib.h>

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

MOCK_INTERFACE_DEFINITION (MockAdvancedLoggerAccessLib);

MOCK_FUNCTION_DEFINITION (MockAdvancedLoggerAccessLib, AdvancedLoggerAccessLibGetNextMessageBlock, 1, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockAdvancedLoggerAccessLib, AdvancedLoggerAccessLibGetNextFormattedLine, 1, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockAdvancedLoggerAccessLib, AdvancedLoggerAccessLibReset, 1, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockAdvancedLoggerAccessLib, AdvancedLoggerAccessLibUnitTestInitialize, 2, EFIAPI);
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## @file
# Google Test mocks for AdvancedLoggerAccessLib
#
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: BSD-2-Clause-Patent
##

[Defines]
INF_VERSION = 0x00010005
BASE_NAME = MockAdvancedLoggerAccessLib
FILE_GUID = 476554ce-578a-5a9d-87ad-52d1fa226108
MODULE_TYPE = HOST_APPLICATION
VERSION_STRING = 1.0
LIBRARY_CLASS = AdvancedLoggerAccessLib

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

[Sources]
MockAdvancedLoggerAccessLib.cpp

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

[LibraryClasses]
GoogleTestLib

[BuildOptions]
MSFT:*_*_*_CC_FLAGS = /EHs /bigobj
apop5 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/** @file
Google Test mocks for AdvancedLoggerHdwPortLib

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

#include <GoogleTest/Library/MockAdvancedLoggerHdwPortLib.h>

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

MOCK_INTERFACE_DEFINITION (MockAdvancedLoggerHdwPortLib);

MOCK_FUNCTION_DEFINITION (MockAdvancedLoggerHdwPortLib, AdvancedLoggerHdwPortInitialize, 0, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockAdvancedLoggerHdwPortLib, AdvancedLoggerHdwPortWrite, 3, EFIAPI);
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## @file
# Google Test mocks for AdvancedLoggerHdwPortLib
#
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: BSD-2-Clause-Patent
##

[Defines]
INF_VERSION = 0x00010005
BASE_NAME = MockAdvancedLoggerHdwPortLib
FILE_GUID = 88069e60-ae8b-5d10-a654-9aa6ce8b328c
MODULE_TYPE = HOST_APPLICATION
VERSION_STRING = 1.0
LIBRARY_CLASS = AdvancedLoggerHdwPortLib

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

[Sources]
MockAdvancedLoggerHdwPortLib.cpp

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

[LibraryClasses]
GoogleTestLib

[BuildOptions]
MSFT:*_*_*_CC_FLAGS = /EHs /bigobj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/** @file
Google Test mocks for AdvancedLoggerLib

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

#include <GoogleTest/Library/MockAdvancedLoggerLib.h>

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

MOCK_INTERFACE_DEFINITION (MockAdvancedLoggerLib);

MOCK_FUNCTION_DEFINITION (MockAdvancedLoggerLib, AdvancedLoggerWrite, 3, EFIAPI);
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## @file
# Google Test mocks for AdvancedLoggerLib
#
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: BSD-2-Clause-Patent
##

[Defines]
INF_VERSION = 0x00010005
BASE_NAME = MockAdvancedLoggerLib
FILE_GUID = 068a7898-bd23-5155-b794-2343a7309f42
MODULE_TYPE = HOST_APPLICATION
VERSION_STRING = 1.0
LIBRARY_CLASS = AdvancedLoggerLib

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

[Sources]
MockAdvancedLoggerLib.cpp

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

[LibraryClasses]
GoogleTestLib

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