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