blob: 91815d02df682d0757da5900566396b3c164028d [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
Sandrine Bailleux68d76a22018-11-07 16:31:23 +010024Once all tests have completed, a report is printed over the serial console.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020025
26Global Code Structure
27---------------------
28
29The code is organised into the following categories (present as directories at
30the top level or under the ``tftf/`` directory):
31
32- **Drivers.**
33
34 Some examples follow, this list might not be exhaustive.
35
36 - Generic GIC driver.
37
38 ``arm_gic.h`` contains the public APIs that tests might use. Both GIC
39 architecture versions 2 and 3 are supported.
40
41 - PL011 UART driver.
42
43 - VExpress NOR flash driver.
44
45 Note that tests are not expected to use this driver in most
46 cases. Instead, they should use the ``tftf_nvm_read()`` and
47 ``tftf_nvm_write()`` wrapper APIs. See definitions in
48 ``tftf/framework/include/nvm.h``. See also the NVM validation test cases
49 (``tftf/tests/framework_validation_tests/test_validation_nvm.c``) for an
50 example of usage of these functions.
51
52 - SP805 watchdog.
53
54 Used solely to generate an interrupt that will reset the system on purpose
55 (used in ``tftf_plat_reset()``).
56
57 - SP804 timer.
58
59 This is used as the system timer on Juno. It is configured such that an
60 interrupt is generated when it reaches 0. It is programmed in one-shot
61 mode, i.e. it must be rearmed every time it reaches 0.
62
63- **Framework.**
64
65 Core features of the test framework.
66
67- **Library code.**
68
Ambroise Vincentd6e806d2019-02-11 14:34:26 +000069 Firstly, there is ``include/libc/`` which provides standard C library
John Tsichritzis4586e0d2018-10-18 10:00:28 +010070 functions like ``memcpy()``, ``printf()`` and so on.
71 Additionally, various other APIs are provided under ``include/lib/``. The
72 below list gives some examples but might not be exhaustive.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020073
74 - ``aarch64/``
75
76 Architecture helper functions for e.g. system registers access, cache
77 maintenance operations, MMU configuration, ...
78
79 - ``events.h``
80
81 Events API. Used to create synchronisation points between CPUs in tests.
82
83 - ``irq.h``
84
85 IRQ handling support. Used to configure IRQs and register/unregister
86 handlers called upon reception of a specific IRQ.
87
88 - ``power_management.h``
89
90 Power management operations (CPU ON/OFF, CPU suspend, etc.).
91
92 - ``sgi.h``
93
94 Software Generated Interrupt support. Used as an inter-CPU communication
95 mechanism.
96
97 - ``spinlock.h``
98
99 Lightweight implementation of synchronisation locks. Used to prevent
100 concurrent accesses to shared data structures.
101
102 - ``timer.h``
103
104 Support for programming the timer. Any timer which is in the `always-on`
105 power domain can be used to exit CPUs from suspend state.
106
107 - ``tftf_lib.h``
108
109 Miscellaneous helper functions/macros: MP-safe ``printf()``, low-level
110 PSCI wrappers, insertion of delays, raw SMC interface, support for writing
111 a string in the test report, macros to skip tests on platforms that do not
112 meet topology requirements, etc.
113
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200114 - ``io_storage.h``
115
116 Low-level IO operations. Tests are not expected to use these APIs
117 directly. They should use higher-level APIs like ``tftf_nvm_read()``
118 and ``tftf_nvm_write()``.
119
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200120- **Platform specific.**
121
122 Note that ``include/plat/common/plat_topology.h`` provides the interfaces
123 that a platform must implement to support topology discovery (i.e. how many
124 CPUs and clusters there are).
125
126- **Tests.**
127
John Tsichritzis88a956f2018-10-19 10:30:00 +0100128 The tests are divided into the following categories (present as directories in
129 the ``tftf/tests/`` directory):
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200130
John Tsichritzis88a956f2018-10-19 10:30:00 +0100131 - **Framework validation tests.**
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200132
John Tsichritzis88a956f2018-10-19 10:30:00 +0100133 Tests that exercise the core features of the framework. Verify that the test
134 framework itself works properly.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200135
John Tsichritzis88a956f2018-10-19 10:30:00 +0100136 - **Runtime services tests.**
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200137
John Tsichritzis88a956f2018-10-19 10:30:00 +0100138 Tests that exercise the runtime services offered by the EL3 Firmware to the
139 Normal World software. For example, this includes tests for the Standard
140 Service (to which PSCI belongs to), the Trusted OS service or the SiP
141 service.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200142
John Tsichritzis88a956f2018-10-19 10:30:00 +0100143 - **CPU extensions tests.**
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200144
John Tsichritzis88a956f2018-10-19 10:30:00 +0100145 Tests some CPU extensions features. For example, the AMU tests ensure that
146 the counters provided by the Activity Monitor Unit are behaving correctly.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200147
John Tsichritzis88a956f2018-10-19 10:30:00 +0100148 - **Firmware Update tests.**
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200149
John Tsichritzis88a956f2018-10-19 10:30:00 +0100150 Tests that exercise the `Firmware Update`_ feature of TF-A.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200151
John Tsichritzis88a956f2018-10-19 10:30:00 +0100152 - **Template tests.**
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200153
John Tsichritzis88a956f2018-10-19 10:30:00 +0100154 Sample test code showing how to write tests in practice. Serves as
155 documentation.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200156
John Tsichritzis88a956f2018-10-19 10:30:00 +0100157 - **Performance tests.**
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200158
John Tsichritzis88a956f2018-10-19 10:30:00 +0100159 Simple tests measuring the latency of an SMC call.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200160
John Tsichritzis88a956f2018-10-19 10:30:00 +0100161 - **Miscellaneous tests.**
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200162
John Tsichritzis88a956f2018-10-19 10:30:00 +0100163 Tests for RAS support, correct system setup, ...
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200164
165All assembler files have the ``.S`` extension. The linker source file has the
166extension ``.ld.S``. This is processed by GCC to create the linker script which
167has the extension ``.ld``.
168
169Detailed Code Structure
170-----------------------
171
172The cold boot entry point is ``tftf_entrypoint`` (see
173``tftf/framework/aarch64/entrypoint.S``). As explained in section `Global
174overview of the TF-A tests behaviour`_, only the primary CPU is expected to
175execute this code.
176
177Tests can power on other CPUs using the function ``tftf_cpu_on()``. This uses
178the PSCI ``CPU_ON`` API of the EL3 Firmware. When entering the Normal World,
179execution starts at the warm boot entry point, which is ``tftf_hotplug_entry()``
180(see ``tftf/framework/aarch64/entrypoint.S``).
181
182Information about the progression of the test session and tests results are
183written into Non-Volatile Memory as we go along. This consists of the following
184data (see struct ``tftf_state_t`` typedef in ``tftf/framework/include/nvm.h``):
185
186- ``test_to_run``
187
188 Reference to the test to run.
189
190- ``test_progress``
191
192 Progress in the execution of ``test_to_run``. This is used to implement the
193 following state machine:
194
195::
196
197 +-> TEST_READY (initial state of the test) <--------------+
198 | | |
199 | | Test framework prepares the test environment. |
200 | | |
201 | v |
202 | TEST_IN_PROGRESS |
203 | | |
204 | | Hand over to the test function. |
205 | | If the test wants to reboot the platform ---> TEST_REBOOTING |
206 | | | |
207 | | Test function returns into framework. | Reboot |
208 | | | |
209 | | +---------+
210 | v
211 | TEST_COMPLETE
212 | |
213 | | Do some framework management.
214 | | Move to next test.
215 +--------+
216
217- ``testcase_buffer``
218
219 A buffer that the test can use as a scratch area for whatever it is doing.
220
221- ``testcase_results``
222
223- ``result_buffer_size``
224
225- ``result_buffer``
226
227 Buffer holding the tests output. Tests output are concatenated.
228
229Interrupts management
230---------------------
231
232The TF-A tests expect SGIs #0 to #7 to be available for their own usage. In
233particular, this means that Trusted World software must configure them as
234non-secure interrupts.
235
236SGI #7 has a special status. It is the SGI that the timer management framework
237sends to all CPUs when the system timer fires off (see the definition of the
238constant ``IRQ_WAKE_SGI`` in the header file ``include/lib/irq.h``). Although
239test cases can use this specific SGI - e.g. they can register an IRQ handler for
240it and use it as an inter-CPU communication mechanism - they have to be aware of
241the underlying consequences. Some tests, like the PSCI ``CPU_SUSPEND`` tests,
242rely on this SGI to be enabled in order to wake up CPUs from their suspend
243state. If it is disabled, these tests will leave the system in an unresponsive
244state.
245
246--------------
247
Sandrine Bailleuxdd842752019-04-10 09:30:10 +0200248*Copyright (c) 2018-2019, Arm Limited. All rights reserved.*
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200249
John Tsichritzis4586e0d2018-10-18 10:00:28 +0100250.. _Summary of build options: user-guide.rst#summary-of-build-options
Sandrine Bailleuxdd842752019-04-10 09:30:10 +0200251.. _Firmware Update: https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/about/docs/firmware-update.rst