blob: 7d254e65ae1f5938a78fe843e1a391484b4b7e0e [file] [log] [blame]
Mate Toth-Pal25dd2172022-10-21 14:24:49 +02001/*
2 * Copyright (c) 2022, Arm Ltd. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <assert.h>
8#include <stdio.h>
9
10#include <mbedtls_common.h>
11#include <plat/common/platform.h>
12#include <psa/crypto.h>
13#include <rss_comms.h>
14
15#include "rss_ap_testsuites.h"
16
17static struct test_suite_t test_suites[] = {
18 {.freg = register_testsuite_delegated_attest},
19 {.freg = register_testsuite_measured_boot},
20};
21
Sandrine Bailleux57cc12c2023-05-05 13:59:07 +020022/*
23 * Return 0 if we could run all tests.
24 * Note that this does not mean that all tests passed - only that they all run.
25 * One should then look at each individual test result inside the
26 * test_suites[].val field.
27 */
28static int run_tests(void)
Mate Toth-Pal25dd2172022-10-21 14:24:49 +020029{
30 enum test_suite_err_t ret;
31 psa_status_t status;
32 size_t i;
33
Sandrine Bailleux57cc12c2023-05-05 13:59:07 +020034 /* Initialize test environment. */
Mate Toth-Pal25dd2172022-10-21 14:24:49 +020035 rss_comms_init(PLAT_RSS_AP_SND_MHU_BASE, PLAT_RSS_AP_RCV_MHU_BASE);
36 mbedtls_init();
37 status = psa_crypto_init();
38 if (status != PSA_SUCCESS) {
39 printf("\n\npsa_crypto_init failed (status = %d)\n", status);
Sandrine Bailleux57cc12c2023-05-05 13:59:07 +020040 return -1;
Mate Toth-Pal25dd2172022-10-21 14:24:49 +020041 }
42
Sandrine Bailleux57cc12c2023-05-05 13:59:07 +020043 /* Run all tests. */
Mate Toth-Pal25dd2172022-10-21 14:24:49 +020044 for (i = 0; i < ARRAY_SIZE(test_suites); ++i) {
45 struct test_suite_t *suite = &(test_suites[i]);
46
47 suite->freg(suite);
48 ret = run_testsuite(suite);
49 if (ret != TEST_SUITE_ERR_NO_ERROR) {
50 printf("\n\nError during executing testsuite '%s'.\n", suite->name);
Sandrine Bailleux57cc12c2023-05-05 13:59:07 +020051 return -1;
Mate Toth-Pal25dd2172022-10-21 14:24:49 +020052 }
53 }
54 printf("\nAll tests are run.\n");
Sandrine Bailleux57cc12c2023-05-05 13:59:07 +020055
56 return 0;
Mate Toth-Pal25dd2172022-10-21 14:24:49 +020057}
58
59void run_platform_tests(void)
60{
61 size_t i;
Sandrine Bailleux57cc12c2023-05-05 13:59:07 +020062 int ret;
Mate Toth-Pal25dd2172022-10-21 14:24:49 +020063
Sandrine Bailleux57cc12c2023-05-05 13:59:07 +020064 ret = run_tests();
65 if (ret != 0) {
66 /* For some reason, we could not run all tests. */
67 return ret;
68 }
Mate Toth-Pal25dd2172022-10-21 14:24:49 +020069
70 printf("\n\n");
71
72 /* Print a summary of all the tests that had been run. */
73 printf("SUMMARY:\n");
74 for (i = 0; i < ARRAY_SIZE(test_suites); ++i) {
75
76 struct test_suite_t *suite = &(test_suites[i]);
77
78 switch (suite->val) {
79 case TEST_PASSED:
80 printf(" %s PASSED.\n", suite->name);
81 break;
82 case TEST_FAILED:
83 printf(" %s FAILED.\n", suite->name);
84 break;
85 case TEST_SKIPPED:
86 printf(" %s SKIPPED.\n", suite->name);
87 break;
88 default:
89 assert(false);
90 break;
91 }
92 }
93
94 printf("\n\n");
Sandrine Bailleux57cc12c2023-05-05 13:59:07 +020095
96 return 0;
Mate Toth-Pal25dd2172022-10-21 14:24:49 +020097}