blob: a59c1d7b4634c0dc14aa414860b060b6eca3887a [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001Trusted Firmware-A Tests - Design
2=================================
3
4.. section-numbering::
5 :suffix: .
6
7.. contents::
8
9This document provides some details about the internals of the TF-A Tests
10design. It is incomplete at the moment.
11
12Global overview of the TF-A tests behaviour
13-------------------------------------------
14
15The EL3 firmware is expected to hand over to the TF-A tests with all secondary
16cores powered down, i.e. only the primary core should enter the TF-A tests.
17
18The primary CPU initialises the platform and the TF-A tests internal data
19structures.
20
21Then the test session begins. The TF-A tests are executed one after the
22other. Tests results are saved in non-volatile memory as we go along.
23
24Once all tests have completed, a report is generated. The TF-A tests currently
25supports 2 report formats:
26
27- Raw output, i.e. text messages over serial console.
28
29- Junit output, i.e. XML file generated over semihosting. This is useful when a
30 post-processing tool needs to parse the test report, as it is more
31 machine-friendly than the raw output.
32
33The report format to use is chosen at build time. For more information,
34refer to the section `Summary of build options`_ in the User Guide.
35
36Global Code Structure
37---------------------
38
39The code is organised into the following categories (present as directories at
40the top level or under the ``tftf/`` directory):
41
42- **Drivers.**
43
44 Some examples follow, this list might not be exhaustive.
45
46 - Generic GIC driver.
47
48 ``arm_gic.h`` contains the public APIs that tests might use. Both GIC
49 architecture versions 2 and 3 are supported.
50
51 - PL011 UART driver.
52
53 - VExpress NOR flash driver.
54
55 Note that tests are not expected to use this driver in most
56 cases. Instead, they should use the ``tftf_nvm_read()`` and
57 ``tftf_nvm_write()`` wrapper APIs. See definitions in
58 ``tftf/framework/include/nvm.h``. See also the NVM validation test cases
59 (``tftf/tests/framework_validation_tests/test_validation_nvm.c``) for an
60 example of usage of these functions.
61
62 - SP805 watchdog.
63
64 Used solely to generate an interrupt that will reset the system on purpose
65 (used in ``tftf_plat_reset()``).
66
67 - SP804 timer.
68
69 This is used as the system timer on Juno. It is configured such that an
70 interrupt is generated when it reaches 0. It is programmed in one-shot
71 mode, i.e. it must be rearmed every time it reaches 0.
72
73- **Framework.**
74
75 Core features of the test framework.
76
77- **Library code.**
78
79 Some examples of APIs provided in ``include/lib/`` follow, this list might
80 not be exhaustive.
81
82 - ``aarch64/``
83
84 Architecture helper functions for e.g. system registers access, cache
85 maintenance operations, MMU configuration, ...
86
87 - ``events.h``
88
89 Events API. Used to create synchronisation points between CPUs in tests.
90
91 - ``irq.h``
92
93 IRQ handling support. Used to configure IRQs and register/unregister
94 handlers called upon reception of a specific IRQ.
95
96 - ``power_management.h``
97
98 Power management operations (CPU ON/OFF, CPU suspend, etc.).
99
100 - ``sgi.h``
101
102 Software Generated Interrupt support. Used as an inter-CPU communication
103 mechanism.
104
105 - ``spinlock.h``
106
107 Lightweight implementation of synchronisation locks. Used to prevent
108 concurrent accesses to shared data structures.
109
110 - ``timer.h``
111
112 Support for programming the timer. Any timer which is in the `always-on`
113 power domain can be used to exit CPUs from suspend state.
114
115 - ``tftf_lib.h``
116
117 Miscellaneous helper functions/macros: MP-safe ``printf()``, low-level
118 PSCI wrappers, insertion of delays, raw SMC interface, support for writing
119 a string in the test report, macros to skip tests on platforms that do not
120 meet topology requirements, etc.
121
122 - ``semihosting.h``
123
124 Semihosting support.
125
126 - ``io_storage.h``
127
128 Low-level IO operations. Tests are not expected to use these APIs
129 directly. They should use higher-level APIs like ``tftf_nvm_read()``
130 and ``tftf_nvm_write()``.
131
132 ``include/stdlib/`` provides standard C library functions (``memcpy()``,
133 ``printf()``, and so on).
134
135- **Platform specific.**
136
137 Note that ``include/plat/common/plat_topology.h`` provides the interfaces
138 that a platform must implement to support topology discovery (i.e. how many
139 CPUs and clusters there are).
140
141- **Tests.**
142
143The tests are divided into the following categories (present as directories in
144the ``tftf/tests/`` directory):
145
146- **Framework validation tests.**
147
148 Tests that exercise the core features of the framework. Verify that the test
149 framework itself works properly.
150
151- **Runtime services tests.**
152
153 Tests that exercise the runtime services offered by the EL3 Firmware to the
154 Normal World software. For example, this includes tests for the Standard
155 Service (to which PSCI belongs to), the Trusted OS service or the SiP
156 service.
157
158- **CPU extensions tests.**
159
160 Tests some CPU extensions features. For example, the AMU tests ensure that
161 the counters provided by the Activity Monitor Unit are behaving correctly.
162
163- **Firmware Update tests.**
164
165 Tests that exercise the `Firmware Update`_ feature of TF-A.
166
167- **Template tests.**
168
169 Sample test code showing how to write tests in practice. Serves as
170 documentation.
171
172- **Performance tests.**
173
174 Simple tests measuring the latency of an SMC call.
175
176- **Miscellaneous tests.**
177
178 Tests for RAS support, correct system setup, ...
179
180All assembler files have the ``.S`` extension. The linker source file has the
181extension ``.ld.S``. This is processed by GCC to create the linker script which
182has the extension ``.ld``.
183
184Detailed Code Structure
185-----------------------
186
187The cold boot entry point is ``tftf_entrypoint`` (see
188``tftf/framework/aarch64/entrypoint.S``). As explained in section `Global
189overview of the TF-A tests behaviour`_, only the primary CPU is expected to
190execute this code.
191
192Tests can power on other CPUs using the function ``tftf_cpu_on()``. This uses
193the PSCI ``CPU_ON`` API of the EL3 Firmware. When entering the Normal World,
194execution starts at the warm boot entry point, which is ``tftf_hotplug_entry()``
195(see ``tftf/framework/aarch64/entrypoint.S``).
196
197Information about the progression of the test session and tests results are
198written into Non-Volatile Memory as we go along. This consists of the following
199data (see struct ``tftf_state_t`` typedef in ``tftf/framework/include/nvm.h``):
200
201- ``test_to_run``
202
203 Reference to the test to run.
204
205- ``test_progress``
206
207 Progress in the execution of ``test_to_run``. This is used to implement the
208 following state machine:
209
210::
211
212 +-> TEST_READY (initial state of the test) <--------------+
213 | | |
214 | | Test framework prepares the test environment. |
215 | | |
216 | v |
217 | TEST_IN_PROGRESS |
218 | | |
219 | | Hand over to the test function. |
220 | | If the test wants to reboot the platform ---> TEST_REBOOTING |
221 | | | |
222 | | Test function returns into framework. | Reboot |
223 | | | |
224 | | +---------+
225 | v
226 | TEST_COMPLETE
227 | |
228 | | Do some framework management.
229 | | Move to next test.
230 +--------+
231
232- ``testcase_buffer``
233
234 A buffer that the test can use as a scratch area for whatever it is doing.
235
236- ``testcase_results``
237
238- ``result_buffer_size``
239
240- ``result_buffer``
241
242 Buffer holding the tests output. Tests output are concatenated.
243
244Interrupts management
245---------------------
246
247The TF-A tests expect SGIs #0 to #7 to be available for their own usage. In
248particular, this means that Trusted World software must configure them as
249non-secure interrupts.
250
251SGI #7 has a special status. It is the SGI that the timer management framework
252sends to all CPUs when the system timer fires off (see the definition of the
253constant ``IRQ_WAKE_SGI`` in the header file ``include/lib/irq.h``). Although
254test cases can use this specific SGI - e.g. they can register an IRQ handler for
255it and use it as an inter-CPU communication mechanism - they have to be aware of
256the underlying consequences. Some tests, like the PSCI ``CPU_SUSPEND`` tests,
257rely on this SGI to be enabled in order to wake up CPUs from their suspend
258state. If it is disabled, these tests will leave the system in an unresponsive
259state.
260
261--------------
262
263*Copyright (c) 2018, Arm Limited. All rights reserved.*
264
265.. _Summary of build options: user-guide.html#summary-of-build-options
266.. _Firmware Update: https://github.com/ARM-software/arm-trusted-firmware/blob/master/docs/firmware-update.rst