blob: 8c40271ba9115ac5eeaef6421ee07ff7200752c5 [file] [log] [blame]
Mate Toth-Pal14ba4af2022-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 Bailleuxe1da6c42023-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-Pal14ba4af2022-10-21 14:24:49 +020029{
30 enum test_suite_err_t ret;
31 psa_status_t status;
32 size_t i;
33
Sandrine Bailleuxe1da6c42023-05-05 13:59:07 +020034 /* Initialize test environment. */
Mate Toth-Pal14ba4af2022-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 Bailleuxe1da6c42023-05-05 13:59:07 +020040 return -1;
Mate Toth-Pal14ba4af2022-10-21 14:24:49 +020041 }
42
Sandrine Bailleuxe1da6c42023-05-05 13:59:07 +020043 /* Run all tests. */
Mate Toth-Pal14ba4af2022-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 Bailleuxe1da6c42023-05-05 13:59:07 +020051 return -1;
Mate Toth-Pal14ba4af2022-10-21 14:24:49 +020052 }
53 }
54 printf("\nAll tests are run.\n");
Sandrine Bailleuxe1da6c42023-05-05 13:59:07 +020055
56 return 0;
Mate Toth-Pal14ba4af2022-10-21 14:24:49 +020057}
58
59void run_platform_tests(void)
60{
61 size_t i;
Sandrine Bailleuxe1da6c42023-05-05 13:59:07 +020062 int ret;
Sandrine Bailleuxfb891a32023-05-05 15:51:28 +020063 int failures = 0;
Mate Toth-Pal14ba4af2022-10-21 14:24:49 +020064
Sandrine Bailleuxe1da6c42023-05-05 13:59:07 +020065 ret = run_tests();
66 if (ret != 0) {
67 /* For some reason, we could not run all tests. */
68 return ret;
69 }
Mate Toth-Pal14ba4af2022-10-21 14:24:49 +020070
71 printf("\n\n");
72
Sandrine Bailleuxfb891a32023-05-05 15:51:28 +020073 /*
74 * Print a summary of all the tests that had been run.
75 * Also count the number of tests failure and report that back to the
76 * caller.
77 */
Mate Toth-Pal14ba4af2022-10-21 14:24:49 +020078 printf("SUMMARY:\n");
79 for (i = 0; i < ARRAY_SIZE(test_suites); ++i) {
80
81 struct test_suite_t *suite = &(test_suites[i]);
82
83 switch (suite->val) {
84 case TEST_PASSED:
85 printf(" %s PASSED.\n", suite->name);
86 break;
87 case TEST_FAILED:
Sandrine Bailleuxfb891a32023-05-05 15:51:28 +020088 failures++;
Mate Toth-Pal14ba4af2022-10-21 14:24:49 +020089 printf(" %s FAILED.\n", suite->name);
90 break;
91 case TEST_SKIPPED:
92 printf(" %s SKIPPED.\n", suite->name);
93 break;
94 default:
95 assert(false);
96 break;
97 }
98 }
99
100 printf("\n\n");
Sandrine Bailleuxe1da6c42023-05-05 13:59:07 +0200101
Sandrine Bailleuxfb891a32023-05-05 15:51:28 +0200102 return failures;
Mate Toth-Pal14ba4af2022-10-21 14:24:49 +0200103}