tests: Move mbedtls_param_failed() call location record

In preparation of moving mbedtls_param_failed() to test
common code, move mbedtls_param_failed() call location
record into a context dedicated to mbedtls_param_failed().

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
This commit is contained in:
Ronald Cron 2020-06-30 17:44:27 +02:00
parent 55d97f2ca8
commit 4e66587545
2 changed files with 40 additions and 5 deletions

View File

@ -370,6 +370,21 @@ test_info_t;
static test_info_t test_info; static test_info_t test_info;
#if defined(MBEDTLS_CHECK_PARAMS) #if defined(MBEDTLS_CHECK_PARAMS)
typedef struct
{
const char *failure_condition;
const char *file;
int line;
}
mbedtls_test_param_failed_location_record_t;
typedef struct
{
mbedtls_test_param_failed_location_record_t location_record;
}
param_failed_ctx_t;
static param_failed_ctx_t param_failed_ctx;
jmp_buf param_fail_jmp; jmp_buf param_fail_jmp;
jmp_buf jmp_tmp; jmp_buf jmp_tmp;
#endif #endif
@ -422,10 +437,29 @@ void test_skip( const char *test, int line_no, const char* filename )
} }
#if defined(MBEDTLS_CHECK_PARAMS) #if defined(MBEDTLS_CHECK_PARAMS)
/**
* \brief Get the location record of the last call to
* mbedtls_test_param_failed().
*
* \note The call expectation is set up and active until the next call to
* mbedtls_test_param_failed_check_expected_call() or
* mbedtls_param_failed() that cancels it.
*/
void mbedtls_test_param_failed_get_location_record(
mbedtls_test_param_failed_location_record_t *location_record )
{
*location_record = param_failed_ctx.location_record;
}
void mbedtls_param_failed( const char *failure_condition, void mbedtls_param_failed( const char *failure_condition,
const char *file, const char *file,
int line ) int line )
{ {
/* Record the location of the failure */
param_failed_ctx.location_record.failure_condition = failure_condition;
param_failed_ctx.location_record.file = file;
param_failed_ctx.location_record.line = line;
/* If we are testing the callback function... */ /* If we are testing the callback function... */
if( test_info.paramfail_test_state == PARAMFAIL_TESTSTATE_PENDING ) if( test_info.paramfail_test_state == PARAMFAIL_TESTSTATE_PENDING )
{ {
@ -435,11 +469,6 @@ void mbedtls_param_failed( const char *failure_condition,
{ {
/* ...else we treat this as an error */ /* ...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 ); longjmp( param_fail_jmp, 1 );
} }
} }

View File

@ -167,6 +167,8 @@ $dispatch_code
void execute_function_ptr(TestWrapper_t fp, void **params) void execute_function_ptr(TestWrapper_t fp, void **params)
{ {
#if defined(MBEDTLS_CHECK_PARAMS) #if defined(MBEDTLS_CHECK_PARAMS)
mbedtls_test_param_failed_location_record_t location_record;
if ( setjmp( param_fail_jmp ) == 0 ) if ( setjmp( param_fail_jmp ) == 0 )
{ {
fp( params ); fp( params );
@ -174,6 +176,10 @@ void execute_function_ptr(TestWrapper_t fp, void **params)
else else
{ {
/* Unexpected parameter validation error */ /* Unexpected parameter validation error */
mbedtls_test_param_failed_get_location_record( &location_record );
test_fail( location_record.failure_condition,
location_record.line,
location_record.file );
test_info.result = TEST_RESULT_FAILED; test_info.result = TEST_RESULT_FAILED;
} }