TianoCore EDK2 master
Loading...
Searching...
No Matches
AssertCmocka.c File Reference
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <Uefi.h>
#include <Library/BaseMemoryLib.h>
#include <Library/UnitTestLib.h>

Go to the source code of this file.

Macros

#define MAX_STRING_SIZE   1025
 

Functions

BOOLEAN EFIAPI UnitTestAssertTrue (IN BOOLEAN Expression, IN CONST CHAR8 *FunctionName, IN UINTN LineNumber, IN CONST CHAR8 *FileName, IN CONST CHAR8 *Description)
 
BOOLEAN EFIAPI UnitTestAssertFalse (IN BOOLEAN Expression, IN CONST CHAR8 *FunctionName, IN UINTN LineNumber, IN CONST CHAR8 *FileName, IN CONST CHAR8 *Description)
 
BOOLEAN EFIAPI UnitTestAssertNotEfiError (IN EFI_STATUS Status, IN CONST CHAR8 *FunctionName, IN UINTN LineNumber, IN CONST CHAR8 *FileName, IN CONST CHAR8 *Description)
 
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)
 
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)
 
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)
 
BOOLEAN EFIAPI UnitTestAssertNotNull (IN VOID *Pointer, IN CONST CHAR8 *FunctionName, IN UINTN LineNumber, IN CONST CHAR8 *FileName, IN CONST CHAR8 *PointerName)
 
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)
 

Detailed Description

Implement UnitTestLib assert services using cmocka services

Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file AssertCmocka.c.

Macro Definition Documentation

◆ MAX_STRING_SIZE

#define MAX_STRING_SIZE   1025

Definition at line 19 of file AssertCmocka.c.

Function Documentation

◆ UnitTestAssertEqual()

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 
)

If ValueA is equal ValueB, then TRUE is returned. If ValueA is not equal to ValueB, then an assert is triggered and the location of the assert provided by FunctionName, LineNumber, FileName, DescriptionA, and DescriptionB are recorded and FALSE is returned.

Parameters
[in]ValueA64-bit value.
[in]ValueB64-bit value.
[in]FunctionNameNull-terminated ASCII string of the function executing the assert macro.
[in]LineNumberThe source file line number of the assert macro.
[in]FileNameNull-terminated ASCII string of the filename executing the assert macro.
[in]DescriptionANull-terminated ASCII string that is a description of ValueA.
[in]DescriptionBNull-terminated ASCII string that is a description of ValueB.
Return values
TRUEValueA is equal to ValueB.
FALSEValueA is not equal to ValueB.

Definition at line 152 of file AssertCmocka.c.

◆ UnitTestAssertFalse()

BOOLEAN EFIAPI UnitTestAssertFalse ( IN BOOLEAN  Expression,
IN CONST CHAR8 *  FunctionName,
IN UINTN  LineNumber,
IN CONST CHAR8 *  FileName,
IN CONST CHAR8 *  Description 
)

If Expression is FALSE, then TRUE is returned. If Expression is TRUE, then an assert is triggered and the location of the assert provided by FunctionName, LineNumber, FileName, and Description are recorded and FALSE is returned.

Parameters
[in]ExpressionThe BOOLEAN result of the expression evaluation.
[in]FunctionNameNull-terminated ASCII string of the function executing the assert macro.
[in]LineNumberThe source file line number of the assert macro.
[in]FileNameNull-terminated ASCII string of the filename executing the assert macro.
[in]DescriptionNull-terminated ASCII string of the expression being evaluated.
Return values
TRUEExpression is FALSE.
FALSEExpression is TRUE.

Definition at line 77 of file AssertCmocka.c.

◆ UnitTestAssertMemEqual()

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 
)

If the contents of BufferA are identical to the contents of BufferB, then TRUE is returned. If the contents of BufferA are not identical to the contents of BufferB, then an assert is triggered and the location of the assert provided by FunctionName, LineNumber, FileName, DescriptionA, and DescriptionB are recorded and FALSE is returned.

Parameters
[in]BufferAPointer to a buffer for comparison.
[in]BufferBPointer to a buffer for comparison.
[in]LengthNumber of bytes to compare in BufferA and BufferB.
[in]FunctionNameNull-terminated ASCII string of the function executing the assert macro.
[in]LineNumberThe source file line number of the assert macro.
[in]FileNameNull-terminated ASCII string of the filename executing the assert macro.
[in]DescriptionANull-terminated ASCII string that is a description of BufferA.
[in]DescriptionBNull-terminated ASCII string that is a description of BufferB.
Return values
TRUEThe contents of BufferA are identical to the contents of BufferB.
FALSEThe contents of BufferA are not identical to the contents of BufferB.

Definition at line 197 of file AssertCmocka.c.

◆ UnitTestAssertNotEfiError()

BOOLEAN EFIAPI UnitTestAssertNotEfiError ( IN EFI_STATUS  Status,
IN CONST CHAR8 *  FunctionName,
IN UINTN  LineNumber,
IN CONST CHAR8 *  FileName,
IN CONST CHAR8 *  Description 
)

If Status is not an EFI_ERROR(), then TRUE is returned. If Status is an EFI_ERROR(), then an assert is triggered and the location of the assert provided by FunctionName, LineNumber, FileName, and Description are recorded and FALSE is returned.

Parameters
[in]StatusThe EFI_STATUS value to evaluate.
[in]FunctionNameNull-terminated ASCII string of the function executing the assert macro.
[in]LineNumberThe source file line number of the assert macro.
[in]FileNameNull-terminated ASCII string of the filename executing the assert macro.
[in]DescriptionNull-terminated ASCII string of the status expression being evaluated.
Return values
TRUEStatus is not an EFI_ERROR().
FALSEStatus is an EFI_ERROR().

Definition at line 113 of file AssertCmocka.c.

◆ UnitTestAssertNotEqual()

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 
)

If ValueA is not equal ValueB, then TRUE is returned. If ValueA is equal to ValueB, then an assert is triggered and the location of the assert provided by FunctionName, LineNumber, FileName, DescriptionA and DescriptionB are recorded and FALSE is returned.

Parameters
[in]ValueA64-bit value.
[in]ValueB64-bit value.
[in]FunctionNameNull-terminated ASCII string of the function executing the assert macro.
[in]LineNumberThe source file line number of the assert macro.
[in]FileNameNull-terminated ASCII string of the filename executing the assert macro.
[in]DescriptionANull-terminated ASCII string that is a description of ValueA.
[in]DescriptionBNull-terminated ASCII string that is a description of ValueB.
Return values
TRUEValueA is not equal to ValueB.
FALSEValueA is equal to ValueB.

Definition at line 242 of file AssertCmocka.c.

◆ UnitTestAssertNotNull()

BOOLEAN EFIAPI UnitTestAssertNotNull ( IN VOID *  Pointer,
IN CONST CHAR8 *  FunctionName,
IN UINTN  LineNumber,
IN CONST CHAR8 *  FileName,
IN CONST CHAR8 *  PointerName 
)

If Pointer is not equal to NULL, then TRUE is returned. If Pointer is equal to NULL, then an assert is triggered and the location of the assert provided by FunctionName, LineNumber, FileName, and PointerName are recorded and FALSE is returned.

Parameters
[in]PointerPointer value to be checked against NULL.
[in]ExpectedThe expected EFI_STATUS return value from a function under test.
[in]FunctionNameNull-terminated ASCII string of the function executing the assert macro.
[in]LineNumberThe source file line number of the assert macro.
[in]FileNameNull-terminated ASCII string of the filename executing the assert macro.
[in]PointerNameNull-terminated ASCII string that is a description of Pointer.
Return values
TRUEPointer is not equal to NULL.
FALSEPointer is equal to NULL.

Definition at line 321 of file AssertCmocka.c.

◆ UnitTestAssertStatusEqual()

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 
)

If Status is equal to Expected, then TRUE is returned. If Status is not equal to Expected, then an assert is triggered and the location of the assert provided by FunctionName, LineNumber, FileName, and Description are recorded and FALSE is returned.

Parameters
[in]StatusEFI_STATUS value returned from an API under test.
[in]ExpectedThe expected EFI_STATUS return value from an API under test.
[in]FunctionNameNull-terminated ASCII string of the function executing the assert macro.
[in]LineNumberThe source file line number of the assert macro.
[in]FileNameNull-terminated ASCII string of the filename executing the assert macro.
[in]DescriptionNull-terminated ASCII string that is a description of Status.
Return values
TRUEStatus is equal to Expected.
FALSEStatus is not equal to Expected.

Definition at line 282 of file AssertCmocka.c.

◆ UnitTestAssertTrue()

BOOLEAN EFIAPI UnitTestAssertTrue ( IN BOOLEAN  Expression,
IN CONST CHAR8 *  FunctionName,
IN UINTN  LineNumber,
IN CONST CHAR8 *  FileName,
IN CONST CHAR8 *  Description 
)

If Expression is TRUE, then TRUE is returned. If Expression is FALSE, then an assert is triggered and the location of the assert provided by FunctionName, LineNumber, FileName, and Description are recorded and FALSE is returned.

Parameters
[in]ExpressionThe BOOLEAN result of the expression evaluation.
[in]FunctionNameNull-terminated ASCII string of the function executing the assert macro.
[in]LineNumberThe source file line number of the assert macro.
[in]FileNameNull-terminated ASCII string of the filename executing the assert macro.
[in]DescriptionNull-terminated ASCII string of the expression being evaluated.
Return values
TRUEExpression is TRUE.
FALSEExpression is FALSE.

Definition at line 41 of file AssertCmocka.c.

◆ UnitTestExpectAssertFailure()

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 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.

Parameters
[in]UnitTestStatusThe status from UT_EXPECT_ASSERT_FAILURE() that is either pass, skipped, or failed.
[in]FunctionNameNull-terminated ASCII string of the function executing the UT_EXPECT_ASSERT_FAILURE() macro.
[in]LineNumberThe source file line number of the the function executing the UT_EXPECT_ASSERT_FAILURE() macro.
[in]FileNameNull-terminated ASCII string of the filename executing the UT_EXPECT_ASSERT_FAILURE() macro.
[in]FunctionCallNull-terminated ASCII string of the function call executed by the UT_EXPECT_ASSERT_FAILURE() macro.
[out]ResultStatusUsed to return the UnitTestStatus value to the caller of UT_EXPECT_ASSERT_FAILURE(). This is optional parameter that may be NULL.
Return values
TRUEUnitTestStatus is UNIT_TEST_PASSED.
TRUEUnitTestStatus is UNIT_TEST_SKIPPED.
FALSEUnitTestStatus is UNIT_TEST_ERROR_TEST_FAILED.

Definition at line 368 of file AssertCmocka.c.