edk2
edk2 copied to clipboard
Add Gmocks for unit tests
Description
- Add mock functions to existing mocks
- Remove cpp files for existing protocol mocks MockHash2 and MockRng.
- 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.
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.
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.
PR can not be merged due to conflict. Please rebase and resubmit
PR can not be merged due to conflict. Please rebase and resubmit
@mdkinney Can I get your review on this PR, please?
@mdkinney Can you help review this PR?
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?
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.
PR can not be merged due to conflict. Please rebase and resubmit
⚠ 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.
PR can not be merged due to conflict. Please rebase and resubmit
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.
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.