Skip to content

Commit

Permalink
For tests, rename ASSERT_ALLOC_WEAK() to TEST_CALLOC_OR_SKIP()
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Cosgrove <[email protected]>
  • Loading branch information
tom-cosgrove-arm committed Sep 4, 2023
1 parent 1357502 commit 20e27de
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
22 changes: 11 additions & 11 deletions tests/include/test/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,18 @@
* This macro behaves like #TEST_CALLOC_OR_FAIL, except that if the allocation
* fails, it marks the test as skipped rather than failed.
*/
#define ASSERT_ALLOC_WEAK(pointer, length) \
do \
{ \
TEST_ASSERT((pointer) == NULL); \
if ((length) != 0) \
{ \
(pointer) = mbedtls_calloc(sizeof(*(pointer)), \
#define TEST_CALLOC_OR_SKIP(pointer, length) \
do { \
TEST_ASSERT((pointer) == NULL); \
if ((length) != 0) { \
(pointer) = mbedtls_calloc(sizeof(*(pointer)), \
(length)); \
TEST_ASSUME((pointer) != NULL); \
} \
} \
while (0)
TEST_ASSUME((pointer) != NULL); \
} \
} while (0)

/* For backwards compatibility */
#define ASSERT_ALLOC_WEAK(pointer, length) TEST_CALLOC_OR_SKIP(pointer, length)

/** Compare two buffers and fail the test case if they differ.
*
Expand Down
2 changes: 1 addition & 1 deletion tests/suites/test_suite_asn1parse.function
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ int get_len_step(const data_t *input, size_t buffer_size,
end = buf + 1;
p = end;
} else {
ASSERT_ALLOC_WEAK(buf, buffer_size);
TEST_CALLOC_OR_SKIP(buf, buffer_size);
if (buffer_size > input->len) {
memcpy(buf, input->x, input->len);
memset(buf + input->len, 'A', buffer_size - input->len);
Expand Down
2 changes: 1 addition & 1 deletion tests/suites/test_suite_ccm.function
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void ccm_lengths(int msg_len, int iv_len, int add_len, int tag_len, int res)

mbedtls_ccm_init(&ctx);

ASSERT_ALLOC_WEAK(add, add_len);
TEST_CALLOC_OR_SKIP(add, add_len);
memset(key, 0, sizeof(key));
memset(msg, 0, sizeof(msg));
memset(iv, 0, sizeof(iv));
Expand Down
2 changes: 1 addition & 1 deletion tests/suites/test_suite_psa_crypto.function
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ void import_large_key(int type_arg, int byte_size_arg,

/* Skip the test case if the target running the test cannot
* accommodate large keys due to heap size constraints */
ASSERT_ALLOC_WEAK(buffer, buffer_size);
TEST_CALLOC_OR_SKIP(buffer, buffer_size);
memset(buffer, 'K', byte_size);

PSA_ASSERT(psa_crypto_init());
Expand Down

0 comments on commit 20e27de

Please sign in to comment.