rse_ap_tests.c 2.1 KB

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