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

@ -19,27 +19,9 @@
#include <test/macros.h>
#include <string.h>
#if defined(MBEDTLS_CHECK_PARAMS)
#include <setjmp.h>
#endif
/*----------------------------------------------------------------------------*/
/* Static global variables */
#if defined(MBEDTLS_CHECK_PARAMS)
typedef struct
{
uint8_t expected_call;
uint8_t expected_call_happened;
jmp_buf state;
mbedtls_test_param_failed_location_record_t location_record;
}
param_failed_ctx_t;
static param_failed_ctx_t param_failed_ctx;
#endif
#if defined(MBEDTLS_PLATFORM_C)
static mbedtls_platform_context platform_ctx;
#endif
@ -222,66 +204,14 @@ int mbedtls_test_hexcmp( uint8_t * a, uint8_t * b,
return ret;
}
#if defined(MBEDTLS_CHECK_PARAMS)
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_test_param_failed_expect_call( void )
{
param_failed_ctx.expected_call_happened = 0;
param_failed_ctx.expected_call = 1;
}
int mbedtls_test_param_failed_check_expected_call( void )
{
param_failed_ctx.expected_call = 0;
if( param_failed_ctx.expected_call_happened != 0 )
return( 0 );
return( -1 );
}
void* mbedtls_test_param_failed_get_state_buf( void )
{
return &param_failed_ctx.state;
}
void mbedtls_test_param_failed_reset_state( void )
{
memset( param_failed_ctx.state, 0, sizeof( param_failed_ctx.state ) );
}
void mbedtls_param_failed( const char *failure_condition,
const char *file,
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( param_failed_ctx.expected_call != 0 )
{
param_failed_ctx.expected_call = 0;
param_failed_ctx.expected_call_happened = 1;
}
else
{
/* ...else try a long jump. If the execution state has not been set-up
* or reset then the long jump buffer is all zero's and the call will
* with high probability fault, emphasizing there is something to look
* at.
*/
longjmp( param_failed_ctx.state, 1 );
}
(void) failure_condition;
(void) file;
(void) line;
}
#endif /* MBEDTLS_CHECK_PARAMS */
#if defined(MBEDTLS_TEST_HOOKS)
void mbedtls_test_err_add_check( int high, int low,