|
@@ -13,6 +13,8 @@
|
|
|
#include <Library/DebugLib.h>
|
|
|
#include <Library/PrintLib.h>
|
|
|
|
|
|
+extern BASE_LIBRARY_JUMP_BUFFER gUnitTestJumpBuffer;
|
|
|
+
|
|
|
STATIC
|
|
|
EFI_STATUS
|
|
|
AddUnitTestFailure (
|
|
@@ -71,7 +73,7 @@ UnitTestLogFailure (
|
|
|
FailureType
|
|
|
);
|
|
|
|
|
|
- return;
|
|
|
+ LongJump (&gUnitTestJumpBuffer, 1);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -103,15 +105,15 @@ UnitTestAssertTrue (
|
|
|
)
|
|
|
{
|
|
|
if (!Expression) {
|
|
|
- UnitTestLogFailure (
|
|
|
- FAILURETYPE_ASSERTTRUE,
|
|
|
- "%a:%d: Expression (%a) is not TRUE!\n",
|
|
|
+ UT_LOG_ERROR (
|
|
|
+ "[ASSERT FAIL] %a:%d: Expression (%a) is not TRUE!\n",
|
|
|
FileName,
|
|
|
LineNumber,
|
|
|
Description
|
|
|
);
|
|
|
- UT_LOG_ERROR (
|
|
|
- "[ASSERT FAIL] %a:%d: Expression (%a) is not TRUE!\n",
|
|
|
+ UnitTestLogFailure (
|
|
|
+ FAILURETYPE_ASSERTTRUE,
|
|
|
+ "%a:%d: Expression (%a) is not TRUE!\n",
|
|
|
FileName,
|
|
|
LineNumber,
|
|
|
Description
|
|
@@ -149,15 +151,15 @@ UnitTestAssertFalse (
|
|
|
)
|
|
|
{
|
|
|
if (Expression) {
|
|
|
- UnitTestLogFailure (
|
|
|
- FAILURETYPE_ASSERTFALSE,
|
|
|
- "%a:%d: Expression(%a) is not FALSE!\n",
|
|
|
+ UT_LOG_ERROR (
|
|
|
+ "[ASSERT FAIL] %a:%d: Expression (%a) is not FALSE!\n",
|
|
|
FileName,
|
|
|
LineNumber,
|
|
|
Description
|
|
|
);
|
|
|
- UT_LOG_ERROR (
|
|
|
- "[ASSERT FAIL] %a:%d: Expression (%a) is not FALSE!\n",
|
|
|
+ UnitTestLogFailure (
|
|
|
+ FAILURETYPE_ASSERTFALSE,
|
|
|
+ "%a:%d: Expression(%a) is not FALSE!\n",
|
|
|
FileName,
|
|
|
LineNumber,
|
|
|
Description
|
|
@@ -195,16 +197,16 @@ UnitTestAssertNotEfiError (
|
|
|
)
|
|
|
{
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
- UnitTestLogFailure (
|
|
|
- FAILURETYPE_ASSERTNOTEFIERROR,
|
|
|
- "%a:%d: Status '%a' is EFI_ERROR (%r)!\n",
|
|
|
+ UT_LOG_ERROR (
|
|
|
+ "[ASSERT FAIL] %a:%d: Status '%a' is EFI_ERROR (%r)!\n",
|
|
|
FileName,
|
|
|
LineNumber,
|
|
|
Description,
|
|
|
Status
|
|
|
);
|
|
|
- UT_LOG_ERROR (
|
|
|
- "[ASSERT FAIL] %a:%d: Status '%a' is EFI_ERROR (%r)!\n",
|
|
|
+ UnitTestLogFailure (
|
|
|
+ FAILURETYPE_ASSERTNOTEFIERROR,
|
|
|
+ "%a:%d: Status '%a' is EFI_ERROR (%r)!\n",
|
|
|
FileName,
|
|
|
LineNumber,
|
|
|
Description,
|
|
@@ -248,9 +250,8 @@ UnitTestAssertEqual (
|
|
|
)
|
|
|
{
|
|
|
if (ValueA != ValueB) {
|
|
|
- UnitTestLogFailure (
|
|
|
- FAILURETYPE_ASSERTEQUAL,
|
|
|
- "%a:%d: Value %a != %a (%d != %d)!\n",
|
|
|
+ UT_LOG_ERROR (
|
|
|
+ "[ASSERT FAIL] %a:%d: Value %a != %a (%d != %d)!\n",
|
|
|
FileName,
|
|
|
LineNumber,
|
|
|
DescriptionA,
|
|
@@ -258,8 +259,9 @@ UnitTestAssertEqual (
|
|
|
ValueA,
|
|
|
ValueB
|
|
|
);
|
|
|
- UT_LOG_ERROR (
|
|
|
- "[ASSERT FAIL] %a:%d: Value %a != %a (%d != %d)!\n",
|
|
|
+ UnitTestLogFailure (
|
|
|
+ FAILURETYPE_ASSERTEQUAL,
|
|
|
+ "%a:%d: Value %a != %a (%d != %d)!\n",
|
|
|
FileName,
|
|
|
LineNumber,
|
|
|
DescriptionA,
|
|
@@ -310,17 +312,17 @@ UnitTestAssertMemEqual (
|
|
|
)
|
|
|
{
|
|
|
if (CompareMem(BufferA, BufferB, Length) != 0) {
|
|
|
- UnitTestLogFailure (
|
|
|
- FAILURETYPE_ASSERTEQUAL,
|
|
|
- "%a:%d: Memory at %a != %a for length %d bytes!\n",
|
|
|
+ UT_LOG_ERROR (
|
|
|
+ "[ASSERT FAIL] %a:%d: Value %a != %a for length %d bytes!\n",
|
|
|
FileName,
|
|
|
LineNumber,
|
|
|
DescriptionA,
|
|
|
DescriptionB,
|
|
|
Length
|
|
|
);
|
|
|
- UT_LOG_ERROR (
|
|
|
- "[ASSERT FAIL] %a:%d: Value %a != %a for length %d bytes!\n",
|
|
|
+ UnitTestLogFailure (
|
|
|
+ FAILURETYPE_ASSERTEQUAL,
|
|
|
+ "%a:%d: Memory at %a != %a for length %d bytes!\n",
|
|
|
FileName,
|
|
|
LineNumber,
|
|
|
DescriptionA,
|
|
@@ -366,9 +368,8 @@ UnitTestAssertNotEqual (
|
|
|
)
|
|
|
{
|
|
|
if (ValueA == ValueB) {
|
|
|
- UnitTestLogFailure (
|
|
|
- FAILURETYPE_ASSERTNOTEQUAL,
|
|
|
- "%a:%d: Value %a == %a (%d == %d)!\n",
|
|
|
+ UT_LOG_ERROR (
|
|
|
+ "[ASSERT FAIL] %a:%d: Value %a == %a (%d == %d)!\n",
|
|
|
FileName,
|
|
|
LineNumber,
|
|
|
DescriptionA,
|
|
@@ -376,8 +377,9 @@ UnitTestAssertNotEqual (
|
|
|
ValueA,
|
|
|
ValueB
|
|
|
);
|
|
|
- UT_LOG_ERROR (
|
|
|
- "[ASSERT FAIL] %a:%d: Value %a == %a (%d == %d)!\n",
|
|
|
+ UnitTestLogFailure (
|
|
|
+ FAILURETYPE_ASSERTNOTEQUAL,
|
|
|
+ "%a:%d: Value %a == %a (%d == %d)!\n",
|
|
|
FileName,
|
|
|
LineNumber,
|
|
|
DescriptionA,
|
|
@@ -421,17 +423,17 @@ UnitTestAssertStatusEqual (
|
|
|
)
|
|
|
{
|
|
|
if (Status != Expected) {
|
|
|
- UnitTestLogFailure (
|
|
|
- FAILURETYPE_ASSERTSTATUSEQUAL,
|
|
|
- "%a:%d: Status '%a' is %r, should be %r!\n",
|
|
|
+ UT_LOG_ERROR (
|
|
|
+ "[ASSERT FAIL] %a:%d: Status '%a' is %r, should be %r!\n",
|
|
|
FileName,
|
|
|
LineNumber,
|
|
|
Description,
|
|
|
Status,
|
|
|
Expected
|
|
|
);
|
|
|
- UT_LOG_ERROR (
|
|
|
- "[ASSERT FAIL] %a:%d: Status '%a' is %r, should be %r!\n",
|
|
|
+ UnitTestLogFailure (
|
|
|
+ FAILURETYPE_ASSERTSTATUSEQUAL,
|
|
|
+ "%a:%d: Status '%a' is %r, should be %r!\n",
|
|
|
FileName,
|
|
|
LineNumber,
|
|
|
Description,
|
|
@@ -473,6 +475,12 @@ UnitTestAssertNotNull (
|
|
|
)
|
|
|
{
|
|
|
if (Pointer == NULL) {
|
|
|
+ UT_LOG_ERROR (
|
|
|
+ "[ASSERT FAIL] %a:%d: Pointer (%a) is NULL!\n",
|
|
|
+ FileName,
|
|
|
+ LineNumber,
|
|
|
+ PointerName
|
|
|
+ );
|
|
|
UnitTestLogFailure (
|
|
|
FAILURETYPE_ASSERTNOTNULL,
|
|
|
"%a:%d: Pointer (%a) is NULL!\n",
|
|
@@ -480,12 +488,83 @@ UnitTestAssertNotNull (
|
|
|
LineNumber,
|
|
|
PointerName
|
|
|
);
|
|
|
+ }
|
|
|
+ return (Pointer != NULL);
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ If UnitTestStatus is UNIT_TEST_PASSED, then log an info message and return
|
|
|
+ TRUE because an ASSERT() was expected when FunctionCall was executed and an
|
|
|
+ ASSERT() was triggered. If UnitTestStatus is UNIT_TEST_SKIPPED, then log a
|
|
|
+ warning message and return TRUE because ASSERT() macros are disabled. If
|
|
|
+ UnitTestStatus is UNIT_TEST_ERROR_TEST_FAILED, then log an error message and
|
|
|
+ return FALSE because an ASSERT() was expected when FunctionCall was executed,
|
|
|
+ but no ASSERT() conditions were triggered. The log messages contain
|
|
|
+ FunctionName, LineNumber, and FileName strings to provide the location of the
|
|
|
+ UT_EXPECT_ASSERT_FAILURE() macro.
|
|
|
+
|
|
|
+ @param[in] UnitTestStatus The status from UT_EXPECT_ASSERT_FAILURE() that
|
|
|
+ is either pass, skipped, or failed.
|
|
|
+ @param[in] FunctionName Null-terminated ASCII string of the function
|
|
|
+ executing the UT_EXPECT_ASSERT_FAILURE() macro.
|
|
|
+ @param[in] LineNumber The source file line number of the the function
|
|
|
+ executing the UT_EXPECT_ASSERT_FAILURE() macro.
|
|
|
+ @param[in] FileName Null-terminated ASCII string of the filename
|
|
|
+ executing the UT_EXPECT_ASSERT_FAILURE() macro.
|
|
|
+ @param[in] FunctionCall Null-terminated ASCII string of the function call
|
|
|
+ executed by the UT_EXPECT_ASSERT_FAILURE() macro.
|
|
|
+ @param[out] ResultStatus Used to return the UnitTestStatus value to the
|
|
|
+ caller of UT_EXPECT_ASSERT_FAILURE(). This is
|
|
|
+ optional parameter that may be NULL.
|
|
|
+
|
|
|
+ @retval TRUE UnitTestStatus is UNIT_TEST_PASSED.
|
|
|
+ @retval TRUE UnitTestStatus is UNIT_TEST_SKIPPED.
|
|
|
+ @retval FALSE UnitTestStatus is UNIT_TEST_ERROR_TEST_FAILED.
|
|
|
+**/
|
|
|
+BOOLEAN
|
|
|
+EFIAPI
|
|
|
+UnitTestExpectAssertFailure (
|
|
|
+ IN UNIT_TEST_STATUS UnitTestStatus,
|
|
|
+ IN CONST CHAR8 *FunctionName,
|
|
|
+ IN UINTN LineNumber,
|
|
|
+ IN CONST CHAR8 *FileName,
|
|
|
+ IN CONST CHAR8 *FunctionCall,
|
|
|
+ OUT UNIT_TEST_STATUS *ResultStatus OPTIONAL
|
|
|
+ )
|
|
|
+{
|
|
|
+ if (ResultStatus != NULL) {
|
|
|
+ *ResultStatus = UnitTestStatus;
|
|
|
+ }
|
|
|
+ if (UnitTestStatus == UNIT_TEST_PASSED) {
|
|
|
+ UT_LOG_INFO (
|
|
|
+ "[ASSERT PASS] %a:%d: UT_EXPECT_ASSERT_FAILURE(%a) detected expected assert\n",
|
|
|
+ FileName,
|
|
|
+ LineNumber,
|
|
|
+ FunctionCall
|
|
|
+ );
|
|
|
+ }
|
|
|
+ if (UnitTestStatus == UNIT_TEST_SKIPPED) {
|
|
|
+ UT_LOG_WARNING (
|
|
|
+ "[ASSERT WARN] %a:%d: UT_EXPECT_ASSERT_FAILURE(%a) disabled\n",
|
|
|
+ FileName,
|
|
|
+ LineNumber,
|
|
|
+ FunctionCall
|
|
|
+ );
|
|
|
+ }
|
|
|
+ if (UnitTestStatus == UNIT_TEST_ERROR_TEST_FAILED) {
|
|
|
UT_LOG_ERROR (
|
|
|
- "[ASSERT FAIL] %a:%d: Pointer (%a) is NULL!\n",
|
|
|
+ "[ASSERT FAIL] %a:%d: Function call (%a) did not ASSERT()!\n",
|
|
|
FileName,
|
|
|
LineNumber,
|
|
|
- PointerName
|
|
|
+ FunctionCall
|
|
|
+ );
|
|
|
+ UnitTestLogFailure (
|
|
|
+ FAILURETYPE_EXPECTASSERT,
|
|
|
+ "%a:%d: Function call (%a) did not ASSERT()!\n",
|
|
|
+ FileName,
|
|
|
+ LineNumber,
|
|
|
+ FunctionCall
|
|
|
);
|
|
|
}
|
|
|
- return (Pointer != NULL);
|
|
|
+ return (UnitTestStatus != UNIT_TEST_ERROR_TEST_FAILED);
|
|
|
}
|