From 5a22ca63d43d7fa162a3adcfbc8d7eb3ffff3c60 Mon Sep 17 00:00:00 2001 From: Bhavani Subramanian Date: Wed, 19 Jun 2024 13:24:14 -0700 Subject: [PATCH] Added mock functions for TimerLib --- .../Include/GoogleTest/Library/MockTimerLib.h | 29 ++++++++++++++++ .../GoogleTest/MockTimerLib/MockTimerLib.cpp | 11 ++++++ .../GoogleTest/MockTimerLib/MockTimerLib.inf | 34 +++++++++++++++++++ UefiCpuPkg/Test/UefiCpuPkgHostTest.dsc | 1 + 4 files changed, 75 insertions(+) create mode 100644 UefiCpuPkg/Test/Mock/Include/GoogleTest/Library/MockTimerLib.h create mode 100644 UefiCpuPkg/Test/Mock/Library/GoogleTest/MockTimerLib/MockTimerLib.cpp create mode 100644 UefiCpuPkg/Test/Mock/Library/GoogleTest/MockTimerLib/MockTimerLib.inf diff --git a/UefiCpuPkg/Test/Mock/Include/GoogleTest/Library/MockTimerLib.h b/UefiCpuPkg/Test/Mock/Include/GoogleTest/Library/MockTimerLib.h new file mode 100644 index 0000000000..e6d8882730 --- /dev/null +++ b/UefiCpuPkg/Test/Mock/Include/GoogleTest/Library/MockTimerLib.h @@ -0,0 +1,29 @@ +/** @file MockTimerLib.h + Google Test mocks for TimerLib + + Copyright (c) Microsoft Corporation. + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef MOCK_TIMER_LIB_H_ +#define MOCK_TIMER_LIB_H_ + +#include +#include +extern "C" { + #include +} + +struct MockTimerLib { + MOCK_INTERFACE_DECLARATION (MockTimerLib); + + MOCK_FUNCTION_DECLARATION ( + UINTN, + MicroSecondDelay, + ( + IN UINTN MicroSeconds + ) + ); +}; + +#endif //MOCK_TIMER_LIB_H_ diff --git a/UefiCpuPkg/Test/Mock/Library/GoogleTest/MockTimerLib/MockTimerLib.cpp b/UefiCpuPkg/Test/Mock/Library/GoogleTest/MockTimerLib/MockTimerLib.cpp new file mode 100644 index 0000000000..d7308e7bd0 --- /dev/null +++ b/UefiCpuPkg/Test/Mock/Library/GoogleTest/MockTimerLib/MockTimerLib.cpp @@ -0,0 +1,11 @@ +/** @file MockTimerLib.cpp + Google Test mocks for TimerLib + + Copyright (c) Microsoft Corporation. + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include + +MOCK_INTERFACE_DEFINITION (MockTimerLib); +MOCK_FUNCTION_DEFINITION (MockTimerLib, MicroSecondDelay, 1, EFIAPI); diff --git a/UefiCpuPkg/Test/Mock/Library/GoogleTest/MockTimerLib/MockTimerLib.inf b/UefiCpuPkg/Test/Mock/Library/GoogleTest/MockTimerLib/MockTimerLib.inf new file mode 100644 index 0000000000..855c65f63f --- /dev/null +++ b/UefiCpuPkg/Test/Mock/Library/GoogleTest/MockTimerLib/MockTimerLib.inf @@ -0,0 +1,34 @@ +## @file MockTimerLib.inf +# Google Test mocks for TimerLib +# +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = MockTimerLib + FILE_GUID = CF06C23E-5B46-4CC9-A5AE-794E0E58A564 + MODULE_TYPE = HOST_APPLICATION + VERSION_STRING = 1.0 + LIBRARY_CLASS = TimerLib + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 +# + +[Sources] + MockTimerLib.cpp + +[Packages] + UefiCpuPkg/UefiCpuPkg.dec + MdePkg/MdePkg.dec + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec + +[LibraryClasses] + GoogleTestLib + +[BuildOptions] + MSFT:*_*_*_CC_FLAGS = /EHsc diff --git a/UefiCpuPkg/Test/UefiCpuPkgHostTest.dsc b/UefiCpuPkg/Test/UefiCpuPkgHostTest.dsc index edd8b5f064..4ed800f508 100644 --- a/UefiCpuPkg/Test/UefiCpuPkgHostTest.dsc +++ b/UefiCpuPkg/Test/UefiCpuPkgHostTest.dsc @@ -42,3 +42,4 @@ # Build HOST_APPLICATION Libraries for GoogleTests # UefiCpuPkg/Test/Mock/Library/GoogleTest/MockLocalApicLib/MockLocalApicLib.inf + UefiCpuPkg/Test/Mock/Library/GoogleTest/MockTimerLib/MockTimerLib.inf