Add platform setup and teardown calls to test suites
Add a global platform context variable available for tests
This commit is contained in:
parent
4ca9a45756
commit
1152fa83f9
2 changed files with 20 additions and 0 deletions
|
@ -109,6 +109,7 @@ static struct
|
|||
}
|
||||
test_info;
|
||||
|
||||
mbedtls_platform_context platform_ctx;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Helper flags for complex dependencies */
|
||||
|
|
|
@ -281,6 +281,14 @@ int main(int argc, const char *argv[])
|
|||
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
|
||||
!defined(TEST_SUITE_MEMORY_BUFFER_ALLOC)
|
||||
unsigned char alloc_buf[1000000];
|
||||
#endif
|
||||
if( mbedtls_platform_setup( &platform_ctx ) )
|
||||
{
|
||||
mbedtls_fprintf( stderr, "FATAL: Failed to initialize platform" );
|
||||
return -1;
|
||||
}
|
||||
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
|
||||
!defined(TEST_SUITE_MEMORY_BUFFER_ALLOC)
|
||||
mbedtls_memory_buffer_alloc_init( alloc_buf, sizeof(alloc_buf) );
|
||||
#endif
|
||||
|
||||
|
@ -293,6 +301,7 @@ int main(int argc, const char *argv[])
|
|||
if( pointer != NULL )
|
||||
{
|
||||
mbedtls_fprintf( stderr, "all-bits-zero is not a NULL pointer\n" );
|
||||
mbedtls_platform_teardown( &platform_ctx );
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
|
@ -302,6 +311,7 @@ int main(int argc, const char *argv[])
|
|||
if( run_test_snprintf() != 0 )
|
||||
{
|
||||
mbedtls_fprintf( stderr, "the snprintf implementation is broken\n" );
|
||||
mbedtls_platform_teardown( &platform_ctx );
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
|
@ -318,6 +328,7 @@ int main(int argc, const char *argv[])
|
|||
strcmp(next_arg, "-h" ) == 0 )
|
||||
{
|
||||
mbedtls_fprintf( stdout, USAGE );
|
||||
mbedtls_platform_teardown( &platform_ctx );
|
||||
mbedtls_exit( EXIT_SUCCESS );
|
||||
}
|
||||
else
|
||||
|
@ -357,6 +368,7 @@ int main(int argc, const char *argv[])
|
|||
{
|
||||
mbedtls_fprintf( stderr, "Failed to open test file: %s\n",
|
||||
test_filename );
|
||||
mbedtls_platform_teardown( &platform_ctx );
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
|
@ -366,6 +378,7 @@ int main(int argc, const char *argv[])
|
|||
{
|
||||
mbedtls_fprintf( stderr,
|
||||
"FATAL: Dep count larger than zero at start of loop\n" );
|
||||
mbedtls_platform_teardown( &platform_ctx );
|
||||
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
|
||||
}
|
||||
unmet_dep_count = 0;
|
||||
|
@ -402,6 +415,7 @@ int main(int argc, const char *argv[])
|
|||
if( unmet_dependencies[ unmet_dep_count ] == NULL )
|
||||
{
|
||||
mbedtls_fprintf( stderr, "FATAL: Out of memory\n" );
|
||||
mbedtls_platform_teardown( &platform_ctx );
|
||||
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
|
||||
}
|
||||
unmet_dep_count++;
|
||||
|
@ -428,6 +442,7 @@ int main(int argc, const char *argv[])
|
|||
if( stdout_fd == -1 )
|
||||
{
|
||||
/* Redirection has failed with no stdout so exit */
|
||||
mbedtls_platform_teardown( &platform_ctx );
|
||||
exit( 1 );
|
||||
}
|
||||
}
|
||||
|
@ -439,6 +454,7 @@ int main(int argc, const char *argv[])
|
|||
if( !option_verbose && restore_output( &stdout, stdout_fd ) )
|
||||
{
|
||||
/* Redirection has failed with no stdout so exit */
|
||||
mbedtls_platform_teardown( &platform_ctx );
|
||||
exit( 1 );
|
||||
}
|
||||
#endif /* __unix__ || __APPLE__ __MACH__ */
|
||||
|
@ -490,6 +506,7 @@ int main(int argc, const char *argv[])
|
|||
{
|
||||
mbedtls_fprintf( stderr, "FAILED: FATAL PARSE ERROR\n" );
|
||||
fclose( file );
|
||||
mbedtls_platform_teardown( &platform_ctx );
|
||||
mbedtls_exit( 2 );
|
||||
}
|
||||
else
|
||||
|
@ -501,6 +518,7 @@ int main(int argc, const char *argv[])
|
|||
{
|
||||
mbedtls_fprintf( stderr, "Should be empty %d\n",
|
||||
(int) strlen( buf ) );
|
||||
mbedtls_platform_teardown( &platform_ctx );
|
||||
return( 1 );
|
||||
}
|
||||
}
|
||||
|
@ -533,5 +551,6 @@ int main(int argc, const char *argv[])
|
|||
close_output( stdout );
|
||||
#endif /* __unix__ || __APPLE__ __MACH__ */
|
||||
|
||||
mbedtls_platform_teardown( &platform_ctx );
|
||||
return( total_errors != 0 );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue