blob: 663caf365e4010570fbb84ed0320452d40579fc2 [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001/*
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 Bailleux3cd87d72018-10-09 11:12:55 +02009#include <stdio.h>
Sandrine Bailleux125d58c2018-11-07 17:11:59 +010010#include <stdbool.h>
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020011#include <tftf.h>
12
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020013static const char *test_result_strings[TEST_RESULT_MAX] = {
14 "Skipped", "Passed", "Failed", "Crashed",
15};
16
Sandrine Bailleux125d58c2018-11-07 17:11:59 +010017static const char *test_result_to_string(test_result_t result)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020018{
19 assert(TEST_RESULT_IS_VALID(result));
20 return test_result_strings[result];
21}
22
Sandrine Bailleux125d58c2018-11-07 17:11:59 +010023void print_testsuite_start(const test_suite_t *testsuite)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020024{
Sandrine Bailleux125d58c2018-11-07 17:11:59 +010025 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 Bailleux3cd87d72018-10-09 11:12:55 +020030
Sandrine Bailleux125d58c2018-11-07 17:11:59 +010031void print_test_start(const test_case_t *test)
32{
33 mp_printf("> Executing '%s'\n", test->name);
34}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020035
Sandrine Bailleux125d58c2018-11-07 17:11:59 +010036void 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
51void 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 Bailleux3cd87d72018-10-09 11:12:55 +020074 continue;
75 }
76
Sandrine Bailleux125d58c2018-11-07 17:11:59 +010077 assert(TEST_RESULT_IS_VALID(result.result));
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020078
Sandrine Bailleux125d58c2018-11-07 17:11:59 +010079 /*
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 Bailleux3cd87d72018-10-09 11:12:55 +020086 }
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020087
Sandrine Bailleux125d58c2018-11-07 17:11:59 +010088 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 Bailleux3cd87d72018-10-09 11:12:55 +020098 test_result_to_string(i), tests_stats[i]);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020099 }
Sandrine Bailleux125d58c2018-11-07 17:11:59 +0100100 mp_printf("%-14s: %d\n", "Total tests", total_tests);
101 mp_printf("=================================\n");
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200102}