summaryrefslogtreecommitdiff
path: root/plat/arm/board/tc/rss_ap_tests.c
blob: 7d254e65ae1f5938a78fe843e1a391484b4b7e0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
 * Copyright (c) 2022, Arm Ltd. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <assert.h>
#include <stdio.h>

#include <mbedtls_common.h>
#include <plat/common/platform.h>
#include <psa/crypto.h>
#include <rss_comms.h>

#include "rss_ap_testsuites.h"

static struct test_suite_t test_suites[] = {
	{.freg = register_testsuite_delegated_attest},
	{.freg = register_testsuite_measured_boot},
};

/*
 * Return 0 if we could run all tests.
 * Note that this does not mean that all tests passed - only that they all run.
 * One should then look at each individual test result inside the
 * test_suites[].val field.
 */
static int run_tests(void)
{
	enum test_suite_err_t ret;
	psa_status_t status;
	size_t i;

	/* Initialize test environment. */
	rss_comms_init(PLAT_RSS_AP_SND_MHU_BASE, PLAT_RSS_AP_RCV_MHU_BASE);
	mbedtls_init();
	status = psa_crypto_init();
	if (status != PSA_SUCCESS) {
		printf("\n\npsa_crypto_init failed (status = %d)\n", status);
		return -1;
	}

	/* Run all tests. */
	for (i = 0; i < ARRAY_SIZE(test_suites); ++i) {
		struct test_suite_t *suite = &(test_suites[i]);

		suite->freg(suite);
		ret = run_testsuite(suite);
		if (ret != TEST_SUITE_ERR_NO_ERROR) {
			printf("\n\nError during executing testsuite '%s'.\n", suite->name);
			return -1;
		}
	}
	printf("\nAll tests are run.\n");

	return 0;
}

void run_platform_tests(void)
{
	size_t i;
	int ret;

	ret = run_tests();
	if (ret != 0) {
		/* For some reason, we could not run all tests. */
		return ret;
	}

	printf("\n\n");

	/* Print a summary of all the tests that had been run. */
	printf("SUMMARY:\n");
	for (i = 0; i < ARRAY_SIZE(test_suites); ++i) {

		struct test_suite_t *suite = &(test_suites[i]);

		switch (suite->val) {
		case TEST_PASSED:
			printf("    %s PASSED.\n", suite->name);
			break;
		case TEST_FAILED:
			printf("    %s FAILED.\n", suite->name);
			break;
		case TEST_SKIPPED:
			printf("    %s SKIPPED.\n", suite->name);
			break;
		default:
			assert(false);
			break;
		}
	}

	printf("\n\n");

	return 0;
}