Skip to content

Commit 3a58913

Browse files
Pataterdgreen-arm
authored andcommitted
Clean up core storage between tests
1 parent b5db3b7 commit 3a58913

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
{
@@ -71,6 +72,23 @@ static struct
7172
psa_status_t return_value;
7273
} mock_destroy_data;
7374

75+
#define MAX_KEY_ID_FOR_TEST 10
76+
static void psa_purge_storage( void )
77+
{
78+
psa_key_id_t id;
79+
psa_key_lifetime_t lifetime;
80+
/* The tests may have potentially created key ids from 1 to
81+
* MAX_KEY_ID_FOR_TEST. In addition, run the destroy function on key id
82+
* 0, which file-based storage uses as a temporary file. */
83+
for( id = 0; id <= MAX_KEY_ID_FOR_TEST; id++ )
84+
psa_destroy_persistent_key( id );
85+
/* Purge the transaction file. */
86+
psa_crypto_stop_transaction( );
87+
/* Purge driver persistent data. */
88+
for( lifetime = 0; lifetime < PSA_MAX_SE_LIFETIME; lifetime++ )
89+
psa_destroy_se_persistent_data( lifetime );
90+
}
91+
7492
static void mock_teardown( void )
7593
{
7694
memset( &mock_import_data, 0, sizeof( mock_import_data ) );
@@ -81,6 +99,7 @@ static void mock_teardown( void )
8199
memset( &mock_allocate_data, 0, sizeof( mock_allocate_data ) );
82100
memset( &mock_destroy_data, 0, sizeof( mock_destroy_data ) );
83101
memset( &mock_generate_data, 0, sizeof( mock_generate_data ) );
102+
psa_purge_storage( );
84103
}
85104

86105
static psa_status_t mock_generate( psa_drv_se_context_t *drv_context,

0 commit comments

Comments
 (0)