blob: faae34b87edae000eb238bfe7fdf7e01b3e91a95 [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>
9#include <platform_def.h> /* For TESTCASE_OUTPUT_MAX_SIZE */
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020010#include <stdio.h>
11#include <string.h>
12#include <tftf.h>
13
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020014static unsigned int total_tests;
15static unsigned int tests_stats[TEST_RESULT_MAX];
16
17static void tftf_update_tests_statistics(test_result_t result)
18{
19 assert(TEST_RESULT_IS_VALID(result));
20 total_tests++;
21 tests_stats[result]++;
22}
23
24static const char *test_result_strings[TEST_RESULT_MAX] = {
25 "Skipped", "Passed", "Failed", "Crashed",
26};
27
28const char *test_result_to_string(test_result_t result)
29{
30 assert(TEST_RESULT_IS_VALID(result));
31 return test_result_strings[result];
32}
33
Sandrine Bailleux68d76a22018-11-07 16:31:23 +010034void tftf_report_generate(void)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020035{
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020036 unsigned i, j;
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020037 const test_case_t *testcases;
38 TESTCASE_RESULT testcase_result;
39 char test_output[TESTCASE_OUTPUT_MAX_SIZE];
40 STATUS status;
41
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020042 /* Extract the result of all the testcases */
Sandrine Bailleux68d76a22018-11-07 16:31:23 +010043 printf("========== TEST REPORT ==========\n");
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020044 for (i = 0; testsuites[i].name != NULL; i++) {
Sandrine Bailleux68d76a22018-11-07 16:31:23 +010045 printf("# Test suite '%s':\n", testsuites[i].name);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020046 testcases = testsuites[i].testcases;
47
48 for (j = 0; testcases[j].name != NULL; j++) {
49 status = tftf_testcase_get_result(&testcases[j], &testcase_result, test_output);
50 if (status != STATUS_SUCCESS) {
Sandrine Bailleux68d76a22018-11-07 16:31:23 +010051 printf("Failed to get test result.\n");
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020052 continue;
53 }
54
55 tftf_update_tests_statistics(testcase_result.result);
56 /* TODO: print test duration */
Sandrine Bailleux68d76a22018-11-07 16:31:23 +010057 printf("\t - %s: %s\n", testcases[j].name,
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020058 test_result_to_string(testcase_result.result));
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020059
60 if (strlen(test_output) != 0) {
Sandrine Bailleux68d76a22018-11-07 16:31:23 +010061 printf("--- output ---\n");
62 printf("%s", test_output);
63 printf("--------------\n");
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020064 }
65 }
66 }
Sandrine Bailleux68d76a22018-11-07 16:31:23 +010067 printf("=================================\n");
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020068
69 for (i = TEST_RESULT_MIN; i < TEST_RESULT_MAX; i++) {
Sandrine Bailleux68d76a22018-11-07 16:31:23 +010070 printf("Tests %-8s: %d\n",
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020071 test_result_to_string(i), tests_stats[i]);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020072 }
Sandrine Bailleux68d76a22018-11-07 16:31:23 +010073 printf("%-14s: %d\n", "Total tests", total_tests);
74 printf("=================================\n");
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020075}