Test suites: print error on failed platform_setup

Return encountered errors instead of covering them
Fix return value on the broken snprintf implementation
This commit is contained in:
Andrzej Kurek 2018-04-18 04:14:31 -04:00
parent a282270a10
commit f13ca9536c
2 changed files with 11 additions and 9 deletions

View file

@ -132,13 +132,11 @@ mbedtls_platform_context platform_ctx;
/* Helper Functions */ /* Helper Functions */
static int platform_setup() static int platform_setup()
{ {
int ret = 0;
#if defined(MBEDTLS_PLATFORM_C) #if defined(MBEDTLS_PLATFORM_C)
if( mbedtls_platform_setup( &platform_ctx ) != 0 ) ret = mbedtls_platform_setup( &platform_ctx );
{
return -1;
}
#endif /* MBEDTLS_PLATFORM_C */ #endif /* MBEDTLS_PLATFORM_C */
return 0; return( ret );
} }
static void platform_teardown() static void platform_teardown()

View file

@ -282,10 +282,14 @@ int main(int argc, const char *argv[])
!defined(TEST_SUITE_MEMORY_BUFFER_ALLOC) !defined(TEST_SUITE_MEMORY_BUFFER_ALLOC)
unsigned char alloc_buf[1000000]; unsigned char alloc_buf[1000000];
#endif #endif
if( platform_setup() != 0 ) /* Platform setup should be called in the beginning */
ret = platform_setup();
if( ret != 0 )
{ {
mbedtls_fprintf( stderr, "FATAL: Failed to initialize platform" ); mbedtls_fprintf( stderr,
return -1; "FATAL: Failed to initialize platform - error %d\n",
ret );
return( -1 );
} }
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \ #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
!defined(TEST_SUITE_MEMORY_BUFFER_ALLOC) !defined(TEST_SUITE_MEMORY_BUFFER_ALLOC)
@ -312,7 +316,7 @@ int main(int argc, const char *argv[])
{ {
mbedtls_fprintf( stderr, "the snprintf implementation is broken\n" ); mbedtls_fprintf( stderr, "the snprintf implementation is broken\n" );
platform_teardown(); platform_teardown();
return( 0 ); return( 1 );
} }
while( arg_index < argc) while( arg_index < argc)