Fix tests where tests were done prior to init
Variables that are in any way destructed on exit should be initialised
prior to any tests that might jump to exit, to save potential
uninitialised memory accesses.
Signed-off-by: Paul Elliott <paul.elliott@arm.com>
diff --git a/tests/suites/test_suite_x509write.function b/tests/suites/test_suite_x509write.function
index 64b4e9e..a378c13 100644
--- a/tests/suites/test_suite_x509write.function
+++ b/tests/suites/test_suite_x509write.function
@@ -298,11 +298,12 @@
mbedtls_test_rnd_pseudo_info rnd_info;
mbedtls_x509write_csr_init(&req);
+ mbedtls_pk_init(&key);
+
MD_OR_USE_PSA_INIT();
memset(&rnd_info, 0x2a, sizeof(mbedtls_test_rnd_pseudo_info));
- mbedtls_pk_init(&key);
TEST_ASSERT(mbedtls_pk_parse_keyfile(&key, key_file, NULL,
mbedtls_test_rnd_std_rand, NULL) == 0);
diff --git a/tf-psa-crypto/tests/suites/test_suite_ctr_drbg.function b/tf-psa-crypto/tests/suites/test_suite_ctr_drbg.function
index 9fa55a7..a19dea3 100644
--- a/tf-psa-crypto/tests/suites/test_suite_ctr_drbg.function
+++ b/tf-psa-crypto/tests/suites/test_suite_ctr_drbg.function
@@ -365,12 +365,12 @@
AES_PSA_INIT();
- TEST_CALLOC(threads, sizeof(mbedtls_test_thread_t) * thread_count);
- memset(out, 0, sizeof(out));
-
mbedtls_ctr_drbg_context ctx;
mbedtls_ctr_drbg_init(&ctx);
+ TEST_CALLOC(threads, sizeof(mbedtls_test_thread_t) * thread_count);
+ memset(out, 0, sizeof(out));
+
test_offset_idx = 0;
/* Need to set a non-default fixed entropy len, to ensure same output across