Move test hook setup and teardown to helpers.c

Setup and teardown test hooks during full test platform setup.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
This commit is contained in:
David Horstmann 2023-12-14 14:17:04 +00:00
parent a7cde5d296
commit b489257a0b
2 changed files with 12 additions and 2 deletions

View File

@ -13,6 +13,10 @@
#include <test/psa_crypto_helpers.h> #include <test/psa_crypto_helpers.h>
#endif #endif
#if defined(MBEDTLS_TEST_HOOKS)
#include <test/psa_memory_poisoning_wrappers.h>
#endif
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Static global variables */ /* Static global variables */
@ -29,6 +33,10 @@ int mbedtls_test_platform_setup(void)
{ {
int ret = 0; int ret = 0;
#if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_TEST_MEMORY_CAN_POISON)
mbedtls_poison_test_hooks_setup();
#endif
#if defined(MBEDTLS_PSA_INJECT_ENTROPY) #if defined(MBEDTLS_PSA_INJECT_ENTROPY)
/* Make sure that injected entropy is present. Otherwise /* Make sure that injected entropy is present. Otherwise
* psa_crypto_init() will fail. This is not necessary for test suites * psa_crypto_init() will fail. This is not necessary for test suites
@ -49,6 +57,10 @@ int mbedtls_test_platform_setup(void)
void mbedtls_test_platform_teardown(void) void mbedtls_test_platform_teardown(void)
{ {
#if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_TEST_MEMORY_CAN_POISON)
mbedtls_poison_test_hooks_teardown();
#endif
#if defined(MBEDTLS_PLATFORM_C) #if defined(MBEDTLS_PLATFORM_C)
mbedtls_platform_teardown(&platform_ctx); mbedtls_platform_teardown(&platform_ctx);
#endif /* MBEDTLS_PLATFORM_C */ #endif /* MBEDTLS_PLATFORM_C */

View File

@ -34,7 +34,6 @@ psa_status_t wrap_psa_cipher_encrypt(mbedtls_svc_key_id_t key,
size_t output_size, size_t output_size,
size_t *output_length) size_t *output_length)
{ {
mbedtls_poison_test_hooks_setup();
MBEDTLS_TEST_MEMORY_POISON(input, input_length); MBEDTLS_TEST_MEMORY_POISON(input, input_length);
MBEDTLS_TEST_MEMORY_POISON(output, output_size); MBEDTLS_TEST_MEMORY_POISON(output, output_size);
psa_status_t status = psa_cipher_encrypt(key, psa_status_t status = psa_cipher_encrypt(key,
@ -46,7 +45,6 @@ psa_status_t wrap_psa_cipher_encrypt(mbedtls_svc_key_id_t key,
output_length); output_length);
MBEDTLS_TEST_MEMORY_UNPOISON(input, input_length); MBEDTLS_TEST_MEMORY_UNPOISON(input, input_length);
MBEDTLS_TEST_MEMORY_UNPOISON(output, output_size); MBEDTLS_TEST_MEMORY_UNPOISON(output, output_size);
mbedtls_poison_test_hooks_teardown();
return status; return status;
} }