Skip to content

Commit 8d10046

Browse files
Document exercise_key and fix one incorrect usage
In one place, exercise_key was used in a such a way that if the test failed inside exercise_key, the test suite would correctly report the test as failed but would not report the exact location of the failure. Fix this. Add documentation for exercise_key that explains how to use it.
1 parent 51a0778 commit 8d10046

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

tests/suites/test_suite_psa_crypto.function

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,33 @@ exit:
771771
return( ok );
772772
}
773773

774+
/** Do smoke tests on a key.
775+
*
776+
* Perform one of each operation indicated by \p alg (decrypt/encrypt,
777+
* sign/verify, or derivation) that is permitted according to \p usage.
778+
* \p usage and \p alg should correspond to the expected policy on the
779+
* key.
780+
*
781+
* Export the key if permitted by \p usage, and check that the output
782+
* looks sensible. If \p usage forbids export, check that
783+
* \p psa_export_key correctly rejects the attempt. If the key is
784+
* asymmetric, also check \p psa_export_public_key.
785+
*
786+
* If the key fails the tests, this function calls the test framework's
787+
* `test_fail` function and returns false. Otherwise this function returns
788+
* true. Therefore it should be used as follows:
789+
* ```
790+
* if( ! exercise_key( ... ) ) goto exit;
791+
* ```
792+
*
793+
* \param handle The key to exercise. It should be capable of performing
794+
* \p alg.
795+
* \param usage The usage flags to assume.
796+
* \param alg The algorithm to exercise.
797+
*
798+
* \retval 0 The key failed the smoke tests.
799+
* \retval 1 The key passed the smoke tests.
800+
*/
774801
static int exercise_key( psa_key_handle_t handle,
775802
psa_key_usage_t usage,
776803
psa_algorithm_t alg )
@@ -920,7 +947,8 @@ void import_twice( int alg_arg, int usage_arg,
920947
if( expected_import1_status == PSA_SUCCESS ||
921948
expected_import2_status == PSA_SUCCESS )
922949
{
923-
TEST_ASSERT( exercise_key( handle, usage, alg ) );
950+
if( ! exercise_key( handle, usage, alg ) )
951+
goto exit;
924952
}
925953

926954
exit:

0 commit comments

Comments
 (0)