Refactor optional parameter check tests

Remove tests related to NULL pointers,
keep tests related to invalid enum values.
Remove test code related to MBEDTLS_CHECK_PARAMS.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
Signed-off-by: TRodziewicz <tomasz.rodziewicz@mobica.com>
This commit is contained in:
Ronald Cron 2021-05-21 08:50:00 +02:00 committed by TRodziewicz
parent 142c205ffc
commit 875b5fb7fa
34 changed files with 42 additions and 3377 deletions

View file

@ -58,10 +58,6 @@
* It allows a library function to return a value and return an error
* code that can be tested.
*
* When MBEDTLS_CHECK_PARAMS is enabled, calls to the parameter failure
* callback, MBEDTLS_PARAM_FAILED(), will be assumed to be a test
* failure.
*
* This macro is not suitable for negative parameter validation tests,
* as it assumes the test step will not create an error.
*
@ -182,70 +178,11 @@
} while( 0 )
#if defined(MBEDTLS_CHECK_PARAMS) && !defined(MBEDTLS_PARAM_FAILED_ALT)
/**
* \brief This macro tests the statement passed to it as a test step or
* individual test in a test case. The macro assumes the test will fail
* and will generate an error.
*
* It allows a library function to return a value and tests the return
* code on return to confirm the given error code was returned.
*
* When MBEDTLS_CHECK_PARAMS is enabled, calls to the parameter failure
* callback, MBEDTLS_PARAM_FAILED(), are assumed to indicate the
* expected failure, and the test will pass.
*
* This macro is intended for negative parameter validation tests,
* where the failing function may return an error value or call
* MBEDTLS_PARAM_FAILED() to indicate the error.
*
* \param PARAM_ERROR_VALUE The expected error code.
*
* \param TEST The test expression to be tested.
*/
#define TEST_INVALID_PARAM_RET( PARAM_ERR_VALUE, TEST ) \
do { \
mbedtls_test_param_failed_expect_call( ); \
if( ( ( TEST ) != ( PARAM_ERR_VALUE ) ) || \
( mbedtls_test_param_failed_check_expected_call( ) != 0 ) ) \
{ \
mbedtls_test_fail( #TEST, __LINE__, __FILE__ ); \
goto exit; \
} \
mbedtls_test_param_failed_check_expected_call( ); \
} while( 0 )
#define TEST_INVALID_PARAM_RET( PARAM_ERR_VALUE, TEST ) \
do { if( ( TEST ) != ( PARAM_ERR_VALUE ) ) goto exit; } while( 0 )
/**
* \brief This macro tests the statement passed to it as a test step or
* individual test in a test case. The macro assumes the test will fail
* and will generate an error.
*
* It assumes the library function under test cannot return a value and
* assumes errors can only be indicated byt calls to
* MBEDTLS_PARAM_FAILED().
*
* When MBEDTLS_CHECK_PARAMS is enabled, calls to the parameter failure
* callback, MBEDTLS_PARAM_FAILED(), are assumed to indicate the
* expected failure. If MBEDTLS_CHECK_PARAMS is not enabled, no test
* can be made.
*
* This macro is intended for negative parameter validation tests,
* where the failing function can only return an error by calling
* MBEDTLS_PARAM_FAILED() to indicate the error.
*
* \param TEST The test expression to be tested.
*/
#define TEST_INVALID_PARAM( TEST ) \
do { \
memcpy( jmp_tmp, mbedtls_test_param_failed_get_state_buf( ), \
sizeof( jmp_tmp ) ); \
if( setjmp( mbedtls_test_param_failed_get_state_buf( ) ) == 0 ) \
{ \
TEST; \
mbedtls_test_fail( #TEST, __LINE__, __FILE__ ); \
goto exit; \
} \
mbedtls_test_param_failed_reset_state( ); \
} while( 0 )
#define TEST_INVALID_PARAM( TEST ) \
do { TEST; } while( 0 )
#endif /* MBEDTLS_CHECK_PARAMS && !MBEDTLS_PARAM_FAILED_ALT */
/**
@ -256,11 +193,6 @@
* assumes errors can only be indicated by calls to
* MBEDTLS_PARAM_FAILED().
*
* When MBEDTLS_CHECK_PARAMS is enabled, calls to the parameter failure
* callback, MBEDTLS_PARAM_FAILED(), are assumed to indicate the
* expected failure. If MBEDTLS_CHECK_PARAMS is not enabled, no test
* can be made.
*
* This macro is intended to test that functions returning void
* accept all of the parameter values they're supposed to accept - eg
* that they don't call MBEDTLS_PARAM_FAILED() when a parameter
@ -271,12 +203,6 @@
* accept is best done by using TEST_ASSERT() and checking the return
* value as well.
*
* Note: this macro is available even when #MBEDTLS_CHECK_PARAMS is
* disabled, as it makes sense to check that the functions accept all
* legal values even if this option is disabled - only in that case,
* the test is more about whether the function segfaults than about
* whether it invokes MBEDTLS_PARAM_FAILED().
*
* \param TEST The test expression to be tested.
*/
#define TEST_VALID_PARAM( TEST ) \