Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 1 | Trusted Firmware-A Tests - Design |
| 2 | ================================= |
| 3 | |
| 4 | .. section-numbering:: |
| 5 | :suffix: . |
| 6 | |
| 7 | .. contents:: |
| 8 | |
| 9 | This document provides some details about the internals of the TF-A Tests |
| 10 | design. It is incomplete at the moment. |
| 11 | |
| 12 | Global overview of the TF-A tests behaviour |
| 13 | ------------------------------------------- |
| 14 | |
| 15 | The EL3 firmware is expected to hand over to the TF-A tests with all secondary |
| 16 | cores powered down, i.e. only the primary core should enter the TF-A tests. |
| 17 | |
| 18 | The primary CPU initialises the platform and the TF-A tests internal data |
| 19 | structures. |
| 20 | |
| 21 | Then the test session begins. The TF-A tests are executed one after the |
| 22 | other. Tests results are saved in non-volatile memory as we go along. |
| 23 | |
| 24 | Once all tests have completed, a report is generated. The TF-A tests currently |
| 25 | supports 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 | |
| 33 | The report format to use is chosen at build time. For more information, |
| 34 | refer to the section `Summary of build options`_ in the User Guide. |
| 35 | |
| 36 | Global Code Structure |
| 37 | --------------------- |
| 38 | |
| 39 | The code is organised into the following categories (present as directories at |
| 40 | the 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 Tsichritzis | 4586e0d | 2018-10-18 10:00:28 +0100 | [diff] [blame] | 79 | 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 Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 83 | |
| 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 Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 134 | - **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 Tsichritzis | 88a956f | 2018-10-19 10:30:00 +0100 | [diff] [blame] | 142 | The tests are divided into the following categories (present as directories in |
| 143 | the ``tftf/tests/`` directory): |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 144 | |
John Tsichritzis | 88a956f | 2018-10-19 10:30:00 +0100 | [diff] [blame] | 145 | - **Framework validation tests.** |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 146 | |
John Tsichritzis | 88a956f | 2018-10-19 10:30:00 +0100 | [diff] [blame] | 147 | Tests that exercise the core features of the framework. Verify that the test |
| 148 | framework itself works properly. |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 149 | |
John Tsichritzis | 88a956f | 2018-10-19 10:30:00 +0100 | [diff] [blame] | 150 | - **Runtime services tests.** |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 151 | |
John Tsichritzis | 88a956f | 2018-10-19 10:30:00 +0100 | [diff] [blame] | 152 | 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 Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 156 | |
John Tsichritzis | 88a956f | 2018-10-19 10:30:00 +0100 | [diff] [blame] | 157 | - **CPU extensions tests.** |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 158 | |
John Tsichritzis | 88a956f | 2018-10-19 10:30:00 +0100 | [diff] [blame] | 159 | 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 Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 161 | |
John Tsichritzis | 88a956f | 2018-10-19 10:30:00 +0100 | [diff] [blame] | 162 | - **Firmware Update tests.** |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 163 | |
John Tsichritzis | 88a956f | 2018-10-19 10:30:00 +0100 | [diff] [blame] | 164 | Tests that exercise the `Firmware Update`_ feature of TF-A. |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 165 | |
John Tsichritzis | 88a956f | 2018-10-19 10:30:00 +0100 | [diff] [blame] | 166 | - **Template tests.** |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 167 | |
John Tsichritzis | 88a956f | 2018-10-19 10:30:00 +0100 | [diff] [blame] | 168 | Sample test code showing how to write tests in practice. Serves as |
| 169 | documentation. |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 170 | |
John Tsichritzis | 88a956f | 2018-10-19 10:30:00 +0100 | [diff] [blame] | 171 | - **Performance tests.** |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 172 | |
John Tsichritzis | 88a956f | 2018-10-19 10:30:00 +0100 | [diff] [blame] | 173 | Simple tests measuring the latency of an SMC call. |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 174 | |
John Tsichritzis | 88a956f | 2018-10-19 10:30:00 +0100 | [diff] [blame] | 175 | - **Miscellaneous tests.** |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 176 | |
John Tsichritzis | 88a956f | 2018-10-19 10:30:00 +0100 | [diff] [blame] | 177 | Tests for RAS support, correct system setup, ... |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 178 | |
| 179 | All assembler files have the ``.S`` extension. The linker source file has the |
| 180 | extension ``.ld.S``. This is processed by GCC to create the linker script which |
| 181 | has the extension ``.ld``. |
| 182 | |
| 183 | Detailed Code Structure |
| 184 | ----------------------- |
| 185 | |
| 186 | The cold boot entry point is ``tftf_entrypoint`` (see |
| 187 | ``tftf/framework/aarch64/entrypoint.S``). As explained in section `Global |
| 188 | overview of the TF-A tests behaviour`_, only the primary CPU is expected to |
| 189 | execute this code. |
| 190 | |
| 191 | Tests can power on other CPUs using the function ``tftf_cpu_on()``. This uses |
| 192 | the PSCI ``CPU_ON`` API of the EL3 Firmware. When entering the Normal World, |
| 193 | execution starts at the warm boot entry point, which is ``tftf_hotplug_entry()`` |
| 194 | (see ``tftf/framework/aarch64/entrypoint.S``). |
| 195 | |
| 196 | Information about the progression of the test session and tests results are |
| 197 | written into Non-Volatile Memory as we go along. This consists of the following |
| 198 | data (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 | |
| 243 | Interrupts management |
| 244 | --------------------- |
| 245 | |
| 246 | The TF-A tests expect SGIs #0 to #7 to be available for their own usage. In |
| 247 | particular, this means that Trusted World software must configure them as |
| 248 | non-secure interrupts. |
| 249 | |
| 250 | SGI #7 has a special status. It is the SGI that the timer management framework |
| 251 | sends to all CPUs when the system timer fires off (see the definition of the |
| 252 | constant ``IRQ_WAKE_SGI`` in the header file ``include/lib/irq.h``). Although |
| 253 | test cases can use this specific SGI - e.g. they can register an IRQ handler for |
| 254 | it and use it as an inter-CPU communication mechanism - they have to be aware of |
| 255 | the underlying consequences. Some tests, like the PSCI ``CPU_SUSPEND`` tests, |
| 256 | rely on this SGI to be enabled in order to wake up CPUs from their suspend |
| 257 | state. If it is disabled, these tests will leave the system in an unresponsive |
| 258 | state. |
| 259 | |
| 260 | -------------- |
| 261 | |
| 262 | *Copyright (c) 2018, Arm Limited. All rights reserved.* |
| 263 | |
John Tsichritzis | 4586e0d | 2018-10-18 10:00:28 +0100 | [diff] [blame] | 264 | .. _Summary of build options: user-guide.rst#summary-of-build-options |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 265 | .. _Firmware Update: https://github.com/ARM-software/arm-trusted-firmware/blob/master/docs/firmware-update.rst |