Paul Beesley | 24a6bd6 | 2019-10-24 11:57:00 +0000 | [diff] [blame] | 1 | Implementing Tests |
| 2 | ================== |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 3 | |
| 4 | This document aims at providing some pointers to help implementing new tests in |
| 5 | the TFTF image. |
| 6 | |
Jimmy Brisson | 06b5be4 | 2020-04-02 15:19:27 -0500 | [diff] [blame] | 7 | Test Structure |
| 8 | -------------- |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 9 | |
| 10 | A test might be divided into 3 logical parts, detailed in the following |
| 11 | sections. |
| 12 | |
| 13 | Prologue |
Jimmy Brisson | 06b5be4 | 2020-04-02 15:19:27 -0500 | [diff] [blame] | 14 | ^^^^^^^^ |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 15 | |
| 16 | A test has a main entry point function, whose type is: |
| 17 | |
| 18 | :: |
| 19 | |
| 20 | typedef test_result_t (*test_function_t)(void); |
| 21 | |
Jimmy Brisson | 7b56d30 | 2020-04-02 15:19:34 -0500 | [diff] [blame] | 22 | See ``tftf/framework/include/tftf.h``. |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 23 | |
| 24 | Only the primary CPU enters this function, while other CPUs are powered down. |
| 25 | |
| 26 | First of all, the test function should check whether this test is applicable to |
| 27 | this platform and environment. Some tests rely on specific hardware features or |
| 28 | firmware capabilities to be present. If these are not available, the test should |
Jimmy Brisson | 7b56d30 | 2020-04-02 15:19:34 -0500 | [diff] [blame] | 29 | be skipped. For example, a multi-core test requires at least 2 CPUs to |
| 30 | run. Macros and functions are provided in ``include/common/test_helpers.h`` to |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 31 | help test code verify that their requirements are met. |
| 32 | |
| 33 | Core |
Jimmy Brisson | 06b5be4 | 2020-04-02 15:19:27 -0500 | [diff] [blame] | 34 | ^^^^ |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 35 | |
| 36 | This is completely dependent on the purpose of the test. The paragraphs below |
| 37 | just provide some useful, general information. |
| 38 | |
| 39 | The primary CPU may power on other CPUs by calling the function |
| 40 | ``tftf_cpu_on()``. It provides an address to which secondary CPUs should jump |
| 41 | to once they have been initialized by the test framework. This address should be |
| 42 | different from the primary CPU test function. |
| 43 | |
Jimmy Brisson | 7b56d30 | 2020-04-02 15:19:34 -0500 | [diff] [blame] | 44 | Synchronization primitives are provided in ``include/lib/events.h`` in case CPUs' |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 45 | execution threads need to be synchronized. Most multi-processing tests will need |
| 46 | some synchronisation points that all/some CPUs need to reach before test |
| 47 | execution may continue. |
| 48 | |
| 49 | Any CPU that is involved in a test must return from its test function. Failure |
Jimmy Brisson | 7b56d30 | 2020-04-02 15:19:34 -0500 | [diff] [blame] | 50 | to do so will put the framework in an unrecoverable state, see the |
| 51 | :ref:`Change Log & Release Notes` for details on this and other known |
| 52 | limitations. The return code indicates the test result from the point of view of |
| 53 | this CPU. At the end of the test, individual CPU results are aggregated and the |
| 54 | overall test result is derived from that. A test is considered as passed if all |
| 55 | involved CPUs reported a success status code. |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 56 | |
| 57 | Epilogue |
Jimmy Brisson | 06b5be4 | 2020-04-02 15:19:27 -0500 | [diff] [blame] | 58 | ^^^^^^^^ |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 59 | |
| 60 | Each test is responsible for releasing any allocated resources and putting the |
| 61 | system back in a clean state when it finishes. Any change to the system |
| 62 | configuration (e.g. MMU setup, GIC configuration, system registers, ...) must be |
| 63 | undone and the original configuration must be restored. This guarantees that the |
| 64 | next test is not affected by the actions of the previous one. |
| 65 | |
| 66 | One exception to this rule is that CPUs powered on as part of a test must not be |
| 67 | powered down. As already stated above, as soon as a CPU enters the test, the |
| 68 | framework expects it to return from the test. |
| 69 | |
Jimmy Brisson | 06b5be4 | 2020-04-02 15:19:27 -0500 | [diff] [blame] | 70 | Template Test Code |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 71 | ------------------ |
| 72 | |
Jimmy Brisson | 7b56d30 | 2020-04-02 15:19:34 -0500 | [diff] [blame] | 73 | Some template test code is provided in ``tftf/tests/template_tests``. It can be |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 74 | used as a starting point for developing new tests. Template code for both |
| 75 | single-core and multi-core tests is provided. |
| 76 | |
Jimmy Brisson | 06b5be4 | 2020-04-02 15:19:27 -0500 | [diff] [blame] | 77 | Build System Integration |
| 78 | ------------------------ |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 79 | |
Jimmy Brisson | 7b56d30 | 2020-04-02 15:19:34 -0500 | [diff] [blame] | 80 | All test code is located under the ``tftf/tests`` directory. Tests are usually |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 81 | divided into categories represented as sub-directories under ``tftf/tests/``. |
| 82 | |
| 83 | The source file implementing the new test code should be added to the |
Jimmy Brisson | 7b56d30 | 2020-04-02 15:19:34 -0500 | [diff] [blame] | 84 | appropriate tests makefile, see `.*mk` files under ``tftf/tests``. |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 85 | |
| 86 | The new test code should also appear in a tests manifest, see ``*.xml`` files |
Jimmy Brisson | 7b56d30 | 2020-04-02 15:19:34 -0500 | [diff] [blame] | 87 | under ``tftf/tests``. A unique name and test function must be provided. An |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 88 | optional description may be provided as well. |
| 89 | |
| 90 | For example, to create a test case named "``Foo test case``", whose test |
| 91 | function is ``foo()``, add the following line in the tests manifest: |
| 92 | |
| 93 | :: |
| 94 | |
| 95 | <testcase name="Foo test case" function="foo" /> |
| 96 | |
| 97 | A testcase must be part of a testsuite. The ``testcase`` XML node above must be |
| 98 | inside a ``testsuite`` XML node. A unique name and a description must be |
| 99 | provided for the testsuite. |
| 100 | |
| 101 | For example, to create a test suite named "``Bar test suite``", whose |
| 102 | description is: "``An example test suite``", add the following 2 lines: |
| 103 | |
| 104 | :: |
| 105 | |
| 106 | <testsuite name="Bar test suite" description="An example test suite"> |
| 107 | </testsuite> |
| 108 | |
Jimmy Brisson | 7b56d30 | 2020-04-02 15:19:34 -0500 | [diff] [blame] | 109 | See the template test manifest for reference: ``tftf/tests/tests-template.xml``. |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 110 | |
| 111 | -------------- |
| 112 | |
Sandrine Bailleux | 5229f23 | 2020-04-27 16:43:13 +0200 | [diff] [blame] | 113 | *Copyright (c) 2018-2020, Arm Limited. All rights reserved.* |