1 /* 2 * Copyright (c) 2022-2026, Arm Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #include <assert.h> 8 #include <stdio.h> 9 10 #include <drivers/arm/sfcp.h> 11 #include <mbedtls_common.h> 12 #include <plat/common/platform.h> 13 #include <psa/crypto.h> 14 15 #include "rse_ap_testsuites.h" 16 17 18 static struct test_suite_t test_suites[] = { 19 {.freg = register_testsuite_delegated_attest}, 20 {.freg = register_testsuite_measured_boot}, 21 }; 22 23 /* 24 * Return 0 if we could run all tests. 25 * Note that this does not mean that all tests passed - only that they all run. 26 * One should then look at each individual test result inside the 27 * test_suites[].val field. 28 */ run_tests(void)29static int run_tests(void) 30 { 31 enum test_suite_err_t ret; 32 enum sfcp_error_t sfcp_err; 33 psa_status_t status; 34 size_t i; 35 36 /* Initialize test environment. */ 37 sfcp_err = sfcp_init(); 38 if (sfcp_err != SFCP_ERROR_SUCCESS) { 39 printf("Unable to initialize SFCP\n"); 40 return -1; 41 } 42 43 mbedtls_init(); 44 status = psa_crypto_init(); 45 if (status != PSA_SUCCESS) { 46 printf("\n\npsa_crypto_init failed (status = %d)\n", status); 47 return -1; 48 } 49 50 /* Run all tests. */ 51 for (i = 0; i < ARRAY_SIZE(test_suites); ++i) { 52 struct test_suite_t *suite = &(test_suites[i]); 53 54 suite->freg(suite); 55 ret = run_testsuite(suite); 56 if (ret != TEST_SUITE_ERR_NO_ERROR) { 57 printf("\n\nError during executing testsuite '%s'.\n", suite->name); 58 return -1; 59 } 60 } 61 printf("\nAll tests are run.\n"); 62 63 return 0; 64 } 65 run_platform_tests(void)66int run_platform_tests(void) 67 { 68 size_t i; 69 int ret; 70 int failures = 0; 71 72 ret = run_tests(); 73 if (ret != 0) { 74 /* For some reason, we could not run all tests. */ 75 return ret; 76 } 77 78 printf("\n\n"); 79 80 /* 81 * Print a summary of all the tests that had been run. 82 * Also count the number of tests failure and report that back to the 83 * caller. 84 */ 85 printf("SUMMARY:\n"); 86 for (i = 0; i < ARRAY_SIZE(test_suites); ++i) { 87 88 struct test_suite_t *suite = &(test_suites[i]); 89 90 switch (suite->val) { 91 case TEST_PASSED: 92 printf(" %s PASSED.\n", suite->name); 93 break; 94 case TEST_FAILED: 95 failures++; 96 printf(" %s FAILED.\n", suite->name); 97 break; 98 case TEST_SKIPPED: 99 printf(" %s SKIPPED.\n", suite->name); 100 break; 101 default: 102 assert(false); 103 break; 104 } 105 } 106 107 printf("\n\n"); 108 109 return failures; 110 } 111