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

[REBASE & FF] Add GoogleTest Mocks and STATIC Testing Ability #830

Merged
merged 5 commits into from
May 2, 2024

Commits on May 2, 2024

  1. Add UefiRuntimeLib GoogleTest Mock

    This patch adds a GoogleTest Mock for UefiRuntimeLib to be
    consumed in a GoogleTest that requires this lib be mocked.
    os-d committed May 2, 2024
    Configuration menu
    Copy the full SHA
    e466282 View commit details
    Browse the repository at this point in the history
  2. Add MemoryAllocationLib GoogleTest Mock

    This patch adds a GoogleTest mock for MemoryAllocationLib, which
    is needed for a GoogleTest that is attempting to mock that lib.
    os-d committed May 2, 2024
    Configuration menu
    Copy the full SHA
    67abf44 View commit details
    Browse the repository at this point in the history
  3. Add GoogleTest Mocks for Install[Multiple]ProtocolInterface[s]

    Gmock does not support mocking variadic functions such as
    gBS->InstallMultipleProtocolInterfaces. This patch adds support for
    mocking gBS->InstallProtocolInterface and a wrapper function that
    calls the mocked gBS->InstallProtocolInterface when code under test
    attemps to call gBS->InstallMultipleProtocolInterfaces, which mirrors
    what the actual code does.
    os-d committed May 2, 2024
    Configuration menu
    Copy the full SHA
    21dcc72 View commit details
    Browse the repository at this point in the history
  4. Use Lowercase static For Static Lifetime Variables

    In order to support GoogleTest testing STATIC functions,
    convert the few instances in the codebase where STATIC
    is used to mean a static lifetime as opposed to meaning
    a private function/global variable.
    
    This allows us to undef STATIC for private functions/global
    variables to allow them to be unit tested by GoogleTest.
    os-d committed May 2, 2024
    Configuration menu
    Copy the full SHA
    dfe6be2 View commit details
    Browse the repository at this point in the history
  5. Allow GoogleTest to Test STATIC Functions

    Cmocka is able to test STATIC functions by including the C file
    in the test file. However, in many scenarios, GoogleTest files
    cannot do this as the C++ compiler has stricter rules than the
    C compiler.
    
    This patch updates the UnitTestFrameworkPkgHost.dsc.in to add
    a new build flag GOOGLETEST_HOST_UNIT_TEST_BUILD for
    HOST_APPLICATIONS only. Base.h is then updated to undef STATIC
    if this flag is set. This allows for STATIC functions to be tested
    in GoogleTest.
    
    There is less danger of symbol collision here, because HOST_APPLICATIONS
    are running with the least amount of dependencies possible. This still
    allows for interfaces tests (where a Library Class is tested, not an
    instance, so the library is linked in to the test instead of compiled)
    as the library in this case will not be compiled as a HOST_APPLICATION
    and so the STATIC functions will remain STATIC.
    os-d committed May 2, 2024
    Configuration menu
    Copy the full SHA
    162f3ca View commit details
    Browse the repository at this point in the history