mbed TLS Build

Dependents:   Encrypt_Decrypt1 mbed_blink_tls encrypt encrypt

Committer:
markrad
Date:
Thu Jan 05 00:18:44 2017 +0000
Revision:
0:cdf462088d13
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
markrad 0:cdf462088d13 1 #line 1 "main_test.function"
markrad 0:cdf462088d13 2 SUITE_PRE_DEP
markrad 0:cdf462088d13 3 #define TEST_SUITE_ACTIVE
markrad 0:cdf462088d13 4
markrad 0:cdf462088d13 5 int verify_string( char **str )
markrad 0:cdf462088d13 6 {
markrad 0:cdf462088d13 7 if( (*str)[0] != '"' ||
markrad 0:cdf462088d13 8 (*str)[strlen( *str ) - 1] != '"' )
markrad 0:cdf462088d13 9 {
markrad 0:cdf462088d13 10 mbedtls_fprintf( stderr,
markrad 0:cdf462088d13 11 "Expected string (with \"\") for parameter and got: %s\n", *str );
markrad 0:cdf462088d13 12 return( -1 );
markrad 0:cdf462088d13 13 }
markrad 0:cdf462088d13 14
markrad 0:cdf462088d13 15 (*str)++;
markrad 0:cdf462088d13 16 (*str)[strlen( *str ) - 1] = '\0';
markrad 0:cdf462088d13 17
markrad 0:cdf462088d13 18 return( 0 );
markrad 0:cdf462088d13 19 }
markrad 0:cdf462088d13 20
markrad 0:cdf462088d13 21 int verify_int( char *str, int *value )
markrad 0:cdf462088d13 22 {
markrad 0:cdf462088d13 23 size_t i;
markrad 0:cdf462088d13 24 int minus = 0;
markrad 0:cdf462088d13 25 int digits = 1;
markrad 0:cdf462088d13 26 int hex = 0;
markrad 0:cdf462088d13 27
markrad 0:cdf462088d13 28 for( i = 0; i < strlen( str ); i++ )
markrad 0:cdf462088d13 29 {
markrad 0:cdf462088d13 30 if( i == 0 && str[i] == '-' )
markrad 0:cdf462088d13 31 {
markrad 0:cdf462088d13 32 minus = 1;
markrad 0:cdf462088d13 33 continue;
markrad 0:cdf462088d13 34 }
markrad 0:cdf462088d13 35
markrad 0:cdf462088d13 36 if( ( ( minus && i == 2 ) || ( !minus && i == 1 ) ) &&
markrad 0:cdf462088d13 37 str[i - 1] == '0' && str[i] == 'x' )
markrad 0:cdf462088d13 38 {
markrad 0:cdf462088d13 39 hex = 1;
markrad 0:cdf462088d13 40 continue;
markrad 0:cdf462088d13 41 }
markrad 0:cdf462088d13 42
markrad 0:cdf462088d13 43 if( ! ( ( str[i] >= '0' && str[i] <= '9' ) ||
markrad 0:cdf462088d13 44 ( hex && ( ( str[i] >= 'a' && str[i] <= 'f' ) ||
markrad 0:cdf462088d13 45 ( str[i] >= 'A' && str[i] <= 'F' ) ) ) ) )
markrad 0:cdf462088d13 46 {
markrad 0:cdf462088d13 47 digits = 0;
markrad 0:cdf462088d13 48 break;
markrad 0:cdf462088d13 49 }
markrad 0:cdf462088d13 50 }
markrad 0:cdf462088d13 51
markrad 0:cdf462088d13 52 if( digits )
markrad 0:cdf462088d13 53 {
markrad 0:cdf462088d13 54 if( hex )
markrad 0:cdf462088d13 55 *value = strtol( str, NULL, 16 );
markrad 0:cdf462088d13 56 else
markrad 0:cdf462088d13 57 *value = strtol( str, NULL, 10 );
markrad 0:cdf462088d13 58
markrad 0:cdf462088d13 59 return( 0 );
markrad 0:cdf462088d13 60 }
markrad 0:cdf462088d13 61
markrad 0:cdf462088d13 62 MAPPING_CODE
markrad 0:cdf462088d13 63
markrad 0:cdf462088d13 64 mbedtls_fprintf( stderr,
markrad 0:cdf462088d13 65 "Expected integer for parameter and got: %s\n", str );
markrad 0:cdf462088d13 66 return( KEY_VALUE_MAPPING_NOT_FOUND );
markrad 0:cdf462088d13 67 }
markrad 0:cdf462088d13 68
markrad 0:cdf462088d13 69
markrad 0:cdf462088d13 70 /*----------------------------------------------------------------------------*/
markrad 0:cdf462088d13 71 /* Test Case code */
markrad 0:cdf462088d13 72
markrad 0:cdf462088d13 73 FUNCTION_CODE
markrad 0:cdf462088d13 74 SUITE_POST_DEP
markrad 0:cdf462088d13 75
markrad 0:cdf462088d13 76 #line !LINE_NO! "main_test.function"
markrad 0:cdf462088d13 77
markrad 0:cdf462088d13 78
markrad 0:cdf462088d13 79 /*----------------------------------------------------------------------------*/
markrad 0:cdf462088d13 80 /* Test dispatch code */
markrad 0:cdf462088d13 81
markrad 0:cdf462088d13 82 int dep_check( char *str )
markrad 0:cdf462088d13 83 {
markrad 0:cdf462088d13 84 if( str == NULL )
markrad 0:cdf462088d13 85 return( 1 );
markrad 0:cdf462088d13 86
markrad 0:cdf462088d13 87 DEP_CHECK_CODE
markrad 0:cdf462088d13 88 #line !LINE_NO! "main_test.function"
markrad 0:cdf462088d13 89
markrad 0:cdf462088d13 90 return( DEPENDENCY_NOT_SUPPORTED );
markrad 0:cdf462088d13 91 }
markrad 0:cdf462088d13 92
markrad 0:cdf462088d13 93 int dispatch_test(int cnt, char *params[50])
markrad 0:cdf462088d13 94 {
markrad 0:cdf462088d13 95 int ret;
markrad 0:cdf462088d13 96 ((void) cnt);
markrad 0:cdf462088d13 97 ((void) params);
markrad 0:cdf462088d13 98
markrad 0:cdf462088d13 99 #if defined(TEST_SUITE_ACTIVE)
markrad 0:cdf462088d13 100 ret = DISPATCH_TEST_SUCCESS;
markrad 0:cdf462088d13 101
markrad 0:cdf462088d13 102 // Cast to void to avoid compiler warnings
markrad 0:cdf462088d13 103 (void)ret;
markrad 0:cdf462088d13 104
markrad 0:cdf462088d13 105 DISPATCH_FUNCTION
markrad 0:cdf462088d13 106 {
markrad 0:cdf462088d13 107 #line !LINE_NO! "main_test.function"
markrad 0:cdf462088d13 108 mbedtls_fprintf( stdout,
markrad 0:cdf462088d13 109 "FAILED\nSkipping unknown test function '%s'\n",
markrad 0:cdf462088d13 110 params[0] );
markrad 0:cdf462088d13 111 fflush( stdout );
markrad 0:cdf462088d13 112 ret = DISPATCH_TEST_FN_NOT_FOUND;
markrad 0:cdf462088d13 113 }
markrad 0:cdf462088d13 114 #else
markrad 0:cdf462088d13 115 ret = DISPATCH_UNSUPPORTED_SUITE;
markrad 0:cdf462088d13 116 #endif
markrad 0:cdf462088d13 117 return( ret );
markrad 0:cdf462088d13 118 }
markrad 0:cdf462088d13 119
markrad 0:cdf462088d13 120
markrad 0:cdf462088d13 121 /*----------------------------------------------------------------------------*/
markrad 0:cdf462088d13 122 /* Main Test code */
markrad 0:cdf462088d13 123
markrad 0:cdf462088d13 124 #line !LINE_NO! "main_test.function"
markrad 0:cdf462088d13 125
markrad 0:cdf462088d13 126 #define USAGE \
markrad 0:cdf462088d13 127 "Usage: %s [OPTIONS] files...\n\n" \
markrad 0:cdf462088d13 128 " Command line arguments:\n" \
markrad 0:cdf462088d13 129 " files... One or more test data file. If no file is specified\n" \
markrad 0:cdf462088d13 130 " the followimg default test case is used:\n" \
markrad 0:cdf462088d13 131 " %s\n\n" \
markrad 0:cdf462088d13 132 " Options:\n" \
markrad 0:cdf462088d13 133 " -v | --verbose Display full information about each test\n" \
markrad 0:cdf462088d13 134 " -h | --help Display this information\n\n", \
markrad 0:cdf462088d13 135 argv[0], \
markrad 0:cdf462088d13 136 "TESTCASE_FILENAME"
markrad 0:cdf462088d13 137
markrad 0:cdf462088d13 138
markrad 0:cdf462088d13 139 int get_line( FILE *f, char *buf, size_t len )
markrad 0:cdf462088d13 140 {
markrad 0:cdf462088d13 141 char *ret;
markrad 0:cdf462088d13 142
markrad 0:cdf462088d13 143 ret = fgets( buf, len, f );
markrad 0:cdf462088d13 144 if( ret == NULL )
markrad 0:cdf462088d13 145 return( -1 );
markrad 0:cdf462088d13 146
markrad 0:cdf462088d13 147 if( strlen( buf ) && buf[strlen(buf) - 1] == '\n' )
markrad 0:cdf462088d13 148 buf[strlen(buf) - 1] = '\0';
markrad 0:cdf462088d13 149 if( strlen( buf ) && buf[strlen(buf) - 1] == '\r' )
markrad 0:cdf462088d13 150 buf[strlen(buf) - 1] = '\0';
markrad 0:cdf462088d13 151
markrad 0:cdf462088d13 152 return( 0 );
markrad 0:cdf462088d13 153 }
markrad 0:cdf462088d13 154
markrad 0:cdf462088d13 155 int parse_arguments( char *buf, size_t len, char *params[50] )
markrad 0:cdf462088d13 156 {
markrad 0:cdf462088d13 157 int cnt = 0, i;
markrad 0:cdf462088d13 158 char *cur = buf;
markrad 0:cdf462088d13 159 char *p = buf, *q;
markrad 0:cdf462088d13 160
markrad 0:cdf462088d13 161 params[cnt++] = cur;
markrad 0:cdf462088d13 162
markrad 0:cdf462088d13 163 while( *p != '\0' && p < buf + len )
markrad 0:cdf462088d13 164 {
markrad 0:cdf462088d13 165 if( *p == '\\' )
markrad 0:cdf462088d13 166 {
markrad 0:cdf462088d13 167 p++;
markrad 0:cdf462088d13 168 p++;
markrad 0:cdf462088d13 169 continue;
markrad 0:cdf462088d13 170 }
markrad 0:cdf462088d13 171 if( *p == ':' )
markrad 0:cdf462088d13 172 {
markrad 0:cdf462088d13 173 if( p + 1 < buf + len )
markrad 0:cdf462088d13 174 {
markrad 0:cdf462088d13 175 cur = p + 1;
markrad 0:cdf462088d13 176 params[cnt++] = cur;
markrad 0:cdf462088d13 177 }
markrad 0:cdf462088d13 178 *p = '\0';
markrad 0:cdf462088d13 179 }
markrad 0:cdf462088d13 180
markrad 0:cdf462088d13 181 p++;
markrad 0:cdf462088d13 182 }
markrad 0:cdf462088d13 183
markrad 0:cdf462088d13 184 /* Replace newlines, question marks and colons in strings */
markrad 0:cdf462088d13 185 for( i = 0; i < cnt; i++ )
markrad 0:cdf462088d13 186 {
markrad 0:cdf462088d13 187 p = params[i];
markrad 0:cdf462088d13 188 q = params[i];
markrad 0:cdf462088d13 189
markrad 0:cdf462088d13 190 while( *p != '\0' )
markrad 0:cdf462088d13 191 {
markrad 0:cdf462088d13 192 if( *p == '\\' && *(p + 1) == 'n' )
markrad 0:cdf462088d13 193 {
markrad 0:cdf462088d13 194 p += 2;
markrad 0:cdf462088d13 195 *(q++) = '\n';
markrad 0:cdf462088d13 196 }
markrad 0:cdf462088d13 197 else if( *p == '\\' && *(p + 1) == ':' )
markrad 0:cdf462088d13 198 {
markrad 0:cdf462088d13 199 p += 2;
markrad 0:cdf462088d13 200 *(q++) = ':';
markrad 0:cdf462088d13 201 }
markrad 0:cdf462088d13 202 else if( *p == '\\' && *(p + 1) == '?' )
markrad 0:cdf462088d13 203 {
markrad 0:cdf462088d13 204 p += 2;
markrad 0:cdf462088d13 205 *(q++) = '?';
markrad 0:cdf462088d13 206 }
markrad 0:cdf462088d13 207 else
markrad 0:cdf462088d13 208 *(q++) = *(p++);
markrad 0:cdf462088d13 209 }
markrad 0:cdf462088d13 210 *q = '\0';
markrad 0:cdf462088d13 211 }
markrad 0:cdf462088d13 212
markrad 0:cdf462088d13 213 return( cnt );
markrad 0:cdf462088d13 214 }
markrad 0:cdf462088d13 215
markrad 0:cdf462088d13 216 static int test_snprintf( size_t n, const char ref_buf[10], int ref_ret )
markrad 0:cdf462088d13 217 {
markrad 0:cdf462088d13 218 int ret;
markrad 0:cdf462088d13 219 char buf[10] = "xxxxxxxxx";
markrad 0:cdf462088d13 220 const char ref[10] = "xxxxxxxxx";
markrad 0:cdf462088d13 221
markrad 0:cdf462088d13 222 ret = mbedtls_snprintf( buf, n, "%s", "123" );
markrad 0:cdf462088d13 223 if( ret < 0 || (size_t) ret >= n )
markrad 0:cdf462088d13 224 ret = -1;
markrad 0:cdf462088d13 225
markrad 0:cdf462088d13 226 if( strncmp( ref_buf, buf, sizeof( buf ) ) != 0 ||
markrad 0:cdf462088d13 227 ref_ret != ret ||
markrad 0:cdf462088d13 228 memcmp( buf + n, ref + n, sizeof( buf ) - n ) != 0 )
markrad 0:cdf462088d13 229 {
markrad 0:cdf462088d13 230 return( 1 );
markrad 0:cdf462088d13 231 }
markrad 0:cdf462088d13 232
markrad 0:cdf462088d13 233 return( 0 );
markrad 0:cdf462088d13 234 }
markrad 0:cdf462088d13 235
markrad 0:cdf462088d13 236 static int run_test_snprintf( void )
markrad 0:cdf462088d13 237 {
markrad 0:cdf462088d13 238 return( test_snprintf( 0, "xxxxxxxxx", -1 ) != 0 ||
markrad 0:cdf462088d13 239 test_snprintf( 1, "", -1 ) != 0 ||
markrad 0:cdf462088d13 240 test_snprintf( 2, "1", -1 ) != 0 ||
markrad 0:cdf462088d13 241 test_snprintf( 3, "12", -1 ) != 0 ||
markrad 0:cdf462088d13 242 test_snprintf( 4, "123", 3 ) != 0 ||
markrad 0:cdf462088d13 243 test_snprintf( 5, "123", 3 ) != 0 );
markrad 0:cdf462088d13 244 }
markrad 0:cdf462088d13 245
markrad 0:cdf462088d13 246 int main(int argc, const char *argv[])
markrad 0:cdf462088d13 247 {
markrad 0:cdf462088d13 248 /* Local Configurations and options */
markrad 0:cdf462088d13 249 const char *default_filename = "TESTCASE_FILENAME";
markrad 0:cdf462088d13 250 const char *test_filename = NULL;
markrad 0:cdf462088d13 251 const char **test_files = NULL;
markrad 0:cdf462088d13 252 int testfile_count = 0;
markrad 0:cdf462088d13 253 int option_verbose = 0;
markrad 0:cdf462088d13 254
markrad 0:cdf462088d13 255 /* Other Local variables */
markrad 0:cdf462088d13 256 int arg_index = 1;
markrad 0:cdf462088d13 257 const char *next_arg;
markrad 0:cdf462088d13 258 int testfile_index, ret, i, cnt;
markrad 0:cdf462088d13 259 int total_errors = 0, total_tests = 0, total_skipped = 0;
markrad 0:cdf462088d13 260 FILE *file;
markrad 0:cdf462088d13 261 char buf[5000];
markrad 0:cdf462088d13 262 char *params[50];
markrad 0:cdf462088d13 263 void *pointer;
markrad 0:cdf462088d13 264 #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
markrad 0:cdf462088d13 265 int stdout_fd = -1;
markrad 0:cdf462088d13 266 #endif /* __unix__ || __APPLE__ __MACH__ */
markrad 0:cdf462088d13 267
markrad 0:cdf462088d13 268 #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
markrad 0:cdf462088d13 269 !defined(TEST_SUITE_MEMORY_BUFFER_ALLOC)
markrad 0:cdf462088d13 270 unsigned char alloc_buf[1000000];
markrad 0:cdf462088d13 271 mbedtls_memory_buffer_alloc_init( alloc_buf, sizeof(alloc_buf) );
markrad 0:cdf462088d13 272 #endif
markrad 0:cdf462088d13 273
markrad 0:cdf462088d13 274 /*
markrad 0:cdf462088d13 275 * The C standard doesn't guarantee that all-bits-0 is the representation
markrad 0:cdf462088d13 276 * of a NULL pointer. We do however use that in our code for initializing
markrad 0:cdf462088d13 277 * structures, which should work on every modern platform. Let's be sure.
markrad 0:cdf462088d13 278 */
markrad 0:cdf462088d13 279 memset( &pointer, 0, sizeof( void * ) );
markrad 0:cdf462088d13 280 if( pointer != NULL )
markrad 0:cdf462088d13 281 {
markrad 0:cdf462088d13 282 mbedtls_fprintf( stderr, "all-bits-zero is not a NULL pointer\n" );
markrad 0:cdf462088d13 283 return( 1 );
markrad 0:cdf462088d13 284 }
markrad 0:cdf462088d13 285
markrad 0:cdf462088d13 286 /*
markrad 0:cdf462088d13 287 * Make sure we have a snprintf that correctly zero-terminates
markrad 0:cdf462088d13 288 */
markrad 0:cdf462088d13 289 if( run_test_snprintf() != 0 )
markrad 0:cdf462088d13 290 {
markrad 0:cdf462088d13 291 mbedtls_fprintf( stderr, "the snprintf implementation is broken\n" );
markrad 0:cdf462088d13 292 return( 0 );
markrad 0:cdf462088d13 293 }
markrad 0:cdf462088d13 294
markrad 0:cdf462088d13 295 while( arg_index < argc)
markrad 0:cdf462088d13 296 {
markrad 0:cdf462088d13 297 next_arg = argv[ arg_index ];
markrad 0:cdf462088d13 298
markrad 0:cdf462088d13 299 if( strcmp(next_arg, "--verbose" ) == 0 ||
markrad 0:cdf462088d13 300 strcmp(next_arg, "-v" ) == 0 )
markrad 0:cdf462088d13 301 {
markrad 0:cdf462088d13 302 option_verbose = 1;
markrad 0:cdf462088d13 303 }
markrad 0:cdf462088d13 304 else if( strcmp(next_arg, "--help" ) == 0 ||
markrad 0:cdf462088d13 305 strcmp(next_arg, "-h" ) == 0 )
markrad 0:cdf462088d13 306 {
markrad 0:cdf462088d13 307 mbedtls_fprintf( stdout, USAGE );
markrad 0:cdf462088d13 308 mbedtls_exit( EXIT_SUCCESS );
markrad 0:cdf462088d13 309 }
markrad 0:cdf462088d13 310 else
markrad 0:cdf462088d13 311 {
markrad 0:cdf462088d13 312 /* Not an option, therefore treat all further arguments as the file
markrad 0:cdf462088d13 313 * list.
markrad 0:cdf462088d13 314 */
markrad 0:cdf462088d13 315 test_files = &argv[ arg_index ];
markrad 0:cdf462088d13 316 testfile_count = argc - arg_index;
markrad 0:cdf462088d13 317 }
markrad 0:cdf462088d13 318
markrad 0:cdf462088d13 319 arg_index++;
markrad 0:cdf462088d13 320 }
markrad 0:cdf462088d13 321
markrad 0:cdf462088d13 322 /* If no files were specified, assume a default */
markrad 0:cdf462088d13 323 if ( test_files == NULL || testfile_count == 0 )
markrad 0:cdf462088d13 324 {
markrad 0:cdf462088d13 325 test_files = &default_filename;
markrad 0:cdf462088d13 326 testfile_count = 1;
markrad 0:cdf462088d13 327 }
markrad 0:cdf462088d13 328
markrad 0:cdf462088d13 329 /* Now begin to execute the tests in the testfiles */
markrad 0:cdf462088d13 330 for ( testfile_index = 0;
markrad 0:cdf462088d13 331 testfile_index < testfile_count;
markrad 0:cdf462088d13 332 testfile_index++ )
markrad 0:cdf462088d13 333 {
markrad 0:cdf462088d13 334 int unmet_dep_count = 0;
markrad 0:cdf462088d13 335 char *unmet_dependencies[20];
markrad 0:cdf462088d13 336
markrad 0:cdf462088d13 337 test_filename = test_files[ testfile_index ];
markrad 0:cdf462088d13 338
markrad 0:cdf462088d13 339 file = fopen( test_filename, "r" );
markrad 0:cdf462088d13 340 if( file == NULL )
markrad 0:cdf462088d13 341 {
markrad 0:cdf462088d13 342 mbedtls_fprintf( stderr, "Failed to open test file: %s\n",
markrad 0:cdf462088d13 343 test_filename );
markrad 0:cdf462088d13 344 return( 1 );
markrad 0:cdf462088d13 345 }
markrad 0:cdf462088d13 346
markrad 0:cdf462088d13 347 while( !feof( file ) )
markrad 0:cdf462088d13 348 {
markrad 0:cdf462088d13 349 if( unmet_dep_count > 0 )
markrad 0:cdf462088d13 350 {
markrad 0:cdf462088d13 351 mbedtls_fprintf( stderr,
markrad 0:cdf462088d13 352 "FATAL: Dep count larger than zero at start of loop\n" );
markrad 0:cdf462088d13 353 mbedtls_exit( MBEDTLS_EXIT_FAILURE );
markrad 0:cdf462088d13 354 }
markrad 0:cdf462088d13 355 unmet_dep_count = 0;
markrad 0:cdf462088d13 356
markrad 0:cdf462088d13 357 if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
markrad 0:cdf462088d13 358 break;
markrad 0:cdf462088d13 359 mbedtls_fprintf( stdout, "%s%.66s", test_errors ? "\n" : "", buf );
markrad 0:cdf462088d13 360 mbedtls_fprintf( stdout, " " );
markrad 0:cdf462088d13 361 for( i = strlen( buf ) + 1; i < 67; i++ )
markrad 0:cdf462088d13 362 mbedtls_fprintf( stdout, "." );
markrad 0:cdf462088d13 363 mbedtls_fprintf( stdout, " " );
markrad 0:cdf462088d13 364 fflush( stdout );
markrad 0:cdf462088d13 365
markrad 0:cdf462088d13 366 total_tests++;
markrad 0:cdf462088d13 367
markrad 0:cdf462088d13 368 if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
markrad 0:cdf462088d13 369 break;
markrad 0:cdf462088d13 370 cnt = parse_arguments( buf, strlen(buf), params );
markrad 0:cdf462088d13 371
markrad 0:cdf462088d13 372 if( strcmp( params[0], "depends_on" ) == 0 )
markrad 0:cdf462088d13 373 {
markrad 0:cdf462088d13 374 for( i = 1; i < cnt; i++ )
markrad 0:cdf462088d13 375 {
markrad 0:cdf462088d13 376 if( dep_check( params[i] ) != DEPENDENCY_SUPPORTED )
markrad 0:cdf462088d13 377 {
markrad 0:cdf462088d13 378 if( 0 == option_verbose )
markrad 0:cdf462088d13 379 {
markrad 0:cdf462088d13 380 /* Only one count is needed if not verbose */
markrad 0:cdf462088d13 381 unmet_dep_count++;
markrad 0:cdf462088d13 382 break;
markrad 0:cdf462088d13 383 }
markrad 0:cdf462088d13 384
markrad 0:cdf462088d13 385 unmet_dependencies[ unmet_dep_count ] = strdup(params[i]);
markrad 0:cdf462088d13 386 if( unmet_dependencies[ unmet_dep_count ] == NULL )
markrad 0:cdf462088d13 387 {
markrad 0:cdf462088d13 388 mbedtls_fprintf( stderr, "FATAL: Out of memory\n" );
markrad 0:cdf462088d13 389 mbedtls_exit( MBEDTLS_EXIT_FAILURE );
markrad 0:cdf462088d13 390 }
markrad 0:cdf462088d13 391 unmet_dep_count++;
markrad 0:cdf462088d13 392 }
markrad 0:cdf462088d13 393 }
markrad 0:cdf462088d13 394
markrad 0:cdf462088d13 395 if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
markrad 0:cdf462088d13 396 break;
markrad 0:cdf462088d13 397 cnt = parse_arguments( buf, strlen(buf), params );
markrad 0:cdf462088d13 398 }
markrad 0:cdf462088d13 399
markrad 0:cdf462088d13 400 // If there are no unmet dependencies execute the test
markrad 0:cdf462088d13 401 if( unmet_dep_count == 0 )
markrad 0:cdf462088d13 402 {
markrad 0:cdf462088d13 403 test_errors = 0;
markrad 0:cdf462088d13 404
markrad 0:cdf462088d13 405 #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
markrad 0:cdf462088d13 406 /* Suppress all output from the library unless we're verbose
markrad 0:cdf462088d13 407 * mode
markrad 0:cdf462088d13 408 */
markrad 0:cdf462088d13 409 if( !option_verbose )
markrad 0:cdf462088d13 410 {
markrad 0:cdf462088d13 411 stdout_fd = redirect_output( &stdout, "/dev/null" );
markrad 0:cdf462088d13 412 if( stdout_fd == -1 )
markrad 0:cdf462088d13 413 {
markrad 0:cdf462088d13 414 /* Redirection has failed with no stdout so exit */
markrad 0:cdf462088d13 415 exit( 1 );
markrad 0:cdf462088d13 416 }
markrad 0:cdf462088d13 417 }
markrad 0:cdf462088d13 418 #endif /* __unix__ || __APPLE__ __MACH__ */
markrad 0:cdf462088d13 419
markrad 0:cdf462088d13 420 ret = dispatch_test( cnt, params );
markrad 0:cdf462088d13 421
markrad 0:cdf462088d13 422 #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
markrad 0:cdf462088d13 423 if( !option_verbose && restore_output( &stdout, stdout_fd ) )
markrad 0:cdf462088d13 424 {
markrad 0:cdf462088d13 425 /* Redirection has failed with no stdout so exit */
markrad 0:cdf462088d13 426 exit( 1 );
markrad 0:cdf462088d13 427 }
markrad 0:cdf462088d13 428 #endif /* __unix__ || __APPLE__ __MACH__ */
markrad 0:cdf462088d13 429
markrad 0:cdf462088d13 430 }
markrad 0:cdf462088d13 431
markrad 0:cdf462088d13 432 if( unmet_dep_count > 0 || ret == DISPATCH_UNSUPPORTED_SUITE )
markrad 0:cdf462088d13 433 {
markrad 0:cdf462088d13 434 total_skipped++;
markrad 0:cdf462088d13 435 mbedtls_fprintf( stdout, "----\n" );
markrad 0:cdf462088d13 436
markrad 0:cdf462088d13 437 if( 1 == option_verbose && ret == DISPATCH_UNSUPPORTED_SUITE )
markrad 0:cdf462088d13 438 {
markrad 0:cdf462088d13 439 mbedtls_fprintf( stdout, " Test Suite not enabled" );
markrad 0:cdf462088d13 440 }
markrad 0:cdf462088d13 441
markrad 0:cdf462088d13 442 if( 1 == option_verbose && unmet_dep_count > 0 )
markrad 0:cdf462088d13 443 {
markrad 0:cdf462088d13 444 mbedtls_fprintf( stdout, " Unmet dependencies: " );
markrad 0:cdf462088d13 445 for( i = 0; i < unmet_dep_count; i++ )
markrad 0:cdf462088d13 446 {
markrad 0:cdf462088d13 447 mbedtls_fprintf(stdout, "%s ",
markrad 0:cdf462088d13 448 unmet_dependencies[i]);
markrad 0:cdf462088d13 449 free(unmet_dependencies[i]);
markrad 0:cdf462088d13 450 }
markrad 0:cdf462088d13 451 mbedtls_fprintf( stdout, "\n" );
markrad 0:cdf462088d13 452 }
markrad 0:cdf462088d13 453 fflush( stdout );
markrad 0:cdf462088d13 454
markrad 0:cdf462088d13 455 unmet_dep_count = 0;
markrad 0:cdf462088d13 456 }
markrad 0:cdf462088d13 457 else if( ret == DISPATCH_TEST_SUCCESS && test_errors == 0 )
markrad 0:cdf462088d13 458 {
markrad 0:cdf462088d13 459 mbedtls_fprintf( stdout, "PASS\n" );
markrad 0:cdf462088d13 460 fflush( stdout );
markrad 0:cdf462088d13 461 }
markrad 0:cdf462088d13 462 else if( ret == DISPATCH_INVALID_TEST_DATA )
markrad 0:cdf462088d13 463 {
markrad 0:cdf462088d13 464 mbedtls_fprintf( stderr, "FAILED: FATAL PARSE ERROR\n" );
markrad 0:cdf462088d13 465 fclose(file);
markrad 0:cdf462088d13 466 mbedtls_exit( 2 );
markrad 0:cdf462088d13 467 }
markrad 0:cdf462088d13 468 else
markrad 0:cdf462088d13 469 total_errors++;
markrad 0:cdf462088d13 470
markrad 0:cdf462088d13 471 if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
markrad 0:cdf462088d13 472 break;
markrad 0:cdf462088d13 473 if( strlen(buf) != 0 )
markrad 0:cdf462088d13 474 {
markrad 0:cdf462088d13 475 mbedtls_fprintf( stderr, "Should be empty %d\n",
markrad 0:cdf462088d13 476 (int) strlen(buf) );
markrad 0:cdf462088d13 477 return( 1 );
markrad 0:cdf462088d13 478 }
markrad 0:cdf462088d13 479 }
markrad 0:cdf462088d13 480 fclose(file);
markrad 0:cdf462088d13 481
markrad 0:cdf462088d13 482 /* In case we encounter early end of file */
markrad 0:cdf462088d13 483 for( i = 0; i < unmet_dep_count; i++ )
markrad 0:cdf462088d13 484 free( unmet_dependencies[i] );
markrad 0:cdf462088d13 485 }
markrad 0:cdf462088d13 486
markrad 0:cdf462088d13 487 mbedtls_fprintf( stdout, "\n----------------------------------------------------------------------------\n\n");
markrad 0:cdf462088d13 488 if( total_errors == 0 )
markrad 0:cdf462088d13 489 mbedtls_fprintf( stdout, "PASSED" );
markrad 0:cdf462088d13 490 else
markrad 0:cdf462088d13 491 mbedtls_fprintf( stdout, "FAILED" );
markrad 0:cdf462088d13 492
markrad 0:cdf462088d13 493 mbedtls_fprintf( stdout, " (%d / %d tests (%d skipped))\n",
markrad 0:cdf462088d13 494 total_tests - total_errors, total_tests, total_skipped );
markrad 0:cdf462088d13 495
markrad 0:cdf462088d13 496 #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
markrad 0:cdf462088d13 497 !defined(TEST_SUITE_MEMORY_BUFFER_ALLOC)
markrad 0:cdf462088d13 498 #if defined(MBEDTLS_MEMORY_DEBUG)
markrad 0:cdf462088d13 499 mbedtls_memory_buffer_alloc_status();
markrad 0:cdf462088d13 500 #endif
markrad 0:cdf462088d13 501 mbedtls_memory_buffer_alloc_free();
markrad 0:cdf462088d13 502 #endif
markrad 0:cdf462088d13 503
markrad 0:cdf462088d13 504 #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
markrad 0:cdf462088d13 505 if( stdout_fd != -1 )
markrad 0:cdf462088d13 506 close_output( stdout );
markrad 0:cdf462088d13 507 #endif /* __unix__ || __APPLE__ __MACH__ */
markrad 0:cdf462088d13 508
markrad 0:cdf462088d13 509 return( total_errors != 0 );
markrad 0:cdf462088d13 510 }
markrad 0:cdf462088d13 511