Skip to content

Commit 8817f61

Browse files
Use PSA_ASSERT(a) in preference to TEST_ASSERT(a==PSA_SUCCESS)
This commit is the result of the following command, followed by reindenting (but not wrapping lines): perl -00 -i -pe 's/^( *)TEST_ASSERT\(([^;=]*)(?: |\n *)==\s*PSA_SUCCESS\s*\);$/${1}PSA_ASSERT($2 );/gm' tests/suites/test_suite_psa_*.function
1 parent 0f915f1 commit 8817f61

7 files changed

+854
-877
lines changed

tests/suites/test_suite_psa_crypto.function

Lines changed: 766 additions & 780 deletions
Large diffs are not rendered by default.

tests/suites/test_suite_psa_crypto_entropy.function

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ void validate_entropy_seed_injection( int seed_length_a,
5555
TEST_ASSERT( status == expected_status_a );
5656
status = mbedtls_psa_inject_entropy( seed, seed_length_b );
5757
TEST_ASSERT( status == expected_status_b );
58-
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
59-
TEST_ASSERT( psa_generate_random( output,
60-
sizeof( output ) ) == PSA_SUCCESS );
58+
PSA_ASSERT( psa_crypto_init( ) );
59+
PSA_ASSERT( psa_generate_random( output,
60+
sizeof( output ) ) );
6161
TEST_ASSERT( memcmp( output, zeros, sizeof( output ) ) != 0 );
6262
exit:
6363
mbedtls_free( seed );
@@ -82,15 +82,15 @@ void run_entropy_inject_with_crypto_init( )
8282
TEST_ASSERT( ( its_status == PSA_ITS_SUCCESS ) ||
8383
( its_status == PSA_ITS_ERROR_KEY_NOT_FOUND ) );
8484
status = mbedtls_psa_inject_entropy( seed, sizeof( seed ) );
85-
TEST_ASSERT( status == PSA_SUCCESS );
85+
PSA_ASSERT( status );
8686
its_status = psa_its_remove( PSA_CRYPTO_ITS_RANDOM_SEED_UID );
8787
TEST_ASSERT( its_status == PSA_ITS_SUCCESS );
8888
status = psa_crypto_init( );
8989
TEST_ASSERT( status == PSA_ERROR_INSUFFICIENT_ENTROPY );
9090
status = mbedtls_psa_inject_entropy( seed, sizeof( seed ) );
91-
TEST_ASSERT( status == PSA_SUCCESS );
91+
PSA_ASSERT( status );
9292
status = psa_crypto_init( );
93-
TEST_ASSERT( status == PSA_SUCCESS );
93+
PSA_ASSERT( status );
9494
mbedtls_psa_crypto_free( );
9595
/* The seed is written by nv_seed callback functions therefore the injection will fail */
9696
status = mbedtls_psa_inject_entropy( seed, sizeof( seed ) );

tests/suites/test_suite_psa_crypto_hash.function

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ void hash_finish( int alg_arg, data_t *input, data_t *expected_hash )
2323
size_t actual_hash_length;
2424
psa_hash_operation_t operation;
2525

26-
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
27-
28-
TEST_ASSERT( psa_hash_setup( &operation, alg ) == PSA_SUCCESS );
29-
TEST_ASSERT( psa_hash_update( &operation,
30-
input->x, input->len ) == PSA_SUCCESS );
31-
TEST_ASSERT( psa_hash_finish( &operation,
32-
actual_hash, sizeof( actual_hash ),
33-
&actual_hash_length ) == PSA_SUCCESS );
26+
PSA_ASSERT( psa_crypto_init( ) );
27+
28+
PSA_ASSERT( psa_hash_setup( &operation, alg ) );
29+
PSA_ASSERT( psa_hash_update( &operation,
30+
input->x, input->len ) );
31+
PSA_ASSERT( psa_hash_finish( &operation,
32+
actual_hash, sizeof( actual_hash ),
33+
&actual_hash_length ) );
3434
ASSERT_COMPARE( expected_hash->x, expected_hash->len,
3535
actual_hash, actual_hash_length );
3636

@@ -45,15 +45,15 @@ void hash_verify( int alg_arg, data_t *input, data_t *expected_hash )
4545
psa_algorithm_t alg = alg_arg;
4646
psa_hash_operation_t operation;
4747

48-
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
48+
PSA_ASSERT( psa_crypto_init( ) );
4949

50-
TEST_ASSERT( psa_hash_setup( &operation, alg ) == PSA_SUCCESS );
51-
TEST_ASSERT( psa_hash_update( &operation,
52-
input->x,
53-
input->len ) == PSA_SUCCESS );
54-
TEST_ASSERT( psa_hash_verify( &operation,
55-
expected_hash->x,
56-
expected_hash->len ) == PSA_SUCCESS );
50+
PSA_ASSERT( psa_hash_setup( &operation, alg ) );
51+
PSA_ASSERT( psa_hash_update( &operation,
52+
input->x,
53+
input->len ) );
54+
PSA_ASSERT( psa_hash_verify( &operation,
55+
expected_hash->x,
56+
expected_hash->len ) );
5757

5858
exit:
5959
mbedtls_psa_crypto_free( );
@@ -69,22 +69,21 @@ void hash_multi_part( int alg_arg, data_t *input, data_t *expected_hash )
6969
psa_hash_operation_t operation;
7070
uint32_t len = 0;
7171

72-
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
72+
PSA_ASSERT( psa_crypto_init( ) );
7373

7474
do
7575
{
7676
memset( actual_hash, 0, sizeof( actual_hash ) );
77-
TEST_ASSERT( psa_hash_setup( &operation, alg ) == PSA_SUCCESS );
77+
PSA_ASSERT( psa_hash_setup( &operation, alg ) );
7878

79-
TEST_ASSERT( psa_hash_update( &operation,
80-
input->x, len ) == PSA_SUCCESS );
81-
TEST_ASSERT( psa_hash_update( &operation,
82-
input->x + len, input->len - len ) ==
83-
PSA_SUCCESS );
79+
PSA_ASSERT( psa_hash_update( &operation,
80+
input->x, len ) );
81+
PSA_ASSERT( psa_hash_update( &operation,
82+
input->x + len, input->len - len ) );
8483

85-
TEST_ASSERT( psa_hash_finish( &operation,
86-
actual_hash, sizeof( actual_hash ),
87-
&actual_hash_length ) == PSA_SUCCESS );
84+
PSA_ASSERT( psa_hash_finish( &operation,
85+
actual_hash, sizeof( actual_hash ),
86+
&actual_hash_length ) );
8887

8988
ASSERT_COMPARE( expected_hash->x, expected_hash->len,
9089
actual_hash, actual_hash_length );

tests/suites/test_suite_psa_crypto_init.function

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ void init_deinit( int count )
142142
for( i = 0; i < count; i++ )
143143
{
144144
status = psa_crypto_init( );
145-
TEST_ASSERT( status == PSA_SUCCESS );
145+
PSA_ASSERT( status );
146146
status = psa_crypto_init( );
147-
TEST_ASSERT( status == PSA_SUCCESS );
147+
PSA_ASSERT( status );
148148
mbedtls_psa_crypto_free( );
149149
}
150150
}
@@ -156,7 +156,7 @@ void deinit_without_init( int count )
156156
int i;
157157
for( i = 0; i < count; i++ )
158158
{
159-
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
159+
PSA_ASSERT( psa_crypto_init( ) );
160160
mbedtls_psa_crypto_free( );
161161
}
162162
mbedtls_psa_crypto_free( );
@@ -172,7 +172,7 @@ void validate_module_init_generate_random( int count )
172172
for( i = 0; i < count; i++ )
173173
{
174174
status = psa_crypto_init( );
175-
TEST_ASSERT( status == PSA_SUCCESS );
175+
PSA_ASSERT( status );
176176
mbedtls_psa_crypto_free( );
177177
}
178178
status = psa_generate_random( random, sizeof( random ) );
@@ -189,7 +189,7 @@ void validate_module_init_key_based( int count )
189189
for( i = 0; i < count; i++ )
190190
{
191191
status = psa_crypto_init( );
192-
TEST_ASSERT( status == PSA_SUCCESS );
192+
PSA_ASSERT( status );
193193
mbedtls_psa_crypto_free( );
194194
}
195195
status = psa_import_key( 1, PSA_KEY_TYPE_RAW_DATA, data, sizeof( data ) );
@@ -204,16 +204,14 @@ void custom_entropy_sources( int sources_arg, int expected_init_status_arg )
204204
uint8_t random[10] = { 0 };
205205

206206
custom_entropy_sources_mask = sources_arg;
207-
TEST_ASSERT( mbedtls_psa_crypto_configure_entropy_sources(
208-
custom_entropy_init, mbedtls_entropy_free ) ==
209-
PSA_SUCCESS );
207+
PSA_ASSERT( mbedtls_psa_crypto_configure_entropy_sources(
208+
custom_entropy_init, mbedtls_entropy_free ) );
210209

211210
TEST_ASSERT( psa_crypto_init( ) == expected_init_status );
212211
if( expected_init_status != PSA_SUCCESS )
213212
goto exit;
214213

215-
TEST_ASSERT( psa_generate_random( random, sizeof( random ) ) ==
216-
PSA_SUCCESS );
214+
PSA_ASSERT( psa_generate_random( random, sizeof( random ) ) );
217215

218216
exit:
219217
mbedtls_psa_crypto_free( );
@@ -246,16 +244,14 @@ void fake_entropy_source( int threshold,
246244
fake_entropy_state.length_sequence = lengths;
247245

248246
custom_entropy_sources_mask = ENTROPY_SOURCE_FAKE;
249-
TEST_ASSERT( mbedtls_psa_crypto_configure_entropy_sources(
250-
custom_entropy_init, mbedtls_entropy_free ) ==
251-
PSA_SUCCESS );
247+
PSA_ASSERT( mbedtls_psa_crypto_configure_entropy_sources(
248+
custom_entropy_init, mbedtls_entropy_free ) );
252249

253250
TEST_ASSERT( psa_crypto_init( ) == expected_init_status );
254251
if( expected_init_status != PSA_SUCCESS )
255252
goto exit;
256253

257-
TEST_ASSERT( psa_generate_random( random, sizeof( random ) ) ==
258-
PSA_SUCCESS );
254+
PSA_ASSERT( psa_generate_random( random, sizeof( random ) ) );
259255

260256
exit:
261257
mbedtls_psa_crypto_free( );
@@ -275,16 +271,14 @@ void entropy_from_nv_seed( int seed_size_arg,
275271
TEST_ASSERT( mbedtls_nv_seed_write( seed, seed_size ) >= 0 );
276272

277273
custom_entropy_sources_mask = ENTROPY_SOURCE_NV_SEED;
278-
TEST_ASSERT( mbedtls_psa_crypto_configure_entropy_sources(
279-
custom_entropy_init, mbedtls_entropy_free ) ==
280-
PSA_SUCCESS );
274+
PSA_ASSERT( mbedtls_psa_crypto_configure_entropy_sources(
275+
custom_entropy_init, mbedtls_entropy_free ) );
281276

282277
TEST_ASSERT( psa_crypto_init( ) == expected_init_status );
283278
if( expected_init_status != PSA_SUCCESS )
284279
goto exit;
285280

286-
TEST_ASSERT( psa_generate_random( random, sizeof( random ) ) ==
287-
PSA_SUCCESS );
281+
PSA_ASSERT( psa_generate_random( random, sizeof( random ) ) );
288282

289283
exit:
290284
mbedtls_free( seed );

tests/suites/test_suite_psa_crypto_persistent_key.function

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ exit:
8181
}
8282
/* END_CASE */
8383

84-
8584
/* BEGIN_CASE */
8685
void save_large_persistent_key( int data_too_large, int expected_status )
8786
{
@@ -95,12 +94,12 @@ void save_large_persistent_key( int data_too_large, int expected_status )
9594

9695
ASSERT_ALLOC( data, data_length );
9796

98-
TEST_ASSERT( psa_crypto_init() == PSA_SUCCESS );
97+
PSA_ASSERT( psa_crypto_init() );
9998

100-
TEST_ASSERT( psa_create_key( PSA_KEY_LIFETIME_PERSISTENT, key_id,
101-
PSA_KEY_TYPE_RAW_DATA,
102-
PSA_BYTES_TO_BITS( data_length ),
103-
&handle ) == PSA_SUCCESS );
99+
PSA_ASSERT( psa_create_key( PSA_KEY_LIFETIME_PERSISTENT, key_id,
100+
PSA_KEY_TYPE_RAW_DATA,
101+
PSA_BYTES_TO_BITS( data_length ),
102+
&handle ) );
104103

105104
TEST_ASSERT( psa_import_key( handle, PSA_KEY_TYPE_RAW_DATA,
106105
data, data_length ) == expected_status );
@@ -123,24 +122,24 @@ void persistent_key_destroy( int key_id_arg, int should_store,
123122
psa_key_type_t first_type = (psa_key_type_t) first_type_arg;
124123
psa_key_type_t second_type = (psa_key_type_t) second_type_arg;
125124

126-
TEST_ASSERT( psa_crypto_init() == PSA_SUCCESS );
125+
PSA_ASSERT( psa_crypto_init() );
127126

128127
psa_key_policy_init( &policy );
129128

130-
TEST_ASSERT( psa_create_key( PSA_KEY_LIFETIME_PERSISTENT, key_id,
131-
first_type,
132-
PSA_BYTES_TO_BITS( first_data->len ),
133-
&handle ) == PSA_SUCCESS );
129+
PSA_ASSERT( psa_create_key( PSA_KEY_LIFETIME_PERSISTENT, key_id,
130+
first_type,
131+
PSA_BYTES_TO_BITS( first_data->len ),
132+
&handle ) );
134133

135134
if( should_store == 1 )
136135
{
137-
TEST_ASSERT( psa_import_key(
138-
handle, first_type,
139-
first_data->x, first_data->len ) == PSA_SUCCESS );
136+
PSA_ASSERT( psa_import_key(
137+
handle, first_type,
138+
first_data->x, first_data->len ) );
140139
}
141140

142141
/* Destroy the key */
143-
TEST_ASSERT( psa_destroy_key( handle ) == PSA_SUCCESS );
142+
PSA_ASSERT( psa_destroy_key( handle ) );
144143

145144
/* Check key slot storage is removed */
146145
TEST_ASSERT( psa_is_key_present_in_storage( key_id ) == 0 );
@@ -150,16 +149,16 @@ void persistent_key_destroy( int key_id_arg, int should_store,
150149

151150
/* Shutdown and restart */
152151
mbedtls_psa_crypto_free();
153-
TEST_ASSERT( psa_crypto_init() == PSA_SUCCESS );
152+
PSA_ASSERT( psa_crypto_init() );
154153

155154
/* Create another key in the same slot */
156-
TEST_ASSERT( psa_create_key( PSA_KEY_LIFETIME_PERSISTENT, key_id,
157-
second_type,
158-
PSA_BYTES_TO_BITS( second_data->len ),
159-
&handle ) == PSA_SUCCESS );
160-
TEST_ASSERT( psa_import_key(
161-
handle, second_type,
162-
second_data->x, second_data->len ) == PSA_SUCCESS );
155+
PSA_ASSERT( psa_create_key( PSA_KEY_LIFETIME_PERSISTENT, key_id,
156+
second_type,
157+
PSA_BYTES_TO_BITS( second_data->len ),
158+
&handle ) );
159+
PSA_ASSERT( psa_import_key(
160+
handle, second_type,
161+
second_data->x, second_data->len ) );
163162

164163
exit:
165164
mbedtls_psa_crypto_free();
@@ -177,12 +176,12 @@ void persistent_key_import( int key_id_arg, int type_arg, data_t *data,
177176
psa_key_type_t type = (psa_key_type_t) type_arg;
178177
psa_key_handle_t handle = 0;
179178

180-
TEST_ASSERT( psa_crypto_init() == PSA_SUCCESS );
179+
PSA_ASSERT( psa_crypto_init() );
181180

182-
TEST_ASSERT( psa_create_key( PSA_KEY_LIFETIME_PERSISTENT, key_id,
183-
type,
184-
PSA_BYTES_TO_BITS( data->len ),
185-
&handle ) == PSA_SUCCESS );
181+
PSA_ASSERT( psa_create_key( PSA_KEY_LIFETIME_PERSISTENT, key_id,
182+
type,
183+
PSA_BYTES_TO_BITS( data->len ),
184+
&handle ) );
186185
psa_key_policy_init( &policy );
187186
TEST_ASSERT( psa_import_key( handle, type,
188187
data->x, data->len ) == expected_status );
@@ -193,7 +192,7 @@ void persistent_key_import( int key_id_arg, int type_arg, data_t *data,
193192
goto exit;
194193
}
195194

196-
TEST_ASSERT( psa_get_key_lifetime( handle, &lifetime ) == PSA_SUCCESS );
195+
PSA_ASSERT( psa_get_key_lifetime( handle, &lifetime ) );
197196
TEST_ASSERT( lifetime == PSA_KEY_LIFETIME_PERSISTENT );
198197

199198
exit:
@@ -219,28 +218,28 @@ void import_export_persistent_key( data_t *data, int type_arg,
219218

220219
ASSERT_ALLOC( exported, export_size );
221220

222-
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
221+
PSA_ASSERT( psa_crypto_init( ) );
223222

224-
TEST_ASSERT( psa_create_key( PSA_KEY_LIFETIME_PERSISTENT, key_id,
225-
type,
226-
PSA_BYTES_TO_BITS( data->len ),
227-
&handle ) == PSA_SUCCESS );
223+
PSA_ASSERT( psa_create_key( PSA_KEY_LIFETIME_PERSISTENT, key_id,
224+
type,
225+
PSA_BYTES_TO_BITS( data->len ),
226+
&handle ) );
228227

229228
psa_key_policy_init( &policy );
230229
psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_EXPORT,
231230
PSA_ALG_VENDOR_FLAG );
232-
TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS );
231+
PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
233232

234233
/* Import the key */
235-
TEST_ASSERT( psa_import_key( handle, type,
236-
data->x, data->len ) == PSA_SUCCESS );
234+
PSA_ASSERT( psa_import_key( handle, type,
235+
data->x, data->len ) );
237236

238-
TEST_ASSERT( psa_get_key_lifetime( handle, &lifetime_get ) == PSA_SUCCESS );
237+
PSA_ASSERT( psa_get_key_lifetime( handle, &lifetime_get ) );
239238
TEST_ASSERT( lifetime_get == PSA_KEY_LIFETIME_PERSISTENT );
240239

241240
/* Test the key information */
242-
TEST_ASSERT( psa_get_key_information(
243-
handle, &got_type, &got_bits ) == PSA_SUCCESS );
241+
PSA_ASSERT( psa_get_key_information(
242+
handle, &got_type, &got_bits ) );
244243
TEST_ASSERT( got_type == type );
245244
TEST_ASSERT( got_bits == (size_t) expected_bits );
246245

@@ -251,13 +250,13 @@ void import_export_persistent_key( data_t *data, int type_arg,
251250
psa_destroy_persistent_key( key_id );
252251
}
253252
/* Export the key */
254-
TEST_ASSERT( psa_export_key( handle, exported, export_size,
255-
&exported_length ) == PSA_SUCCESS );
253+
PSA_ASSERT( psa_export_key( handle, exported, export_size,
254+
&exported_length ) );
256255

257256
ASSERT_COMPARE( data->x, data->len, exported, exported_length );
258257

259258
/* Destroy the key */
260-
TEST_ASSERT( psa_destroy_key( handle ) == PSA_SUCCESS );
259+
PSA_ASSERT( psa_destroy_key( handle ) );
261260
TEST_ASSERT( psa_is_key_present_in_storage( key_id ) == 0 );
262261

263262
exit:

tests/suites/test_suite_psa_crypto_slot_management.function

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ void many_transient_handles( int max_handles_arg )
367367
&handles[i] );
368368
if( status == PSA_ERROR_INSUFFICIENT_MEMORY )
369369
break;
370-
TEST_ASSERT( status == PSA_SUCCESS );
370+
PSA_ASSERT( status );
371371
TEST_ASSERT( handles[i] != 0 );
372372
for( j = 0; j < i; j++ )
373373
TEST_ASSERT( handles[i] != handles[j] );

tests/suites/test_suite_psa_crypto_storage_file.function

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ exit:
9797
}
9898
/* END_CASE */
9999

100-
101100
/* BEGIN_CASE */
102101
void get_file_size( data_t *data, int expected_data_length,
103102
int expected_status, int should_make_file )

0 commit comments

Comments
 (0)