UnitTestDebugAssertLib.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /** @file
  2. Unit Test Debug Assert Library
  3. Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <Uefi.h>
  7. #include <Library/BaseLib.h>
  8. #include <Library/UnitTestLib.h>
  9. ///
  10. /// Point to jump buffer used with SetJump()/LongJump() to test if a function
  11. /// under test generates an expected ASSERT() condition.
  12. ///
  13. BASE_LIBRARY_JUMP_BUFFER *gUnitTestExpectAssertFailureJumpBuffer = NULL;
  14. /**
  15. Unit test library replacement for DebugAssert() in DebugLib.
  16. If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.
  17. If Description is NULL, then a <Description> string of "(NULL) Description" is printed.
  18. @param FileName The pointer to the name of the source file that generated the assert condition.
  19. @param LineNumber The line number in the source file that generated the assert condition
  20. @param Description The pointer to the description of the assert condition.
  21. **/
  22. VOID
  23. EFIAPI
  24. UnitTestDebugAssert (
  25. IN CONST CHAR8 *FileName,
  26. IN UINTN LineNumber,
  27. IN CONST CHAR8 *Description
  28. )
  29. {
  30. CHAR8 Message[256];
  31. if (gUnitTestExpectAssertFailureJumpBuffer != NULL) {
  32. UT_LOG_INFO ("Detected expected ASSERT: %a(%d): %a\n", FileName, LineNumber, Description);
  33. LongJump (gUnitTestExpectAssertFailureJumpBuffer, 1);
  34. } else {
  35. AsciiStrCpyS (Message, sizeof(Message), "Detected unexpected ASSERT(");
  36. AsciiStrCatS (Message, sizeof(Message), Description);
  37. AsciiStrCatS (Message, sizeof(Message), ")");
  38. UnitTestAssertTrue (FALSE, "", LineNumber, FileName, Message);
  39. }
  40. }