Skip to content

Commit 9e0a4a5

Browse files
Test abort after failed setup
Commit "Smoke-test operation contexts after setup+abort" replaced {failed-setup; abort} sequences by {failed-setup; successful-setup}. We want to test that, but we also want to test {failed-setup; abort}. So test {failed-setup; abort; failed-setup; successful-setup}.
1 parent 9ab61b6 commit 9e0a4a5

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

tests/suites/test_suite_psa_crypto.function

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,14 @@ int exercise_mac_setup( psa_key_type_t key_type,
219219
PSA_ASSERT( psa_import_key( handle, key_type, key_bytes, key_length ) );
220220

221221
*status = psa_mac_sign_setup( operation, handle, alg );
222-
if( *status == PSA_SUCCESS )
222+
/* Whether setup succeeded or failed, abort must succeed. */
223+
PSA_ASSERT( psa_mac_abort( operation ) );
224+
/* If setup failed, reproduce the failure, so that the caller can
225+
* test the resulting state of the operation object. */
226+
if( *status != PSA_SUCCESS )
223227
{
224-
PSA_ASSERT( psa_mac_abort( operation ) );
228+
TEST_EQUAL( psa_mac_sign_setup( operation, handle, alg ),
229+
*status );
225230
}
226231

227232
psa_destroy_key( handle );
@@ -248,9 +253,14 @@ int exercise_cipher_setup( psa_key_type_t key_type,
248253
PSA_ASSERT( psa_import_key( handle, key_type, key_bytes, key_length ) );
249254

250255
*status = psa_cipher_encrypt_setup( operation, handle, alg );
251-
if( *status == PSA_SUCCESS )
256+
/* Whether setup succeeded or failed, abort must succeed. */
257+
PSA_ASSERT( psa_cipher_abort( operation ) );
258+
/* If setup failed, reproduce the failure, so that the caller can
259+
* test the resulting state of the operation object. */
260+
if( *status != PSA_SUCCESS )
252261
{
253-
PSA_ASSERT( psa_cipher_abort( operation ) );
262+
TEST_EQUAL( psa_cipher_encrypt_setup( operation, handle, alg ),
263+
*status );
254264
}
255265

256266
psa_destroy_key( handle );
@@ -2118,8 +2128,14 @@ void hash_setup( int alg_arg,
21182128
status = psa_hash_setup( &operation, alg );
21192129
TEST_EQUAL( status, expected_status );
21202130

2121-
if( status == PSA_SUCCESS )
2122-
PSA_ASSERT( psa_hash_abort( &operation ) );
2131+
/* Whether setup succeeded or failed, abort must succeed. */
2132+
PSA_ASSERT( psa_hash_abort( &operation ) );
2133+
2134+
/* If setup failed, reproduce the failure, so as to
2135+
* test the resulting state of the operation object. */
2136+
if( status != PSA_SUCCESS )
2137+
TEST_EQUAL( psa_hash_setup( &operation, alg ), status );
2138+
21232139
/* Now the operation object should be reusable. */
21242140
#if defined(KNOWN_SUPPORTED_HASH_ALG)
21252141
PSA_ASSERT( psa_hash_setup( &operation, KNOWN_SUPPORTED_HASH_ALG ) );

0 commit comments

Comments
 (0)