Mate Toth-Pal | 14ba4af | 2022-10-21 14:24:49 +0200 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | static struct test_suite_t test_suites[] = { |
| 18 | {.freg = register_testsuite_delegated_attest}, |
| 19 | {.freg = register_testsuite_measured_boot}, |
| 20 | }; |
| 21 | |
Sandrine Bailleux | e1da6c4 | 2023-05-05 13:59:07 +0200 | [diff] [blame] | 22 | /* |
| 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 | */ |
| 28 | static int run_tests(void) |
Mate Toth-Pal | 14ba4af | 2022-10-21 14:24:49 +0200 | [diff] [blame] | 29 | { |
| 30 | enum test_suite_err_t ret; |
| 31 | psa_status_t status; |
| 32 | size_t i; |
| 33 | |
Sandrine Bailleux | e1da6c4 | 2023-05-05 13:59:07 +0200 | [diff] [blame] | 34 | /* Initialize test environment. */ |
Mate Toth-Pal | 14ba4af | 2022-10-21 14:24:49 +0200 | [diff] [blame] | 35 | 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 Bailleux | e1da6c4 | 2023-05-05 13:59:07 +0200 | [diff] [blame] | 40 | return -1; |
Mate Toth-Pal | 14ba4af | 2022-10-21 14:24:49 +0200 | [diff] [blame] | 41 | } |
| 42 | |
Sandrine Bailleux | e1da6c4 | 2023-05-05 13:59:07 +0200 | [diff] [blame] | 43 | /* Run all tests. */ |
Mate Toth-Pal | 14ba4af | 2022-10-21 14:24:49 +0200 | [diff] [blame] | 44 | 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 Bailleux | e1da6c4 | 2023-05-05 13:59:07 +0200 | [diff] [blame] | 51 | return -1; |
Mate Toth-Pal | 14ba4af | 2022-10-21 14:24:49 +0200 | [diff] [blame] | 52 | } |
| 53 | } |
| 54 | printf("\nAll tests are run.\n"); |
Sandrine Bailleux | e1da6c4 | 2023-05-05 13:59:07 +0200 | [diff] [blame] | 55 | |
| 56 | return 0; |
Mate Toth-Pal | 14ba4af | 2022-10-21 14:24:49 +0200 | [diff] [blame] | 57 | } |
| 58 | |
Jimmy Brisson | fbac83e | 2023-07-03 20:28:48 -0500 | [diff] [blame^] | 59 | int run_platform_tests(void) |
Mate Toth-Pal | 14ba4af | 2022-10-21 14:24:49 +0200 | [diff] [blame] | 60 | { |
| 61 | size_t i; |
Sandrine Bailleux | e1da6c4 | 2023-05-05 13:59:07 +0200 | [diff] [blame] | 62 | int ret; |
Sandrine Bailleux | fb891a3 | 2023-05-05 15:51:28 +0200 | [diff] [blame] | 63 | int failures = 0; |
Mate Toth-Pal | 14ba4af | 2022-10-21 14:24:49 +0200 | [diff] [blame] | 64 | |
Sandrine Bailleux | e1da6c4 | 2023-05-05 13:59:07 +0200 | [diff] [blame] | 65 | ret = run_tests(); |
| 66 | if (ret != 0) { |
| 67 | /* For some reason, we could not run all tests. */ |
| 68 | return ret; |
| 69 | } |
Mate Toth-Pal | 14ba4af | 2022-10-21 14:24:49 +0200 | [diff] [blame] | 70 | |
| 71 | printf("\n\n"); |
| 72 | |
Sandrine Bailleux | fb891a3 | 2023-05-05 15:51:28 +0200 | [diff] [blame] | 73 | /* |
| 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-Pal | 14ba4af | 2022-10-21 14:24:49 +0200 | [diff] [blame] | 78 | 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 Bailleux | fb891a3 | 2023-05-05 15:51:28 +0200 | [diff] [blame] | 88 | failures++; |
Mate Toth-Pal | 14ba4af | 2022-10-21 14:24:49 +0200 | [diff] [blame] | 89 | 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 Bailleux | e1da6c4 | 2023-05-05 13:59:07 +0200 | [diff] [blame] | 101 | |
Sandrine Bailleux | fb891a3 | 2023-05-05 15:51:28 +0200 | [diff] [blame] | 102 | return failures; |
Mate Toth-Pal | 14ba4af | 2022-10-21 14:24:49 +0200 | [diff] [blame] | 103 | } |