10#ifndef __UNIT_TEST_LIB_H__
11#define __UNIT_TEST_LIB_H__
17#define UNIT_TEST_PASSED (0)
18#define UNIT_TEST_ERROR_PREREQUISITE_NOT_MET (1)
19#define UNIT_TEST_ERROR_TEST_FAILED (2)
20#define UNIT_TEST_ERROR_CLEANUP_FAILED (3)
21#define UNIT_TEST_SKIPPED (0xFFFFFFFD)
22#define UNIT_TEST_RUNNING (0xFFFFFFFE)
23#define UNIT_TEST_PENDING (0xFFFFFFFF)
28#define UNIT_TEST_LOG_LEVEL_ERROR BIT0
29#define UNIT_TEST_LOG_LEVEL_WARN BIT1
30#define UNIT_TEST_LOG_LEVEL_INFO BIT2
31#define UNIT_TEST_LOG_LEVEL_VERBOSE BIT3
36struct UNIT_TEST_FRAMEWORK_OBJECT;
37typedef struct UNIT_TEST_FRAMEWORK_OBJECT *UNIT_TEST_FRAMEWORK_HANDLE;
42struct UNIT_TEST_SUITE_OBJECT;
43typedef struct UNIT_TEST_SUITE_OBJECT *UNIT_TEST_SUITE_HANDLE;
48struct UNIT_TEST_OBJECT;
49typedef struct UNIT_TEST_OBJECT *UNIT_TEST_HANDLE;
189 OUT UNIT_TEST_FRAMEWORK_HANDLE *FrameworkHandle,
191 IN CHAR8 *ShortTitle,
192 IN CHAR8 *VersionString
224 OUT UNIT_TEST_SUITE_HANDLE *SuiteHandle,
225 IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle,
259 IN UNIT_TEST_SUITE_HANDLE SuiteHandle,
260 IN CHAR8 *Description,
285 IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle
305 IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle
350#define UT_ASSERT_TRUE(Expression) \
351 if(!UnitTestAssertTrue ((Expression), __func__, DEBUG_LINE_NUMBER, __FILE__, #Expression)) { \
352 return UNIT_TEST_ERROR_TEST_FAILED; \
362#define UT_ASSERT_FALSE(Expression) \
363 if(!UnitTestAssertFalse ((Expression), __func__, DEBUG_LINE_NUMBER, __FILE__, #Expression)) { \
364 return UNIT_TEST_ERROR_TEST_FAILED; \
375#define UT_ASSERT_EQUAL(ValueA, ValueB) \
376 if(!UnitTestAssertEqual ((UINT64)(ValueA), (UINT64)(ValueB), __func__, DEBUG_LINE_NUMBER, __FILE__, #ValueA, #ValueB)) { \
377 return UNIT_TEST_ERROR_TEST_FAILED; \
389#define UT_ASSERT_MEM_EQUAL(BufferA, BufferB, Length) \
390 if(!UnitTestAssertMemEqual ((VOID *)(UINTN)(BufferA), (VOID *)(UINTN)(BufferB), (UINTN)Length, __func__, DEBUG_LINE_NUMBER, __FILE__, #BufferA, #BufferB)) { \
391 return UNIT_TEST_ERROR_TEST_FAILED; \
402#define UT_ASSERT_NOT_EQUAL(ValueA, ValueB) \
403 if(!UnitTestAssertNotEqual ((UINT64)(ValueA), (UINT64)(ValueB), __func__, DEBUG_LINE_NUMBER, __FILE__, #ValueA, #ValueB)) { \
404 return UNIT_TEST_ERROR_TEST_FAILED; \
414#define UT_ASSERT_NOT_EFI_ERROR(Status) \
415 if(!UnitTestAssertNotEfiError ((Status), __func__, DEBUG_LINE_NUMBER, __FILE__, #Status)) { \
416 return UNIT_TEST_ERROR_TEST_FAILED; \
427#define UT_ASSERT_STATUS_EQUAL(Status, Expected) \
428 if(!UnitTestAssertStatusEqual ((Status), (Expected), __func__, DEBUG_LINE_NUMBER, __FILE__, #Status)) { \
429 return UNIT_TEST_ERROR_TEST_FAILED; \
439#define UT_ASSERT_NOT_NULL(Pointer) \
440 if(!UnitTestAssertNotNull ((Pointer), __func__, DEBUG_LINE_NUMBER, __FILE__, #Pointer)) { \
441 return UNIT_TEST_ERROR_TEST_FAILED; \
459#if defined (EDKII_UNIT_TEST_FRAMEWORK_ENABLED)
468#define UT_EXPECT_ASSERT_FAILURE(FunctionCall, Status) \
470 UNIT_TEST_STATUS UnitTestJumpStatus; \
471 BASE_LIBRARY_JUMP_BUFFER UnitTestJumpBuffer; \
472 UnitTestJumpStatus = UNIT_TEST_SKIPPED; \
473 if (DebugAssertEnabled ()) { \
474 gUnitTestExpectAssertFailureJumpBuffer = &UnitTestJumpBuffer; \
475 if (SetJump (gUnitTestExpectAssertFailureJumpBuffer) == 0) { \
477 UnitTestJumpStatus = UNIT_TEST_ERROR_TEST_FAILED; \
479 UnitTestJumpStatus = UNIT_TEST_PASSED; \
481 gUnitTestExpectAssertFailureJumpBuffer = NULL; \
483 if (!UnitTestExpectAssertFailure ( \
484 UnitTestJumpStatus, \
485 __func__, DEBUG_LINE_NUMBER, __FILE__, \
486 #FunctionCall, Status)) { \
487 return UNIT_TEST_ERROR_TEST_FAILED; \
491#define UT_EXPECT_ASSERT_FAILURE(FunctionCall, Status) FunctionCall;
515 IN BOOLEAN Expression,
543 IN BOOLEAN Expression,
791#define UT_LOG_ERROR(Format, ...) \
792 UnitTestLog (UNIT_TEST_LOG_LEVEL_ERROR, Format, ##__VA_ARGS__)
802#define UT_LOG_WARNING(Format, ...) \
803 UnitTestLog (UNIT_TEST_LOG_LEVEL_WARN, Format, ##__VA_ARGS__)
813#define UT_LOG_INFO(Format, ...) \
814 UnitTestLog (UNIT_TEST_LOG_LEVEL_INFO, Format, ##__VA_ARGS__)
824#define UT_LOG_VERBOSE(Format, ...) \
825 UnitTestLog (UNIT_TEST_LOG_LEVEL_VERBOSE, Format, ##__VA_ARGS__)
BASE_LIBRARY_JUMP_BUFFER * gUnitTestExpectAssertFailureJumpBuffer
BOOLEAN EFIAPI UnitTestAssertEqual(IN UINT64 ValueA, IN UINT64 ValueB, IN CONST CHAR8 *FunctionName, IN UINTN LineNumber, IN CONST CHAR8 *FileName, IN CONST CHAR8 *DescriptionA, IN CONST CHAR8 *DescriptionB)
EFI_STATUS EFIAPI SaveFrameworkState(IN UNIT_TEST_CONTEXT ContextToSave OPTIONAL, IN UINTN ContextToSaveSize)
BOOLEAN EFIAPI UnitTestAssertNotNull(IN VOID *Pointer, IN CONST CHAR8 *FunctionName, IN UINTN LineNumber, IN CONST CHAR8 *FileName, IN CONST CHAR8 *PointerName)
VOID EFIAPI UnitTestLog(IN UINTN ErrorLevel, IN CONST CHAR8 *Format,...)
EFI_STATUS EFIAPI RunAllTestSuites(IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle)
BOOLEAN EFIAPI UnitTestAssertFalse(IN BOOLEAN Expression, IN CONST CHAR8 *FunctionName, IN UINTN LineNumber, IN CONST CHAR8 *FileName, IN CONST CHAR8 *Description)
UNIT_TEST_STATUS(EFIAPI * UNIT_TEST_PREREQUISITE)(IN UNIT_TEST_CONTEXT Context)
VOID(EFIAPI * UNIT_TEST_SUITE_TEARDOWN)(VOID)
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)
BOOLEAN EFIAPI UnitTestAssertTrue(IN BOOLEAN Expression, IN CONST CHAR8 *FunctionName, IN UINTN LineNumber, IN CONST CHAR8 *FileName, IN CONST CHAR8 *Description)
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)
BOOLEAN EFIAPI UnitTestAssertNotEfiError(IN EFI_STATUS Status, IN CONST CHAR8 *FunctionName, IN UINTN LineNumber, IN CONST CHAR8 *FileName, IN CONST CHAR8 *Description)
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)
VOID(EFIAPI * UNIT_TEST_SUITE_SETUP)(VOID)
BOOLEAN EFIAPI UnitTestAssertNotEqual(IN UINT64 ValueA, IN UINT64 ValueB, IN CONST CHAR8 *FunctionName, IN UINTN LineNumber, IN CONST CHAR8 *FileName, IN CONST CHAR8 *DescriptionA, IN CONST CHAR8 *DescriptionB)
BOOLEAN EFIAPI UnitTestAssertStatusEqual(IN EFI_STATUS Status, IN EFI_STATUS Expected, IN CONST CHAR8 *FunctionName, IN UINTN LineNumber, IN CONST CHAR8 *FileName, IN CONST CHAR8 *Description)
EFI_STATUS EFIAPI InitUnitTestFramework(OUT UNIT_TEST_FRAMEWORK_HANDLE *FrameworkHandle, IN CHAR8 *Title, IN CHAR8 *ShortTitle, IN CHAR8 *VersionString)
BOOLEAN EFIAPI UnitTestAssertMemEqual(IN VOID *BufferA, IN VOID *BufferB, IN UINTN Length, IN CONST CHAR8 *FunctionName, IN UINTN LineNumber, IN CONST CHAR8 *FileName, IN CONST CHAR8 *DescriptionA, IN CONST CHAR8 *DescriptionB)
UNIT_TEST_STATUS(EFIAPI * UNIT_TEST_FUNCTION)(IN UNIT_TEST_CONTEXT Context)
VOID(EFIAPI * UNIT_TEST_CLEANUP)(IN UNIT_TEST_CONTEXT Context)