Skip to content

Commit 37a41ec

Browse files
committed
Clean up core storage between tests
1 parent 015ae2f commit 37a41ec

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/suites/test_suite_psa_crypto_se_driver_hal_mocks.function

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "psa/crypto_se_driver.h"
44

55
#include "psa_crypto_se.h"
6+
#include "psa_crypto_storage.h"
67

78
static struct
89
{
@@ -76,6 +77,23 @@ static struct
7677
psa_status_t return_value;
7778
} mock_destroy_data;
7879

80+
#define MAX_KEY_ID_FOR_TEST 10
81+
static void psa_purge_storage( void )
82+
{
83+
psa_key_id_t id;
84+
psa_key_lifetime_t lifetime;
85+
/* The tests may have potentially created key ids from 1 to
86+
* MAX_KEY_ID_FOR_TEST. In addition, run the destroy function on key id
87+
* 0, which file-based storage uses as a temporary file. */
88+
for( id = 0; id <= MAX_KEY_ID_FOR_TEST; id++ )
89+
psa_destroy_persistent_key( id );
90+
/* Purge the transaction file. */
91+
psa_crypto_stop_transaction( );
92+
/* Purge driver persistent data. */
93+
for( lifetime = 0; lifetime < PSA_MAX_SE_LIFETIME; lifetime++ )
94+
psa_destroy_se_persistent_data( lifetime );
95+
}
96+
7997
static void mock_teardown( void )
8098
{
8199
memset( &mock_generate_data, 0, sizeof( mock_generate_data ) );
@@ -86,6 +104,7 @@ static void mock_teardown( void )
86104
memset( &mock_verify_data, 0, sizeof( mock_verify_data ) );
87105
memset( &mock_allocate_data, 0, sizeof( mock_allocate_data ) );
88106
memset( &mock_destroy_data, 0, sizeof( mock_destroy_data ) );
107+
psa_purge_storage( );
89108
}
90109

91110
static psa_status_t mock_generate( psa_drv_se_context_t *context,

0 commit comments

Comments
 (0)