test(tc): centralize platform error handling

Note that this change only affects the platform tests execution
path. It has no impact on the normal boot flow.

Make individual test functions propagate an error code, instead of
calling the platform error handler at the point of failure. The latter
is now the responsibility of the caller - in this case
tc_bl31_common_platform_setup().

Note that right now, tc_bl31_common_platform_setup() does not look at
the said error code but this initial change opens up an opportunity to
centralize any error handling in tc_bl31_common_platform_setup(),
which we will seize in subsequent patches.

Signed-off-by: Sandrine Bailleux <sandrine.bailleux@arm.com>
Change-Id: Ib282b64039e0b1ec6e6d29476fbaa2bcd33cb0c7
diff --git a/plat/arm/board/tc/rss_ap_tests.c b/plat/arm/board/tc/rss_ap_tests.c
index b62043e..7d254e6 100644
--- a/plat/arm/board/tc/rss_ap_tests.c
+++ b/plat/arm/board/tc/rss_ap_tests.c
@@ -19,21 +19,28 @@
 	{.freg = register_testsuite_measured_boot},
 };
 
-static void run_tests(void)
+/*
+ * Return 0 if we could run all tests.
+ * Note that this does not mean that all tests passed - only that they all run.
+ * One should then look at each individual test result inside the
+ * test_suites[].val field.
+ */
+static int run_tests(void)
 {
 	enum test_suite_err_t ret;
 	psa_status_t status;
 	size_t i;
 
+	/* Initialize test environment. */
 	rss_comms_init(PLAT_RSS_AP_SND_MHU_BASE, PLAT_RSS_AP_RCV_MHU_BASE);
 	mbedtls_init();
 	status = psa_crypto_init();
 	if (status != PSA_SUCCESS) {
 		printf("\n\npsa_crypto_init failed (status = %d)\n", status);
-		assert(false);
-		plat_error_handler(-1);
+		return -1;
 	}
 
+	/* Run all tests. */
 	for (i = 0; i < ARRAY_SIZE(test_suites); ++i) {
 		struct test_suite_t *suite = &(test_suites[i]);
 
@@ -41,18 +48,24 @@
 		ret = run_testsuite(suite);
 		if (ret != TEST_SUITE_ERR_NO_ERROR) {
 			printf("\n\nError during executing testsuite '%s'.\n", suite->name);
-			assert(false);
-			plat_error_handler(-1);
+			return -1;
 		}
 	}
 	printf("\nAll tests are run.\n");
+
+	return 0;
 }
 
 void run_platform_tests(void)
 {
 	size_t i;
+	int ret;
 
-	run_tests();
+	ret = run_tests();
+	if (ret != 0) {
+		/* For some reason, we could not run all tests. */
+		return ret;
+	}
 
 	printf("\n\n");
 
@@ -79,4 +92,6 @@
 	}
 
 	printf("\n\n");
+
+	return 0;
 }