Skip to content

Commit 3034bdb

Browse files
Add tests of deprecated PSA macros
When MBEDTLS_TEST_DEPRECATED is defined, run some additional tests to validate deprecated PSA macros. We don't need to test deprecated features extensively, but we should at least ensure that they don't break the build. Add some code to component_build_deprecated in all.sh to run these tests with MBEDTLS_DEPRECATED_WARNING enabled. The tests are also executed when MBEDTLS_DEPRECATED_WARNING and MBEDTLS_DEPRECATED_REMOVED are both disabled.
1 parent 473c07b commit 3034bdb

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

tests/scripts/all.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,10 @@ component_build_deprecated () {
715715
make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
716716
make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
717717

718+
msg "test: make, full config + DEPRECATED_WARNING, expect warnings" # ~ 30s
719+
make -C test clean
720+
make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=deprecated-declarations -DMBEDTLS_TEST_DEPRECATED' tests
721+
718722
msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
719723
# No cleanup, just tweak the configuration and rebuild
720724
make clean

tests/suites/main_test.function

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
#include "psa/crypto.h"
3030
#endif /* MBEDTLS_USE_PSA_CRYPTO */
3131

32+
#if !defined(MBEDTLS_DEPRECATED_REMOVED) && !defined(MBEDTLS_DEPRECATED_WARNING)
33+
#define MBEDTLS_TEST_DEPRECATED
34+
#endif
35+
3236
/*----------------------------------------------------------------------------*/
3337
/* Common helper code */
3438

tests/suites/test_suite_psa_crypto.function

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,18 @@ void static_checks( )
11641164
* encoding. The shifted mask is the maximum truncated value. The
11651165
* untruncated algorithm may be one byte larger. */
11661166
TEST_ASSERT( PSA_MAC_MAX_SIZE <= 1 + max_truncated_mac_size );
1167+
1168+
#if defined(MBEDTLS_TEST_DEPRECATED)
1169+
/* Check deprecated constants. */
1170+
TEST_EQUAL( PSA_ERROR_UNKNOWN_ERROR, PSA_ERROR_GENERIC_ERROR );
1171+
TEST_EQUAL( PSA_ERROR_OCCUPIED_SLOT, PSA_ERROR_ALREADY_EXISTS );
1172+
TEST_EQUAL( PSA_ERROR_EMPTY_SLOT, PSA_ERROR_DOES_NOT_EXIST );
1173+
TEST_EQUAL( PSA_ERROR_INSUFFICIENT_CAPACITY, PSA_ERROR_INSUFFICIENT_DATA );
1174+
TEST_EQUAL( PSA_ERROR_TAMPERING_DETECTED, PSA_ERROR_CORRUPTION_DETECTED );
1175+
TEST_EQUAL( PSA_KEY_USAGE_SIGN, PSA_KEY_USAGE_SIGN_HASH );
1176+
TEST_EQUAL( PSA_KEY_USAGE_VERIFY, PSA_KEY_USAGE_VERIFY_HASH );
1177+
TEST_EQUAL( PSA_ASYMMETRIC_SIGNATURE_MAX_SIZE, PSA_SIGNATURE_MAX_SIZE );
1178+
#endif /* MBEDTLS_TEST_DEPRECATED */
11671179
}
11681180
/* END_CASE */
11691181

@@ -3703,7 +3715,13 @@ void signature_size( int type_arg,
37033715
psa_key_type_t type = type_arg;
37043716
psa_algorithm_t alg = alg_arg;
37053717
size_t actual_size = PSA_SIGN_OUTPUT_SIZE( type, bits, alg );
3718+
37063719
TEST_EQUAL( actual_size, (size_t) expected_size_arg );
3720+
#if defined(MBEDTLS_TEST_DEPRECATED)
3721+
TEST_EQUAL( actual_size,
3722+
PSA_ASYMMETRIC_SIGN_OUTPUT_SIZE( type, bits, alg ) );
3723+
#endif /* MBEDTLS_TEST_DEPRECATED */
3724+
37073725
exit:
37083726
;
37093727
}

0 commit comments

Comments
 (0)