From 9e1be6a246cffccbaec50ed9831d9e79b1dbb7c3 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 20 Nov 2018 23:21:37 +0100 Subject: [PATCH] Create the NV seed file for the tests if needed Write an all-bits-zero NV seed file for the tests. Without this, if the seed file is not present when this test suite is executed, the PSA module initialization will fail, causing most test cases to fail. Also write an all-bits-zero NV seed file at the end. The test cases in this test suite mess with the file, but subsequent test suites may need it. --- tests/suites/test_suite_psa_crypto_init.data | 6 ++++++ tests/suites/test_suite_psa_crypto_init.function | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/tests/suites/test_suite_psa_crypto_init.data b/tests/suites/test_suite_psa_crypto_init.data index 6996c115be..c57a764efe 100644 --- a/tests/suites/test_suite_psa_crypto_init.data +++ b/tests/suites/test_suite_psa_crypto_init.data @@ -1,3 +1,6 @@ +Create NV seed file +create_nv_seed: + PSA init/deinit init_deinit:2 @@ -48,3 +51,6 @@ entropy_from_nv_seed:MBEDTLS_ENTROPY_BLOCK_SIZE - 1:PSA_ERROR_INSUFFICIENT_ENTRO NV seed only: just enough entropy_from_nv_seed:ENTROPY_MIN_NV_SEED_SIZE:PSA_SUCCESS + +Recreate NV seed file +create_nv_seed: diff --git a/tests/suites/test_suite_psa_crypto_init.function b/tests/suites/test_suite_psa_crypto_init.function index f4bb86f095..3596504298 100644 --- a/tests/suites/test_suite_psa_crypto_init.function +++ b/tests/suites/test_suite_psa_crypto_init.function @@ -127,6 +127,14 @@ static void custom_entropy_init( mbedtls_entropy_context *ctx ) * END_DEPENDENCIES */ +/* BEGIN_CASE depends_on:MBEDTLS_ENTROPY_NV_SEED */ +void create_nv_seed( ) +{ + static unsigned char seed[ENTROPY_MIN_NV_SEED_SIZE]; + TEST_ASSERT( mbedtls_nv_seed_write( seed, sizeof( seed ) ) >= 0 ); +} +/* END_CASE */ + /* BEGIN_CASE */ void init_deinit( int count ) {