SecurityPkg: Apply uncrustify formatting to relevant files

Apply uncrustify formatting to GoogleTest cpp and header files.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Signed-off-by: Vivian Nowka-Keane <vnowkakeane@linux.microsoft.com>
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
This commit is contained in:
Vivian Nowka-Keane
2023-08-16 14:15:20 -07:00
committed by mergify[bot]
parent 716a3292e0
commit a00f7a355a
3 changed files with 124 additions and 89 deletions

View File

@ -21,12 +21,15 @@ using namespace testing;
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
class SetSecureBootModeTest : public Test { class SetSecureBootModeTest : public Test {
protected: protected:
MockUefiRuntimeServicesTableLib RtServicesMock; MockUefiRuntimeServicesTableLib RtServicesMock;
UINT8 SecureBootMode; UINT8 SecureBootMode;
EFI_STATUS Status; EFI_STATUS Status;
void SetUp() override { void
SetUp (
) override
{
// Any random magic number can be used for these tests // Any random magic number can be used for these tests
SecureBootMode = 0xAB; SecureBootMode = 0xAB;
} }
@ -34,40 +37,46 @@ class SetSecureBootModeTest : public Test {
// Test SetSecureBootMode() API from SecureBootVariableLib to verify the // Test SetSecureBootMode() API from SecureBootVariableLib to verify the
// expected error is returned when the call to gRT->SetVariable() fails. // expected error is returned when the call to gRT->SetVariable() fails.
TEST_F(SetSecureBootModeTest, SetVarError) { TEST_F (SetSecureBootModeTest, SetVarError) {
EXPECT_CALL(RtServicesMock, gRT_SetVariable) EXPECT_CALL (RtServicesMock, gRT_SetVariable)
.WillOnce(Return(EFI_INVALID_PARAMETER)); .WillOnce (Return (EFI_INVALID_PARAMETER));
Status = SetSecureBootMode(SecureBootMode); Status = SetSecureBootMode (SecureBootMode);
EXPECT_EQ(Status, EFI_INVALID_PARAMETER); EXPECT_EQ (Status, EFI_INVALID_PARAMETER);
} }
// Test SetSecureBootMode() API from SecureBootVariableLib to verify the // Test SetSecureBootMode() API from SecureBootVariableLib to verify the
// expected secure boot mode is written to the correct variable in the call // expected secure boot mode is written to the correct variable in the call
// to gRT->SetVariable(). // to gRT->SetVariable().
TEST_F(SetSecureBootModeTest, PropogateModeToSetVar) { TEST_F (SetSecureBootModeTest, PropogateModeToSetVar) {
EXPECT_CALL(RtServicesMock, EXPECT_CALL (
gRT_SetVariable( RtServicesMock,
Char16StrEq(EFI_CUSTOM_MODE_NAME), gRT_SetVariable (
BufferEq(&gEfiCustomModeEnableGuid, sizeof(EFI_GUID)), Char16StrEq (EFI_CUSTOM_MODE_NAME),
BufferEq (&gEfiCustomModeEnableGuid, sizeof (EFI_GUID)),
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
sizeof(SecureBootMode), sizeof (SecureBootMode),
BufferEq(&SecureBootMode, sizeof(SecureBootMode)))) BufferEq (&SecureBootMode, sizeof (SecureBootMode))
.WillOnce(Return(EFI_SUCCESS)); )
)
.WillOnce (Return (EFI_SUCCESS));
Status = SetSecureBootMode(SecureBootMode); Status = SetSecureBootMode (SecureBootMode);
EXPECT_EQ(Status, EFI_SUCCESS); EXPECT_EQ (Status, EFI_SUCCESS);
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
class GetSetupModeTest : public Test { class GetSetupModeTest : public Test {
protected: protected:
MockUefiRuntimeServicesTableLib RtServicesMock; MockUefiRuntimeServicesTableLib RtServicesMock;
UINT8 SetupMode; UINT8 SetupMode;
EFI_STATUS Status; EFI_STATUS Status;
UINT8 ExpSetupMode; UINT8 ExpSetupMode;
void SetUp() override { void
SetUp (
) override
{
// Any random magic number can be used for these tests // Any random magic number can be used for these tests
ExpSetupMode = 0xAB; ExpSetupMode = 0xAB;
} }
@ -75,100 +84,126 @@ class GetSetupModeTest : public Test {
// Test GetSetupMode() API from SecureBootVariableLib to verify the expected // Test GetSetupMode() API from SecureBootVariableLib to verify the expected
// error is returned when the call to gRT->GetVariable() fails. // error is returned when the call to gRT->GetVariable() fails.
TEST_F(GetSetupModeTest, GetVarError) { TEST_F (GetSetupModeTest, GetVarError) {
EXPECT_CALL(RtServicesMock, gRT_GetVariable) EXPECT_CALL (RtServicesMock, gRT_GetVariable)
.WillOnce(Return(EFI_INVALID_PARAMETER)); .WillOnce (Return (EFI_INVALID_PARAMETER));
Status = GetSetupMode (&SetupMode); Status = GetSetupMode (&SetupMode);
EXPECT_EQ(Status, EFI_INVALID_PARAMETER); EXPECT_EQ (Status, EFI_INVALID_PARAMETER);
} }
// Test GetSetupMode() API from SecureBootVariableLib to verify the expected // Test GetSetupMode() API from SecureBootVariableLib to verify the expected
// setup mode is returned (and with a success return code) when the mode is // setup mode is returned (and with a success return code) when the mode is
// successfully read from the call to gRT->GetVariable(). // successfully read from the call to gRT->GetVariable().
TEST_F(GetSetupModeTest, FetchModeFromGetVar) { TEST_F (GetSetupModeTest, FetchModeFromGetVar) {
EXPECT_CALL(RtServicesMock, EXPECT_CALL (
gRT_GetVariable( RtServicesMock,
Char16StrEq(EFI_SETUP_MODE_NAME), gRT_GetVariable (
BufferEq(&gEfiGlobalVariableGuid, sizeof(EFI_GUID)), Char16StrEq (EFI_SETUP_MODE_NAME),
BufferEq (&gEfiGlobalVariableGuid, sizeof (EFI_GUID)),
_, _,
Pointee(Eq(sizeof(SetupMode))), Pointee (Eq (sizeof (SetupMode))),
NotNull())) NotNull ()
.WillOnce(DoAll( )
SetArgPointee<3>(sizeof(ExpSetupMode)), )
SetArgBuffer<4>(&ExpSetupMode, sizeof(ExpSetupMode)), .WillOnce (
Return(EFI_SUCCESS))); DoAll (
SetArgPointee<3>(sizeof (ExpSetupMode)),
SetArgBuffer<4>(&ExpSetupMode, sizeof (ExpSetupMode)),
Return (EFI_SUCCESS)
)
);
Status = GetSetupMode (&SetupMode); Status = GetSetupMode (&SetupMode);
ASSERT_EQ(Status, EFI_SUCCESS); ASSERT_EQ (Status, EFI_SUCCESS);
EXPECT_EQ(SetupMode, ExpSetupMode); EXPECT_EQ (SetupMode, ExpSetupMode);
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
class IsSecureBootEnabledTest : public Test { class IsSecureBootEnabledTest : public Test {
protected: protected:
MockUefiLib UefiLibMock; MockUefiLib UefiLibMock;
BOOLEAN Enabled; BOOLEAN Enabled;
}; };
// Test IsSecureBootEnabled() API from SecureBootVariableLib to verify FALSE // Test IsSecureBootEnabled() API from SecureBootVariableLib to verify FALSE
// is returned when the call to GetEfiGlobalVariable2() fails. // is returned when the call to GetEfiGlobalVariable2() fails.
TEST_F(IsSecureBootEnabledTest, GetVarError) { TEST_F (IsSecureBootEnabledTest, GetVarError) {
EXPECT_CALL(UefiLibMock, GetEfiGlobalVariable2) EXPECT_CALL (UefiLibMock, GetEfiGlobalVariable2)
.WillOnce(Return(EFI_ABORTED)); .WillOnce (Return (EFI_ABORTED));
Enabled = IsSecureBootEnabled (); Enabled = IsSecureBootEnabled ();
EXPECT_EQ(Enabled, FALSE); EXPECT_EQ (Enabled, FALSE);
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
class IsSecureBootEnabledAllocTest : public IsSecureBootEnabledTest { class IsSecureBootEnabledAllocTest : public IsSecureBootEnabledTest {
protected: protected:
UINT8 *BootEnabledBuffer; UINT8 *BootEnabledBuffer;
void SetUp() override { void
BootEnabledBuffer = (UINT8*) AllocatePool(1); SetUp (
ASSERT_NE(BootEnabledBuffer, nullptr); ) override
{
BootEnabledBuffer = (UINT8 *)AllocatePool (1);
ASSERT_NE (BootEnabledBuffer, nullptr);
} }
}; };
// Test IsSecureBootEnabled() API from SecureBootVariableLib to verify TRUE // Test IsSecureBootEnabled() API from SecureBootVariableLib to verify TRUE
// is returned when the call to GetEfiGlobalVariable2() is successful and // is returned when the call to GetEfiGlobalVariable2() is successful and
// returns SECURE_BOOT_MODE_ENABLE. // returns SECURE_BOOT_MODE_ENABLE.
TEST_F(IsSecureBootEnabledAllocTest, IsEnabled) { TEST_F (IsSecureBootEnabledAllocTest, IsEnabled) {
*BootEnabledBuffer = SECURE_BOOT_MODE_ENABLE; *BootEnabledBuffer = SECURE_BOOT_MODE_ENABLE;
EXPECT_CALL(UefiLibMock, EXPECT_CALL (
GetEfiGlobalVariable2( UefiLibMock,
Char16StrEq(EFI_SECURE_BOOT_MODE_NAME), GetEfiGlobalVariable2 (
NotNull(), Char16StrEq (EFI_SECURE_BOOT_MODE_NAME),
_)) NotNull (),
.WillOnce(DoAll( _
SetArgBuffer<1>(&BootEnabledBuffer, sizeof(VOID*)), )
Return(EFI_SUCCESS))); )
.WillOnce (
DoAll (
SetArgBuffer<1>(&BootEnabledBuffer, sizeof (VOID *)),
Return (EFI_SUCCESS)
)
);
Enabled = IsSecureBootEnabled (); Enabled = IsSecureBootEnabled ();
EXPECT_EQ(Enabled, TRUE); EXPECT_EQ (Enabled, TRUE);
} }
// Test IsSecureBootEnabled() API from SecureBootVariableLib to verify FALSE // Test IsSecureBootEnabled() API from SecureBootVariableLib to verify FALSE
// is returned when the call to GetEfiGlobalVariable2() is successful and // is returned when the call to GetEfiGlobalVariable2() is successful and
// returns SECURE_BOOT_MODE_DISABLE. // returns SECURE_BOOT_MODE_DISABLE.
TEST_F(IsSecureBootEnabledAllocTest, IsDisabled) { TEST_F (IsSecureBootEnabledAllocTest, IsDisabled) {
*BootEnabledBuffer = SECURE_BOOT_MODE_DISABLE; *BootEnabledBuffer = SECURE_BOOT_MODE_DISABLE;
EXPECT_CALL(UefiLibMock, EXPECT_CALL (
GetEfiGlobalVariable2( UefiLibMock,
Char16StrEq(EFI_SECURE_BOOT_MODE_NAME), GetEfiGlobalVariable2 (
NotNull(), Char16StrEq (EFI_SECURE_BOOT_MODE_NAME),
_)) NotNull (),
.WillOnce(DoAll( _
SetArgBuffer<1>(&BootEnabledBuffer, sizeof(VOID*)), )
Return(EFI_SUCCESS))); )
.WillOnce (
DoAll (
SetArgBuffer<1>(&BootEnabledBuffer, sizeof (VOID *)),
Return (EFI_SUCCESS)
)
);
Enabled = IsSecureBootEnabled (); Enabled = IsSecureBootEnabled ();
EXPECT_EQ(Enabled, FALSE); EXPECT_EQ (Enabled, FALSE);
} }
int main(int argc, char* argv[]) { int
testing::InitGoogleTest(&argc, argv); main (
return RUN_ALL_TESTS(); int argc,
char *argv[]
)
{
testing::InitGoogleTest (&argc, argv);
return RUN_ALL_TESTS ();
} }

View File

@ -11,8 +11,8 @@
#include <Library/GoogleTestLib.h> #include <Library/GoogleTestLib.h>
#include <Library/FunctionMockLib.h> #include <Library/FunctionMockLib.h>
extern "C" { extern "C" {
#include <Uefi.h> #include <Uefi.h>
#include <Library/PlatformPKProtectionLib.h> #include <Library/PlatformPKProtectionLib.h>
} }
struct MockPlatformPKProtectionLib { struct MockPlatformPKProtectionLib {

View File

@ -6,6 +6,6 @@
**/ **/
#include <GoogleTest/Library/MockPlatformPKProtectionLib.h> #include <GoogleTest/Library/MockPlatformPKProtectionLib.h>
MOCK_INTERFACE_DEFINITION(MockPlatformPKProtectionLib); MOCK_INTERFACE_DEFINITION (MockPlatformPKProtectionLib);
MOCK_FUNCTION_DEFINITION(MockPlatformPKProtectionLib, DisablePKProtection, 0, EFIAPI); MOCK_FUNCTION_DEFINITION (MockPlatformPKProtectionLib, DisablePKProtection, 0, EFIAPI);