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