TianoCore EDK2 master
|
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <Uefi.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UnitTestLib.h>
#include <Library/VariablePolicyLib.h>
#include <Library/VariablePolicyHelperLib.h>
#include <Protocol/VariableLock.h>
Go to the source code of this file.
Macros | |
#define | UNIT_TEST_NAME "VarPol/VarLock Shim Unit Test" |
#define | UNIT_TEST_VERSION "1.0" |
#define | TEST_VAR_1_NAME L"TestVar1" |
#define | TEST_VAR_2_NAME L"TestVar2" |
#define | TEST_VAR_3_NAME L"TestVar3" |
#define | TEST_POLICY_ATTRIBUTES_NULL 0 |
#define | TEST_POLICY_MIN_SIZE_NULL 0 |
#define | TEST_POLICY_MAX_SIZE_NULL MAX_UINT32 |
#define | TEST_POLICY_MIN_SIZE_10 10 |
#define | TEST_POLICY_MAX_SIZE_200 200 |
#define | Main main |
Variables | |
EFI_GUID | mTestGuid1 |
=== TEST DATA ================================================================================== | |
EFI_GUID | mTestGuid2 |
EFI_GUID | mTestGuid3 |
This is a host-based unit test for the VariableLockRequestToLock shim.
Copyright (c) Microsoft Corporation. SPDX-License-Identifier: BSD-2-Clause-Patent
Definition in file VariableLockRequestToLockUnitTest.c.
#define Main main |
Avoid ECC error for function name that starts with lower case letter
Definition at line 588 of file VariableLockRequestToLockUnitTest.c.
#define TEST_POLICY_ATTRIBUTES_NULL 0 |
Definition at line 66 of file VariableLockRequestToLockUnitTest.c.
#define TEST_POLICY_MAX_SIZE_200 200 |
Definition at line 71 of file VariableLockRequestToLockUnitTest.c.
#define TEST_POLICY_MAX_SIZE_NULL MAX_UINT32 |
Definition at line 68 of file VariableLockRequestToLockUnitTest.c.
#define TEST_POLICY_MIN_SIZE_10 10 |
Definition at line 70 of file VariableLockRequestToLockUnitTest.c.
#define TEST_POLICY_MIN_SIZE_NULL 0 |
Definition at line 67 of file VariableLockRequestToLockUnitTest.c.
#define TEST_VAR_1_NAME L"TestVar1" |
Definition at line 62 of file VariableLockRequestToLockUnitTest.c.
#define TEST_VAR_2_NAME L"TestVar2" |
Definition at line 63 of file VariableLockRequestToLockUnitTest.c.
#define TEST_VAR_3_NAME L"TestVar3" |
Definition at line 64 of file VariableLockRequestToLockUnitTest.c.
#define UNIT_TEST_NAME "VarPol/VarLock Shim Unit Test" |
Definition at line 26 of file VariableLockRequestToLockUnitTest.c.
#define UNIT_TEST_VERSION "1.0" |
Definition at line 27 of file VariableLockRequestToLockUnitTest.c.
STATIC VOID EFIAPI LibCleanup | ( | IN UNIT_TEST_CONTEXT | Context | ) |
Common cleanup function to make sure that the library is always de-initialized prior to the next test case.
[in] | Context | Unit test case context |
Definition at line 152 of file VariableLockRequestToLockUnitTest.c.
STATIC UNIT_TEST_STATUS EFIAPI LibInitMocked | ( | IN UNIT_TEST_CONTEXT | Context | ) |
This is a common setup function that will ensure the library is always initialized with the stubbed GetVariable.
Not used by all test cases, but by most.
[in] | Context | Unit test case context |
Definition at line 136 of file VariableLockRequestToLockUnitTest.c.
UNIT_TEST_STATUS EFIAPI LockingALockedVariableShouldSucceed | ( | IN UNIT_TEST_CONTEXT | Context | ) |
Test Case that locks a variable using the Variable Policy Protocol then locks the same variable using the Variable Lock Protocol. Both calls are expected to succeed.
[in] | Context | Unit test case context |
Definition at line 215 of file VariableLockRequestToLockUnitTest.c.
UNIT_TEST_STATUS EFIAPI LockingALockedVariableWithMatchingDataShouldSucceed | ( | IN UNIT_TEST_CONTEXT | Context | ) |
Test Case that locks a variable using the Variable Policy Protocol with a policy other than LOCK_NOW, but is currently locked. Then attempts to lock the same variable using the Variable Lock Protocol. The call to Variable Policy is expected to succeed and the call to Variable Lock also expected to succeed.
[in] | Context | Unit test case context |
Definition at line 315 of file VariableLockRequestToLockUnitTest.c.
UNIT_TEST_STATUS EFIAPI LockingALockedVariableWithNonMatchingDataShouldFail | ( | IN UNIT_TEST_CONTEXT | Context | ) |
Test Case that locks a variable using the Variable Policy Protocol with a policy other than LOCK_NOW, but variable data does not match. Then attempts to lock the same variable using the Variable Lock Protocol. The call to Variable Policy is expected to succeed and the call to Variable Lock is expected to fail.
[in] | Context | Unit test case context |
Definition at line 372 of file VariableLockRequestToLockUnitTest.c.
UNIT_TEST_STATUS EFIAPI LockingAnUnlockedVariableShouldFail | ( | IN UNIT_TEST_CONTEXT | Context | ) |
Test Case that locks a variable using the Variable Policy Protocol with a policy other than LOCK_NOW then attempts to lock the same variable using the Variable Lock Protocol. The call to Variable Policy is expected to succeed and the call to Variable Lock is expected to fail.
[in] | Context | Unit test case context |
Definition at line 260 of file VariableLockRequestToLockUnitTest.c.
UNIT_TEST_STATUS EFIAPI LockingTwiceShouldSucceed | ( | IN UNIT_TEST_CONTEXT | Context | ) |
Test Case that locks the same variable twice using the Variable Lock Protocol. Both calls are expected to succeed.
[in] | Context | Unit test case context |
Definition at line 191 of file VariableLockRequestToLockUnitTest.c.
UNIT_TEST_STATUS EFIAPI LockingWithoutAnyPoliciesShouldSucceed | ( | IN UNIT_TEST_CONTEXT | Context | ) |
=== TEST CASES =================================================================================
===== SHIM SUITE =========================================================== Test Case that locks a single variable using the Variable Lock Protocol. The call is expected to succeed.
[in] | Context | Unit test case context |
Definition at line 171 of file VariableLockRequestToLockUnitTest.c.
Standard POSIX C entry point for host based unit test execution.
[in] | Argc | Number of arguments |
[in] | Argv | Array of pointers to arguments |
0 | Success |
other | Error |
Definition at line 600 of file VariableLockRequestToLockUnitTest.c.
UNIT_TEST_STATUS EFIAPI SettingPolicyForALockedVariableShouldFail | ( | IN UNIT_TEST_CONTEXT | Context | ) |
Test Case that locks a variable using Variable Lock Protocol Policy Protocol then and then attempts to lock the same variable using the Variable Policy Protocol. The call to Variable Lock is expected to succeed and the call to Variable Policy is expected to fail.
[in] | Context | Unit test case context |
Definition at line 428 of file VariableLockRequestToLockUnitTest.c.
EFI_STATUS EFIAPI StubGetVariableNull | ( | IN CHAR16 * | VariableName, |
IN EFI_GUID * | VendorGuid, | ||
OUT UINT32 *Attributes | OPTIONAL, | ||
IN OUT UINTN * | DataSize, | ||
OUT VOID *Data | OPTIONAL | ||
) |
=== HELPER FUNCTIONS ===========================================================================
Mocked version of GetVariable, for testing.
VariableName | |
VendorGuid | |
Attributes | |
DataSize | |
Data |
Definition at line 86 of file VariableLockRequestToLockUnitTest.c.
VOID EFIAPI UnitTestMain | ( | VOID | ) |
Main entry point to this unit test application.
Sets up and runs the test suites.
Definition at line 470 of file VariableLockRequestToLockUnitTest.c.
EFI_STATUS EFIAPI VariableLockRequestToLock | ( | IN CONST EDKII_VARIABLE_LOCK_PROTOCOL * | This, |
IN CHAR16 * | VariableName, | ||
IN EFI_GUID * | VendorGuid | ||
) |
=== CODE UNDER TEST ===========================================================================
DEPRECATED. THIS IS ONLY HERE AS A CONVENIENCE WHILE PORTING. Mark a variable that will become read-only after leaving the DXE phase of execution. Write request coming from SMM environment through EFI_SMM_VARIABLE_PROTOCOL is allowed.
[in] | This | The VARIABLE_LOCK_PROTOCOL instance. |
[in] | VariableName | A pointer to the variable name that will be made read-only subsequently. |
[in] | VendorGuid | A pointer to the vendor GUID that will be made read-only subsequently. |
EFI_SUCCESS | The variable specified by the VariableName and the VendorGuid was marked as pending to be read-only. |
EFI_INVALID_PARAMETER | VariableName or VendorGuid is NULL. Or VariableName is an empty string. |
EFI_ACCESS_DENIED | EFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has already been signaled. |
EFI_OUT_OF_RESOURCES | There is not enough resource to hold the lock request. |
Mark a variable that will become read-only after leaving the DXE phase of execution.
[in] | This | The VARIABLE_LOCK_PROTOCOL instance. |
[in] | VariableName | A pointer to the variable name that will be made read-only subsequently. |
[in] | VendorGuid | A pointer to the vendor GUID that will be made read-only subsequently. |
EFI_SUCCESS | The variable specified by the VariableName and the VendorGuid was marked as pending to be read-only. |
EFI_INVALID_PARAMETER | VariableName or VendorGuid is NULL. Or VariableName is an empty string. |
EFI_ACCESS_DENIED | EFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has already been signaled. |
EFI_OUT_OF_RESOURCES | There is not enough resource to hold the lock request. |
Definition at line 42 of file VariableLockRequestToLock.c.
EFI_GUID mTestGuid1 |
=== TEST DATA ==================================================================================
Definition at line 44 of file VariableLockRequestToLockUnitTest.c.
EFI_GUID mTestGuid2 |
Definition at line 51 of file VariableLockRequestToLockUnitTest.c.
EFI_GUID mTestGuid3 |
Definition at line 58 of file VariableLockRequestToLockUnitTest.c.