Use ASSERT_COMPARE in test_suite_md

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
This commit is contained in:
Manuel Pégourié-Gonnard 2023-02-09 09:15:04 +01:00
parent cced3521cb
commit a9a1b21ca9
2 changed files with 11 additions and 28 deletions

View file

@ -168,7 +168,7 @@
#define ASSERT_COMPARE(p1, size1, p2, size2) \
do \
{ \
TEST_ASSERT((size1) == (size2)); \
TEST_EQUAL((size1), (size2)); \
if ((size1) != 0) \
TEST_ASSERT(memcmp((p1), (p2), (size1)) == 0); \
} \

View file

@ -141,9 +141,7 @@ void md_text(int md_type, char *text_src_string, data_t *hash)
TEST_EQUAL(0, mbedtls_md(md_info, src, src_len, output));
TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x,
mbedtls_md_get_size(md_info),
hash->len) == 0);
ASSERT_COMPARE(output, mbedtls_md_get_size(md_info), hash->x, hash->len);
}
/* END_CASE */
@ -159,9 +157,7 @@ void md_hex(int md_type, data_t *src_str, data_t *hash)
TEST_EQUAL(0, mbedtls_md(md_info, src_str->x, src_str->len, output));
TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x,
mbedtls_md_get_size(md_info),
hash->len) == 0);
ASSERT_COMPARE(output, mbedtls_md_get_size(md_info), hash->x, hash->len);
}
/* END_CASE */
@ -196,18 +192,14 @@ void md_text_multi(int md_type, char *text_src_string,
TEST_EQUAL(0, mbedtls_md_update(&ctx, src + halfway, src_len - halfway));
TEST_EQUAL(0, mbedtls_md_finish(&ctx, output));
TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x,
mbedtls_md_get_size(md_info),
hash->len) == 0);
ASSERT_COMPARE(output, mbedtls_md_get_size(md_info), hash->x, hash->len);
/* Test clone */
memset(output, 0x00, sizeof(output));
TEST_EQUAL(0, mbedtls_md_update(&ctx_copy, src + halfway, src_len - halfway));
TEST_EQUAL(0, mbedtls_md_finish(&ctx_copy, output));
TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x,
mbedtls_md_get_size(md_info),
hash->len) == 0);
ASSERT_COMPARE(output, mbedtls_md_get_size(md_info), hash->x, hash->len);
exit:
mbedtls_md_free(&ctx);
@ -242,18 +234,14 @@ void md_hex_multi(int md_type, data_t *src_str, data_t *hash)
TEST_EQUAL(0, mbedtls_md_update(&ctx, src_str->x + halfway, src_str->len - halfway));
TEST_EQUAL(0, mbedtls_md_finish(&ctx, output));
TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x,
mbedtls_md_get_size(md_info),
hash->len) == 0);
ASSERT_COMPARE(output, mbedtls_md_get_size(md_info), hash->x, hash->len);
/* Test clone */
memset(output, 0x00, sizeof(output));
TEST_EQUAL(0, mbedtls_md_update(&ctx_copy, src_str->x + halfway, src_str->len - halfway));
TEST_EQUAL(0, mbedtls_md_finish(&ctx_copy, output));
TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x,
mbedtls_md_get_size(md_info),
hash->len) == 0);
ASSERT_COMPARE(output, mbedtls_md_get_size(md_info), hash->x, hash->len);
exit:
mbedtls_md_free(&ctx);
@ -276,8 +264,7 @@ void mbedtls_md_hmac(int md_type, int trunc_size,
TEST_EQUAL(0, mbedtls_md_hmac(md_info, key_str->x, key_str->len,
src_str->x, src_str->len, output));
TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x,
trunc_size, hash->len) == 0);
ASSERT_COMPARE(output, trunc_size, hash->x, hash->len);
}
/* END_CASE */
@ -305,8 +292,7 @@ void md_hmac_multi(int md_type, int trunc_size, data_t *key_str,
TEST_EQUAL(0, mbedtls_md_hmac_update(&ctx, src_str->x + halfway, src_str->len - halfway));
TEST_EQUAL(0, mbedtls_md_hmac_finish(&ctx, output));
TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x,
trunc_size, hash->len) == 0);
ASSERT_COMPARE(output, trunc_size, hash->x, hash->len);
/* Test again, for reset() */
memset(output, 0x00, sizeof(output));
@ -316,8 +302,7 @@ void md_hmac_multi(int md_type, int trunc_size, data_t *key_str,
TEST_EQUAL(0, mbedtls_md_hmac_update(&ctx, src_str->x + halfway, src_str->len - halfway));
TEST_EQUAL(0, mbedtls_md_hmac_finish(&ctx, output));
TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x,
trunc_size, hash->len) == 0);
ASSERT_COMPARE(output, trunc_size, hash->x, hash->len);
exit:
mbedtls_md_free(&ctx);
@ -336,8 +321,6 @@ void mbedtls_md_file(int md_type, char *filename,
TEST_EQUAL(0, mbedtls_md_file(md_info, filename, output));
TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x,
mbedtls_md_get_size(md_info),
hash->len) == 0);
ASSERT_COMPARE(output, mbedtls_md_get_size(md_info), hash->x, hash->len);
}
/* END_CASE */