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

IpmiFeaturePkg/IpmiSmbios/GoogleTest/IpmiSmbiosGoogleTest: Fix unit t… #239

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 41 additions & 27 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,27 +31,6 @@ 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 +50,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 +88,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 +98,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 +127,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 +169,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 +184,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
Loading