edk2 icon indicating copy to clipboard operation
edk2 copied to clipboard

Add Gmocks for unit tests

Open VivianNK opened this issue 1 year ago • 4 comments

Description

  1. Add mock functions to existing mocks
  2. Remove cpp files for existing protocol mocks MockHash2 and MockRng.
  3. Adds gmocks for the following libraries and protocols:

Libraries

MdePkg

  • IoLib
  • MemoryAllocationLib
  • MmServicesTableLib
  • SmmServicesTableLib
  • UefiRuntimeLib
  • SmmCpu

MdeModulePkg

  • SmmVarCheck

UefiCpuPkg

  • LocalApicLib
  • TimerLib

Protocols

MdePkg

  • DebugPort
  • IsaHsc
  • NvmeExpressPassthru
  • PciIoProtocol
  • ServiceBinding
  • SmBios
  • SmmBase2
  • SmmCpu
  • UsbIo

  • [x] Breaking change?
  • [ ] Impacts security?
  • [ ] Includes tests?

How This Was Tested

CI and Unit test execution

Integration Instructions

The cpp files for mock protocols MockHash2 and MockRng were removed and the logic was moved to the header files. Any test consuming these mock protocols will need to update their inf to remove the cpp file as a source.

VivianNK avatar Jul 22 '24 23:07 VivianNK

Why are only a subset of the mock functions from a libclass being added. If a mock library is added, it should include a complete set of the APIs.

mdkinney avatar Aug 07 '24 21:08 mdkinney

Why are only a subset of the mock functions from a libclass being added. If a mock library is added, it should include a complete set of the APIs.

Updated to include a complete set of library classe functions based on their header files.

VivianNK avatar Sep 12 '24 20:09 VivianNK

PR can not be merged due to conflict. Please rebase and resubmit

mergify[bot] avatar Sep 13 '24 04:09 mergify[bot]

PR can not be merged due to conflict. Please rebase and resubmit

mergify[bot] avatar Oct 17 '24 17:10 mergify[bot]

@mdkinney Can I get your review on this PR, please?

VivianNK avatar Oct 21 '24 20:10 VivianNK

@mdkinney Can you help review this PR?

VivianNK avatar Oct 25 '24 21:10 VivianNK

I can't recall id it was this PR or a different PR. Why are global variables in .h file? Can that be moved to a C file?

mdkinney avatar Oct 25 '24 21:10 mdkinney

I can't recall id it was this PR or a different PR. Why are global variables in .h file? Can that be moved to a C file?

@mdkinney

For PPIs, protocols, and other non-library mocks, we're able to use just a header file and not need cpp or inf mock files. Part of that involves having the global mock variable(s) in the header file. This allows use of those mocks without having to include a cpp file as a source in the GoogleTest inf.

For example, before we had under [Sources]:

../../../MdePkg/Test/Mock/Library/GoogleTest/Protocol/MockRng.cpp

Another alternative I considered was having a mock dsc.inc for all the protocols/PPIs in a package, but then we'd be including a lot of unnecessary mocks in every test that only needed 1. Also, my understanding is that it's not precedented to have infs for protocols/PPIs. They only exist as header files, so this mocking method more closely aligns with that.

Would be happy to discuss more at the upcoming Tools & CI Meeting.

VivianNK avatar Oct 25 '24 22:10 VivianNK

PR can not be merged due to conflict. Please rebase and resubmit

mergify[bot] avatar Oct 28 '24 17:10 mergify[bot]

WARNING: Cannot add some reviewers: A user specified as a reviewer for this PR is not a collaborator of the repository. Please add them as a collaborator to the repository so they can be requested in the future.

Non-collaborators requested:

  • @td36

Attn Admins:

  • @jljusten
  • @ardbiesheuvel
  • @lgao4
  • @mdkinney
  • @jkmathews
  • @miki-intel-work

Admin Instructions:

  • Add the non-collaborators as collaborators to the appropriate team(s) listed in teams
  • If they are no longer needed as reviewers, remove them from Maintainers.txt

This PR has been automatically marked as stale because it has not had activity in 60 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions.

github-actions[bot] avatar Feb 08 '25 23:02 github-actions[bot]

PR can not be merged due to conflict. Please rebase and resubmit

mergify[bot] avatar Feb 08 '25 23:02 mergify[bot]

This PR has been automatically marked as stale because it has not had activity in 60 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions.

github-actions[bot] avatar Apr 10 '25 23:04 github-actions[bot]

This pull request has been automatically been closed because it did not have any activity in 60 days and no follow up within 7 days after being marked stale. Thank you for your contributions.

github-actions[bot] avatar Apr 18 '25 23:04 github-actions[bot]