Make tests output more concise and clearer

Also refactor the code that generates this output.

This is only a first step, subsequent patches will further improve
the output.

Here is a sample of the old output:

[cpu 0x0000] NOTICE:  Starting unittest 'Template - Single core test'
[cpu 0x0000] NOTICE:  Unittest 'Template - Single core test' complete. Result: Passed
[cpu 0x0000] NOTICE:  Starting unittest 'Template - Multi core test'
[cpu 0x0000] NOTICE:  Unittest 'Template - Multi core test' complete. Result: Passed
========== TEST REPORT ==========
 # Test suite 'Template':
- Single core test: Passed
- Multi core test: Passed
=================================
Tests Skipped : 0
Tests Passed  : 2
Tests Failed  : 0
Tests Crashed : 0
Total tests   : 2
=================================
[cpu 0x0000] NOTICE:  Exiting tests.

And now the new output:

[cpu 0x0000] --
[cpu 0x0000] Running test suite 'Template'
[cpu 0x0000] Description: Template test code
[cpu 0x0000]
[cpu 0x0000] > Executing 'Single core test'
[cpu 0x0000]   TEST COMPLETE                                                 Passed
[cpu 0x0000]
[cpu 0x0000] > Executing 'Multi core test'
[cpu 0x0000]   TEST COMPLETE                                                 Passed
[cpu 0x0000]
[cpu 0x0000] ******************************* Summary *******************************
[cpu 0x0000] > Test suite 'Template'
[cpu 0x0000]                                                                 Passed
[cpu 0x0000] =================================
[cpu 0x0000] Tests Skipped : 0
[cpu 0x0000] Tests Passed  : 2
[cpu 0x0000] Tests Failed  : 0
[cpu 0x0000] Tests Crashed : 0
[cpu 0x0000] Total tests   : 2
[cpu 0x0000] =================================
[cpu 0x0000] NOTICE:  Exiting tests.

Change-Id: I9d52f2da8905962ab1df73d0691846d88622d3b5
Signed-off-by: Sandrine Bailleux <sandrine.bailleux@arm.com>
diff --git a/tftf/framework/report.c b/tftf/framework/report.c
index faae34b..663caf3 100644
--- a/tftf/framework/report.c
+++ b/tftf/framework/report.c
@@ -6,70 +6,97 @@
 
 #include <assert.h>
 #include <debug.h>
-#include <platform_def.h>  /* For TESTCASE_OUTPUT_MAX_SIZE */
 #include <stdio.h>
-#include <string.h>
+#include <stdbool.h>
 #include <tftf.h>
 
-static unsigned int total_tests;
-static unsigned int tests_stats[TEST_RESULT_MAX];
-
-static void tftf_update_tests_statistics(test_result_t result)
-{
-	assert(TEST_RESULT_IS_VALID(result));
-	total_tests++;
-	tests_stats[result]++;
-}
-
 static const char *test_result_strings[TEST_RESULT_MAX] = {
 	"Skipped", "Passed", "Failed", "Crashed",
 };
 
-const char *test_result_to_string(test_result_t result)
+static const char *test_result_to_string(test_result_t result)
 {
 	assert(TEST_RESULT_IS_VALID(result));
 	return test_result_strings[result];
 }
 
-void tftf_report_generate(void)
+void print_testsuite_start(const test_suite_t *testsuite)
 {
-	unsigned i, j;
-	const test_case_t *testcases;
-	TESTCASE_RESULT testcase_result;
-	char test_output[TESTCASE_OUTPUT_MAX_SIZE];
-	STATUS status;
+	mp_printf("--\n");
+	mp_printf("Running test suite '%s'\n", testsuite->name);
+	mp_printf("Description: %s\n", testsuite->description);
+	mp_printf("\n");
+}
 
-	/* Extract the result of all the testcases */
-	printf("========== TEST REPORT ==========\n");
-	for (i = 0; testsuites[i].name != NULL; i++) {
-		printf("# Test suite '%s':\n", testsuites[i].name);
-		testcases = testsuites[i].testcases;
+void print_test_start(const test_case_t *test)
+{
+	mp_printf("> Executing '%s'\n", test->name);
+}
 
-		for (j = 0; testcases[j].name != NULL; j++) {
-			status = tftf_testcase_get_result(&testcases[j], &testcase_result, test_output);
-			if (status != STATUS_SUCCESS) {
-				printf("Failed to get test result.\n");
+void print_test_end(const test_case_t *test)
+{
+	TESTCASE_RESULT result;
+	char output[TESTCASE_OUTPUT_MAX_SIZE];
+
+	tftf_testcase_get_result(test, &result, output);
+
+	mp_printf("  TEST COMPLETE %54s\n",
+		  test_result_to_string(result.result));
+	if (strlen(output) != 0) {
+		mp_printf("%s", output);
+	}
+	mp_printf("\n");
+}
+
+void print_tests_summary(void)
+{
+	int total_tests = 0;
+	int tests_stats[TEST_RESULT_MAX] = { 0 };
+
+	mp_printf("******************************* Summary *******************************\n");
+
+	/* Go through the list of test suites. */
+	for (int i = 0; testsuites[i].name != NULL; i++) {
+		bool passed = true;
+
+		mp_printf("> Test suite '%s'\n", testsuites[i].name);
+
+		const test_case_t *testcases = testsuites[i].testcases;
+
+		/* Go through the list of tests inside this test suite. */
+		for (int j = 0; testcases[j].name != NULL; j++) {
+			TESTCASE_RESULT result;
+			char output[TESTCASE_OUTPUT_MAX_SIZE];
+
+			if (tftf_testcase_get_result(&testcases[j], &result,
+					output) != STATUS_SUCCESS) {
+				mp_printf("Failed to get test result.\n");
 				continue;
 			}
 
-			tftf_update_tests_statistics(testcase_result.result);
-			/* TODO: print test duration */
-			printf("\t - %s: %s\n", testcases[j].name,
-				test_result_to_string(testcase_result.result));
+			assert(TEST_RESULT_IS_VALID(result.result));
 
-			if (strlen(test_output) != 0) {
-				printf("--- output ---\n");
-				printf("%s", test_output);
-				printf("--------------\n");
+			/*
+			 * Consider that a test suite passed if all of its
+			 * tests passed or were skipped.
+			 */
+			if ((result.result != TEST_RESULT_SUCCESS) &&
+			    (result.result != TEST_RESULT_SKIPPED)) {
+				passed = false;
 			}
-		}
-	}
-	printf("=================================\n");
 
-	for (i = TEST_RESULT_MIN; i < TEST_RESULT_MAX; i++) {
-		printf("Tests %-8s: %d\n",
+			total_tests++;
+			tests_stats[result.result]++;
+		}
+		mp_printf("%70s\n", passed ? "Passed" : "Failed");
+	}
+
+	mp_printf("=================================\n");
+
+	for (int i = TEST_RESULT_MIN; i < TEST_RESULT_MAX; i++) {
+		mp_printf("Tests %-8s: %d\n",
 			test_result_to_string(i), tests_stats[i]);
 	}
-	printf("%-14s: %d\n", "Total tests", total_tests);
-	printf("=================================\n");
+	mp_printf("%-14s: %d\n", "Total tests", total_tests);
+	mp_printf("=================================\n");
 }