Clean up core storage between tests

This commit is contained in:
Jaeden Amero 2019-07-30 16:01:45 +01:00 committed by Darryl Green
parent f740b0abbb
commit 4abb40cab3

View file

@ -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 @@ static struct
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 @@ static void mock_teardown( void )
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,