Skip to content

Commit

Permalink
IpmiFeaturePkg/IpmiSmbios/GoogleTest/IpmiSmbiosGoogleTest: Fix unit t…
Browse files Browse the repository at this point in the history
…est compilation errors.

Unit tests started failing due to compilation errors. This stemmed from
a bug fixed in microsoft/mu_basecore#891. Once this bug was fixed, the
unit tests starting to be compiled which blocked pipelines.
  • Loading branch information
apop5 committed Jun 21, 2024
1 parent 429bc82 commit 8fbf760
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 27 deletions.
66 changes: 41 additions & 25 deletions IpmiFeaturePkg/IpmiSmbios/GoogleTest/IpmiSmbiosGoogleTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
**/
#include <Library/GoogleTestLib.h>
#include <Library/FunctionMockLib.h>
#include <GoogleTest/Library/MockUefiBootServicesTableLib.h>

extern "C" {
#include <Uefi.h>
#include <IndustryStandard/SmBios.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Protocol/Smbios.h>
#include <IpmiInterface.h>
#include <IndustryStandard/Ipmi.h>
#include <IndustryStandard/IpmiNetFnApp.h>

extern SMBIOS_TABLE_TYPE38 mSmbiosTableType38;

Expand All @@ -28,26 +31,7 @@ extern "C" {

using namespace testing;

//
// Declarations to handle usage of the UefiBootServiceTableLib by creating mock
//
struct MockUefiBootServicesTableLib {
MOCK_INTERFACE_DECLARATION (MockUefiBootServicesTableLib);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
gBS_LocateProtocol,
(IN EFI_GUID *Protocol,
IN VOID *Registration OPTIONAL,
OUT VOID **Interface)
);
};

MOCK_INTERFACE_DEFINITION (MockUefiBootServicesTableLib);
MOCK_FUNCTION_DEFINITION (MockUefiBootServicesTableLib, gBS_LocateProtocol, 3, EFIAPI);

static EFI_BOOT_SERVICES LocalBs;
EFI_BOOT_SERVICES *gBS = &LocalBs;

//
// Declarations to handle usage of the IPMI_TRANSPORT by creating mock
Expand All @@ -68,8 +52,25 @@ struct MockIpmiBaseLib {
};

MOCK_INTERFACE_DEFINITION (MockIpmiBaseLib);

MOCK_FUNCTION_DEFINITION (MockIpmiBaseLib, IpmiSubmitCommand, 6, EFIAPI);

//
// Declarations to handle Ipmi Command Lib
//
struct MockIpmiCommandLib {
MOCK_INTERFACE_DECLARATION (MockIpmiCommandLib);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
IpmiGetDeviceId,
(OUT IPMI_GET_DEVICE_ID_RESPONSE *DeviceId)
);
};

MOCK_INTERFACE_DEFINITION (MockIpmiCommandLib);
MOCK_FUNCTION_DEFINITION (MockIpmiCommandLib, IpmiGetDeviceId, 1, EFIAPI);

//
// Declarations to handle usage of the EFI_SMBIOS_PROTOCOL by creating mock
//
Expand All @@ -89,7 +90,8 @@ struct MockSmbiosProtocol {
MOCK_INTERFACE_DEFINITION (MockSmbiosProtocol);
MOCK_FUNCTION_DEFINITION (MockSmbiosProtocol, MockSmbiosAdd, 4, EFIAPI);

static EFI_SMBIOS_PROTOCOL LocalSmbiosProtocol;
static EFI_SMBIOS_PROTOCOL LocalSmbiosProtocol;
static IPMI_GET_DEVICE_ID_RESPONSE DeviceIdResponse;

class MockIpmiSmbios : public Test {
protected:
Expand All @@ -98,12 +100,24 @@ class MockIpmiSmbios : public Test {
MockUefiBootServicesTableLib UefiBootServicesTableLib;
MockIpmiBaseLib IpmiBaseLib;
MockSmbiosProtocol EFI_SMBIOS_PROTOCOL;
MockIpmiCommandLib IpmiCommandLib;
virtual void
SetUp (
)
{
LocalBs.LocateProtocol = gBS_LocateProtocol;
LocalSmbiosProtocol.Add = MockSmbiosAdd;
LocalSmbiosProtocol.Add = MockSmbiosAdd;
DeviceIdResponse.CompletionCode = IPMI_COMP_CODE_NORMAL;
DeviceIdResponse.DeviceId = 0xAB;
DeviceIdResponse.DeviceRevision.Uint8 = 0;
DeviceIdResponse.FirmwareRev1.Uint8 = 0x0;
DeviceIdResponse.MinorFirmwareRev = 0;
DeviceIdResponse.SpecificationVersion = 2;
DeviceIdResponse.DeviceSupport.Uint8 = 0;
DeviceIdResponse.ManufacturerId[0] = 0xB;
DeviceIdResponse.ManufacturerId[1] = 0xA;
DeviceIdResponse.ManufacturerId[2] = 0xD;
DeviceIdResponse.ProductId = 1;
DeviceIdResponse.AuxFirmwareRevInfo = 0;
}
};

Expand All @@ -115,7 +129,8 @@ TEST_F (MockIpmiSmbios, VerifyCreateIpmiSmbiosType38TestCase) {
Return (EFI_SUCCESS)
)
);
EXPECT_CALL (IpmiBaseLib, IpmiSubmitCommand)

EXPECT_CALL (IpmiCommandLib, IpmiGetDeviceId (_))
.WillOnce (Return (EFI_SUCCESS));
EXPECT_CALL (EFI_SMBIOS_PROTOCOL, MockSmbiosAdd)
.WillOnce (Return (EFI_SUCCESS));
Expand Down Expand Up @@ -156,7 +171,7 @@ TEST_F (MockIpmiSmbios, VerifyCreateIpmiSmbiosType38IpmiSubmitCommandFailTestCas
Return (EFI_SUCCESS)
)
);
EXPECT_CALL (IpmiBaseLib, IpmiSubmitCommand)
EXPECT_CALL (IpmiCommandLib, IpmiGetDeviceId (_))
.WillOnce (Return (EFI_NOT_READY));

Status = CreateIpmiSmbiosType38 ();
Expand All @@ -171,8 +186,9 @@ TEST_F (MockIpmiSmbios, VerifyCreateIpmiSmbiosType38SmbiosAddFailTestCase) {
Return (EFI_SUCCESS)
)
);
EXPECT_CALL (IpmiBaseLib, IpmiSubmitCommand)
EXPECT_CALL (IpmiCommandLib, IpmiGetDeviceId (_))
.WillOnce (Return (EFI_SUCCESS));

EXPECT_CALL (EFI_SMBIOS_PROTOCOL, MockSmbiosAdd)
.WillOnce (Return (EFI_INVALID_PARAMETER));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
MemoryAllocationLib
BaseMemoryLib
DebugLib
IpmiCommandLib
GoogleTestLib

[Protocols]
Expand Down
5 changes: 4 additions & 1 deletion IpmiFeaturePkg/Test/IpmiFeaturePkgHostTest.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@
gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x06 # Disable Debug ASSERT for googletest
}

IpmiFeaturePkg/IpmiSmbios/GoogleTest/IpmiSmbiosGoogleTest.inf
IpmiFeaturePkg/IpmiSmbios/GoogleTest/IpmiSmbiosGoogleTest.inf {
<LibraryClasses>
UefiBootServicesTableLib|MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.inf
}

#
# Build HOST_APPLICATION Libraries
Expand Down

0 comments on commit 8fbf760

Please sign in to comment.