]> git.baikalelectronics.ru Git - arm-tf.git/commitdiff
test(tc): centralize platform error handling
authorSandrine Bailleux <sandrine.bailleux@arm.com>
Fri, 5 May 2023 11:59:07 +0000 (13:59 +0200)
committerSandrine Bailleux <sandrine.bailleux@arm.com>
Mon, 15 May 2023 11:02:19 +0000 (13:02 +0200)
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

plat/arm/board/tc/include/tc_plat.h
plat/arm/board/tc/nv_counter_test.c
plat/arm/board/tc/rss_ap_tests.c
plat/arm/board/tc/tc_bl31_setup.c

index 195366e4843072e92e69d6d2894c7689ab652d7e..117fbb43034b3889f02796d63b8bd7a599607d7f 100644 (file)
 void tc_bl31_common_platform_setup(void);
 
 #ifdef PLATFORM_TEST_TFM_TESTSUITE
-void run_platform_tests(void);
+int run_platform_tests(void);
 #endif
+
 #ifdef PLATFORM_TEST_NV_COUNTERS
-void nv_counter_test(void);
+int nv_counter_test(void);
 #endif
 
 #endif /* TC_PLAT_H */
index 76c99159ad2db96e611fcd468957f8cea479ef37..f9e001ea87271fb76f6e879c8996608fe6fe5a02 100644 (file)
@@ -13,7 +13,7 @@
 
 #include <platform_def.h>
 
-void nv_counter_test(void)
+int nv_counter_test(void)
 {
        psa_status_t status;
        uint32_t old_val;
@@ -23,7 +23,7 @@ void nv_counter_test(void)
        status = rss_comms_init(PLAT_RSS_AP_SND_MHU_BASE, PLAT_RSS_AP_RCV_MHU_BASE);
        if (status != PSA_SUCCESS) {
                printf("Failed to initialize RSS communication channel\n");
-               plat_error_handler(-1);
+               return -1;
        }
 
        for (id = 0; id < 3; id++) {
@@ -31,28 +31,30 @@ void nv_counter_test(void)
                if (status != PSA_SUCCESS) {
                        printf("Failed during first id=(%d) rss_platform_nv_counter_read\n",
                                       id);
-                       plat_error_handler(-1);
+                       return -1;
                }
 
                status = rss_platform_nv_counter_increment(id);
                if (status != PSA_SUCCESS) {
                        printf("Failed during id=(%d) rss_platform_nv_counter_increment\n",
                                        id);
-                       plat_error_handler(-1);
+                       return -1;
                }
 
                status = rss_platform_nv_counter_read(id, sizeof(new_val), (uint8_t *)&new_val);
                if (status != PSA_SUCCESS) {
                        printf("Failed during second id=(%d) rss_platform_nv_counter_read\n",
                                        id);
-                       plat_error_handler(-1);
+                       return -1;
                }
 
                if (old_val + 1 != new_val) {
                        printf("Failed nv_counter_test: old_val (%d) + 1 != new_val (%d)\n",
                                        old_val, new_val);
-                       plat_error_handler(-1);
+                       return -1;
                }
        }
        printf("Passed nv_counter_test\n");
+
+       return 0;
 }
index b62043ecedc017f830c069fee7d78ac6246f1b5f..7d254e65ae1f5938a78fe843e1a391484b4b7e0e 100644 (file)
@@ -19,21 +19,28 @@ static struct test_suite_t test_suites[] = {
        {.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 @@ static void run_tests(void)
                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 @@ void run_platform_tests(void)
        }
 
        printf("\n\n");
+
+       return 0;
 }
index d2a14d2877524341eac57146658347d775fae0d2..ec28f3a1f840dcf765a004a20c10eacb30169c51 100644 (file)
@@ -59,7 +59,7 @@ void tc_bl31_common_platform_setup(void)
 #elif PLATFORM_TEST_TFM_TESTSUITE
        run_platform_tests();
 #endif
-       /* Suspend booting */
+       /* Suspend booting, no matter the tests outcome. */
        plat_error_handler(-1);
 #endif
 }