summaryrefslogtreecommitdiff
path: root/framework/include/tftf.h
blob: 02e6346d209389513319b86c53e3b8313ad508ff (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/** @file
*
*  Copyright (c) 2013, ARM Limited. All rights reserved.
*
*  This program and the accompanying materials
*  are licensed and made available under the terms and conditions of the BSD License
*  which accompanies this distribution.  The full text of the license may be found at
*  http://opensource.org/licenses/bsd-license.php
*
*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*
**/

#ifndef __TFTF_H__
#define __TFTF_H__

#ifndef __ASSEMBLY__
#include <stddef.h>
#include <tests_api.h>
#include <tftf_common.h>

#define TFTF_WELCOME_STR	"Booting trusted firmware test framework"

#define TESTS_MAGIC_VALUE	0xCAFED00D

/* Maximum size of test output (in bytes) */
#define TESTCASE_OUTPUT_MAX_SIZE	512

#define TEST_REPORT_FORMAT_RAW 0
#define TEST_REPORT_FORMAT_JUNIT 1

extern const char build_message[];

typedef TEST_RESULT (*TESTCASE_FUNC)(void);

typedef struct {
  TFTF_TASK         task;
  TEST_RESULT       result;
  void*             arguments;
} TASK_ENTRY;

typedef struct {
  /// Test result (success, crashed, failed, ...).
  TEST_RESULT           result;
  unsigned long long    duration;
  /**
   ** Offset of test output string from TEST_NVM_RESULT_BUFFER_OFFSET.
   ** Only relevant if test has an output, i.e. if \a output_size is not zero.
   */
  unsigned              output_offset;
  /// Size of test output string, excluding final \0.
  unsigned              output_size;
} TESTCASE_RESULT;

typedef struct {
  unsigned              index;
  const char*           name;
  const char*           description;
  TESTCASE_FUNC        test;
} TESTCASE;

typedef struct {
  const char*           name;
  const char*           description;
  const TESTCASE       *testcases;
} TEST_SUITE;

/**
** @brief Write a string in the test output buffer.
**
** @note The test output buffer we are talking about here is a temporary buffer
** stored in RAM. This function doesn't write anything into NVM.
*/
void tftf_testcase_output(const char* string);

// The definition of this global variable is generated by the script 'tftf_generate_test_list'
// during the build process
extern const TEST_SUITE testsuites[];

extern TESTCASE_RESULT testcase_results[];

STATUS tftf_get_testcase_index(TESTCASE_FUNC testcase_function, unsigned *testsuite_index,
                               unsigned *testcase_index, unsigned get_next);
STATUS test_set_passed_and_next(TESTCASE_FUNC testcase_function);
STATUS tftf_testcase_set_result_as_crashed(TESTCASE_FUNC crashed_testcase_function);

void tftf_set_current_testcase(TESTCASE_FUNC testcase_function);
STATUS tftf_get_current_testcase(TESTCASE_FUNC* testcase_function);
void tftf_set_next_testcase(TESTCASE_FUNC testcase_function);
STATUS tftf_get_next_testcase(TESTCASE_FUNC* testcase_function);

/**
** Save test result into NVM.
*/
STATUS tftf_testcase_set_result(const TESTCASE* testcase, TEST_RESULT result, const char* output,
                                unsigned long long duration);
/**
** Get a testcase result from NVM.
**
** @param[in]  testcase The targeted testcase.
** @param[out] result Testcase result. Only \a result.result and
**   \a result.duration are of interest for the caller and the 2 other fields
**   should be ignored (they correspond to a location in NVM).
** @param[out] test_output Buffer to store the test output, if any.
**   \a test_output must be big enough to hold the whole test output.
**   Test output will be \a TESTCASE_OUTPUT_MAX_SIZE bytes maximum.
*/
STATUS tftf_testcase_get_result(const TESTCASE* testcase, TESTCASE_RESULT *result, char *test_output);
STATUS tftf_testcase_update_result(const TESTCASE* testcase, TEST_RESULT result);

typedef unsigned TEST_REPORT_FORMAT;

void tftf_report_generate(void);

/*
 * Exit the TFTF.
 * This function can be used when a fatal error is encountered or as part of the
 * normal termination process. It does the necessary cleanups then put the
 * core in a low-power state.
 */
void __dead2 tftf_exit(void);

void tftf_arch_setup(void);
void tftf_register_gic_id(void);
uint8_t tftf_get_gic_cpu_id_from_mpidr(unsigned long mpidr);
uint8_t tftf_get_cpu_id_from_gic_id(uint8_t gic_id);

/* Print a debug message */
#if DEBUG
#define pr_debug(...) mp_printf(__VA_ARGS__)
#else
#define pr_debug(...)  /* do nothing */
#endif /* DEBUG */

int tftf_systimer_setup(void);

/*
 * Run the next test on the calling CPU.
 * Once the test is complete, if the calling CPU is the last one to exit the
 * test then do the necessary bookkeeping, report the overall test result and
 * move on to the next test. Otherwise, shut down the calling CPU.
 *
 * This function never returns.
 */
void __dead2 run_tests(void);

/*
 * Prevent the compiler from optimising the access to a variable.
 * Note that this only affects the compiler, this is NOT a run-time
 * memory barrier.
 */
#define ACCESS(var)	(*(volatile __typeof__(var) *)&(var))

#endif /*__ASSEMBLY__*/

#endif