mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-01-12 23:35:26 +00:00
Make test suites compatible with #include <assert.h>
Don't use the macro name assert. It's technically permitted as long as <assert.h> is not included, but it's fragile, because it means the code and any header that it includes must not include <assert.h>.
This commit is contained in:
parent
47f2de1329
commit
9e23bea692
|
@ -286,7 +286,7 @@ typedef enum
|
||||||
#define TEST_VALID_PARAM( TEST ) \
|
#define TEST_VALID_PARAM( TEST ) \
|
||||||
TEST_ASSERT( ( TEST, 1 ) );
|
TEST_ASSERT( ( TEST, 1 ) );
|
||||||
|
|
||||||
#define assert(a) if( !( a ) ) \
|
#define TEST_HELPER_ASSERT(a) if( !( a ) ) \
|
||||||
{ \
|
{ \
|
||||||
mbedtls_fprintf( stderr, "Assertion Failed at %s:%d - %s\n", \
|
mbedtls_fprintf( stderr, "Assertion Failed at %s:%d - %s\n", \
|
||||||
__FILE__, __LINE__, #a ); \
|
__FILE__, __LINE__, #a ); \
|
||||||
|
@ -504,7 +504,7 @@ static int unhexify( unsigned char *obuf, const char *ibuf )
|
||||||
{
|
{
|
||||||
unsigned char c, c2;
|
unsigned char c, c2;
|
||||||
int len = strlen( ibuf ) / 2;
|
int len = strlen( ibuf ) / 2;
|
||||||
assert( strlen( ibuf ) % 2 == 0 ); /* must be even number of bytes */
|
TEST_HELPER_ASSERT( strlen( ibuf ) % 2 == 0 ); /* must be even number of bytes */
|
||||||
|
|
||||||
while( *ibuf != 0 )
|
while( *ibuf != 0 )
|
||||||
{
|
{
|
||||||
|
@ -516,7 +516,7 @@ static int unhexify( unsigned char *obuf, const char *ibuf )
|
||||||
else if( c >= 'A' && c <= 'F' )
|
else if( c >= 'A' && c <= 'F' )
|
||||||
c -= 'A' - 10;
|
c -= 'A' - 10;
|
||||||
else
|
else
|
||||||
assert( 0 );
|
TEST_HELPER_ASSERT( 0 );
|
||||||
|
|
||||||
c2 = *ibuf++;
|
c2 = *ibuf++;
|
||||||
if( c2 >= '0' && c2 <= '9' )
|
if( c2 >= '0' && c2 <= '9' )
|
||||||
|
@ -526,7 +526,7 @@ static int unhexify( unsigned char *obuf, const char *ibuf )
|
||||||
else if( c2 >= 'A' && c2 <= 'F' )
|
else if( c2 >= 'A' && c2 <= 'F' )
|
||||||
c2 -= 'A' - 10;
|
c2 -= 'A' - 10;
|
||||||
else
|
else
|
||||||
assert( 0 );
|
TEST_HELPER_ASSERT( 0 );
|
||||||
|
|
||||||
*obuf++ = ( c << 4 ) | c2;
|
*obuf++ = ( c << 4 ) | c2;
|
||||||
}
|
}
|
||||||
|
@ -571,7 +571,7 @@ static unsigned char *zero_alloc( size_t len )
|
||||||
size_t actual_len = ( len != 0 ) ? len : 1;
|
size_t actual_len = ( len != 0 ) ? len : 1;
|
||||||
|
|
||||||
p = mbedtls_calloc( 1, actual_len );
|
p = mbedtls_calloc( 1, actual_len );
|
||||||
assert( p != NULL );
|
TEST_HELPER_ASSERT( p != NULL );
|
||||||
|
|
||||||
memset( p, 0x00, actual_len );
|
memset( p, 0x00, actual_len );
|
||||||
|
|
||||||
|
@ -598,7 +598,7 @@ static unsigned char *unhexify_alloc( const char *ibuf, size_t *olen )
|
||||||
return( zero_alloc( *olen ) );
|
return( zero_alloc( *olen ) );
|
||||||
|
|
||||||
obuf = mbedtls_calloc( 1, *olen );
|
obuf = mbedtls_calloc( 1, *olen );
|
||||||
assert( obuf != NULL );
|
TEST_HELPER_ASSERT( obuf != NULL );
|
||||||
|
|
||||||
(void) unhexify( obuf, ibuf );
|
(void) unhexify( obuf, ibuf );
|
||||||
|
|
||||||
|
|
|
@ -179,7 +179,7 @@ static int parse_arguments( char *buf, size_t len, char **params,
|
||||||
if( p + 1 < buf + len )
|
if( p + 1 < buf + len )
|
||||||
{
|
{
|
||||||
cur = p + 1;
|
cur = p + 1;
|
||||||
assert( cnt < params_len );
|
TEST_HELPER_ASSERT( cnt < params_len );
|
||||||
params[cnt++] = cur;
|
params[cnt++] = cur;
|
||||||
}
|
}
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
|
|
|
@ -13,11 +13,11 @@
|
||||||
*/
|
*/
|
||||||
#define INCR_ASSERT(p, start, len, step) do \
|
#define INCR_ASSERT(p, start, len, step) do \
|
||||||
{ \
|
{ \
|
||||||
assert( ( p ) >= ( start ) ); \
|
TEST_HELPER_ASSERT( ( p ) >= ( start ) ); \
|
||||||
assert( sizeof( *( p ) ) == sizeof( *( start ) ) ); \
|
TEST_HELPER_ASSERT( sizeof( *( p ) ) == sizeof( *( start ) ) ); \
|
||||||
/* <= is checked to support use inside a loop where \
|
/* <= is checked to support use inside a loop where \
|
||||||
pointer is incremented after reading data. */ \
|
pointer is incremented after reading data. */ \
|
||||||
assert( (uint32_t)( ( ( p ) - ( start ) ) + ( step ) ) <= ( len ) );\
|
TEST_HELPER_ASSERT( (uint32_t)( ( ( p ) - ( start ) ) + ( step ) ) <= ( len ) );\
|
||||||
( p ) += ( step ); \
|
( p ) += ( step ); \
|
||||||
} \
|
} \
|
||||||
while( 0 )
|
while( 0 )
|
||||||
|
@ -127,7 +127,7 @@ uint8_t * receive_data( uint32_t * data_len )
|
||||||
/* Read data length */
|
/* Read data length */
|
||||||
*data_len = receive_uint32();
|
*data_len = receive_uint32();
|
||||||
data = (uint8_t *)malloc( *data_len );
|
data = (uint8_t *)malloc( *data_len );
|
||||||
assert( data != NULL );
|
TEST_HELPER_ASSERT( data != NULL );
|
||||||
|
|
||||||
greentea_getc(); // read ';' received after key i.e. *data_len
|
greentea_getc(); // read ';' received after key i.e. *data_len
|
||||||
|
|
||||||
|
@ -221,7 +221,7 @@ void ** parse_parameters( uint8_t count, uint8_t * data, uint32_t data_len,
|
||||||
hex_count = find_hex_count(count, data, data_len);
|
hex_count = find_hex_count(count, data, data_len);
|
||||||
|
|
||||||
params = (void **)malloc( sizeof( void *) * ( count + hex_count ) );
|
params = (void **)malloc( sizeof( void *) * ( count + hex_count ) );
|
||||||
assert( params != NULL );
|
TEST_HELPER_ASSERT( params != NULL );
|
||||||
cur = params;
|
cur = params;
|
||||||
|
|
||||||
p = data;
|
p = data;
|
||||||
|
@ -360,7 +360,7 @@ int execute_tests( int args, const char ** argv )
|
||||||
{
|
{
|
||||||
/* Read dependency count */
|
/* Read dependency count */
|
||||||
count = *p;
|
count = *p;
|
||||||
assert( count < data_len );
|
TEST_HELPER_ASSERT( count < data_len );
|
||||||
INCR_ASSERT( p, data, data_len, sizeof( uint8_t ) );
|
INCR_ASSERT( p, data, data_len, sizeof( uint8_t ) );
|
||||||
ret = verify_dependencies( count, p );
|
ret = verify_dependencies( count, p );
|
||||||
if ( ret != DEPENDENCY_SUPPORTED )
|
if ( ret != DEPENDENCY_SUPPORTED )
|
||||||
|
|
Loading…
Reference in a new issue