mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-12-23 17:55:37 +00:00
Replace old template and code generator with new ones. Keep names
This commit is contained in:
parent
975d97eb8b
commit
191e904bb2
|
@ -316,12 +316,23 @@ static int convert_params( size_t cnt , char ** params , int * int_params_store
|
|||
/**
|
||||
* \brief Tests snprintf implementation with test input.
|
||||
*
|
||||
* \note
|
||||
* At high optimization levels (e.g. gcc -O3), this function may be
|
||||
* inlined in run_test_snprintf. This can trigger a spurious warning about
|
||||
* potential misuse of snprintf from gcc -Wformat-truncation (observed with
|
||||
* gcc 7.2). This warning makes tests in run_test_snprintf redundant on gcc
|
||||
* only. They are still valid for other compilers. Avoid this warning by
|
||||
* forbidding inlining of this function by gcc.
|
||||
*
|
||||
* \param n Buffer test length.
|
||||
* \param ref_buf Expected buffer.
|
||||
* \param ref_ret Expected snprintf return value.
|
||||
*
|
||||
* \return 0 for success else 1
|
||||
*/
|
||||
#if defined(__GNUC__)
|
||||
__attribute__((__noinline__))
|
||||
#endif
|
||||
static int test_snprintf( size_t n, const char ref_buf[10], int ref_ret )
|
||||
{
|
||||
int ret;
|
||||
|
@ -417,7 +428,7 @@ int execute_tests( int argc , const char ** argv )
|
|||
if( run_test_snprintf() != 0 )
|
||||
{
|
||||
mbedtls_fprintf( stderr, "the snprintf implementation is broken\n" );
|
||||
return( 0 );
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
while( arg_index < argc )
|
||||
|
|
|
@ -1,571 +1,184 @@
|
|||
#line 1 "main_test.function"
|
||||
SUITE_PRE_DEP
|
||||
#define TEST_SUITE_ACTIVE
|
||||
#line 2 "suites/mbed_test.function"
|
||||
/*
|
||||
* *** THIS FILE HAS BEEN MACHINE GENERATED ***
|
||||
*
|
||||
* This file has been machine generated using the script:
|
||||
* {generator_script}
|
||||
*
|
||||
* Test file : {test_file}
|
||||
*
|
||||
* The following files were used to create this file.
|
||||
*
|
||||
* Main code file : {test_main_file}
|
||||
* Platform code file : {test_platform_file}
|
||||
* Helper file : {test_common_helper_file}
|
||||
* Test suite file : {test_case_file}
|
||||
* Test suite data : {test_case_data_file}
|
||||
*
|
||||
*
|
||||
* This file is part of mbed TLS (https://tls.mbed.org)
|
||||
*/
|
||||
|
||||
int verify_string( char **str )
|
||||
{
|
||||
if( (*str)[0] != '"' ||
|
||||
(*str)[strlen( *str ) - 1] != '"' )
|
||||
{
|
||||
mbedtls_fprintf( stderr,
|
||||
"Expected string (with \"\") for parameter and got: %s\n", *str );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
(*str)++;
|
||||
(*str)[strlen( *str ) - 1] = '\0';
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int verify_int( char *str, int *value )
|
||||
{
|
||||
size_t i;
|
||||
int minus = 0;
|
||||
int digits = 1;
|
||||
int hex = 0;
|
||||
|
||||
for( i = 0; i < strlen( str ); i++ )
|
||||
{
|
||||
if( i == 0 && str[i] == '-' )
|
||||
{
|
||||
minus = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if( ( ( minus && i == 2 ) || ( !minus && i == 1 ) ) &&
|
||||
str[i - 1] == '0' && str[i] == 'x' )
|
||||
{
|
||||
hex = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if( ! ( ( str[i] >= '0' && str[i] <= '9' ) ||
|
||||
( hex && ( ( str[i] >= 'a' && str[i] <= 'f' ) ||
|
||||
( str[i] >= 'A' && str[i] <= 'F' ) ) ) ) )
|
||||
{
|
||||
digits = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( digits )
|
||||
{
|
||||
if( hex )
|
||||
*value = strtol( str, NULL, 16 );
|
||||
else
|
||||
*value = strtol( str, NULL, 10 );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
MAPPING_CODE
|
||||
|
||||
mbedtls_fprintf( stderr,
|
||||
"Expected integer for parameter and got: %s\n", str );
|
||||
return( KEY_VALUE_MAPPING_NOT_FOUND );
|
||||
}
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include <mbedtls/config.h>
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Test Case code */
|
||||
/* Common helper code */
|
||||
|
||||
FUNCTION_CODE
|
||||
SUITE_POST_DEP
|
||||
{test_common_helpers}
|
||||
|
||||
#line !LINE_NO! "main_test.function"
|
||||
#line {line_no} "suites/mbed_test.function"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Test Suite Code */
|
||||
|
||||
|
||||
#define TEST_SUITE_ACTIVE
|
||||
|
||||
{function_headers}
|
||||
|
||||
{functions_code}
|
||||
|
||||
#line {line_no} "suites/mbed_test.function"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Test dispatch code */
|
||||
|
||||
int dep_check( char *str )
|
||||
{
|
||||
if( str == NULL )
|
||||
return( 1 );
|
||||
|
||||
DEP_CHECK_CODE
|
||||
#line !LINE_NO! "main_test.function"
|
||||
/**
|
||||
* \brief Evaluates an expression/macro into its literal integer value.
|
||||
* For optimizing space for embedded targets each expression/macro
|
||||
* is identified by a unique identifier instead of string literals.
|
||||
* Identifiers and evaluation code is generated by script:
|
||||
* {generator_script}
|
||||
*
|
||||
* \param exp_id Expression identifier.
|
||||
* \param out_value Pointer to int to hold the integer.
|
||||
*
|
||||
* \return 0 if exp_id is found. 1 otherwise.
|
||||
*/
|
||||
int get_expression( int32_t exp_id, int32_t * out_value )
|
||||
{{
|
||||
{expression_code}
|
||||
#line {line_no} "suites/mbed_test.function"
|
||||
{{
|
||||
return( KEY_VALUE_MAPPING_NOT_FOUND );
|
||||
}}
|
||||
return( KEY_VALUE_MAPPING_FOUND );
|
||||
}}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Checks if the dependency i.e. the compile flag is set.
|
||||
* For optimizing space for embedded targets each dependency
|
||||
* is identified by a unique identifier instead of string literals.
|
||||
* Identifiers and check code is generated by script:
|
||||
* {generator_script}
|
||||
*
|
||||
* \param exp_id Dependency identifier.
|
||||
*
|
||||
* \return DEPENDENCY_SUPPORTED if set else DEPENDENCY_NOT_SUPPORTED
|
||||
*/
|
||||
int dep_check( int dep_id )
|
||||
{{
|
||||
{dep_check_code}
|
||||
#line {line_no} "suites/mbed_test.function"
|
||||
{{
|
||||
return( DEPENDENCY_NOT_SUPPORTED );
|
||||
}
|
||||
}}
|
||||
}}
|
||||
|
||||
int dispatch_test(int cnt, char *params[50])
|
||||
{
|
||||
int ret;
|
||||
((void) cnt);
|
||||
((void) params);
|
||||
|
||||
#if defined(TEST_SUITE_ACTIVE)
|
||||
ret = DISPATCH_TEST_SUCCESS;
|
||||
/**
|
||||
* \brief Function pointer type for test function wrappers.
|
||||
*
|
||||
*
|
||||
* \param void ** Pointer to void pointers. Represents an array of test
|
||||
* function parameters.
|
||||
*
|
||||
* \return void
|
||||
*/
|
||||
typedef void (*TestWrapper_t)( void ** );
|
||||
|
||||
// Cast to void to avoid compiler warnings
|
||||
(void)ret;
|
||||
|
||||
DISPATCH_FUNCTION
|
||||
{
|
||||
#line !LINE_NO! "main_test.function"
|
||||
mbedtls_fprintf( stdout,
|
||||
"FAILED\nSkipping unknown test function '%s'\n",
|
||||
params[0] );
|
||||
fflush( stdout );
|
||||
ret = DISPATCH_TEST_FN_NOT_FOUND;
|
||||
}
|
||||
#else
|
||||
ret = DISPATCH_UNSUPPORTED_SUITE;
|
||||
#endif
|
||||
/**
|
||||
* \brief Table of test function wrappers. Used by dispatch_test().
|
||||
* This table is populated by script:
|
||||
* {generator_script}
|
||||
*
|
||||
*/
|
||||
TestWrapper_t test_funcs[] =
|
||||
{{
|
||||
{dispatch_code}
|
||||
#line {line_no} "suites/mbed_test.function"
|
||||
}};
|
||||
|
||||
|
||||
/**
|
||||
* \brief Dispatches test functions based on function index.
|
||||
*
|
||||
* \param exp_id Test function index.
|
||||
*
|
||||
* \return DISPATCH_TEST_SUCCESS if found
|
||||
* DISPATCH_TEST_FN_NOT_FOUND if not found
|
||||
* DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
|
||||
*/
|
||||
int dispatch_test( int func_idx, void ** params )
|
||||
{{
|
||||
int ret = DISPATCH_TEST_SUCCESS;
|
||||
TestWrapper_t fp = NULL;
|
||||
|
||||
if ( func_idx < (int)( sizeof(test_funcs)/sizeof( TestWrapper_t ) ) )
|
||||
{{
|
||||
fp = test_funcs[func_idx];
|
||||
if ( fp )
|
||||
fp( params );
|
||||
else
|
||||
ret = ( DISPATCH_UNSUPPORTED_SUITE );
|
||||
}}
|
||||
else
|
||||
{{
|
||||
ret = ( DISPATCH_TEST_FN_NOT_FOUND );
|
||||
}}
|
||||
|
||||
return( ret );
|
||||
}
|
||||
}}
|
||||
|
||||
|
||||
{platform_code}
|
||||
|
||||
#line {line_no} "suites/mbed_test.function"
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Main Test code */
|
||||
|
||||
#line !LINE_NO! "main_test.function"
|
||||
|
||||
#define USAGE \
|
||||
"Usage: %s [OPTIONS] files...\n\n" \
|
||||
" Command line arguments:\n" \
|
||||
" files... One or more test data file. If no file is specified\n" \
|
||||
" the followimg default test case is used:\n" \
|
||||
" %s\n\n" \
|
||||
" Options:\n" \
|
||||
" -v | --verbose Display full information about each test\n" \
|
||||
" -h | --help Display this information\n\n", \
|
||||
argv[0], \
|
||||
"TESTCASE_FILENAME"
|
||||
|
||||
|
||||
/** Retrieve one input line into buf, which must have room for len
|
||||
* bytes. The trailing line break (if any) is stripped from the result.
|
||||
* Lines beginning with the character '#' are skipped. Lines that are
|
||||
* more than len-1 bytes long including the trailing line break are
|
||||
* truncated; note that the following bytes remain in the input stream.
|
||||
/**
|
||||
* \brief Program main. Invokes platform specific execute_tests().
|
||||
*
|
||||
* \return 0 on success, -1 on error or end of file
|
||||
* \param argc Command line arguments count.
|
||||
* \param argv Array of command line arguments.
|
||||
*
|
||||
* \return Exit code.
|
||||
*/
|
||||
int get_line( FILE *f, char *buf, size_t len )
|
||||
{
|
||||
char *ret;
|
||||
|
||||
do
|
||||
{
|
||||
ret = fgets( buf, len, f );
|
||||
if( ret == NULL )
|
||||
return( -1 );
|
||||
}
|
||||
while( buf[0] == '#' );
|
||||
|
||||
ret = buf + strlen( buf );
|
||||
if( ret-- > buf && *ret == '\n' )
|
||||
*ret = '\0';
|
||||
if( ret-- > buf && *ret == '\r' )
|
||||
*ret = '\0';
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int parse_arguments( char *buf, size_t len, char *params[50] )
|
||||
{
|
||||
int cnt = 0, i;
|
||||
char *cur = buf;
|
||||
char *p = buf, *q;
|
||||
|
||||
params[cnt++] = cur;
|
||||
|
||||
while( *p != '\0' && p < buf + len )
|
||||
{
|
||||
if( *p == '\\' )
|
||||
{
|
||||
p++;
|
||||
p++;
|
||||
continue;
|
||||
}
|
||||
if( *p == ':' )
|
||||
{
|
||||
if( p + 1 < buf + len )
|
||||
{
|
||||
cur = p + 1;
|
||||
params[cnt++] = cur;
|
||||
}
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
p++;
|
||||
}
|
||||
|
||||
/* Replace newlines, question marks and colons in strings */
|
||||
for( i = 0; i < cnt; i++ )
|
||||
{
|
||||
p = params[i];
|
||||
q = params[i];
|
||||
|
||||
while( *p != '\0' )
|
||||
{
|
||||
if( *p == '\\' && *(p + 1) == 'n' )
|
||||
{
|
||||
p += 2;
|
||||
*(q++) = '\n';
|
||||
}
|
||||
else if( *p == '\\' && *(p + 1) == ':' )
|
||||
{
|
||||
p += 2;
|
||||
*(q++) = ':';
|
||||
}
|
||||
else if( *p == '\\' && *(p + 1) == '?' )
|
||||
{
|
||||
p += 2;
|
||||
*(q++) = '?';
|
||||
}
|
||||
else
|
||||
*(q++) = *(p++);
|
||||
}
|
||||
*q = '\0';
|
||||
}
|
||||
|
||||
return( cnt );
|
||||
}
|
||||
|
||||
#if defined(__GNUC__)
|
||||
/* At high optimization levels (e.g. gcc -O3), this function may be
|
||||
* inlined in run_test_snprintf. This can trigger a spurious warning about
|
||||
* potential misuse of snprintf from gcc -Wformat-truncation (observed with
|
||||
* gcc 7.2). This warning makes tests in run_test_snprintf redundant on gcc
|
||||
* only. They are still valid for other compilers. Avoid this warning by
|
||||
* forbidding inlining of this function by gcc. */
|
||||
__attribute__((__noinline__))
|
||||
#endif
|
||||
static int test_snprintf( size_t n, const char ref_buf[10], int ref_ret )
|
||||
{
|
||||
int ret;
|
||||
char buf[10] = "xxxxxxxxx";
|
||||
const char ref[10] = "xxxxxxxxx";
|
||||
|
||||
if( n >= sizeof( buf ) )
|
||||
return( -1 );
|
||||
ret = mbedtls_snprintf( buf, n, "%s", "123" );
|
||||
if( ret < 0 || (size_t) ret >= n )
|
||||
ret = -1;
|
||||
|
||||
if( strncmp( ref_buf, buf, sizeof( buf ) ) != 0 ||
|
||||
ref_ret != ret ||
|
||||
memcmp( buf + n, ref + n, sizeof( buf ) - n ) != 0 )
|
||||
{
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
static int run_test_snprintf( void )
|
||||
{
|
||||
return( test_snprintf( 0, "xxxxxxxxx", -1 ) != 0 ||
|
||||
test_snprintf( 1, "", -1 ) != 0 ||
|
||||
test_snprintf( 2, "1", -1 ) != 0 ||
|
||||
test_snprintf( 3, "12", -1 ) != 0 ||
|
||||
test_snprintf( 4, "123", 3 ) != 0 ||
|
||||
test_snprintf( 5, "123", 3 ) != 0 );
|
||||
}
|
||||
|
||||
int main( int argc, const char *argv[] )
|
||||
{
|
||||
/* Local Configurations and options */
|
||||
const char *default_filename = "TESTCASE_FILENAME";
|
||||
const char *test_filename = NULL;
|
||||
const char **test_files = NULL;
|
||||
int testfile_count = 0;
|
||||
int option_verbose = 0;
|
||||
|
||||
/* Other Local variables */
|
||||
int arg_index = 1;
|
||||
const char *next_arg;
|
||||
int testfile_index, ret, i, cnt;
|
||||
int total_errors = 0, total_tests = 0, total_skipped = 0;
|
||||
FILE *file;
|
||||
char buf[5000];
|
||||
char *params[50];
|
||||
void *pointer;
|
||||
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
||||
int stdout_fd = -1;
|
||||
#endif /* __unix__ || __APPLE__ __MACH__ */
|
||||
|
||||
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
|
||||
!defined(TEST_SUITE_MEMORY_BUFFER_ALLOC)
|
||||
unsigned char alloc_buf[1000000];
|
||||
#endif
|
||||
/* Platform setup should be called in the beginning */
|
||||
ret = platform_setup();
|
||||
{{
|
||||
int ret = platform_setup();
|
||||
if( ret != 0 )
|
||||
{
|
||||
{{
|
||||
mbedtls_fprintf( stderr,
|
||||
"FATAL: Failed to initialize platform - error %d\n",
|
||||
ret );
|
||||
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
|
||||
|
||||
/*
|
||||
* The C standard doesn't guarantee that all-bits-0 is the representation
|
||||
* of a NULL pointer. We do however use that in our code for initializing
|
||||
* structures, which should work on every modern platform. Let's be sure.
|
||||
*/
|
||||
memset( &pointer, 0, sizeof( void * ) );
|
||||
if( pointer != NULL )
|
||||
{
|
||||
mbedtls_fprintf( stderr, "all-bits-zero is not a NULL pointer\n" );
|
||||
}}
|
||||
ret = execute_tests( argc, argv );
|
||||
platform_teardown();
|
||||
return( 1 );
|
||||
}
|
||||
return( ret );
|
||||
}}
|
||||
|
||||
/*
|
||||
* Make sure we have a snprintf that correctly zero-terminates
|
||||
*/
|
||||
if( run_test_snprintf() != 0 )
|
||||
{
|
||||
mbedtls_fprintf( stderr, "the snprintf implementation is broken\n" );
|
||||
platform_teardown();
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
while( arg_index < argc)
|
||||
{
|
||||
next_arg = argv[ arg_index ];
|
||||
|
||||
if( strcmp(next_arg, "--verbose" ) == 0 ||
|
||||
strcmp(next_arg, "-v" ) == 0 )
|
||||
{
|
||||
option_verbose = 1;
|
||||
}
|
||||
else if( strcmp(next_arg, "--help" ) == 0 ||
|
||||
strcmp(next_arg, "-h" ) == 0 )
|
||||
{
|
||||
mbedtls_fprintf( stdout, USAGE );
|
||||
platform_teardown();
|
||||
mbedtls_exit( EXIT_SUCCESS );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Not an option, therefore treat all further arguments as the file
|
||||
* list.
|
||||
*/
|
||||
test_files = &argv[ arg_index ];
|
||||
testfile_count = argc - arg_index;
|
||||
}
|
||||
|
||||
arg_index++;
|
||||
}
|
||||
|
||||
/* If no files were specified, assume a default */
|
||||
if ( test_files == NULL || testfile_count == 0 )
|
||||
{
|
||||
test_files = &default_filename;
|
||||
testfile_count = 1;
|
||||
}
|
||||
|
||||
/* Initialize the struct that holds information about the last test */
|
||||
memset( &test_info, 0, sizeof( test_info ) );
|
||||
|
||||
/* Now begin to execute the tests in the testfiles */
|
||||
for ( testfile_index = 0;
|
||||
testfile_index < testfile_count;
|
||||
testfile_index++ )
|
||||
{
|
||||
int unmet_dep_count = 0;
|
||||
char *unmet_dependencies[20];
|
||||
|
||||
test_filename = test_files[ testfile_index ];
|
||||
|
||||
file = fopen( test_filename, "r" );
|
||||
if( file == NULL )
|
||||
{
|
||||
mbedtls_fprintf( stderr, "Failed to open test file: %s\n",
|
||||
test_filename );
|
||||
platform_teardown();
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
while( !feof( file ) )
|
||||
{
|
||||
if( unmet_dep_count > 0 )
|
||||
{
|
||||
mbedtls_fprintf( stderr,
|
||||
"FATAL: Dep count larger than zero at start of loop\n" );
|
||||
platform_teardown();
|
||||
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
|
||||
}
|
||||
unmet_dep_count = 0;
|
||||
|
||||
if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
|
||||
break;
|
||||
mbedtls_fprintf( stdout, "%s%.66s", test_info.failed ? "\n" : "", buf );
|
||||
mbedtls_fprintf( stdout, " " );
|
||||
for( i = strlen( buf ) + 1; i < 67; i++ )
|
||||
mbedtls_fprintf( stdout, "." );
|
||||
mbedtls_fprintf( stdout, " " );
|
||||
fflush( stdout );
|
||||
|
||||
total_tests++;
|
||||
|
||||
if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
|
||||
break;
|
||||
cnt = parse_arguments( buf, strlen(buf), params );
|
||||
|
||||
if( strcmp( params[0], "depends_on" ) == 0 )
|
||||
{
|
||||
for( i = 1; i < cnt; i++ )
|
||||
{
|
||||
if( dep_check( params[i] ) != DEPENDENCY_SUPPORTED )
|
||||
{
|
||||
if( 0 == option_verbose )
|
||||
{
|
||||
/* Only one count is needed if not verbose */
|
||||
unmet_dep_count++;
|
||||
break;
|
||||
}
|
||||
|
||||
unmet_dependencies[ unmet_dep_count ] = strdup(params[i]);
|
||||
if( unmet_dependencies[ unmet_dep_count ] == NULL )
|
||||
{
|
||||
mbedtls_fprintf( stderr, "FATAL: Out of memory\n" );
|
||||
platform_teardown();
|
||||
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
|
||||
}
|
||||
unmet_dep_count++;
|
||||
}
|
||||
}
|
||||
|
||||
if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
|
||||
break;
|
||||
cnt = parse_arguments( buf, strlen(buf), params );
|
||||
}
|
||||
|
||||
// If there are no unmet dependencies execute the test
|
||||
if( unmet_dep_count == 0 )
|
||||
{
|
||||
test_info.failed = 0;
|
||||
|
||||
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
||||
/* Suppress all output from the library unless we're verbose
|
||||
* mode
|
||||
*/
|
||||
if( !option_verbose )
|
||||
{
|
||||
stdout_fd = redirect_output( &stdout, "/dev/null" );
|
||||
if( stdout_fd == -1 )
|
||||
{
|
||||
platform_teardown();
|
||||
/* Redirection has failed with no stdout so exit */
|
||||
exit( 1 );
|
||||
}
|
||||
}
|
||||
#endif /* __unix__ || __APPLE__ __MACH__ */
|
||||
|
||||
ret = dispatch_test( cnt, params );
|
||||
|
||||
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
||||
if( !option_verbose && restore_output( &stdout, stdout_fd ) )
|
||||
{
|
||||
/* Redirection has failed with no stdout so exit */
|
||||
platform_teardown();
|
||||
exit( 1 );
|
||||
}
|
||||
#endif /* __unix__ || __APPLE__ __MACH__ */
|
||||
|
||||
}
|
||||
|
||||
if( unmet_dep_count > 0 || ret == DISPATCH_UNSUPPORTED_SUITE )
|
||||
{
|
||||
total_skipped++;
|
||||
mbedtls_fprintf( stdout, "----" );
|
||||
|
||||
if( 1 == option_verbose && ret == DISPATCH_UNSUPPORTED_SUITE )
|
||||
{
|
||||
mbedtls_fprintf( stdout, "\n Test Suite not enabled" );
|
||||
}
|
||||
|
||||
if( 1 == option_verbose && unmet_dep_count > 0 )
|
||||
{
|
||||
mbedtls_fprintf( stdout, "\n Unmet dependencies: " );
|
||||
for( i = 0; i < unmet_dep_count; i++ )
|
||||
{
|
||||
mbedtls_fprintf(stdout, "%s ",
|
||||
unmet_dependencies[i]);
|
||||
free(unmet_dependencies[i]);
|
||||
}
|
||||
}
|
||||
mbedtls_fprintf( stdout, "\n" );
|
||||
fflush( stdout );
|
||||
|
||||
unmet_dep_count = 0;
|
||||
}
|
||||
else if( ret == DISPATCH_TEST_SUCCESS )
|
||||
{
|
||||
if( test_info.failed == 0 )
|
||||
{
|
||||
mbedtls_fprintf( stdout, "PASS\n" );
|
||||
}
|
||||
else
|
||||
{
|
||||
total_errors++;
|
||||
mbedtls_fprintf( stdout, "FAILED\n" );
|
||||
mbedtls_fprintf( stdout, " %s\n at line %d, %s\n",
|
||||
test_info.test, test_info.line_no,
|
||||
test_info.filename );
|
||||
}
|
||||
fflush( stdout );
|
||||
}
|
||||
else if( ret == DISPATCH_INVALID_TEST_DATA )
|
||||
{
|
||||
mbedtls_fprintf( stderr, "FAILED: FATAL PARSE ERROR\n" );
|
||||
fclose( file );
|
||||
platform_teardown();
|
||||
mbedtls_exit( 2 );
|
||||
}
|
||||
else
|
||||
total_errors++;
|
||||
|
||||
if( ( ret = get_line( file, buf, sizeof( buf ) ) ) != 0 )
|
||||
break;
|
||||
if( strlen( buf ) != 0 )
|
||||
{
|
||||
mbedtls_fprintf( stderr, "Should be empty %d\n",
|
||||
(int) strlen( buf ) );
|
||||
platform_teardown();
|
||||
return( 1 );
|
||||
}
|
||||
}
|
||||
fclose( file );
|
||||
|
||||
/* In case we encounter early end of file */
|
||||
for( i = 0; i < unmet_dep_count; i++ )
|
||||
free( unmet_dependencies[i] );
|
||||
}
|
||||
|
||||
mbedtls_fprintf( stdout, "\n----------------------------------------------------------------------------\n\n");
|
||||
if( total_errors == 0 )
|
||||
mbedtls_fprintf( stdout, "PASSED" );
|
||||
else
|
||||
mbedtls_fprintf( stdout, "FAILED" );
|
||||
|
||||
mbedtls_fprintf( stdout, " (%d / %d tests (%d skipped))\n",
|
||||
total_tests - total_errors, total_tests, total_skipped );
|
||||
|
||||
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
|
||||
!defined(TEST_SUITE_MEMORY_BUFFER_ALLOC)
|
||||
#if defined(MBEDTLS_MEMORY_DEBUG)
|
||||
mbedtls_memory_buffer_alloc_status();
|
||||
#endif
|
||||
mbedtls_memory_buffer_alloc_free();
|
||||
#endif
|
||||
|
||||
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
||||
if( stdout_fd != -1 )
|
||||
close_output( stdout );
|
||||
#endif /* __unix__ || __APPLE__ __MACH__ */
|
||||
|
||||
platform_teardown();
|
||||
return( total_errors != 0 );
|
||||
}
|
||||
|
|
|
@ -1,174 +0,0 @@
|
|||
#line 2 "suites/mbed_test.function"
|
||||
/*
|
||||
* *** THIS FILE HAS BEEN MACHINE GENERATED ***
|
||||
*
|
||||
* This file has been machine generated using the script:
|
||||
* {generator_script}
|
||||
*
|
||||
* Test file : {test_file}
|
||||
*
|
||||
* The following files were used to create this file.
|
||||
*
|
||||
* Main code file : {test_main_file}
|
||||
* Platform code file : {test_platform_file}
|
||||
* Helper file : {test_common_helper_file}
|
||||
* Test suite file : {test_case_file}
|
||||
* Test suite data : {test_case_data_file}
|
||||
*
|
||||
*
|
||||
* This file is part of mbed TLS (https://tls.mbed.org)
|
||||
*/
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include <mbedtls/config.h>
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Common helper code */
|
||||
|
||||
{test_common_helpers}
|
||||
|
||||
#line {line_no} "suites/mbed_test.function"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Test Suite Code */
|
||||
|
||||
|
||||
#define TEST_SUITE_ACTIVE
|
||||
|
||||
{function_headers}
|
||||
|
||||
{functions_code}
|
||||
|
||||
#line {line_no} "suites/mbed_test.function"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Test dispatch code */
|
||||
|
||||
|
||||
/**
|
||||
* \brief Evaluates an expression/macro into its literal integer value.
|
||||
* For optimizing space for embedded targets each expression/macro
|
||||
* is identified by a unique identifier instead of string literals.
|
||||
* Identifiers and evaluation code is generated by script:
|
||||
* {generator_script}
|
||||
*
|
||||
* \param exp_id Expression identifier.
|
||||
* \param out_value Pointer to int to hold the integer.
|
||||
*
|
||||
* \return 0 if exp_id is found. 1 otherwise.
|
||||
*/
|
||||
int get_expression( int32_t exp_id, int32_t * out_value )
|
||||
{{
|
||||
{expression_code}
|
||||
#line {line_no} "suites/mbed_test.function"
|
||||
{{
|
||||
return( KEY_VALUE_MAPPING_NOT_FOUND );
|
||||
}}
|
||||
return( KEY_VALUE_MAPPING_FOUND );
|
||||
}}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Checks if the dependency i.e. the compile flag is set.
|
||||
* For optimizing space for embedded targets each dependency
|
||||
* is identified by a unique identifier instead of string literals.
|
||||
* Identifiers and check code is generated by script:
|
||||
* {generator_script}
|
||||
*
|
||||
* \param exp_id Dependency identifier.
|
||||
*
|
||||
* \return DEPENDENCY_SUPPORTED if set else DEPENDENCY_NOT_SUPPORTED
|
||||
*/
|
||||
int dep_check( int dep_id )
|
||||
{{
|
||||
{dep_check_code}
|
||||
#line {line_no} "suites/mbed_test.function"
|
||||
{{
|
||||
return( DEPENDENCY_NOT_SUPPORTED );
|
||||
}}
|
||||
}}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Function pointer type for test function wrappers.
|
||||
*
|
||||
*
|
||||
* \param void ** Pointer to void pointers. Represents an array of test
|
||||
* function parameters.
|
||||
*
|
||||
* \return void
|
||||
*/
|
||||
typedef void (*TestWrapper_t)( void ** );
|
||||
|
||||
|
||||
/**
|
||||
* \brief Table of test function wrappers. Used by dispatch_test().
|
||||
* This table is populated by script:
|
||||
* {generator_script}
|
||||
*
|
||||
*/
|
||||
TestWrapper_t test_funcs[] =
|
||||
{{
|
||||
{dispatch_code}
|
||||
#line {line_no} "suites/mbed_test.function"
|
||||
}};
|
||||
|
||||
|
||||
/**
|
||||
* \brief Dispatches test functions based on function index.
|
||||
*
|
||||
* \param exp_id Test function index.
|
||||
*
|
||||
* \return DISPATCH_TEST_SUCCESS if found
|
||||
* DISPATCH_TEST_FN_NOT_FOUND if not found
|
||||
* DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
|
||||
*/
|
||||
int dispatch_test( int func_idx, void ** params )
|
||||
{{
|
||||
int ret = DISPATCH_TEST_SUCCESS;
|
||||
TestWrapper_t fp = NULL;
|
||||
|
||||
if ( func_idx < (int)( sizeof(test_funcs)/sizeof( TestWrapper_t ) ) )
|
||||
{{
|
||||
fp = test_funcs[func_idx];
|
||||
if ( fp )
|
||||
fp( params );
|
||||
else
|
||||
ret = ( DISPATCH_UNSUPPORTED_SUITE );
|
||||
}}
|
||||
else
|
||||
{{
|
||||
ret = ( DISPATCH_TEST_FN_NOT_FOUND );
|
||||
}}
|
||||
|
||||
return( ret );
|
||||
}}
|
||||
|
||||
|
||||
{platform_code}
|
||||
|
||||
#line {line_no} "suites/mbed_test.function"
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Main Test code */
|
||||
|
||||
|
||||
/**
|
||||
* \brief Program main. Invokes platform specific execute_tests().
|
||||
*
|
||||
* \param argc Command line arguments count.
|
||||
* \param argv Array of command line arguments.
|
||||
*
|
||||
* \return Exit code.
|
||||
*/
|
||||
int main( int argc, const char *argv[] )
|
||||
{{
|
||||
return execute_tests( argc, argv );
|
||||
}}
|
||||
|
Loading…
Reference in a new issue