From c08fc1d7e97bbc84d6ed7d6e2d212a9650ed0dd0 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 18 Dec 2018 08:47:00 +0100 Subject: [PATCH] Move MIN and MAX macros from PSA tests to helpers.function --- tests/suites/helpers.function | 17 +++++++++++++++++ tests/suites/test_suite_psa_crypto.function | 2 -- .../test_suite_psa_crypto_entropy.function | 5 ----- .../suites/test_suite_psa_crypto_init.function | 3 --- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/tests/suites/helpers.function b/tests/suites/helpers.function index da843b2b3a..5f9f7b0997 100644 --- a/tests/suites/helpers.function +++ b/tests/suites/helpers.function @@ -202,6 +202,23 @@ typedef struct data_tag ( STATIC_ASSERT_THEN_RETURN( IS_ARRAY_NOT_POINTER( array ), \ ARRAY_LENGTH_UNSAFE( array ) ) ) +/** Return the smaller of two values. + * + * \param x An integer-valued expression without side effects. + * \param y An integer-valued expression without side effects. + * + * \return The smaller of \p x and \p y. + */ +#define MIN( x, y ) ( ( x ) < ( y ) ? ( x ) : ( y ) ) + +/** Return the larger of two values. + * + * \param x An integer-valued expression without side effects. + * \param y An integer-valued expression without side effects. + * + * \return The larger of \p x and \p y. + */ +#define MAX( x, y ) ( ( x ) > ( y ) ? ( x ) : ( y ) ) /* * 32-bit integer manipulation macros (big endian) diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function index f8c9c7492c..c1339c015a 100644 --- a/tests/suites/test_suite_psa_crypto.function +++ b/tests/suites/test_suite_psa_crypto.function @@ -11,8 +11,6 @@ #include "psa/crypto.h" -#define MAX( x, y ) ( ( x ) > ( y ) ? ( x ) : ( y ) ) - /** An invalid export length that will never be set by psa_export_key(). */ static const size_t INVALID_EXPORT_LENGTH = ~0U; diff --git a/tests/suites/test_suite_psa_crypto_entropy.function b/tests/suites/test_suite_psa_crypto_entropy.function index 704fad913f..727db43e54 100644 --- a/tests/suites/test_suite_psa_crypto_entropy.function +++ b/tests/suites/test_suite_psa_crypto_entropy.function @@ -6,11 +6,6 @@ #include "mbedtls/entropy.h" #include "mbedtls/entropy_poll.h" -/* MAX value support macro */ -#if !defined(MAX) -#define MAX(a,b) (((a)>(b))?(a):(b)) -#endif - /* Calculating the minimum allowed entropy size in bytes */ #define MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE MAX(MBEDTLS_ENTROPY_MIN_PLATFORM, MBEDTLS_ENTROPY_BLOCK_SIZE) diff --git a/tests/suites/test_suite_psa_crypto_init.function b/tests/suites/test_suite_psa_crypto_init.function index e04652fda2..c8f6e1b0a5 100644 --- a/tests/suites/test_suite_psa_crypto_init.function +++ b/tests/suites/test_suite_psa_crypto_init.function @@ -12,9 +12,6 @@ #include "mbedtls/entropy.h" #include "mbedtls/entropy_poll.h" -#define MIN( x, y ) ( ( x ) < ( y ) ? ( x ) : ( y ) ) -#define MAX( x, y ) ( ( x ) > ( y ) ? ( x ) : ( y ) ) - #define ENTROPY_MIN_NV_SEED_SIZE \ MAX(MBEDTLS_ENTROPY_MIN_PLATFORM, MBEDTLS_ENTROPY_BLOCK_SIZE)