public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "gaoliming" <gaoliming@byosoft.com.cn>
To: "'Michael D Kinney'" <michael.d.kinney@intel.com>,
	<devel@edk2.groups.io>
Cc: "'Chris Johnson'" <chris.n.johnson@intel.com>,
	"'Zhiguang Liu'" <zhiguang.liu@intel.com>
Subject: 回复: [Patch v2 05/12] MdePkg: Add gmock examples
Date: Thu, 6 Apr 2023 09:15:47 +0800	[thread overview]
Message-ID: <00f701d96825$519c3290$f4d497b0$@byosoft.com.cn> (raw)
In-Reply-To: <20230404182220.688-6-michael.d.kinney@intel.com>

Acked-by: Liming Gao <gaoliming@byosoft.com.cn>

> -----邮件原件-----
> 发件人: Michael D Kinney <michael.d.kinney@intel.com>
> 发送时间: 2023年4月5日 2:22
> 收件人: devel@edk2.groups.io
> 抄送: Chris Johnson <chris.n.johnson@intel.com>; Liming Gao
> <gaoliming@byosoft.com.cn>; Zhiguang Liu <zhiguang.liu@intel.com>
> 主题: [Patch v2 05/12] MdePkg: Add gmock examples
> 
> From: Chris Johnson <chris.n.johnson@intel.com>
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4389
> 
> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Zhiguang Liu <zhiguang.liu@intel.com>
> Signed-off-by: Chris Johnson <chris.n.johnson@intel.com>
> ---
>  MdePkg/MdePkg.dec                             |  1 +
>  MdePkg/Test/MdePkgHostTest.dsc                |  2 +
>  .../Include/GoogleTest/Library/MockUefiLib.h  | 39 +++++++++++++++++
>  .../Library/MockUefiRuntimeServicesTableLib.h | 42 +++++++++++++++++++
>  .../GoogleTest/MockUefiLib/MockUefiLib.cpp    | 12 ++++++
>  .../GoogleTest/MockUefiLib/MockUefiLib.inf    | 33 +++++++++++++++
>  .../MockUefiRuntimeServicesTableLib.cpp       | 40
> ++++++++++++++++++
>  .../MockUefiRuntimeServicesTableLib.inf       | 33 +++++++++++++++
>  8 files changed, 202 insertions(+)
>  create mode 100644
> MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiLib.h
>  create mode 100644
> MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiRuntimeServicesTa
> bleLib.h
>  create mode 100644
> MdePkg/Test/Mock/Library/GoogleTest/MockUefiLib/MockUefiLib.cpp
>  create mode 100644
> MdePkg/Test/Mock/Library/GoogleTest/MockUefiLib/MockUefiLib.inf
>  create mode 100644
> MdePkg/Test/Mock/Library/GoogleTest/MockUefiRuntimeServicesTableLib/
> MockUefiRuntimeServicesTableLib.cpp
>  create mode 100644
> MdePkg/Test/Mock/Library/GoogleTest/MockUefiRuntimeServicesTableLib/
> MockUefiRuntimeServicesTableLib.inf
> 
> diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec
> index 2d643bede1d7..2a1d7694aa18 100644
> --- a/MdePkg/MdePkg.dec
> +++ b/MdePkg/MdePkg.dec
> @@ -26,6 +26,7 @@ [Defines]
>  [Includes]
>    Include
>    Test/UnitTest/Include
> +  Test/Mock/Include
> 
>  [Includes.IA32]
>    Include/Ia32
> diff --git a/MdePkg/Test/MdePkgHostTest.dsc
> b/MdePkg/Test/MdePkgHostTest.dsc
> index b8b186dd8b17..35e3ef6d9729 100644
> --- a/MdePkg/Test/MdePkgHostTest.dsc
> +++ b/MdePkg/Test/MdePkgHostTest.dsc
> @@ -34,3 +34,5 @@ [Components]
>    # Build HOST_APPLICATION Libraries
>    #
>    MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf
> +  MdePkg/Test/Mock/Library/GoogleTest/MockUefiLib/MockUefiLib.inf
> +
> MdePkg/Test/Mock/Library/GoogleTest/MockUefiRuntimeServicesTableLib/
> MockUefiRuntimeServicesTableLib.inf
> diff --git a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiLib.h
> b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiLib.h
> new file mode 100644
> index 000000000000..dec2c93e1b34
> --- /dev/null
> +++ b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiLib.h
> @@ -0,0 +1,39 @@
> +/** @file
> +  Google Test mocks for UefiLib
> +
> +  Copyright (c) 2022, Intel Corporation. All rights reserved.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +**/
> +
> +#ifndef MOCK_UEFI_LIB_H_
> +#define MOCK_UEFI_LIB_H_
> +
> +#include <Library/GoogleTestLib.h>
> +#include <Library/FunctionMockLib.h>
> +extern "C" {
> +#include <Uefi.h>
> +#include <Library/UefiLib.h>
> +}
> +
> +struct MockUefiLib {
> +  MOCK_INTERFACE_DECLARATION (MockUefiLib);
> +
> +  MOCK_FUNCTION_DECLARATION (
> +    EFI_STATUS,
> +    GetVariable2,
> +    (IN CONST CHAR16    *Name,
> +     IN CONST EFI_GUID  *Guid,
> +     OUT VOID           **Value,
> +     OUT UINTN          *Size OPTIONAL)
> +    );
> +
> +  MOCK_FUNCTION_DECLARATION (
> +    EFI_STATUS,
> +    GetEfiGlobalVariable2,
> +    (IN CONST CHAR16  *Name,
> +     OUT VOID         **Value,
> +     OUT UINTN        *Size OPTIONAL)
> +    );
> +};
> +
> +#endif
> diff --git
> a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiRuntimeServices
> TableLib.h
> b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiRuntimeServices
> TableLib.h
> new file mode 100644
> index 000000000000..afdfc6b85597
> --- /dev/null
> +++
> b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiRuntimeServices
> TableLib.h
> @@ -0,0 +1,42 @@
> +/** @file
> +  Google Test mocks for UefiRuntimeServicesTableLib
> +
> +  Copyright (c) 2022, Intel Corporation. All rights reserved.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +**/
> +
> +#ifndef MOCK_UEFI_RUNTIME_SERVICES_TABLE_LIB_H_
> +#define MOCK_UEFI_RUNTIME_SERVICES_TABLE_LIB_H_
> +
> +#include <Library/GoogleTestLib.h>
> +#include <Library/FunctionMockLib.h>
> +extern "C" {
> +#include <Uefi.h>
> +#include <Library/UefiRuntimeServicesTableLib.h>
> +}
> +
> +struct MockUefiRuntimeServicesTableLib {
> +  MOCK_INTERFACE_DECLARATION (MockUefiRuntimeServicesTableLib);
> +
> +  MOCK_FUNCTION_DECLARATION (
> +    EFI_STATUS,
> +    gRT_GetVariable,
> +    (IN      CHAR16    *VariableName,
> +     IN      EFI_GUID  *VendorGuid,
> +     OUT     UINT32    *Attributes OPTIONAL,
> +     IN OUT  UINTN     *DataSize,
> +     OUT     VOID      *Data)
> +    );
> +
> +  MOCK_FUNCTION_DECLARATION (
> +    EFI_STATUS,
> +    gRT_SetVariable,
> +    (IN CHAR16    *VariableName,
> +     IN EFI_GUID  *VendorGuid,
> +     IN UINT32    Attributes,
> +     IN UINTN     DataSize,
> +     IN VOID      *Data)
> +    );
> +};
> +
> +#endif
> diff --git
> a/MdePkg/Test/Mock/Library/GoogleTest/MockUefiLib/MockUefiLib.cpp
> b/MdePkg/Test/Mock/Library/GoogleTest/MockUefiLib/MockUefiLib.cpp
> new file mode 100644
> index 000000000000..5339d040c999
> --- /dev/null
> +++ b/MdePkg/Test/Mock/Library/GoogleTest/MockUefiLib/MockUefiLib.cpp
> @@ -0,0 +1,12 @@
> +/** @file
> +  Google Test mocks for UefiLib
> +
> +  Copyright (c) 2022, Intel Corporation. All rights reserved.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +**/
> +#include <GoogleTest/Library/MockUefiLib.h>
> +
> +MOCK_INTERFACE_DEFINITION(MockUefiLib);
> +
> +MOCK_FUNCTION_DEFINITION(MockUefiLib, GetVariable2, 4, EFIAPI);
> +MOCK_FUNCTION_DEFINITION(MockUefiLib, GetEfiGlobalVariable2, 3,
> EFIAPI);
> diff --git
> a/MdePkg/Test/Mock/Library/GoogleTest/MockUefiLib/MockUefiLib.inf
> b/MdePkg/Test/Mock/Library/GoogleTest/MockUefiLib/MockUefiLib.inf
> new file mode 100644
> index 000000000000..1a7461e44449
> --- /dev/null
> +++ b/MdePkg/Test/Mock/Library/GoogleTest/MockUefiLib/MockUefiLib.inf
> @@ -0,0 +1,33 @@
> +## @file
> +# Google Test mocks for UefiLib
> +#
> +# Copyright (c) 2022, Intel Corporation. All rights reserved.
> +# SPDX-License-Identifier: BSD-2-Clause-Patent
> +##
> +
> +[Defines]
> +  INF_VERSION                    = 0x00010005
> +  BASE_NAME                      = MockUefiLib
> +  FILE_GUID                      =
> 47211F7A-6D90-4DFB-BDF9-610B69197C2E
> +  MODULE_TYPE                    = HOST_APPLICATION
> +  VERSION_STRING                 = 1.0
> +  LIBRARY_CLASS                  = UefiLib
> +
> +#
> +# The following information is for reference only and not required by the
> build tools.
> +#
> +#  VALID_ARCHITECTURES           = IA32 X64
> +#
> +
> +[Sources]
> +  MockUefiLib.cpp
> +
> +[Packages]
> +  MdePkg/MdePkg.dec
> +  UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
> +
> +[LibraryClasses]
> +  GoogleTestLib
> +
> +[BuildOptions]
> +  MSFT:*_*_*_CC_FLAGS = /EHsc
> diff --git
> a/MdePkg/Test/Mock/Library/GoogleTest/MockUefiRuntimeServicesTableLib
> /MockUefiRuntimeServicesTableLib.cpp
> b/MdePkg/Test/Mock/Library/GoogleTest/MockUefiRuntimeServicesTableLib
> /MockUefiRuntimeServicesTableLib.cpp
> new file mode 100644
> index 000000000000..ecd1ba82366c
> --- /dev/null
> +++
> b/MdePkg/Test/Mock/Library/GoogleTest/MockUefiRuntimeServicesTableLib
> /MockUefiRuntimeServicesTableLib.cpp
> @@ -0,0 +1,40 @@
> +/** @file
> +  Google Test mocks for UefiRuntimeServicesTableLib
> +
> +  Copyright (c) 2022, Intel Corporation. All rights reserved.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +**/
> +#include <GoogleTest/Library/MockUefiRuntimeServicesTableLib.h>
> +
> +MOCK_INTERFACE_DEFINITION(MockUefiRuntimeServicesTableLib);
> +
> +MOCK_FUNCTION_DEFINITION(MockUefiRuntimeServicesTableLib,
> gRT_GetVariable, 5, EFIAPI);
> +MOCK_FUNCTION_DEFINITION(MockUefiRuntimeServicesTableLib,
> gRT_SetVariable, 5, EFIAPI);
> +
> +static EFI_RUNTIME_SERVICES localRt = {
> +  {0},              // EFI_TABLE_HEADER
> +
> +  NULL,             // EFI_GET_TIME
> +  NULL,             // EFI_SET_TIME
> +  NULL,             // EFI_GET_WAKEUP_TIME
> +  NULL,             // EFI_SET_WAKEUP_TIME
> +
> +  NULL,             // EFI_SET_VIRTUAL_ADDRESS_MAP
> +  NULL,             // EFI_CONVERT_POINTER
> +
> +  gRT_GetVariable,  // EFI_GET_VARIABLE
> +  NULL,             // EFI_GET_NEXT_VARIABLE_NAME
> +  gRT_SetVariable,  // EFI_SET_VARIABLE
> +
> +  NULL,             // EFI_GET_NEXT_HIGH_MONO_COUNT
> +  NULL,             // EFI_RESET_SYSTEM
> +
> +  NULL,             // EFI_UPDATE_CAPSULE
> +  NULL,             // EFI_QUERY_CAPSULE_CAPABILITIES
> +
> +  NULL,             // EFI_QUERY_VARIABLE_INFO
> +};
> +
> +extern "C" {
> +  EFI_RUNTIME_SERVICES* gRT = &localRt;
> +}
> diff --git
> a/MdePkg/Test/Mock/Library/GoogleTest/MockUefiRuntimeServicesTableLib
> /MockUefiRuntimeServicesTableLib.inf
> b/MdePkg/Test/Mock/Library/GoogleTest/MockUefiRuntimeServicesTableLib
> /MockUefiRuntimeServicesTableLib.inf
> new file mode 100644
> index 000000000000..7ba74d93bfc2
> --- /dev/null
> +++
> b/MdePkg/Test/Mock/Library/GoogleTest/MockUefiRuntimeServicesTableLib
> /MockUefiRuntimeServicesTableLib.inf
> @@ -0,0 +1,33 @@
> +## @file
> +# Google Test mocks for UefiRuntimeServicesTableLib
> +#
> +# Copyright (c) 2022, Intel Corporation. All rights reserved.
> +# SPDX-License-Identifier: BSD-2-Clause-Patent
> +##
> +
> +[Defines]
> +  INF_VERSION                    = 0x00010005
> +  BASE_NAME                      =
> MockUefiRuntimeServicesTableLib
> +  FILE_GUID                      =
> 0A0E13C2-4176-4293-89C7-C2497AA31B92
> +  MODULE_TYPE                    = HOST_APPLICATION
> +  VERSION_STRING                 = 1.0
> +  LIBRARY_CLASS                  = UefiRuntimeServicesTableLib
> +
> +#
> +# The following information is for reference only and not required by the
> build tools.
> +#
> +#  VALID_ARCHITECTURES           = IA32 X64
> +#
> +
> +[Sources]
> +  MockUefiRuntimeServicesTableLib.cpp
> +
> +[Packages]
> +  MdePkg/MdePkg.dec
> +  UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
> +
> +[LibraryClasses]
> +  GoogleTestLib
> +
> +[BuildOptions]
> +  MSFT:*_*_*_CC_FLAGS = /EHsc
> --
> 2.39.1.windows.1




  reply	other threads:[~2023-04-06  1:15 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-04 18:22 [Patch v2 00/12] Add gmock support for host-based unit testing Michael D Kinney
2023-04-04 18:22 ` [Patch v2 01/12] UnitTestFrameworkPkg: Add subhook submodule required for gmock Michael D Kinney
2023-04-05  1:51   ` [edk2-devel] " Michael Kubacki
2023-04-05 18:16   ` Leif Lindholm
2023-04-05 21:34     ` Michael D Kinney
2023-04-07 21:31       ` Michael D Kinney
2023-04-04 18:22 ` [Patch v2 02/12] .pytool/CISettings.py: Add subhook submodule Michael D Kinney
2023-04-05  1:51   ` Michael Kubacki
2023-04-04 18:22 ` [Patch v2 03/12] UnitTestFrameworkPkg: Add gmock support to GoogleTestLib Michael D Kinney
2023-04-05  1:51   ` Michael Kubacki
2023-04-04 18:22 ` [Patch v2 04/12] UnitTestFrameworkPkg/ReadMe.md: Add gmock documentation Michael D Kinney
2023-04-05  1:51   ` [edk2-devel] " Michael Kubacki
2023-04-04 18:22 ` [Patch v2 05/12] MdePkg: Add gmock examples Michael D Kinney
2023-04-06  1:15   ` gaoliming [this message]
2023-04-04 18:22 ` [Patch v2 06/12] MdeModulePkg/Library/UefiSortLib: Add GoogleTestLib example Michael D Kinney
2023-04-04 18:22 ` [Patch v2 07/12] SecurityPkg: Add gmock example Michael D Kinney
2023-04-04 18:22 ` [Patch v2 08/12] SecurityPkg/Library/SecureBootVariableLib: Fix VS20xx 4122 errors Michael D Kinney
2023-04-04 18:22 ` [Patch v2 09/12] SecurityPkg/Library/SecureBootVariableLib: HOST_APPLICATION IA32/X64 only Michael D Kinney
2023-04-04 18:22 ` [Patch v2 10/12] MdePkg/Library/BaseLib: " Michael D Kinney
2023-04-06  1:15   ` 回复: " gaoliming
2023-04-04 18:22 ` [Patch v2 11/12] MdeModulePkg: " Michael D Kinney
2023-04-04 18:22 ` [Patch v2 12/12] PrmPkg/Library: " Michael D Kinney
2023-04-05  1:51   ` Michael Kubacki
2023-04-05  7:50   ` [edk2-devel] " Ard Biesheuvel
2023-04-05 12:46     ` Michael Kubacki
2023-04-05 14:27       ` Michael D Kinney
2023-04-05 20:33 ` [edk2-devel] [Patch v2 00/12] Add gmock support for host-based unit testing Oliver Smith-Denny
2023-04-07 21:20 ` Michael D Kinney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='00f701d96825$519c3290$f4d497b0$@byosoft.com.cn' \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox