1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-29 11:41:15 +03:00

Merge pull request #3474 from ronald-cron-arm/common-mbedtls_param_failed

Common mbedtls_param_failed()
This commit is contained in:
Gilles Peskine
2020-10-06 22:15:42 +02:00
committed by GitHub
28 changed files with 458 additions and 446 deletions

View File

@ -74,16 +74,6 @@ typedef struct data_tag
#define DISPATCH_UNSUPPORTED_SUITE -5 /* Test suite not supported by the
build */
typedef enum
{
PARAMFAIL_TESTSTATE_IDLE = 0, /* No parameter failure call test */
PARAMFAIL_TESTSTATE_PENDING, /* Test call to the parameter failure
* is pending */
PARAMFAIL_TESTSTATE_CALLED /* The test call to the parameter
* failure function has been made */
} paramfail_test_state_t;
/*----------------------------------------------------------------------------*/
/* Macros */
@ -237,15 +227,16 @@ typedef enum
*
* \param TEST The test expression to be tested.
*/
#define TEST_INVALID_PARAM_RET( PARAM_ERR_VALUE, TEST ) \
do { \
test_info.paramfail_test_state = PARAMFAIL_TESTSTATE_PENDING; \
if( (TEST) != (PARAM_ERR_VALUE) || \
test_info.paramfail_test_state != PARAMFAIL_TESTSTATE_CALLED ) \
{ \
test_fail( #TEST, __LINE__, __FILE__ ); \
goto exit; \
} \
#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 ) ) \
{ \
test_fail( #TEST, __LINE__, __FILE__ ); \
goto exit; \
} \
mbedtls_test_param_failed_check_expected_call( ); \
} while( 0 )
/**
@ -268,16 +259,17 @@ typedef enum
*
* \param TEST The test expression to be tested.
*/
#define TEST_INVALID_PARAM( TEST ) \
do { \
memcpy(jmp_tmp, param_fail_jmp, sizeof(jmp_buf)); \
if( setjmp( param_fail_jmp ) == 0 ) \
{ \
TEST; \
test_fail( #TEST, __LINE__, __FILE__ ); \
goto exit; \
} \
memcpy(param_fail_jmp, jmp_tmp, sizeof(jmp_buf)); \
#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; \
test_fail( #TEST, __LINE__, __FILE__ ); \
goto exit; \
} \
mbedtls_test_param_failed_reset_state( ); \
} while( 0 )
#endif /* MBEDTLS_CHECK_PARAMS && !MBEDTLS_PARAM_FAILED_ALT */
@ -359,7 +351,6 @@ typedef enum
typedef struct
{
paramfail_test_state_t paramfail_test_state;
test_result_t result;
const char *test;
const char *filename;
@ -370,7 +361,6 @@ test_info_t;
static test_info_t test_info;
#if defined(MBEDTLS_CHECK_PARAMS)
jmp_buf param_fail_jmp;
jmp_buf jmp_tmp;
#endif
@ -427,30 +417,6 @@ void test_skip( const char *test, int line_no, const char* filename )
test_info.filename = filename;
}
#if defined(MBEDTLS_CHECK_PARAMS)
void mbedtls_param_failed( const char *failure_condition,
const char *file,
int line )
{
/* If we are testing the callback function... */
if( test_info.paramfail_test_state == PARAMFAIL_TESTSTATE_PENDING )
{
test_info.paramfail_test_state = PARAMFAIL_TESTSTATE_CALLED;
}
else
{
/* ...else we treat this as an error */
/* Record the location of the failure, but not as a failure yet, in case
* it was part of the test */
test_fail( failure_condition, line, file );
test_info.result = TEST_RESULT_SUCCESS;
longjmp( param_fail_jmp, 1 );
}
}
#endif
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
static int redirect_output( FILE* out_stream, const char* path )
{