Introduce TEST_CALLOC_NONNULL
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
This commit is contained in:
parent
ba600b2fd9
commit
a328635305
1 changed files with 26 additions and 0 deletions
|
@ -143,6 +143,32 @@
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
/** Allocate memory dynamically and fail the test case if this fails.
|
||||
* The allocated memory will be filled with zeros.
|
||||
*
|
||||
* You must set \p pointer to \c NULL before calling this macro and
|
||||
* put `mbedtls_free(pointer)` in the test's cleanup code.
|
||||
*
|
||||
* If \p item_count is zero, the resulting \p pointer will not be \c NULL.
|
||||
*
|
||||
* This macro expands to an instruction, not an expression.
|
||||
* It may jump to the \c exit label.
|
||||
*
|
||||
* \param pointer An lvalue where the address of the allocated buffer
|
||||
* will be stored.
|
||||
* This expression may be evaluated multiple times.
|
||||
* \param item_count Number of elements to allocate.
|
||||
* This expression may be evaluated multiple times.
|
||||
*
|
||||
*/
|
||||
#define TEST_CALLOC_NONNULL(pointer, item_count) \
|
||||
do { \
|
||||
TEST_ASSERT((pointer) == NULL); \
|
||||
(pointer) = mbedtls_calloc(sizeof(*(pointer)), \
|
||||
(item_count)); \
|
||||
TEST_ASSERT((pointer) != NULL); \
|
||||
} while (0)
|
||||
|
||||
/* For backwards compatibility */
|
||||
#define ASSERT_ALLOC(pointer, item_count) TEST_CALLOC(pointer, item_count)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue