Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <assert.h> |
| 8 | #include <debug.h> |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 9 | #include <stdio.h> |
Sandrine Bailleux | 125d58c | 2018-11-07 17:11:59 +0100 | [diff] [blame] | 10 | #include <stdbool.h> |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 11 | #include <tftf.h> |
| 12 | |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 13 | static const char *test_result_strings[TEST_RESULT_MAX] = { |
| 14 | "Skipped", "Passed", "Failed", "Crashed", |
| 15 | }; |
| 16 | |
Sandrine Bailleux | 125d58c | 2018-11-07 17:11:59 +0100 | [diff] [blame] | 17 | static const char *test_result_to_string(test_result_t result) |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 18 | { |
| 19 | assert(TEST_RESULT_IS_VALID(result)); |
| 20 | return test_result_strings[result]; |
| 21 | } |
| 22 | |
Sandrine Bailleux | 125d58c | 2018-11-07 17:11:59 +0100 | [diff] [blame] | 23 | void print_testsuite_start(const test_suite_t *testsuite) |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 24 | { |
Sandrine Bailleux | 125d58c | 2018-11-07 17:11:59 +0100 | [diff] [blame] | 25 | mp_printf("--\n"); |
| 26 | mp_printf("Running test suite '%s'\n", testsuite->name); |
| 27 | mp_printf("Description: %s\n", testsuite->description); |
| 28 | mp_printf("\n"); |
| 29 | } |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 30 | |
Sandrine Bailleux | 125d58c | 2018-11-07 17:11:59 +0100 | [diff] [blame] | 31 | void print_test_start(const test_case_t *test) |
| 32 | { |
| 33 | mp_printf("> Executing '%s'\n", test->name); |
| 34 | } |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 35 | |
Sandrine Bailleux | 125d58c | 2018-11-07 17:11:59 +0100 | [diff] [blame] | 36 | void print_test_end(const test_case_t *test) |
| 37 | { |
| 38 | TESTCASE_RESULT result; |
| 39 | char output[TESTCASE_OUTPUT_MAX_SIZE]; |
| 40 | |
| 41 | tftf_testcase_get_result(test, &result, output); |
| 42 | |
| 43 | mp_printf(" TEST COMPLETE %54s\n", |
| 44 | test_result_to_string(result.result)); |
| 45 | if (strlen(output) != 0) { |
| 46 | mp_printf("%s", output); |
| 47 | } |
| 48 | mp_printf("\n"); |
| 49 | } |
| 50 | |
| 51 | void print_tests_summary(void) |
| 52 | { |
| 53 | int total_tests = 0; |
| 54 | int tests_stats[TEST_RESULT_MAX] = { 0 }; |
| 55 | |
| 56 | mp_printf("******************************* Summary *******************************\n"); |
| 57 | |
| 58 | /* Go through the list of test suites. */ |
| 59 | for (int i = 0; testsuites[i].name != NULL; i++) { |
| 60 | bool passed = true; |
| 61 | |
| 62 | mp_printf("> Test suite '%s'\n", testsuites[i].name); |
| 63 | |
| 64 | const test_case_t *testcases = testsuites[i].testcases; |
| 65 | |
| 66 | /* Go through the list of tests inside this test suite. */ |
| 67 | for (int j = 0; testcases[j].name != NULL; j++) { |
| 68 | TESTCASE_RESULT result; |
| 69 | char output[TESTCASE_OUTPUT_MAX_SIZE]; |
| 70 | |
| 71 | if (tftf_testcase_get_result(&testcases[j], &result, |
| 72 | output) != STATUS_SUCCESS) { |
| 73 | mp_printf("Failed to get test result.\n"); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 74 | continue; |
| 75 | } |
| 76 | |
Sandrine Bailleux | 125d58c | 2018-11-07 17:11:59 +0100 | [diff] [blame] | 77 | assert(TEST_RESULT_IS_VALID(result.result)); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 78 | |
Sandrine Bailleux | 125d58c | 2018-11-07 17:11:59 +0100 | [diff] [blame] | 79 | /* |
| 80 | * Consider that a test suite passed if all of its |
| 81 | * tests passed or were skipped. |
| 82 | */ |
| 83 | if ((result.result != TEST_RESULT_SUCCESS) && |
| 84 | (result.result != TEST_RESULT_SKIPPED)) { |
| 85 | passed = false; |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 86 | } |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 87 | |
Sandrine Bailleux | 125d58c | 2018-11-07 17:11:59 +0100 | [diff] [blame] | 88 | total_tests++; |
| 89 | tests_stats[result.result]++; |
| 90 | } |
| 91 | mp_printf("%70s\n", passed ? "Passed" : "Failed"); |
| 92 | } |
| 93 | |
| 94 | mp_printf("=================================\n"); |
| 95 | |
| 96 | for (int i = TEST_RESULT_MIN; i < TEST_RESULT_MAX; i++) { |
| 97 | mp_printf("Tests %-8s: %d\n", |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 98 | test_result_to_string(i), tests_stats[i]); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 99 | } |
Sandrine Bailleux | 125d58c | 2018-11-07 17:11:59 +0100 | [diff] [blame] | 100 | mp_printf("%-14s: %d\n", "Total tests", total_tests); |
| 101 | mp_printf("=================================\n"); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 102 | } |