17#include "../DxeTpmMeasureBootLibSanitization.h"
19#define UNIT_TEST_NAME "DxeTpmMeasureBootLibSanitizationTest"
20#define UNIT_TEST_VERSION "1.0"
22#define DEFAULT_PRIMARY_TABLE_HEADER_REVISION 0x00010000
23#define DEFAULT_PRIMARY_TABLE_HEADER_NUMBER_OF_PARTITION_ENTRIES 1
24#define DEFAULT_PRIMARY_TABLE_HEADER_SIZE_OF_PARTITION_ENTRY 128
63 BlockIo.
Media = &BlockMedia;
65 BlockIo.ReadBlocks =
NULL;
66 BlockIo.WriteBlocks =
NULL;
67 BlockIo.FlushBlocks =
NULL;
71 PrimaryHeader.
Header.
Revision = DEFAULT_PRIMARY_TABLE_HEADER_REVISION;
73 PrimaryHeader.
MyLBA = 1;
109 DEBUG ((DEBUG_INFO,
"%a: Test passed\n", __func__));
111 return UNIT_TEST_PASSED;
130 UINT32 AllocationSize;
163 DEBUG ((DEBUG_INFO,
"%a: Test passed\n", __func__));
165 return UNIT_TEST_PASSED;
185 UINT32 ExistingLogicEventSize;
188 UINTN NumberOfPartition;
195 NumberOfPartition = 13;
217 DEBUG ((DEBUG_INFO,
"%a: Test passed\n", __func__));
219 return UNIT_TEST_PASSED;
240 UINTN ExistingLogicEventSize;
247 TestStatus = UNIT_TEST_ERROR_TEST_FAILED;
257 if (ImageLoadEvent ==
NULL) {
258 DEBUG ((DEBUG_ERROR,
"%a: AllocateZeroPool failed\n", __func__));
264 ImageLoadEvent->ImageLengthInMemory = 0x1000;
265 ImageLoadEvent->ImageLinkTimeAddress = (
UINTN)ImageLoadEvent;
273 if (EFI_ERROR (Status)) {
274 UT_LOG_ERROR (
"SanitizePeImageEventSize failed with %r\n", Status);
282 if (EventSize != ExistingLogicEventSize) {
283 UT_LOG_ERROR (
"SanitizePeImageEventSize returned an incorrect event size. Expected %u, got %u\n", ExistingLogicEventSize, EventSize);
289 if (Status != EFI_BAD_BUFFER_SIZE) {
290 UT_LOG_ERROR (
"SanitizePeImageEventSize succeded when it was supposed to fail with %r\n", Status);
294 TestStatus = UNIT_TEST_PASSED;
297 if (ImageLoadEvent !=
NULL) {
301 if (TestStatus == UNIT_TEST_ERROR_TEST_FAILED) {
302 DEBUG ((DEBUG_ERROR,
"%a: Test failed\n", __func__));
304 DEBUG ((DEBUG_INFO,
"%a: Test passed\n", __func__));
329 UNIT_TEST_FRAMEWORK_HANDLE Framework;
330 UNIT_TEST_SUITE_HANDLE TcgMeasureBootLibValidationTestSuite;
334 DEBUG ((DEBUG_INFO,
"%a: TestMain() - Start\n", UNIT_TEST_NAME));
337 if (EFI_ERROR (Status)) {
338 DEBUG ((DEBUG_ERROR,
"%a: Failed in InitUnitTestFramework. Status = %r\n", UNIT_TEST_NAME, Status));
342 Status =
CreateUnitTestSuite (&TcgMeasureBootLibValidationTestSuite, Framework,
"TcgMeasureBootLibValidationTestSuite",
"Common.TcgMeasureBootLibValidation",
NULL,
NULL);
343 if (EFI_ERROR (Status)) {
344 DEBUG ((DEBUG_ERROR,
"%s: Failed in CreateUnitTestSuite for TcgMeasureBootLibValidationTestSuite\n", UNIT_TEST_NAME));
345 Status = EFI_OUT_OF_RESOURCES;
358 if (Framework !=
NULL) {
362 DEBUG ((DEBUG_INFO,
"%a: TestMain() - End\n", UNIT_TEST_NAME));
369#define DxeTpmMeasureBootLibUnitTestMain main
UINT32 EFIAPI CalculateCrc32(IN VOID *Buffer, IN UINTN Length)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
EFI_STATUS EFIAPI TpmSanitizePrimaryHeaderAllocationSize(IN CONST EFI_PARTITION_TABLE_HEADER *PrimaryHeader, OUT UINT32 *AllocationSize)
EFI_STATUS TpmSanitizePrimaryHeaderGptEventSize(IN CONST EFI_PARTITION_TABLE_HEADER *PrimaryHeader, IN UINTN NumberOfPartition, OUT UINT32 *EventSize)
EFI_STATUS EFIAPI TpmSanitizeEfiPartitionTableHeader(IN CONST EFI_PARTITION_TABLE_HEADER *PrimaryHeader, IN CONST EFI_BLOCK_IO_PROTOCOL *BlockIo)
EFI_STATUS TpmSanitizePeImageEventSize(IN UINT32 FilePathSize, OUT UINT32 *EventSize)
EFI_STATUS EFIAPI UefiTestMain(VOID)
UNIT_TEST_STATUS EFIAPI TestSanitizePeImageEventSize(IN UNIT_TEST_CONTEXT Context)
#define DxeTpmMeasureBootLibUnitTestMain
UNIT_TEST_STATUS EFIAPI TestSanitizeEfiPartitionTableHeader(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI TestSanitizePrimaryHeaderAllocationSize(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI TestSanitizePrimaryHeaderGptEventSize(IN UNIT_TEST_CONTEXT Context)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define OFFSET_OF(TYPE, Field)
#define DEBUG(Expression)
VOID EFIAPI Exit(IN EFI_STATUS Status)
UINT64 EFI_PHYSICAL_ADDRESS
#define EFI_PTAB_HEADER_ID
EFI_STATUS EFIAPI RunAllTestSuites(IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle)
#define UT_LOG_ERROR(Format,...)
#define UT_ASSERT_EQUAL(ValueA, ValueB)
EFI_STATUS EFIAPI CreateUnitTestSuite(OUT UNIT_TEST_SUITE_HANDLE *SuiteHandle, IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle, IN CHAR8 *Title, IN CHAR8 *Name, IN UNIT_TEST_SUITE_SETUP Setup OPTIONAL, IN UNIT_TEST_SUITE_TEARDOWN Teardown OPTIONAL)
EFI_STATUS EFIAPI FreeUnitTestFramework(IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle)
EFI_STATUS EFIAPI AddTestCase(IN UNIT_TEST_SUITE_HANDLE SuiteHandle, IN CHAR8 *Description, IN CHAR8 *Name, IN UNIT_TEST_FUNCTION Function, IN UNIT_TEST_PREREQUISITE Prerequisite OPTIONAL, IN UNIT_TEST_CLEANUP CleanUp OPTIONAL, IN UNIT_TEST_CONTEXT Context OPTIONAL)
EFI_STATUS EFIAPI InitUnitTestFramework(OUT UNIT_TEST_FRAMEWORK_HANDLE *FrameworkHandle, IN CHAR8 *Title, IN CHAR8 *ShortTitle, IN CHAR8 *VersionString)
#define UT_ASSERT_NOT_EFI_ERROR(Status)
EFI_BLOCK_IO_MEDIA * Media
UINT32 SizeOfPartitionEntry
EFI_LBA PartitionEntryLBA
UINT32 PartitionEntryArrayCRC32
UINT32 NumberOfPartitionEntries