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}.
diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function
index 7da7456..4cec118 100644
--- a/tests/suites/test_suite_psa_crypto.function
+++ b/tests/suites/test_suite_psa_crypto.function
@@ -219,9 +219,14 @@
PSA_ASSERT( psa_import_key( handle, key_type, key_bytes, key_length ) );
*status = psa_mac_sign_setup( operation, handle, alg );
- if( *status == PSA_SUCCESS )
+ /* Whether setup succeeded or failed, abort must succeed. */
+ PSA_ASSERT( psa_mac_abort( operation ) );
+ /* If setup failed, reproduce the failure, so that the caller can
+ * test the resulting state of the operation object. */
+ if( *status != PSA_SUCCESS )
{
- PSA_ASSERT( psa_mac_abort( operation ) );
+ TEST_EQUAL( psa_mac_sign_setup( operation, handle, alg ),
+ *status );
}
psa_destroy_key( handle );
@@ -248,9 +253,14 @@
PSA_ASSERT( psa_import_key( handle, key_type, key_bytes, key_length ) );
*status = psa_cipher_encrypt_setup( operation, handle, alg );
- if( *status == PSA_SUCCESS )
+ /* Whether setup succeeded or failed, abort must succeed. */
+ PSA_ASSERT( psa_cipher_abort( operation ) );
+ /* If setup failed, reproduce the failure, so that the caller can
+ * test the resulting state of the operation object. */
+ if( *status != PSA_SUCCESS )
{
- PSA_ASSERT( psa_cipher_abort( operation ) );
+ TEST_EQUAL( psa_cipher_encrypt_setup( operation, handle, alg ),
+ *status );
}
psa_destroy_key( handle );
@@ -2118,8 +2128,14 @@
status = psa_hash_setup( &operation, alg );
TEST_EQUAL( status, expected_status );
- if( status == PSA_SUCCESS )
- PSA_ASSERT( psa_hash_abort( &operation ) );
+ /* Whether setup succeeded or failed, abort must succeed. */
+ PSA_ASSERT( psa_hash_abort( &operation ) );
+
+ /* If setup failed, reproduce the failure, so as to
+ * test the resulting state of the operation object. */
+ if( status != PSA_SUCCESS )
+ TEST_EQUAL( psa_hash_setup( &operation, alg ), status );
+
/* Now the operation object should be reusable. */
#if defined(KNOWN_SUPPORTED_HASH_ALG)
PSA_ASSERT( psa_hash_setup( &operation, KNOWN_SUPPORTED_HASH_ALG ) );