blob: b9bf705b97b98ae5ba867f67e8feead530eb4cf5 [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001/*
2 * Copyright (c) 2018, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef __TFTF_H__
8#define __TFTF_H__
9
10#ifndef __ASSEMBLY__
11#include <status.h>
12#include <stddef.h>
13#include <tftf_lib.h>
14
15#define TFTF_WELCOME_STR "Booting trusted firmware test framework"
16
17/* Maximum size of test output (in bytes) */
Prasad Kummari7e99cb02024-02-22 11:46:00 +053018#define TESTCASE_OUTPUT_MAX_SIZE 1024
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020019
20/* Size of build message used to differentiate different TFTF binaries */
21#define BUILD_MESSAGE_SIZE 0x20
22
23extern const char build_message[];
24
25typedef test_result_t (*test_function_t)(void);
26
27typedef struct {
28 /* Test result (success, crashed, failed, ...). */
29 test_result_t result;
30 unsigned long long duration;
31 /*
32 * Offset of test output string from TEST_NVM_RESULT_BUFFER_OFFSET.
33 * Only relevant if test has an output, i.e. if \a output_size is not
34 * zero.
35 */
36 unsigned output_offset;
37 /* Size of test output string, excluding final \0. */
38 unsigned output_size;
39} TESTCASE_RESULT;
40
41typedef struct {
42 unsigned index;
43 const char *name;
44 const char *description;
45 test_function_t test;
46} test_case_t;
47
48typedef struct {
49 const char *name;
50 const char *description;
51 const test_case_t *testcases;
52} test_suite_t;
53
54/*
55 * Reference to a specific test.
56 */
57typedef struct {
58 unsigned int testsuite_idx;
59 unsigned int testcase_idx;
60} test_ref_t;
61
62/*
63 * The progress in the execution of a test.
64 * This is used to implement the following state machine.
65 *
66 * +-> TEST_READY (initial state of the test) <--------------+
67 * | | |
68 * | | Test framework prepares the test environment. |
69 * | | |
70 * | v |
71 * | TEST_IN_PROGRESS |
72 * | | |
73 * | | Hand over to the test function. |
74 * | | If the test wants to reboot the platform ---> TEST_REBOOTING |
75 * | | Test function returns into framework. | |
76 * | | | Reboot |
77 * | | | |
78 * | | +---------+
79 * | v
80 * | TEST_COMPLETE
81 * | |
82 * | | Do some framework management.
83 * | | Move to next test.
84 * +--------+
85 */
86typedef enum {
87 TEST_PROGRESS_MIN = 0,
88 TEST_READY = TEST_PROGRESS_MIN,
89 TEST_IN_PROGRESS,
90 TEST_COMPLETE,
91 TEST_REBOOTING,
92
93 TEST_PROGRESS_MAX,
94} test_progress_t;
95
96#define TEST_PROGRESS_IS_VALID(_progress) \
97 ((_progress >= TEST_PROGRESS_MIN) && (_progress < TEST_PROGRESS_MAX))
98
99/*
100 * The definition of this global variable is generated by the script
101 * 'tftf_generate_test_list' during the build process
102 */
103extern const test_suite_t testsuites[];
104
105extern TESTCASE_RESULT testcase_results[];
106
107/* Set/Get the test to run in NVM */
108STATUS tftf_set_test_to_run(const test_ref_t test_to_run);
109STATUS tftf_get_test_to_run(test_ref_t *test_to_run);
110/* Set/Get the progress of the current test in NVM */
111STATUS tftf_set_test_progress(test_progress_t test_progress);
112STATUS tftf_get_test_progress(test_progress_t *test_progress);
113
114/**
115** Save test result into NVM.
116*/
117STATUS tftf_testcase_set_result(const test_case_t *testcase,
118 test_result_t result,
119 unsigned long long duration);
120/**
121** Get a testcase result from NVM.
122**
123** @param[in] testcase The targeted testcase.
124** @param[out] result Testcase result. Only \a result.result and
125** \a result.duration are of interest for the caller and the 2 other fields
126** should be ignored (they correspond to a location in NVM).
127** @param[out] test_output Buffer to store the test output, if any.
128** \a test_output must be big enough to hold the whole test output.
129** Test output will be \a TESTCASE_OUTPUT_MAX_SIZE bytes maximum.
130*/
131STATUS tftf_testcase_get_result(const test_case_t *testcase, TESTCASE_RESULT *result, char *test_output);
132
Sandrine Bailleux125d58c2018-11-07 17:11:59 +0100133void print_testsuite_start(const test_suite_t *testsuite);
134void print_test_start(const test_case_t *test);
135void print_test_end(const test_case_t *test);
136void print_tests_summary(void);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200137
138/*
139 * Exit the TFTF.
140 * This function can be used when a fatal error is encountered or as part of the
141 * normal termination process. It does the necessary cleanups then put the
142 * core in a low-power state.
143 */
144void __dead2 tftf_exit(void);
145
146void tftf_arch_setup(void);
147
148/*
149 * This function detects the power state format used by PSCI which can
150 * be either extended or original format. For the Original format,
151 * the State-ID can either be NULL or can be using the recommended encoding.
152 * This function needs to be invoked once during cold boot prior to the
153 * invocation of any PSCI power state helper functions.
154 */
155void tftf_detect_psci_pstate_format(void);
156
157/*
158 * Run the next test on the calling CPU.
159 * Once the test is complete, if the calling CPU is the last one to exit the
160 * test then do the necessary bookkeeping, report the overall test result and
161 * move on to the next test. Otherwise, shut down the calling CPU.
162 *
163 * This function never returns.
164 */
165void __dead2 run_tests(void);
166
167/* Entry point for a CPU that has just been powered up */
168void tftf_hotplug_entry(void);
169
170#endif /*__ASSEMBLY__*/
171
172#endif