Files
edk2-upstream/MdeModulePkg/Library/DxeReportStatusCodeLib/GoogleTest/DxeReportStatusCodeLibGoogleTest.cpp
Joey Vagedes 0ab766c6b6 MdeModulePkg: Add unit tests for DxeReportStatusCodeLib
This commit adds a host based unit test for DxeReportStatusCodeLib
that ensures that the platform cannot invert the TPL on an initial
call to ReportStatusCode functionality.

Signed-off-by: Joey Vagedes <joey.vagedes@gmail.com>
2026-01-14 04:00:20 +00:00

48 lines
1.3 KiB
C++

/** @file
UEFI based application for unit testing the DxeReportStatusCodeLib.
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <Library/GoogleTestLib.h>
#include <GoogleTest/Library/MockUefiLib.h>
#include <GoogleTest/Library/MockUefiBootServicesTableLib.h>
extern "C" {
#include <Uefi.h>
#include <Library/ReportStatusCodeLib.h>
#include <Library/UefiBootServicesTableLib.h>
}
using namespace testing;
class DxeReportStatusCodeLibGeneralTest : public Test {
protected:
StrictMock<MockUefiBootServicesTableLib> BsMock;
};
// Verify that ReportStatusCode does not attempt to locate the ReportStatusCode protocol
// on demand if not cached. It should only be updated via events outside of a call to
// ReportStatusCode to prevent possible TPL inversion.
TEST_F (DxeReportStatusCodeLibGeneralTest, DoNotCallLocateProtocol) {
EFI_STATUS Status;
// LocateProtocol should never be called
EXPECT_CALL (BsMock, gBS_LocateProtocol (_, _, _))
.Times (0);
Status = ReportStatusCode (EFI_PROGRESS_CODE, 0x0);
ASSERT_EQ (Status, EFI_UNSUPPORTED); // We have not located the protocol, so this is expected.
}
int
main (
int argc,
char *argv[]
)
{
testing::InitGoogleTest (&argc, argv);
return RUN_ALL_TESTS ();
}