Changeset 108794 in vbox for trunk/src/VBox/Devices/EFI/FirmwareNew/UnitTestFrameworkPkg/Library
- Timestamp:
- Mar 31, 2025 11:31:09 AM (5 weeks ago)
- svn:sync-xref-src-repo-rev:
- 168237
- Location:
- trunk/src/VBox/Devices/EFI/FirmwareNew
- Files:
-
- 2 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/EFI/FirmwareNew
-
Property svn:mergeinfo
changed from (toggle deleted branches)
to (toggle deleted branches)/vendor/edk2/current 103735-103757,103769-103776,129194-164365 /vendor/edk2/current 103735-103757,103769-103776,129194-168232
-
Property svn:mergeinfo
changed from (toggle deleted branches)
-
trunk/src/VBox/Devices/EFI/FirmwareNew/UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.inf
r105670 r108794 29 29 30 30 [BuildOptions] 31 MSFT:*_*_*_CC_FLAGS == /c /EHs /Zi /Od /MT 31 MSFT:*_*_*_CC_FLAGS == /c /EHs /Zi /Od /MTd 32 32 GCC:*_*_IA32_CC_FLAGS == -g -c -fshort-wchar -fexceptions -O0 -m32 -malign-double -fno-pie 33 33 GCC:*_*_X64_CC_FLAGS == -g -c -fshort-wchar -fexceptions -O0 -m64 -fno-pie "-DEFIAPI=__attribute__((ms_abi))" -
trunk/src/VBox/Devices/EFI/FirmwareNew/UnitTestFrameworkPkg/Library/Posix/MemoryAllocationLibPosix/MemoryAllocationLibPosix.c
r99404 r108794 28 28 typedef struct { 29 29 UINT32 Signature; 30 VOID *AllocatedBuff fer;30 VOID *AllocatedBuffer; 31 31 UINTN TotalPages; 32 32 VOID *AlignedBuffer; … … 34 34 } PAGE_HEAD; 35 35 36 #define POOL_HEAD_PRIVATE_SIGNATURE SIGNATURE_32 ('P', 'O', 'H', 'D') 37 38 typedef struct { 39 UINT32 Signature; 40 UINT32 TotalSize; 41 } POOL_HEAD; 42 36 43 /** 37 44 Allocates one or more 4KB pages of type EfiBootServicesData. … … 166 173 // We need reserve Alignment pages for PAGE_HEAD, as meta data. 167 174 // 168 PageHead.Signature = PAGE_HEAD_PRIVATE_SIGNATURE; 169 PageHead.TotalPages = Pages + EFI_SIZE_TO_PAGES (Alignment) * 2; 170 PageHead.AlignedPages = Pages; 171 PageHead.AllocatedBufffer = malloc (EFI_PAGES_TO_SIZE (PageHead.TotalPages)); 172 if (PageHead.AllocatedBufffer == NULL) { 173 return NULL; 174 } 175 176 PageHead.AlignedBuffer = (VOID *)(((UINTN)PageHead.AllocatedBufffer + AlignmentMask) & ~AlignmentMask); 177 if ((UINTN)PageHead.AlignedBuffer - (UINTN)PageHead.AllocatedBufffer < sizeof (PAGE_HEAD)) { 175 PageHead.Signature = PAGE_HEAD_PRIVATE_SIGNATURE; 176 PageHead.TotalPages = Pages + EFI_SIZE_TO_PAGES (Alignment) * 2; 177 PageHead.AlignedPages = Pages; 178 PageHead.AllocatedBuffer = malloc (EFI_PAGES_TO_SIZE (PageHead.TotalPages)); 179 180 ASSERT (PageHead.AllocatedBuffer != NULL); 181 182 DEBUG_CLEAR_MEMORY (PageHead.AllocatedBuffer, EFI_PAGES_TO_SIZE (PageHead.TotalPages)); 183 184 PageHead.AlignedBuffer = (VOID *)(((UINTN)PageHead.AllocatedBuffer + AlignmentMask) & ~AlignmentMask); 185 if ((UINTN)PageHead.AlignedBuffer - (UINTN)PageHead.AllocatedBuffer < sizeof (PAGE_HEAD)) { 178 186 PageHead.AlignedBuffer = (VOID *)((UINTN)PageHead.AlignedBuffer + Alignment); 179 187 } … … 266 274 { 267 275 PAGE_HEAD *PageHeadPtr; 268 269 // 270 // NOTE: Partial free is not supported. Just keep it. 271 // 272 PageHeadPtr = (VOID *)((UINTN)Buffer - sizeof (PAGE_HEAD)); 273 if (PageHeadPtr->Signature != PAGE_HEAD_PRIVATE_SIGNATURE) { 274 return; 275 } 276 277 if (PageHeadPtr->AlignedPages != Pages) { 278 return; 279 } 280 281 PageHeadPtr->Signature = 0; 282 free (PageHeadPtr->AllocatedBufffer); 276 VOID *AllocatedBuffer; 277 UINTN Length; 278 279 ASSERT (Buffer != NULL); 280 281 PageHeadPtr = ((PAGE_HEAD *)Buffer) - 1; 282 283 ASSERT (PageHeadPtr != NULL); 284 ASSERT (PageHeadPtr->Signature == PAGE_HEAD_PRIVATE_SIGNATURE); 285 ASSERT (PageHeadPtr->AlignedPages == Pages); 286 ASSERT (PageHeadPtr->AllocatedBuffer != NULL); 287 288 AllocatedBuffer = PageHeadPtr->AllocatedBuffer; 289 Length = EFI_PAGES_TO_SIZE (PageHeadPtr->TotalPages); 290 291 DEBUG_CLEAR_MEMORY (AllocatedBuffer, Length); 292 293 free (AllocatedBuffer); 283 294 } 284 295 … … 294 305 @return A pointer to the allocated buffer or NULL if allocation fails. 295 306 296 **/VOID * 307 **/ 308 VOID * 297 309 EFIAPI 298 310 AllocatePool ( … … 300 312 ) 301 313 { 302 return malloc (AllocationSize); 314 POOL_HEAD *PoolHead; 315 UINTN TotalSize; 316 317 TotalSize = sizeof (POOL_HEAD) + AllocationSize; 318 PoolHead = malloc (TotalSize); 319 if (PoolHead == NULL) { 320 return NULL; 321 } 322 323 DEBUG_CLEAR_MEMORY (PoolHead, TotalSize); 324 PoolHead->Signature = POOL_HEAD_PRIVATE_SIGNATURE; 325 PoolHead->TotalSize = (UINT32)TotalSize; 326 327 return (VOID *)(PoolHead + 1); 303 328 } 304 329 … … 366 391 VOID *Buffer; 367 392 368 Buffer = malloc(AllocationSize);393 Buffer = AllocatePool (AllocationSize); 369 394 if (Buffer == NULL) { 370 395 return NULL; … … 445 470 VOID *Memory; 446 471 447 Memory = malloc(AllocationSize);472 Memory = AllocatePool (AllocationSize); 448 473 if (Memory == NULL) { 449 474 return NULL; … … 539 564 VOID *NewBuffer; 540 565 541 NewBuffer = malloc(NewSize);566 NewBuffer = AllocatePool (NewSize); 542 567 if ((NewBuffer != NULL) && (OldBuffer != NULL)) { 543 568 memcpy (NewBuffer, OldBuffer, MIN (OldSize, NewSize)); … … 635 660 ) 636 661 { 637 free (Buffer); 638 } 662 POOL_HEAD *PoolHead; 663 664 ASSERT (Buffer != NULL); 665 666 PoolHead = ((POOL_HEAD *)Buffer) - 1; 667 668 ASSERT (PoolHead != NULL); 669 ASSERT (PoolHead->Signature == POOL_HEAD_PRIVATE_SIGNATURE); 670 ASSERT (PoolHead->TotalSize >= sizeof (POOL_HEAD)); 671 672 DEBUG_CLEAR_MEMORY (PoolHead, PoolHead->TotalSize); 673 free (PoolHead); 674 } -
trunk/src/VBox/Devices/EFI/FirmwareNew/UnitTestFrameworkPkg/Library/Posix/MemoryAllocationLibPosix/MemoryAllocationLibPosix.inf
r85718 r108794 17 17 VERSION_STRING = 1.0 18 18 LIBRARY_CLASS = MemoryAllocationLib|HOST_APPLICATION 19 LIBRARY_CLASS = HostMemoryAllocationBelowAddressLib|HOST_APPLICATION 19 20 20 21 [Sources] 21 22 MemoryAllocationLibPosix.c 23 AllocateBelowAddress.c 24 WinInclude.h 22 25 23 26 [Packages] 24 27 MdePkg/MdePkg.dec 28 UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec 25 29 26 30 [LibraryClasses] 27 BaseLib31 DebugLib -
trunk/src/VBox/Devices/EFI/FirmwareNew/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLibHost.cpp
r105670 r108794 18 18 #include <Library/BaseLib.h> 19 19 #include <Library/UnitTestLib.h> 20 21 // 22 // If address sanitizer is enabled, then declare the function that is used to 23 // handle custom long jump implementation. 24 // 25 #ifdef __SANITIZE_ADDRESS__ 26 void 27 __asan_handle_no_return ( 28 ); 29 30 #endif 20 31 21 32 /// … … 48 59 if (gUnitTestExpectAssertFailureJumpBuffer != NULL) { 49 60 UT_LOG_INFO ("Detected expected ASSERT: %a(%d): %a\n", FileName, LineNumber, Description); 61 62 // 63 // If address sanitizer is enabled, then inform sanitizer that a no return 64 // function is being called that will reset to a previous stack frame. 65 // This is required to avoid false positives from the address sanitizer 66 // due to the use of a custom long jump implementation. 67 // 68 #ifdef __SANITIZE_ADDRESS__ 69 __asan_handle_no_return (); 70 #endif 71 50 72 LongJump (gUnitTestExpectAssertFailureJumpBuffer, 1); 51 73 } else { -
trunk/src/VBox/Devices/EFI/FirmwareNew/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLibHost.inf
r105670 r108794 32 32 33 33 [BuildOptions] 34 MSFT:*_*_*_CC_FLAGS == /c /EHs /Zi /Od /MT 34 MSFT:*_*_*_CC_FLAGS == /c /EHs /Zi /Od /MTd 35 35 GCC:*_*_IA32_CC_FLAGS == -g -c -fshort-wchar -fexceptions -O0 -m32 -malign-double -fno-pie 36 36 GCC:*_*_X64_CC_FLAGS == -g -c -fshort-wchar -fexceptions -O0 -m64 -fno-pie "-DEFIAPI=__attribute__((ms_abi))" -
trunk/src/VBox/Devices/EFI/FirmwareNew/UnitTestFrameworkPkg/Library/UnitTestLib/Assert.c
r105670 r108794 34 34 AsciiStrCpyS ( 35 35 &UnitTest->FailureMessage[0], 36 UNIT_TEST_ TESTFAILUREMSG_LENGTH,36 UNIT_TEST_MAX_STRING_LENGTH, 37 37 FailureMessage 38 38 ); … … 51 51 { 52 52 UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle; 53 CHAR8 LogString[UNIT_TEST_ TESTFAILUREMSG_LENGTH];53 CHAR8 LogString[UNIT_TEST_MAX_STRING_LENGTH]; 54 54 VA_LIST Marker; 55 55 -
trunk/src/VBox/Devices/EFI/FirmwareNew/UnitTestFrameworkPkg/Library/UnitTestLib/AssertCmocka.c
r99404 r108794 382 382 383 383 if (UnitTestStatus == UNIT_TEST_PASSED) { 384 UT_LOG_INFO ( 385 "[ASSERT PASS] %a:%d: UT_EXPECT_ASSERT_FAILURE(%a) detected expected assert\n", 384 snprintf ( 385 TempStr, 386 sizeof (TempStr), 387 "[ASSERT PASS] %s:%d: UT_EXPECT_ASSERT_FAILURE(%s) detected expected assert\n", 386 388 FileName, 387 LineNumber,389 (int)LineNumber, 388 390 FunctionCall 389 391 ); 392 UT_LOG_INFO (TempStr); 390 393 } 391 394 392 395 if (UnitTestStatus == UNIT_TEST_SKIPPED) { 393 UT_LOG_WARNING ( 394 "[ASSERT WARN] %a:%d: UT_EXPECT_ASSERT_FAILURE(%a) disabled\n", 396 snprintf ( 397 TempStr, 398 sizeof (TempStr), 399 "[ASSERT WARN] %s:%d: UT_EXPECT_ASSERT_FAILURE(%s) disabled\n", 395 400 FileName, 396 LineNumber,401 (int)LineNumber, 397 402 FunctionCall 398 403 ); 404 UT_LOG_WARNING (TempStr); 399 405 } 400 406 -
trunk/src/VBox/Devices/EFI/FirmwareNew/UnitTestFrameworkPkg/Library/UnitTestLib/Log.c
r105670 r108794 16 16 #include <Library/PcdLib.h> 17 17 18 #define UNIT_TEST_MAX_SINGLE_LOG_STRING_LENGTH (512) 19 #define UNIT_TEST_MAX_LOG_BUFFER SIZE_16KB 18 #define UNIT_TEST_MAX_LOG_BUFFER SIZE_16KB 20 19 21 20 struct _UNIT_TEST_LOG_PREFIX_STRING { … … 86 85 UNIT_TEST_MAX_LOG_BUFFER / sizeof (CHAR8), 87 86 String, 88 UNIT_TEST_MAX_S INGLE_LOG_STRING_LENGTH87 UNIT_TEST_MAX_STRING_LENGTH 89 88 ); 90 89 if (EFI_ERROR (Status)) { … … 161 160 { 162 161 UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle; 163 CHAR8 NewFormatString[UNIT_TEST_MAX_S INGLE_LOG_STRING_LENGTH];164 CHAR8 LogString[UNIT_TEST_MAX_S INGLE_LOG_STRING_LENGTH];162 CHAR8 NewFormatString[UNIT_TEST_MAX_STRING_LENGTH]; 163 CHAR8 LogString[UNIT_TEST_MAX_STRING_LENGTH]; 165 164 CONST CHAR8 *LogTypePrefix; 166 165 VA_LIST Marker; -
trunk/src/VBox/Devices/EFI/FirmwareNew/UnitTestFrameworkPkg/Library/UnitTestLib/RunTestsCmocka.c
r105670 r108794 112 112 // 113 113 if (UnitTest->Log != NULL) { 114 print_message ("UnitTest: %s - %s\n", UnitTest->Name, UnitTest->Description); 115 print_message ("Log Output Start\n"); 116 print_message ("%s", UnitTest->Log); 117 print_message ("Log Output End\n"); 114 // 115 // UnitTest->Log can be a large buffer that is larger than what DEBUG() 116 // can support. Use printf() directly. 117 // 118 printf ("UnitTest: %s - %s\n", UnitTest->Name, UnitTest->Description); 119 printf ("Log Output Start\n"); 120 printf (UnitTest->Log); 121 printf ("Log Output End\n"); 118 122 } 119 123 -
trunk/src/VBox/Devices/EFI/FirmwareNew/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c
r105670 r108794 132 132 } 133 133 134 STATIC 135 VOID 136 FreeUnitTestTestEntry ( 137 IN UNIT_TEST_LIST_ENTRY *TestEntry 138 ) 139 { 140 if (TestEntry) { 141 if (TestEntry->UT.Description) { 142 FreePool (TestEntry->UT.Description); 143 } 144 145 if (TestEntry->UT.Name) { 146 FreePool (TestEntry->UT.Name); 147 } 148 149 FreePool (TestEntry); 150 } 151 } 152 153 STATIC 154 EFI_STATUS 155 FreeUnitTestSuiteEntry ( 156 IN UNIT_TEST_SUITE_LIST_ENTRY *SuiteEntry 157 ) 158 { 159 UNIT_TEST_LIST_ENTRY *TestCase; 160 UNIT_TEST_LIST_ENTRY *NextTestCase; 161 LIST_ENTRY *TestCaseList; 162 163 if (SuiteEntry) { 164 TestCaseList = &(SuiteEntry->UTS.TestCaseList); 165 TestCase = (UNIT_TEST_LIST_ENTRY *)GetFirstNode (TestCaseList); 166 while (&TestCase->Entry != TestCaseList) { 167 NextTestCase = (UNIT_TEST_LIST_ENTRY *)GetNextNode (TestCaseList, &TestCase->Entry); 168 RemoveEntryList (&TestCase->Entry); 169 FreeUnitTestTestEntry (TestCase); 170 TestCase = NextTestCase; 171 } 172 173 if (SuiteEntry->UTS.Title) { 174 FreePool (SuiteEntry->UTS.Title); 175 } 176 177 if (SuiteEntry->UTS.Name) { 178 FreePool (SuiteEntry->UTS.Name); 179 } 180 181 FreePool (SuiteEntry); 182 } 183 184 return EFI_SUCCESS; 185 } 186 134 187 /** 135 188 Cleanup a test framework. … … 152 205 ) 153 206 { 154 // TODO: Finish this function. 155 return EFI_SUCCESS; 156 } 157 158 STATIC 159 EFI_STATUS 160 FreeUnitTestSuiteEntry ( 161 IN UNIT_TEST_SUITE_LIST_ENTRY *SuiteEntry 162 ) 163 { 164 // TODO: Finish this function. 165 return EFI_SUCCESS; 166 } 167 168 STATIC 169 EFI_STATUS 170 FreeUnitTestTestEntry ( 171 IN UNIT_TEST_LIST_ENTRY *TestEntry 172 ) 173 { 174 // TODO: Finish this function. 207 UNIT_TEST_FRAMEWORK *Framework; 208 UNIT_TEST_SUITE_LIST_ENTRY *Suite; 209 UNIT_TEST_SUITE_LIST_ENTRY *NextSuite; 210 211 Framework = (UNIT_TEST_FRAMEWORK *)FrameworkHandle; 212 if (Framework) { 213 Suite = (UNIT_TEST_SUITE_LIST_ENTRY *)GetFirstNode (&Framework->TestSuiteList); 214 while ((LIST_ENTRY *)Suite != &Framework->TestSuiteList) { 215 NextSuite = (UNIT_TEST_SUITE_LIST_ENTRY *)GetNextNode (&Framework->TestSuiteList, (LIST_ENTRY *)Suite); 216 RemoveEntryList ((LIST_ENTRY *)Suite); 217 FreeUnitTestSuiteEntry (Suite); 218 Suite = NextSuite; 219 } 220 221 if (Framework->Title) { 222 FreePool (Framework->Title); 223 } 224 225 if (Framework->ShortTitle) { 226 FreePool (Framework->ShortTitle); 227 } 228 229 if (Framework->VersionString) { 230 FreePool (Framework->VersionString); 231 } 232 233 FreePool (Framework); 234 } 235 175 236 return EFI_SUCCESS; 176 237 } … … 572 633 AsciiStrnCpyS ( 573 634 &Test->FailureMessage[0], 574 UNIT_TEST_ TESTFAILUREMSG_LENGTH,635 UNIT_TEST_MAX_STRING_LENGTH, 575 636 &MatchingTest->FailureMessage[0], 576 UNIT_TEST_ TESTFAILUREMSG_LENGTH637 UNIT_TEST_MAX_STRING_LENGTH 577 638 ); 578 639 … … 749 810 TestSaveData->Result = UnitTest->Result; 750 811 TestSaveData->FailureType = UnitTest->FailureType; 751 AsciiStrnCpyS (&TestSaveData->FailureMessage[0], UNIT_TEST_ TESTFAILUREMSG_LENGTH, &UnitTest->FailureMessage[0], UNIT_TEST_TESTFAILUREMSG_LENGTH);812 AsciiStrnCpyS (&TestSaveData->FailureMessage[0], UNIT_TEST_MAX_STRING_LENGTH, &UnitTest->FailureMessage[0], UNIT_TEST_MAX_STRING_LENGTH); 752 813 753 814 //
Note:
See TracChangeset
for help on using the changeset viewer.