2016-04-25 20:34:49 +00:00
|
|
|
#line 1 "main_test.function"
|
2013-09-15 15:05:21 +00:00
|
|
|
SUITE_PRE_DEP
|
|
|
|
#define TEST_SUITE_ACTIVE
|
|
|
|
|
2013-08-16 11:31:10 +00:00
|
|
|
int verify_string( char **str )
|
|
|
|
{
|
|
|
|
if( (*str)[0] != '"' ||
|
|
|
|
(*str)[strlen( *str ) - 1] != '"' )
|
|
|
|
{
|
2016-09-30 12:11:29 +00:00
|
|
|
mbedtls_fprintf( stderr,
|
|
|
|
"Expected string (with \"\") for parameter and got: %s\n", *str );
|
2013-08-16 11:31:10 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-02-01 10:54:28 +00:00
|
|
|
if( ! ( ( str[i] >= '0' && str[i] <= '9' ) ||
|
|
|
|
( hex && ( ( str[i] >= 'a' && str[i] <= 'f' ) ||
|
|
|
|
( str[i] >= 'A' && str[i] <= 'F' ) ) ) ) )
|
2013-08-16 11:31:10 +00:00
|
|
|
{
|
|
|
|
digits = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( digits )
|
|
|
|
{
|
|
|
|
if( hex )
|
|
|
|
*value = strtol( str, NULL, 16 );
|
|
|
|
else
|
|
|
|
*value = strtol( str, NULL, 10 );
|
|
|
|
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
MAPPING_CODE
|
|
|
|
|
2016-09-30 12:11:29 +00:00
|
|
|
mbedtls_fprintf( stderr,
|
|
|
|
"Expected integer for parameter and got: %s\n", str );
|
2016-04-17 22:24:50 +00:00
|
|
|
return( KEY_VALUE_MAPPING_NOT_FOUND );
|
2013-08-16 11:31:10 +00:00
|
|
|
}
|
|
|
|
|
2016-02-15 23:27:28 +00:00
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
/* Test Case code */
|
|
|
|
|
2013-09-15 15:05:21 +00:00
|
|
|
FUNCTION_CODE
|
|
|
|
SUITE_POST_DEP
|
|
|
|
|
2016-04-25 20:34:49 +00:00
|
|
|
#line !LINE_NO! "main_test.function"
|
|
|
|
|
2016-02-15 23:27:28 +00:00
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
/* Test dispatch code */
|
|
|
|
|
2013-08-16 11:31:10 +00:00
|
|
|
int dep_check( char *str )
|
|
|
|
{
|
|
|
|
if( str == NULL )
|
|
|
|
return( 1 );
|
|
|
|
|
|
|
|
DEP_CHECK_CODE
|
2016-05-23 22:18:26 +00:00
|
|
|
#line !LINE_NO! "main_test.function"
|
2013-08-16 11:31:10 +00:00
|
|
|
|
2016-04-17 22:24:50 +00:00
|
|
|
return( DEPENDENCY_NOT_SUPPORTED );
|
2013-08-16 11:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int dispatch_test(int cnt, char *params[50])
|
|
|
|
{
|
|
|
|
int ret;
|
2013-08-20 10:06:33 +00:00
|
|
|
((void) cnt);
|
|
|
|
((void) params);
|
2013-08-16 11:31:10 +00:00
|
|
|
|
2013-08-20 10:06:33 +00:00
|
|
|
#if defined(TEST_SUITE_ACTIVE)
|
2016-04-17 22:24:50 +00:00
|
|
|
ret = DISPATCH_TEST_SUCCESS;
|
|
|
|
|
2016-05-23 22:18:26 +00:00
|
|
|
// Cast to void to avoid compiler warnings
|
|
|
|
(void)ret;
|
|
|
|
|
2013-08-16 11:31:10 +00:00
|
|
|
DISPATCH_FUNCTION
|
|
|
|
{
|
2016-05-23 22:18:26 +00:00
|
|
|
#line !LINE_NO! "main_test.function"
|
2016-04-17 22:24:50 +00:00
|
|
|
mbedtls_fprintf( stdout,
|
|
|
|
"FAILED\nSkipping unknown test function '%s'\n",
|
|
|
|
params[0] );
|
2013-08-16 11:31:10 +00:00
|
|
|
fflush( stdout );
|
2016-04-17 22:24:50 +00:00
|
|
|
ret = DISPATCH_TEST_FN_NOT_FOUND;
|
2013-08-16 11:31:10 +00:00
|
|
|
}
|
2013-08-20 10:06:33 +00:00
|
|
|
#else
|
2016-04-17 22:24:50 +00:00
|
|
|
ret = DISPATCH_UNSUPPORTED_SUITE;
|
2013-08-20 10:06:33 +00:00
|
|
|
#endif
|
2013-08-16 11:31:10 +00:00
|
|
|
return( ret );
|
|
|
|
}
|
|
|
|
|
2016-02-15 23:27:28 +00:00
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
/* Main Test code */
|
|
|
|
|
2016-04-25 20:34:49 +00:00
|
|
|
#line !LINE_NO! "main_test.function"
|
|
|
|
|
2016-04-17 22:24:50 +00:00
|
|
|
#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], \
|
2016-04-25 20:34:49 +00:00
|
|
|
"TESTCASE_FILENAME"
|
2016-04-17 22:24:50 +00:00
|
|
|
|
|
|
|
|
2017-09-29 16:00:25 +00:00
|
|
|
/** 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.
|
|
|
|
*
|
|
|
|
* \return 0 on success, -1 on error or end of file
|
|
|
|
*/
|
2013-08-16 11:31:10 +00:00
|
|
|
int get_line( FILE *f, char *buf, size_t len )
|
|
|
|
{
|
|
|
|
char *ret;
|
|
|
|
|
2017-09-29 16:00:25 +00:00
|
|
|
do
|
2017-09-29 13:45:12 +00:00
|
|
|
{
|
|
|
|
ret = fgets( buf, len, f );
|
|
|
|
if( ret == NULL )
|
|
|
|
return( -1 );
|
|
|
|
}
|
2017-09-29 16:00:25 +00:00
|
|
|
while( buf[0] == '#' );
|
|
|
|
|
|
|
|
ret = buf + strlen( buf );
|
|
|
|
if( ret-- > buf && *ret == '\n' )
|
|
|
|
*ret = '\0';
|
|
|
|
if( ret-- > buf && *ret == '\r' )
|
|
|
|
*ret = '\0';
|
2013-08-16 11:31:10 +00:00
|
|
|
|
|
|
|
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 == '\\' )
|
|
|
|
{
|
2014-01-22 15:01:17 +00:00
|
|
|
p++;
|
|
|
|
p++;
|
2013-08-16 11:31:10 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if( *p == ':' )
|
|
|
|
{
|
|
|
|
if( p + 1 < buf + len )
|
|
|
|
{
|
|
|
|
cur = p + 1;
|
|
|
|
params[cnt++] = cur;
|
|
|
|
}
|
|
|
|
*p = '\0';
|
|
|
|
}
|
|
|
|
|
2014-01-22 15:01:17 +00:00
|
|
|
p++;
|
2013-08-16 11:31:10 +00:00
|
|
|
}
|
|
|
|
|
2016-02-17 23:34:30 +00:00
|
|
|
/* Replace newlines, question marks and colons in strings */
|
2013-08-16 11:31:10 +00:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2018-05-01 09:17:48 +00:00
|
|
|
#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
|
2015-06-22 08:48:01 +00:00
|
|
|
static int test_snprintf( size_t n, const char ref_buf[10], int ref_ret )
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
char buf[10] = "xxxxxxxxx";
|
2015-06-26 09:24:32 +00:00
|
|
|
const char ref[10] = "xxxxxxxxx";
|
2015-06-22 08:48:01 +00:00
|
|
|
|
2018-05-01 09:17:48 +00:00
|
|
|
if( n >= sizeof( buf ) )
|
|
|
|
return( -1 );
|
2015-06-22 08:48:01 +00:00
|
|
|
ret = mbedtls_snprintf( buf, n, "%s", "123" );
|
|
|
|
if( ret < 0 || (size_t) ret >= n )
|
|
|
|
ret = -1;
|
|
|
|
|
2015-06-26 09:24:32 +00:00
|
|
|
if( strncmp( ref_buf, buf, sizeof( buf ) ) != 0 ||
|
|
|
|
ref_ret != ret ||
|
|
|
|
memcmp( buf + n, ref + n, sizeof( buf ) - n ) != 0 )
|
2015-06-22 08:48:01 +00:00
|
|
|
{
|
|
|
|
return( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
static int run_test_snprintf( void )
|
|
|
|
{
|
|
|
|
return( test_snprintf( 0, "xxxxxxxxx", -1 ) != 0 ||
|
2015-06-26 09:24:32 +00:00
|
|
|
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 );
|
2015-06-22 08:48:01 +00:00
|
|
|
}
|
|
|
|
|
2016-01-26 22:13:58 +00:00
|
|
|
int main(int argc, const char *argv[])
|
2013-08-16 11:31:10 +00:00
|
|
|
{
|
2016-04-17 22:24:50 +00:00
|
|
|
/* Local Configurations and options */
|
2016-04-25 20:34:49 +00:00
|
|
|
const char *default_filename = "TESTCASE_FILENAME";
|
2016-01-26 22:13:58 +00:00
|
|
|
const char *test_filename = NULL;
|
|
|
|
const char **test_files = NULL;
|
2016-04-17 22:24:50 +00:00
|
|
|
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;
|
2013-08-16 11:31:10 +00:00
|
|
|
FILE *file;
|
|
|
|
char buf[5000];
|
|
|
|
char *params[50];
|
2015-05-29 09:26:37 +00:00
|
|
|
void *pointer;
|
2016-11-02 10:17:00 +00:00
|
|
|
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
2016-10-12 22:07:30 +00:00
|
|
|
int stdout_fd = -1;
|
2016-11-02 10:17:00 +00:00
|
|
|
#endif /* __unix__ || __APPLE__ __MACH__ */
|
2013-08-16 11:31:10 +00:00
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
|
2014-11-27 10:55:27 +00:00
|
|
|
!defined(TEST_SUITE_MEMORY_BUFFER_ALLOC)
|
2013-09-29 12:45:34 +00:00
|
|
|
unsigned char alloc_buf[1000000];
|
2018-03-13 15:22:58 +00:00
|
|
|
#endif
|
2018-04-18 08:14:31 +00:00
|
|
|
/* Platform setup should be called in the beginning */
|
|
|
|
ret = platform_setup();
|
|
|
|
if( ret != 0 )
|
2018-04-13 09:15:17 +00:00
|
|
|
{
|
2018-04-18 08:14:31 +00:00
|
|
|
mbedtls_fprintf( stderr,
|
|
|
|
"FATAL: Failed to initialize platform - error %d\n",
|
|
|
|
ret );
|
|
|
|
return( -1 );
|
2018-04-13 09:15:17 +00:00
|
|
|
}
|
|
|
|
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
|
|
|
|
!defined(TEST_SUITE_MEMORY_BUFFER_ALLOC)
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_memory_buffer_alloc_init( alloc_buf, sizeof(alloc_buf) );
|
2013-08-16 11:31:10 +00:00
|
|
|
#endif
|
|
|
|
|
2015-05-29 09:26:37 +00:00
|
|
|
/*
|
|
|
|
* 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" );
|
2018-04-13 10:16:04 +00:00
|
|
|
platform_teardown();
|
2015-05-29 09:26:37 +00:00
|
|
|
return( 1 );
|
|
|
|
}
|
|
|
|
|
2015-06-22 08:48:01 +00:00
|
|
|
/*
|
|
|
|
* Make sure we have a snprintf that correctly zero-terminates
|
|
|
|
*/
|
|
|
|
if( run_test_snprintf() != 0 )
|
|
|
|
{
|
|
|
|
mbedtls_fprintf( stderr, "the snprintf implementation is broken\n" );
|
2018-04-13 10:16:04 +00:00
|
|
|
platform_teardown();
|
2018-04-18 08:14:31 +00:00
|
|
|
return( 1 );
|
2015-06-22 08:48:01 +00:00
|
|
|
}
|
|
|
|
|
2016-04-17 22:24:50 +00:00
|
|
|
while( arg_index < argc)
|
2013-08-16 11:31:10 +00:00
|
|
|
{
|
2016-04-17 22:24:50 +00:00
|
|
|
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 );
|
2018-04-13 10:16:04 +00:00
|
|
|
platform_teardown();
|
2016-04-17 22:24:50 +00:00
|
|
|
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++;
|
2016-01-26 22:13:58 +00:00
|
|
|
}
|
2016-04-17 22:24:50 +00:00
|
|
|
|
|
|
|
/* If no files were specified, assume a default */
|
|
|
|
if ( test_files == NULL || testfile_count == 0 )
|
2016-01-26 22:13:58 +00:00
|
|
|
{
|
2016-04-17 22:24:50 +00:00
|
|
|
test_files = &default_filename;
|
|
|
|
testfile_count = 1;
|
2013-08-16 11:31:10 +00:00
|
|
|
}
|
|
|
|
|
2017-10-01 15:42:29 +00:00
|
|
|
/* Initialize the struct that holds information about the last test */
|
|
|
|
memset( &test_info, 0, sizeof( test_info ) );
|
|
|
|
|
2016-04-17 22:24:50 +00:00
|
|
|
/* Now begin to execute the tests in the testfiles */
|
2016-01-26 22:13:58 +00:00
|
|
|
for ( testfile_index = 0;
|
|
|
|
testfile_index < testfile_count;
|
|
|
|
testfile_index++ )
|
2013-08-16 11:31:10 +00:00
|
|
|
{
|
2016-05-12 14:59:48 +00:00
|
|
|
int unmet_dep_count = 0;
|
|
|
|
char *unmet_dependencies[20];
|
|
|
|
|
2016-01-26 22:13:58 +00:00
|
|
|
test_filename = test_files[ testfile_index ];
|
2013-08-16 11:31:10 +00:00
|
|
|
|
2016-01-26 22:13:58 +00:00
|
|
|
file = fopen( test_filename, "r" );
|
|
|
|
if( file == NULL )
|
|
|
|
{
|
|
|
|
mbedtls_fprintf( stderr, "Failed to open test file: %s\n",
|
|
|
|
test_filename );
|
2018-04-13 10:16:04 +00:00
|
|
|
platform_teardown();
|
2016-01-26 22:13:58 +00:00
|
|
|
return( 1 );
|
|
|
|
}
|
2013-08-16 11:31:10 +00:00
|
|
|
|
2016-01-26 22:13:58 +00:00
|
|
|
while( !feof( file ) )
|
|
|
|
{
|
2016-05-12 14:59:48 +00:00
|
|
|
if( unmet_dep_count > 0 )
|
|
|
|
{
|
2016-09-30 12:11:29 +00:00
|
|
|
mbedtls_fprintf( stderr,
|
2016-10-05 09:57:49 +00:00
|
|
|
"FATAL: Dep count larger than zero at start of loop\n" );
|
2018-04-13 10:16:04 +00:00
|
|
|
platform_teardown();
|
2016-05-12 14:59:48 +00:00
|
|
|
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
unmet_dep_count = 0;
|
2013-08-16 11:31:10 +00:00
|
|
|
|
2016-01-26 22:13:58 +00:00
|
|
|
if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
|
|
|
|
break;
|
2017-10-01 15:42:29 +00:00
|
|
|
mbedtls_fprintf( stdout, "%s%.66s", test_info.failed ? "\n" : "", buf );
|
2016-01-26 22:13:58 +00:00
|
|
|
mbedtls_fprintf( stdout, " " );
|
|
|
|
for( i = strlen( buf ) + 1; i < 67; i++ )
|
|
|
|
mbedtls_fprintf( stdout, "." );
|
|
|
|
mbedtls_fprintf( stdout, " " );
|
|
|
|
fflush( stdout );
|
2013-08-16 11:31:10 +00:00
|
|
|
|
2016-01-26 22:13:58 +00:00
|
|
|
total_tests++;
|
2013-08-16 11:31:10 +00:00
|
|
|
|
|
|
|
if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
|
|
|
|
break;
|
|
|
|
cnt = parse_arguments( buf, strlen(buf), params );
|
|
|
|
|
2016-01-26 22:13:58 +00:00
|
|
|
if( strcmp( params[0], "depends_on" ) == 0 )
|
|
|
|
{
|
|
|
|
for( i = 1; i < cnt; i++ )
|
2016-04-17 22:24:50 +00:00
|
|
|
{
|
|
|
|
if( dep_check( params[i] ) != DEPENDENCY_SUPPORTED )
|
|
|
|
{
|
2016-05-12 14:55:37 +00:00
|
|
|
if( 0 == option_verbose )
|
|
|
|
{
|
|
|
|
/* Only one count is needed if not verbose */
|
|
|
|
unmet_dep_count++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-05-12 14:52:48 +00:00
|
|
|
unmet_dependencies[ unmet_dep_count ] = strdup(params[i]);
|
|
|
|
if( unmet_dependencies[ unmet_dep_count ] == NULL )
|
2016-04-17 22:24:50 +00:00
|
|
|
{
|
2016-10-05 09:57:49 +00:00
|
|
|
mbedtls_fprintf( stderr, "FATAL: Out of memory\n" );
|
2018-04-13 10:16:04 +00:00
|
|
|
platform_teardown();
|
2016-04-18 17:18:48 +00:00
|
|
|
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
|
2016-04-17 22:24:50 +00:00
|
|
|
}
|
|
|
|
unmet_dep_count++;
|
|
|
|
}
|
|
|
|
}
|
2013-08-16 11:31:10 +00:00
|
|
|
|
2016-01-26 22:13:58 +00:00
|
|
|
if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
|
|
|
|
break;
|
|
|
|
cnt = parse_arguments( buf, strlen(buf), params );
|
|
|
|
}
|
2017-10-01 15:42:29 +00:00
|
|
|
|
2016-04-17 22:24:50 +00:00
|
|
|
// If there are no unmet dependencies execute the test
|
|
|
|
if( unmet_dep_count == 0 )
|
2016-01-26 22:13:58 +00:00
|
|
|
{
|
2017-10-01 15:42:29 +00:00
|
|
|
test_info.failed = 0;
|
2016-09-30 12:11:29 +00:00
|
|
|
|
|
|
|
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
|
|
|
/* Suppress all output from the library unless we're verbose
|
|
|
|
* mode
|
|
|
|
*/
|
|
|
|
if( !option_verbose )
|
|
|
|
{
|
2016-10-05 09:57:49 +00:00
|
|
|
stdout_fd = redirect_output( &stdout, "/dev/null" );
|
|
|
|
if( stdout_fd == -1 )
|
2016-09-30 12:11:29 +00:00
|
|
|
{
|
2018-04-13 10:16:04 +00:00
|
|
|
platform_teardown();
|
2016-09-30 12:11:29 +00:00
|
|
|
/* Redirection has failed with no stdout so exit */
|
2016-10-05 09:57:49 +00:00
|
|
|
exit( 1 );
|
2016-09-30 12:11:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* __unix__ || __APPLE__ __MACH__ */
|
|
|
|
|
2016-01-26 22:13:58 +00:00
|
|
|
ret = dispatch_test( cnt, params );
|
2016-09-30 12:11:29 +00:00
|
|
|
|
|
|
|
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
2016-10-05 09:57:49 +00:00
|
|
|
if( !option_verbose && restore_output( &stdout, stdout_fd ) )
|
2016-09-30 12:11:29 +00:00
|
|
|
{
|
|
|
|
/* Redirection has failed with no stdout so exit */
|
2018-04-13 10:16:04 +00:00
|
|
|
platform_teardown();
|
2016-10-05 09:57:49 +00:00
|
|
|
exit( 1 );
|
2016-09-30 12:11:29 +00:00
|
|
|
}
|
|
|
|
#endif /* __unix__ || __APPLE__ __MACH__ */
|
|
|
|
|
2016-01-26 22:13:58 +00:00
|
|
|
}
|
|
|
|
|
2016-04-17 22:24:50 +00:00
|
|
|
if( unmet_dep_count > 0 || ret == DISPATCH_UNSUPPORTED_SUITE )
|
2016-01-26 22:13:58 +00:00
|
|
|
{
|
|
|
|
total_skipped++;
|
2017-07-23 09:23:24 +00:00
|
|
|
mbedtls_fprintf( stdout, "----" );
|
2016-04-17 22:24:50 +00:00
|
|
|
|
|
|
|
if( 1 == option_verbose && ret == DISPATCH_UNSUPPORTED_SUITE )
|
|
|
|
{
|
2017-07-23 09:23:24 +00:00
|
|
|
mbedtls_fprintf( stdout, "\n Test Suite not enabled" );
|
2016-04-17 22:24:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( 1 == option_verbose && unmet_dep_count > 0 )
|
|
|
|
{
|
2017-07-23 09:23:24 +00:00
|
|
|
mbedtls_fprintf( stdout, "\n Unmet dependencies: " );
|
2016-05-12 14:59:48 +00:00
|
|
|
for( i = 0; i < unmet_dep_count; i++ )
|
2016-04-17 22:24:50 +00:00
|
|
|
{
|
|
|
|
mbedtls_fprintf(stdout, "%s ",
|
2016-05-12 14:59:48 +00:00
|
|
|
unmet_dependencies[i]);
|
|
|
|
free(unmet_dependencies[i]);
|
2016-04-17 22:24:50 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-23 09:23:24 +00:00
|
|
|
mbedtls_fprintf( stdout, "\n" );
|
2016-01-26 22:13:58 +00:00
|
|
|
fflush( stdout );
|
2016-05-12 14:59:48 +00:00
|
|
|
|
|
|
|
unmet_dep_count = 0;
|
2016-01-26 22:13:58 +00:00
|
|
|
}
|
2017-10-01 15:42:29 +00:00
|
|
|
else if( ret == DISPATCH_TEST_SUCCESS )
|
2016-01-26 22:13:58 +00:00
|
|
|
{
|
2017-10-01 15:42:29 +00:00
|
|
|
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 );
|
|
|
|
}
|
2016-01-26 22:13:58 +00:00
|
|
|
fflush( stdout );
|
|
|
|
}
|
2016-04-17 22:24:50 +00:00
|
|
|
else if( ret == DISPATCH_INVALID_TEST_DATA )
|
2016-01-26 22:13:58 +00:00
|
|
|
{
|
|
|
|
mbedtls_fprintf( stderr, "FAILED: FATAL PARSE ERROR\n" );
|
2017-07-23 09:23:43 +00:00
|
|
|
fclose( file );
|
2018-04-13 10:16:04 +00:00
|
|
|
platform_teardown();
|
2016-01-26 22:13:58 +00:00
|
|
|
mbedtls_exit( 2 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
total_errors++;
|
|
|
|
|
2017-07-23 09:23:43 +00:00
|
|
|
if( ( ret = get_line( file, buf, sizeof( buf ) ) ) != 0 )
|
2016-01-26 22:13:58 +00:00
|
|
|
break;
|
2017-07-23 09:23:43 +00:00
|
|
|
if( strlen( buf ) != 0 )
|
2016-01-26 22:13:58 +00:00
|
|
|
{
|
|
|
|
mbedtls_fprintf( stderr, "Should be empty %d\n",
|
2017-07-23 09:23:43 +00:00
|
|
|
(int) strlen( buf ) );
|
2018-04-13 10:16:04 +00:00
|
|
|
platform_teardown();
|
2016-01-26 22:13:58 +00:00
|
|
|
return( 1 );
|
|
|
|
}
|
2013-08-16 11:31:10 +00:00
|
|
|
}
|
2017-07-23 09:23:43 +00:00
|
|
|
fclose( file );
|
2016-05-12 14:59:48 +00:00
|
|
|
|
|
|
|
/* In case we encounter early end of file */
|
|
|
|
for( i = 0; i < unmet_dep_count; i++ )
|
|
|
|
free( unmet_dependencies[i] );
|
2013-08-16 11:31:10 +00:00
|
|
|
}
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_fprintf( stdout, "\n----------------------------------------------------------------------------\n\n");
|
2013-08-16 11:31:10 +00:00
|
|
|
if( total_errors == 0 )
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_fprintf( stdout, "PASSED" );
|
2013-08-16 11:31:10 +00:00
|
|
|
else
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_fprintf( stdout, "FAILED" );
|
2013-08-16 11:31:10 +00:00
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_fprintf( stdout, " (%d / %d tests (%d skipped))\n",
|
2013-08-16 11:31:10 +00:00
|
|
|
total_tests - total_errors, total_tests, total_skipped );
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
|
2014-11-27 10:55:27 +00:00
|
|
|
!defined(TEST_SUITE_MEMORY_BUFFER_ALLOC)
|
2015-04-08 10:49:31 +00:00
|
|
|
#if defined(MBEDTLS_MEMORY_DEBUG)
|
|
|
|
mbedtls_memory_buffer_alloc_status();
|
2013-08-16 11:31:10 +00:00
|
|
|
#endif
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_memory_buffer_alloc_free();
|
2013-09-29 12:45:34 +00:00
|
|
|
#endif
|
2013-08-16 11:31:10 +00:00
|
|
|
|
2016-10-12 22:07:30 +00:00
|
|
|
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
|
|
|
if( stdout_fd != -1 )
|
|
|
|
close_output( stdout );
|
|
|
|
#endif /* __unix__ || __APPLE__ __MACH__ */
|
|
|
|
|
2018-04-13 10:16:04 +00:00
|
|
|
platform_teardown();
|
2013-08-16 11:31:10 +00:00
|
|
|
return( total_errors != 0 );
|
|
|
|
}
|