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> |
| 9 | #include <platform_def.h> /* For TESTCASE_OUTPUT_MAX_SIZE */ |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 10 | #include <stdio.h> |
| 11 | #include <string.h> |
| 12 | #include <tftf.h> |
| 13 | |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 14 | static unsigned int total_tests; |
| 15 | static unsigned int tests_stats[TEST_RESULT_MAX]; |
| 16 | |
| 17 | static 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 | |
| 24 | static const char *test_result_strings[TEST_RESULT_MAX] = { |
| 25 | "Skipped", "Passed", "Failed", "Crashed", |
| 26 | }; |
| 27 | |
| 28 | const 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 Bailleux | 68d76a2 | 2018-11-07 16:31:23 +0100 | [diff] [blame] | 34 | void tftf_report_generate(void) |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 35 | { |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 36 | unsigned i, j; |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 37 | const test_case_t *testcases; |
| 38 | TESTCASE_RESULT testcase_result; |
| 39 | char test_output[TESTCASE_OUTPUT_MAX_SIZE]; |
| 40 | STATUS status; |
| 41 | |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 42 | /* Extract the result of all the testcases */ |
Sandrine Bailleux | 68d76a2 | 2018-11-07 16:31:23 +0100 | [diff] [blame] | 43 | printf("========== TEST REPORT ==========\n"); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 44 | for (i = 0; testsuites[i].name != NULL; i++) { |
Sandrine Bailleux | 68d76a2 | 2018-11-07 16:31:23 +0100 | [diff] [blame] | 45 | printf("# Test suite '%s':\n", testsuites[i].name); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 46 | 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 Bailleux | 68d76a2 | 2018-11-07 16:31:23 +0100 | [diff] [blame] | 51 | printf("Failed to get test result.\n"); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 52 | continue; |
| 53 | } |
| 54 | |
| 55 | tftf_update_tests_statistics(testcase_result.result); |
| 56 | /* TODO: print test duration */ |
Sandrine Bailleux | 68d76a2 | 2018-11-07 16:31:23 +0100 | [diff] [blame] | 57 | printf("\t - %s: %s\n", testcases[j].name, |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 58 | test_result_to_string(testcase_result.result)); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 59 | |
| 60 | if (strlen(test_output) != 0) { |
Sandrine Bailleux | 68d76a2 | 2018-11-07 16:31:23 +0100 | [diff] [blame] | 61 | printf("--- output ---\n"); |
| 62 | printf("%s", test_output); |
| 63 | printf("--------------\n"); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 64 | } |
| 65 | } |
| 66 | } |
Sandrine Bailleux | 68d76a2 | 2018-11-07 16:31:23 +0100 | [diff] [blame] | 67 | printf("=================================\n"); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 68 | |
| 69 | for (i = TEST_RESULT_MIN; i < TEST_RESULT_MAX; i++) { |
Sandrine Bailleux | 68d76a2 | 2018-11-07 16:31:23 +0100 | [diff] [blame] | 70 | printf("Tests %-8s: %d\n", |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 71 | test_result_to_string(i), tests_stats[i]); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 72 | } |
Sandrine Bailleux | 68d76a2 | 2018-11-07 16:31:23 +0100 | [diff] [blame] | 73 | printf("%-14s: %d\n", "Total tests", total_tests); |
| 74 | printf("=================================\n"); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 75 | } |