blob: 7163aade08ea93bd16ec67e4f85313c4a03512c3 [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
John Tsichritzis4586e0d2018-10-18 10:00:28 +010079 Firstly, there is ``include/stdlib/`` which provides standard C library
80 functions like ``memcpy()``, ``printf()`` and so on.
81 Additionally, various other APIs are provided under ``include/lib/``. The
82 below list gives some examples but might not be exhaustive.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020083
84 - ``aarch64/``
85
86 Architecture helper functions for e.g. system registers access, cache
87 maintenance operations, MMU configuration, ...
88
89 - ``events.h``
90
91 Events API. Used to create synchronisation points between CPUs in tests.
92
93 - ``irq.h``
94
95 IRQ handling support. Used to configure IRQs and register/unregister
96 handlers called upon reception of a specific IRQ.
97
98 - ``power_management.h``
99
100 Power management operations (CPU ON/OFF, CPU suspend, etc.).
101
102 - ``sgi.h``
103
104 Software Generated Interrupt support. Used as an inter-CPU communication
105 mechanism.
106
107 - ``spinlock.h``
108
109 Lightweight implementation of synchronisation locks. Used to prevent
110 concurrent accesses to shared data structures.
111
112 - ``timer.h``
113
114 Support for programming the timer. Any timer which is in the `always-on`
115 power domain can be used to exit CPUs from suspend state.
116
117 - ``tftf_lib.h``
118
119 Miscellaneous helper functions/macros: MP-safe ``printf()``, low-level
120 PSCI wrappers, insertion of delays, raw SMC interface, support for writing
121 a string in the test report, macros to skip tests on platforms that do not
122 meet topology requirements, etc.
123
124 - ``semihosting.h``
125
126 Semihosting support.
127
128 - ``io_storage.h``
129
130 Low-level IO operations. Tests are not expected to use these APIs
131 directly. They should use higher-level APIs like ``tftf_nvm_read()``
132 and ``tftf_nvm_write()``.
133
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200134- **Platform specific.**
135
136 Note that ``include/plat/common/plat_topology.h`` provides the interfaces
137 that a platform must implement to support topology discovery (i.e. how many
138 CPUs and clusters there are).
139
140- **Tests.**
141
John Tsichritzis88a956f2018-10-19 10:30:00 +0100142 The tests are divided into the following categories (present as directories in
143 the ``tftf/tests/`` directory):
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200144
John Tsichritzis88a956f2018-10-19 10:30:00 +0100145 - **Framework validation tests.**
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200146
John Tsichritzis88a956f2018-10-19 10:30:00 +0100147 Tests that exercise the core features of the framework. Verify that the test
148 framework itself works properly.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200149
John Tsichritzis88a956f2018-10-19 10:30:00 +0100150 - **Runtime services tests.**
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200151
John Tsichritzis88a956f2018-10-19 10:30:00 +0100152 Tests that exercise the runtime services offered by the EL3 Firmware to the
153 Normal World software. For example, this includes tests for the Standard
154 Service (to which PSCI belongs to), the Trusted OS service or the SiP
155 service.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200156
John Tsichritzis88a956f2018-10-19 10:30:00 +0100157 - **CPU extensions tests.**
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200158
John Tsichritzis88a956f2018-10-19 10:30:00 +0100159 Tests some CPU extensions features. For example, the AMU tests ensure that
160 the counters provided by the Activity Monitor Unit are behaving correctly.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200161
John Tsichritzis88a956f2018-10-19 10:30:00 +0100162 - **Firmware Update tests.**
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200163
John Tsichritzis88a956f2018-10-19 10:30:00 +0100164 Tests that exercise the `Firmware Update`_ feature of TF-A.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200165
John Tsichritzis88a956f2018-10-19 10:30:00 +0100166 - **Template tests.**
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200167
John Tsichritzis88a956f2018-10-19 10:30:00 +0100168 Sample test code showing how to write tests in practice. Serves as
169 documentation.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200170
John Tsichritzis88a956f2018-10-19 10:30:00 +0100171 - **Performance tests.**
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200172
John Tsichritzis88a956f2018-10-19 10:30:00 +0100173 Simple tests measuring the latency of an SMC call.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200174
John Tsichritzis88a956f2018-10-19 10:30:00 +0100175 - **Miscellaneous tests.**
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200176
John Tsichritzis88a956f2018-10-19 10:30:00 +0100177 Tests for RAS support, correct system setup, ...
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200178
179All assembler files have the ``.S`` extension. The linker source file has the
180extension ``.ld.S``. This is processed by GCC to create the linker script which
181has the extension ``.ld``.
182
183Detailed Code Structure
184-----------------------
185
186The cold boot entry point is ``tftf_entrypoint`` (see
187``tftf/framework/aarch64/entrypoint.S``). As explained in section `Global
188overview of the TF-A tests behaviour`_, only the primary CPU is expected to
189execute this code.
190
191Tests can power on other CPUs using the function ``tftf_cpu_on()``. This uses
192the PSCI ``CPU_ON`` API of the EL3 Firmware. When entering the Normal World,
193execution starts at the warm boot entry point, which is ``tftf_hotplug_entry()``
194(see ``tftf/framework/aarch64/entrypoint.S``).
195
196Information about the progression of the test session and tests results are
197written into Non-Volatile Memory as we go along. This consists of the following
198data (see struct ``tftf_state_t`` typedef in ``tftf/framework/include/nvm.h``):
199
200- ``test_to_run``
201
202 Reference to the test to run.
203
204- ``test_progress``
205
206 Progress in the execution of ``test_to_run``. This is used to implement the
207 following state machine:
208
209::
210
211 +-> TEST_READY (initial state of the test) <--------------+
212 | | |
213 | | Test framework prepares the test environment. |
214 | | |
215 | v |
216 | TEST_IN_PROGRESS |
217 | | |
218 | | Hand over to the test function. |
219 | | If the test wants to reboot the platform ---> TEST_REBOOTING |
220 | | | |
221 | | Test function returns into framework. | Reboot |
222 | | | |
223 | | +---------+
224 | v
225 | TEST_COMPLETE
226 | |
227 | | Do some framework management.
228 | | Move to next test.
229 +--------+
230
231- ``testcase_buffer``
232
233 A buffer that the test can use as a scratch area for whatever it is doing.
234
235- ``testcase_results``
236
237- ``result_buffer_size``
238
239- ``result_buffer``
240
241 Buffer holding the tests output. Tests output are concatenated.
242
243Interrupts management
244---------------------
245
246The TF-A tests expect SGIs #0 to #7 to be available for their own usage. In
247particular, this means that Trusted World software must configure them as
248non-secure interrupts.
249
250SGI #7 has a special status. It is the SGI that the timer management framework
251sends to all CPUs when the system timer fires off (see the definition of the
252constant ``IRQ_WAKE_SGI`` in the header file ``include/lib/irq.h``). Although
253test cases can use this specific SGI - e.g. they can register an IRQ handler for
254it and use it as an inter-CPU communication mechanism - they have to be aware of
255the underlying consequences. Some tests, like the PSCI ``CPU_SUSPEND`` tests,
256rely on this SGI to be enabled in order to wake up CPUs from their suspend
257state. If it is disabled, these tests will leave the system in an unresponsive
258state.
259
260--------------
261
262*Copyright (c) 2018, Arm Limited. All rights reserved.*
263
John Tsichritzis4586e0d2018-10-18 10:00:28 +0100264.. _Summary of build options: user-guide.rst#summary-of-build-options
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200265.. _Firmware Update: https://github.com/ARM-software/arm-trusted-firmware/blob/master/docs/firmware-update.rst