Clean up core storage between tests
diff --git a/tests/suites/test_suite_psa_crypto_se_driver_hal_mocks.function b/tests/suites/test_suite_psa_crypto_se_driver_hal_mocks.function
index ba51428..9d73d8f 100644
--- a/tests/suites/test_suite_psa_crypto_se_driver_hal_mocks.function
+++ b/tests/suites/test_suite_psa_crypto_se_driver_hal_mocks.function
@@ -3,6 +3,7 @@
#include "psa/crypto_se_driver.h"
#include "psa_crypto_se.h"
+#include "psa_crypto_storage.h"
static struct
{
@@ -71,6 +72,23 @@
psa_status_t return_value;
} mock_destroy_data;
+#define MAX_KEY_ID_FOR_TEST 10
+static void psa_purge_storage( void )
+{
+ psa_key_id_t id;
+ psa_key_lifetime_t lifetime;
+ /* The tests may have potentially created key ids from 1 to
+ * MAX_KEY_ID_FOR_TEST. In addition, run the destroy function on key id
+ * 0, which file-based storage uses as a temporary file. */
+ for( id = 0; id <= MAX_KEY_ID_FOR_TEST; id++ )
+ psa_destroy_persistent_key( id );
+ /* Purge the transaction file. */
+ psa_crypto_stop_transaction( );
+ /* Purge driver persistent data. */
+ for( lifetime = 0; lifetime < PSA_MAX_SE_LIFETIME; lifetime++ )
+ psa_destroy_se_persistent_data( lifetime );
+}
+
static void mock_teardown( void )
{
memset( &mock_import_data, 0, sizeof( mock_import_data ) );
@@ -81,6 +99,7 @@
memset( &mock_allocate_data, 0, sizeof( mock_allocate_data ) );
memset( &mock_destroy_data, 0, sizeof( mock_destroy_data ) );
memset( &mock_generate_data, 0, sizeof( mock_generate_data ) );
+ psa_purge_storage( );
}
static psa_status_t mock_generate( psa_drv_se_context_t *drv_context,