host_test.function 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. #line 2 "suites/host_test.function"
  2. /**
  3. * \brief Verifies that string is in string parameter format i.e. "<str>"
  4. * It also strips enclosing '"' from the input string.
  5. *
  6. * \param str String parameter.
  7. *
  8. * \return 0 if success else 1
  9. */
  10. int verify_string(char **str)
  11. {
  12. if ((*str)[0] != '"' ||
  13. (*str)[strlen(*str) - 1] != '"') {
  14. mbedtls_fprintf(stderr,
  15. "Expected string (with \"\") for parameter and got: %s\n", *str);
  16. return -1;
  17. }
  18. (*str)++;
  19. (*str)[strlen(*str) - 1] = '\0';
  20. return 0;
  21. }
  22. /**
  23. * \brief Verifies that string is an integer. Also gives the converted
  24. * integer value.
  25. *
  26. * \param str Input string.
  27. * \param value Pointer to int for output value.
  28. *
  29. * \return 0 if success else 1
  30. */
  31. int verify_int(char *str, int32_t *value)
  32. {
  33. size_t i;
  34. int minus = 0;
  35. int digits = 1;
  36. int hex = 0;
  37. for (i = 0; i < strlen(str); i++) {
  38. if (i == 0 && str[i] == '-') {
  39. minus = 1;
  40. continue;
  41. }
  42. if (((minus && i == 2) || (!minus && i == 1)) &&
  43. str[i - 1] == '0' && (str[i] == 'x' || str[i] == 'X')) {
  44. hex = 1;
  45. continue;
  46. }
  47. if (!((str[i] >= '0' && str[i] <= '9') ||
  48. (hex && ((str[i] >= 'a' && str[i] <= 'f') ||
  49. (str[i] >= 'A' && str[i] <= 'F'))))) {
  50. digits = 0;
  51. break;
  52. }
  53. }
  54. if (digits) {
  55. if (hex) {
  56. *value = strtol(str, NULL, 16);
  57. } else {
  58. *value = strtol(str, NULL, 10);
  59. }
  60. return 0;
  61. }
  62. mbedtls_fprintf(stderr,
  63. "Expected integer for parameter and got: %s\n", str);
  64. return KEY_VALUE_MAPPING_NOT_FOUND;
  65. }
  66. /**
  67. * \brief Usage string.
  68. *
  69. */
  70. #define USAGE \
  71. "Usage: %s [OPTIONS] files...\n\n" \
  72. " Command line arguments:\n" \
  73. " files... One or more test data files. If no file is\n" \
  74. " specified the following default test case\n" \
  75. " file is used:\n" \
  76. " %s\n\n" \
  77. " Options:\n" \
  78. " -v | --verbose Display full information about each test\n" \
  79. " -h | --help Display this information\n\n", \
  80. argv[0], \
  81. "TESTCASE_FILENAME"
  82. /**
  83. * \brief Read a line from the passed file pointer.
  84. *
  85. * \param f FILE pointer
  86. * \param buf Pointer to memory to hold read line.
  87. * \param len Length of the buf.
  88. *
  89. * \return 0 if success else -1
  90. */
  91. int get_line(FILE *f, char *buf, size_t len)
  92. {
  93. char *ret;
  94. int i = 0, str_len = 0, has_string = 0;
  95. /* Read until we get a valid line */
  96. do {
  97. ret = fgets(buf, len, f);
  98. if (ret == NULL) {
  99. return -1;
  100. }
  101. str_len = strlen(buf);
  102. /* Skip empty line and comment */
  103. if (str_len == 0 || buf[0] == '#') {
  104. continue;
  105. }
  106. has_string = 0;
  107. for (i = 0; i < str_len; i++) {
  108. char c = buf[i];
  109. if (c != ' ' && c != '\t' && c != '\n' &&
  110. c != '\v' && c != '\f' && c != '\r') {
  111. has_string = 1;
  112. break;
  113. }
  114. }
  115. } while (!has_string);
  116. /* Strip new line and carriage return */
  117. ret = buf + strlen(buf);
  118. if (ret-- > buf && *ret == '\n') {
  119. *ret = '\0';
  120. }
  121. if (ret-- > buf && *ret == '\r') {
  122. *ret = '\0';
  123. }
  124. return 0;
  125. }
  126. /**
  127. * \brief Splits string delimited by ':'. Ignores '\:'.
  128. *
  129. * \param buf Input string
  130. * \param len Input string length
  131. * \param params Out params found
  132. * \param params_len Out params array len
  133. *
  134. * \return Count of strings found.
  135. */
  136. static int parse_arguments(char *buf, size_t len, char **params,
  137. size_t params_len)
  138. {
  139. size_t cnt = 0, i;
  140. char *cur = buf;
  141. char *p = buf, *q;
  142. params[cnt++] = cur;
  143. while (*p != '\0' && p < (buf + len)) {
  144. if (*p == '\\') {
  145. p++;
  146. p++;
  147. continue;
  148. }
  149. if (*p == ':') {
  150. if (p + 1 < buf + len) {
  151. cur = p + 1;
  152. TEST_HELPER_ASSERT(cnt < params_len);
  153. params[cnt++] = cur;
  154. }
  155. *p = '\0';
  156. }
  157. p++;
  158. }
  159. /* Replace newlines, question marks and colons in strings */
  160. for (i = 0; i < cnt; i++) {
  161. p = params[i];
  162. q = params[i];
  163. while (*p != '\0') {
  164. if (*p == '\\' && *(p + 1) == 'n') {
  165. p += 2;
  166. *(q++) = '\n';
  167. } else if (*p == '\\' && *(p + 1) == ':') {
  168. p += 2;
  169. *(q++) = ':';
  170. } else if (*p == '\\' && *(p + 1) == '?') {
  171. p += 2;
  172. *(q++) = '?';
  173. } else {
  174. *(q++) = *(p++);
  175. }
  176. }
  177. *q = '\0';
  178. }
  179. return cnt;
  180. }
  181. /**
  182. * \brief Converts parameters into test function consumable parameters.
  183. * Example: Input: {"int", "0", "char*", "Hello",
  184. * "hex", "abef", "exp", "1"}
  185. * Output: {
  186. * 0, // Verified int
  187. * "Hello", // Verified string
  188. * 2, { 0xab, 0xef },// Converted len,hex pair
  189. * 9600 // Evaluated expression
  190. * }
  191. *
  192. *
  193. * \param cnt Parameter array count.
  194. * \param params Out array of found parameters.
  195. * \param int_params_store Memory for storing processed integer parameters.
  196. *
  197. * \return 0 for success else 1
  198. */
  199. static int convert_params(size_t cnt, char **params, int32_t *int_params_store)
  200. {
  201. char **cur = params;
  202. char **out = params;
  203. int ret = DISPATCH_TEST_SUCCESS;
  204. while (cur < params + cnt) {
  205. char *type = *cur++;
  206. char *val = *cur++;
  207. if (strcmp(type, "char*") == 0) {
  208. if (verify_string(&val) == 0) {
  209. *out++ = val;
  210. } else {
  211. ret = (DISPATCH_INVALID_TEST_DATA);
  212. break;
  213. }
  214. } else if (strcmp(type, "int") == 0) {
  215. if (verify_int(val, int_params_store) == 0) {
  216. *out++ = (char *) int_params_store++;
  217. } else {
  218. ret = (DISPATCH_INVALID_TEST_DATA);
  219. break;
  220. }
  221. } else if (strcmp(type, "hex") == 0) {
  222. if (verify_string(&val) == 0) {
  223. size_t len;
  224. TEST_HELPER_ASSERT(
  225. mbedtls_test_unhexify((unsigned char *) val, strlen(val),
  226. val, &len) == 0);
  227. *int_params_store = len;
  228. *out++ = val;
  229. *out++ = (char *) (int_params_store++);
  230. } else {
  231. ret = (DISPATCH_INVALID_TEST_DATA);
  232. break;
  233. }
  234. } else if (strcmp(type, "exp") == 0) {
  235. int exp_id = strtol(val, NULL, 10);
  236. if (get_expression(exp_id, int_params_store) == 0) {
  237. *out++ = (char *) int_params_store++;
  238. } else {
  239. ret = (DISPATCH_INVALID_TEST_DATA);
  240. break;
  241. }
  242. } else {
  243. ret = (DISPATCH_INVALID_TEST_DATA);
  244. break;
  245. }
  246. }
  247. return ret;
  248. }
  249. /**
  250. * \brief Tests snprintf implementation with test input.
  251. *
  252. * \note
  253. * At high optimization levels (e.g. gcc -O3), this function may be
  254. * inlined in run_test_snprintf. This can trigger a spurious warning about
  255. * potential misuse of snprintf from gcc -Wformat-truncation (observed with
  256. * gcc 7.2). This warning makes tests in run_test_snprintf redundant on gcc
  257. * only. They are still valid for other compilers. Avoid this warning by
  258. * forbidding inlining of this function by gcc.
  259. *
  260. * \param n Buffer test length.
  261. * \param ref_buf Expected buffer.
  262. * \param ref_ret Expected snprintf return value.
  263. *
  264. * \return 0 for success else 1
  265. */
  266. #if defined(__GNUC__)
  267. __attribute__((__noinline__))
  268. #endif
  269. static int test_snprintf(size_t n, const char *ref_buf, int ref_ret)
  270. {
  271. int ret;
  272. char buf[10] = "xxxxxxxxx";
  273. const char ref[10] = "xxxxxxxxx";
  274. if (n >= sizeof(buf)) {
  275. return -1;
  276. }
  277. ret = mbedtls_snprintf(buf, n, "%s", "123");
  278. if (ret < 0 || (size_t) ret >= n) {
  279. ret = -1;
  280. }
  281. if (strncmp(ref_buf, buf, sizeof(buf)) != 0 ||
  282. ref_ret != ret ||
  283. memcmp(buf + n, ref + n, sizeof(buf) - n) != 0) {
  284. return 1;
  285. }
  286. return 0;
  287. }
  288. /**
  289. * \brief Tests snprintf implementation.
  290. *
  291. * \return 0 for success else 1
  292. */
  293. static int run_test_snprintf(void)
  294. {
  295. return test_snprintf(0, "xxxxxxxxx", -1) != 0 ||
  296. test_snprintf(1, "", -1) != 0 ||
  297. test_snprintf(2, "1", -1) != 0 ||
  298. test_snprintf(3, "12", -1) != 0 ||
  299. test_snprintf(4, "123", 3) != 0 ||
  300. test_snprintf(5, "123", 3) != 0;
  301. }
  302. /** \brief Write the description of the test case to the outcome CSV file.
  303. *
  304. * \param outcome_file The file to write to.
  305. * If this is \c NULL, this function does nothing.
  306. * \param argv0 The test suite name.
  307. * \param test_case The test case description.
  308. */
  309. static void write_outcome_entry(FILE *outcome_file,
  310. const char *argv0,
  311. const char *test_case)
  312. {
  313. /* The non-varying fields are initialized on first use. */
  314. static const char *platform = NULL;
  315. static const char *configuration = NULL;
  316. static const char *test_suite = NULL;
  317. if (outcome_file == NULL) {
  318. return;
  319. }
  320. if (platform == NULL) {
  321. platform = getenv("MBEDTLS_TEST_PLATFORM");
  322. if (platform == NULL) {
  323. platform = "unknown";
  324. }
  325. }
  326. if (configuration == NULL) {
  327. configuration = getenv("MBEDTLS_TEST_CONFIGURATION");
  328. if (configuration == NULL) {
  329. configuration = "unknown";
  330. }
  331. }
  332. if (test_suite == NULL) {
  333. test_suite = strrchr(argv0, '/');
  334. if (test_suite != NULL) {
  335. test_suite += 1; // skip the '/'
  336. } else {
  337. test_suite = argv0;
  338. }
  339. }
  340. /* Write the beginning of the outcome line.
  341. * Ignore errors: writing the outcome file is on a best-effort basis. */
  342. mbedtls_fprintf(outcome_file, "%s;%s;%s;%s;",
  343. platform, configuration, test_suite, test_case);
  344. }
  345. /** \brief Write the result of the test case to the outcome CSV file.
  346. *
  347. * \param outcome_file The file to write to.
  348. * If this is \c NULL, this function does nothing.
  349. * \param unmet_dep_count The number of unmet dependencies.
  350. * \param unmet_dependencies The array of unmet dependencies.
  351. * \param missing_unmet_dependencies Non-zero if there was a problem tracking
  352. * all unmet dependencies, 0 otherwise.
  353. * \param ret The test dispatch status (DISPATCH_xxx).
  354. * \param info A pointer to the test info structure.
  355. */
  356. static void write_outcome_result(FILE *outcome_file,
  357. size_t unmet_dep_count,
  358. int unmet_dependencies[],
  359. int missing_unmet_dependencies,
  360. int ret,
  361. const mbedtls_test_info_t *info)
  362. {
  363. if (outcome_file == NULL) {
  364. return;
  365. }
  366. /* Write the end of the outcome line.
  367. * Ignore errors: writing the outcome file is on a best-effort basis. */
  368. switch (ret) {
  369. case DISPATCH_TEST_SUCCESS:
  370. if (unmet_dep_count > 0) {
  371. size_t i;
  372. mbedtls_fprintf(outcome_file, "SKIP");
  373. for (i = 0; i < unmet_dep_count; i++) {
  374. mbedtls_fprintf(outcome_file, "%c%d",
  375. i == 0 ? ';' : ':',
  376. unmet_dependencies[i]);
  377. }
  378. if (missing_unmet_dependencies) {
  379. mbedtls_fprintf(outcome_file, ":...");
  380. }
  381. break;
  382. }
  383. switch (info->result) {
  384. case MBEDTLS_TEST_RESULT_SUCCESS:
  385. mbedtls_fprintf(outcome_file, "PASS;");
  386. break;
  387. case MBEDTLS_TEST_RESULT_SKIPPED:
  388. mbedtls_fprintf(outcome_file, "SKIP;Runtime skip");
  389. break;
  390. default:
  391. mbedtls_fprintf(outcome_file, "FAIL;%s:%d:%s",
  392. info->filename, info->line_no,
  393. info->test);
  394. break;
  395. }
  396. break;
  397. case DISPATCH_TEST_FN_NOT_FOUND:
  398. mbedtls_fprintf(outcome_file, "FAIL;Test function not found");
  399. break;
  400. case DISPATCH_INVALID_TEST_DATA:
  401. mbedtls_fprintf(outcome_file, "FAIL;Invalid test data");
  402. break;
  403. case DISPATCH_UNSUPPORTED_SUITE:
  404. mbedtls_fprintf(outcome_file, "SKIP;Unsupported suite");
  405. break;
  406. default:
  407. mbedtls_fprintf(outcome_file, "FAIL;Unknown cause");
  408. break;
  409. }
  410. mbedtls_fprintf(outcome_file, "\n");
  411. fflush(outcome_file);
  412. }
  413. /**
  414. * \brief Desktop implementation of execute_tests().
  415. * Parses command line and executes tests from
  416. * supplied or default data file.
  417. *
  418. * \param argc Command line argument count.
  419. * \param argv Argument array.
  420. *
  421. * \return Program exit status.
  422. */
  423. int execute_tests(int argc, const char **argv)
  424. {
  425. /* Local Configurations and options */
  426. const char *default_filename = "DATA_FILE";
  427. const char *test_filename = NULL;
  428. const char **test_files = NULL;
  429. size_t testfile_count = 0;
  430. int option_verbose = 0;
  431. size_t function_id = 0;
  432. /* Other Local variables */
  433. int arg_index = 1;
  434. const char *next_arg;
  435. size_t testfile_index, i, cnt;
  436. int ret;
  437. unsigned total_errors = 0, total_tests = 0, total_skipped = 0;
  438. FILE *file;
  439. char buf[5000];
  440. char *params[50];
  441. /* Store for processed integer params. */
  442. int32_t int_params[50];
  443. void *pointer;
  444. #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
  445. int stdout_fd = -1;
  446. #endif /* __unix__ || __APPLE__ __MACH__ */
  447. const char *outcome_file_name = getenv("MBEDTLS_TEST_OUTCOME_FILE");
  448. FILE *outcome_file = NULL;
  449. #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
  450. !defined(TEST_SUITE_MEMORY_BUFFER_ALLOC)
  451. unsigned char alloc_buf[1000000];
  452. mbedtls_memory_buffer_alloc_init(alloc_buf, sizeof(alloc_buf));
  453. #endif
  454. #if defined(MBEDTLS_TEST_MUTEX_USAGE)
  455. mbedtls_test_mutex_usage_init();
  456. #endif
  457. /*
  458. * The C standard doesn't guarantee that all-bits-0 is the representation
  459. * of a NULL pointer. We do however use that in our code for initializing
  460. * structures, which should work on every modern platform. Let's be sure.
  461. */
  462. memset(&pointer, 0, sizeof(void *));
  463. if (pointer != NULL) {
  464. mbedtls_fprintf(stderr, "all-bits-zero is not a NULL pointer\n");
  465. return 1;
  466. }
  467. /*
  468. * Make sure we have a snprintf that correctly zero-terminates
  469. */
  470. if (run_test_snprintf() != 0) {
  471. mbedtls_fprintf(stderr, "the snprintf implementation is broken\n");
  472. return 1;
  473. }
  474. if (outcome_file_name != NULL && *outcome_file_name != '\0') {
  475. outcome_file = fopen(outcome_file_name, "a");
  476. if (outcome_file == NULL) {
  477. mbedtls_fprintf(stderr, "Unable to open outcome file. Continuing anyway.\n");
  478. }
  479. }
  480. while (arg_index < argc) {
  481. next_arg = argv[arg_index];
  482. if (strcmp(next_arg, "--verbose") == 0 ||
  483. strcmp(next_arg, "-v") == 0) {
  484. option_verbose = 1;
  485. } else if (strcmp(next_arg, "--help") == 0 ||
  486. strcmp(next_arg, "-h") == 0) {
  487. mbedtls_fprintf(stdout, USAGE);
  488. mbedtls_exit(EXIT_SUCCESS);
  489. } else {
  490. /* Not an option, therefore treat all further arguments as the file
  491. * list.
  492. */
  493. test_files = &argv[arg_index];
  494. testfile_count = argc - arg_index;
  495. break;
  496. }
  497. arg_index++;
  498. }
  499. /* If no files were specified, assume a default */
  500. if (test_files == NULL || testfile_count == 0) {
  501. test_files = &default_filename;
  502. testfile_count = 1;
  503. }
  504. /* Initialize the struct that holds information about the last test */
  505. mbedtls_test_info_reset();
  506. /* Now begin to execute the tests in the testfiles */
  507. for (testfile_index = 0;
  508. testfile_index < testfile_count;
  509. testfile_index++) {
  510. size_t unmet_dep_count = 0;
  511. int unmet_dependencies[20];
  512. int missing_unmet_dependencies = 0;
  513. test_filename = test_files[testfile_index];
  514. file = fopen(test_filename, "r");
  515. if (file == NULL) {
  516. mbedtls_fprintf(stderr, "Failed to open test file: %s\n",
  517. test_filename);
  518. if (outcome_file != NULL) {
  519. fclose(outcome_file);
  520. }
  521. return 1;
  522. }
  523. while (!feof(file)) {
  524. if (unmet_dep_count > 0) {
  525. mbedtls_fprintf(stderr,
  526. "FATAL: Dep count larger than zero at start of loop\n");
  527. mbedtls_exit(MBEDTLS_EXIT_FAILURE);
  528. }
  529. unmet_dep_count = 0;
  530. missing_unmet_dependencies = 0;
  531. if ((ret = get_line(file, buf, sizeof(buf))) != 0) {
  532. break;
  533. }
  534. mbedtls_fprintf(stdout, "%s%.66s",
  535. mbedtls_test_info.result == MBEDTLS_TEST_RESULT_FAILED ?
  536. "\n" : "", buf);
  537. mbedtls_fprintf(stdout, " ");
  538. for (i = strlen(buf) + 1; i < 67; i++) {
  539. mbedtls_fprintf(stdout, ".");
  540. }
  541. mbedtls_fprintf(stdout, " ");
  542. fflush(stdout);
  543. write_outcome_entry(outcome_file, argv[0], buf);
  544. total_tests++;
  545. if ((ret = get_line(file, buf, sizeof(buf))) != 0) {
  546. break;
  547. }
  548. cnt = parse_arguments(buf, strlen(buf), params,
  549. sizeof(params) / sizeof(params[0]));
  550. if (strcmp(params[0], "depends_on") == 0) {
  551. for (i = 1; i < cnt; i++) {
  552. int dep_id = strtol(params[i], NULL, 10);
  553. if (dep_check(dep_id) != DEPENDENCY_SUPPORTED) {
  554. if (unmet_dep_count <
  555. ARRAY_LENGTH(unmet_dependencies)) {
  556. unmet_dependencies[unmet_dep_count] = dep_id;
  557. unmet_dep_count++;
  558. } else {
  559. missing_unmet_dependencies = 1;
  560. }
  561. }
  562. }
  563. if ((ret = get_line(file, buf, sizeof(buf))) != 0) {
  564. break;
  565. }
  566. cnt = parse_arguments(buf, strlen(buf), params,
  567. sizeof(params) / sizeof(params[0]));
  568. }
  569. // If there are no unmet dependencies execute the test
  570. if (unmet_dep_count == 0) {
  571. mbedtls_test_info_reset();
  572. #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
  573. /* Suppress all output from the library unless we're verbose
  574. * mode
  575. */
  576. if (!option_verbose) {
  577. stdout_fd = redirect_output(stdout, "/dev/null");
  578. if (stdout_fd == -1) {
  579. /* Redirection has failed with no stdout so exit */
  580. exit(1);
  581. }
  582. }
  583. #endif /* __unix__ || __APPLE__ __MACH__ */
  584. function_id = strtoul(params[0], NULL, 10);
  585. if ((ret = check_test(function_id)) == DISPATCH_TEST_SUCCESS) {
  586. ret = convert_params(cnt - 1, params + 1, int_params);
  587. if (DISPATCH_TEST_SUCCESS == ret) {
  588. ret = dispatch_test(function_id, (void **) (params + 1));
  589. }
  590. }
  591. #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
  592. if (!option_verbose && restore_output(stdout, stdout_fd)) {
  593. /* Redirection has failed with no stdout so exit */
  594. exit(1);
  595. }
  596. #endif /* __unix__ || __APPLE__ __MACH__ */
  597. }
  598. write_outcome_result(outcome_file,
  599. unmet_dep_count, unmet_dependencies,
  600. missing_unmet_dependencies,
  601. ret, &mbedtls_test_info);
  602. if (unmet_dep_count > 0 || ret == DISPATCH_UNSUPPORTED_SUITE) {
  603. total_skipped++;
  604. mbedtls_fprintf(stdout, "----");
  605. if (1 == option_verbose && ret == DISPATCH_UNSUPPORTED_SUITE) {
  606. mbedtls_fprintf(stdout, "\n Test Suite not enabled");
  607. }
  608. if (1 == option_verbose && unmet_dep_count > 0) {
  609. mbedtls_fprintf(stdout, "\n Unmet dependencies: ");
  610. for (i = 0; i < unmet_dep_count; i++) {
  611. mbedtls_fprintf(stdout, "%d ",
  612. unmet_dependencies[i]);
  613. }
  614. if (missing_unmet_dependencies) {
  615. mbedtls_fprintf(stdout, "...");
  616. }
  617. }
  618. mbedtls_fprintf(stdout, "\n");
  619. fflush(stdout);
  620. unmet_dep_count = 0;
  621. missing_unmet_dependencies = 0;
  622. } else if (ret == DISPATCH_TEST_SUCCESS) {
  623. if (mbedtls_test_info.result == MBEDTLS_TEST_RESULT_SUCCESS) {
  624. mbedtls_fprintf(stdout, "PASS\n");
  625. } else if (mbedtls_test_info.result == MBEDTLS_TEST_RESULT_SKIPPED) {
  626. mbedtls_fprintf(stdout, "----\n");
  627. total_skipped++;
  628. } else {
  629. total_errors++;
  630. mbedtls_fprintf(stdout, "FAILED\n");
  631. mbedtls_fprintf(stdout, " %s\n at ",
  632. mbedtls_test_info.test);
  633. if (mbedtls_test_info.step != (unsigned long) (-1)) {
  634. mbedtls_fprintf(stdout, "step %lu, ",
  635. mbedtls_test_info.step);
  636. }
  637. mbedtls_fprintf(stdout, "line %d, %s",
  638. mbedtls_test_info.line_no,
  639. mbedtls_test_info.filename);
  640. if (mbedtls_test_info.line1[0] != 0) {
  641. mbedtls_fprintf(stdout, "\n %s",
  642. mbedtls_test_info.line1);
  643. }
  644. if (mbedtls_test_info.line2[0] != 0) {
  645. mbedtls_fprintf(stdout, "\n %s",
  646. mbedtls_test_info.line2);
  647. }
  648. }
  649. fflush(stdout);
  650. } else if (ret == DISPATCH_INVALID_TEST_DATA) {
  651. mbedtls_fprintf(stderr, "FAILED: FATAL PARSE ERROR\n");
  652. fclose(file);
  653. mbedtls_exit(2);
  654. } else if (ret == DISPATCH_TEST_FN_NOT_FOUND) {
  655. mbedtls_fprintf(stderr, "FAILED: FATAL TEST FUNCTION NOT FOUND\n");
  656. fclose(file);
  657. mbedtls_exit(2);
  658. } else {
  659. total_errors++;
  660. }
  661. }
  662. fclose(file);
  663. }
  664. if (outcome_file != NULL) {
  665. fclose(outcome_file);
  666. }
  667. mbedtls_fprintf(stdout,
  668. "\n----------------------------------------------------------------------------\n\n");
  669. if (total_errors == 0) {
  670. mbedtls_fprintf(stdout, "PASSED");
  671. } else {
  672. mbedtls_fprintf(stdout, "FAILED");
  673. }
  674. mbedtls_fprintf(stdout, " (%u / %u tests (%u skipped))\n",
  675. total_tests - total_errors, total_tests, total_skipped);
  676. #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
  677. !defined(TEST_SUITE_MEMORY_BUFFER_ALLOC)
  678. #if defined(MBEDTLS_MEMORY_DEBUG)
  679. mbedtls_memory_buffer_alloc_status();
  680. #endif
  681. mbedtls_memory_buffer_alloc_free();
  682. #endif
  683. return total_errors != 0;
  684. }