Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 1 | ################################# |
| 2 | Adding TF-M Regression Test Suite |
| 3 | ################################# |
| 4 | |
| 5 | .. contents:: Table of Contents |
| 6 | |
| 7 | ************************************* |
| 8 | Introduction of TF-M regression tests |
| 9 | ************************************* |
| 10 | |
| 11 | TF-M regression tests test whether changes to TF-M code work as expected. |
| 12 | A new regression test can consist of following 3 components: |
| 13 | |
| 14 | 1. ``test suite``: A series of tests of a certain function. |
| 15 | 2. ``test case``: A specific test instance in test suites. |
| 16 | 3. ``test service or partition``: Optional secure services or partitions to |
| 17 | support related test suites. |
| 18 | |
| 19 | Source structure |
| 20 | ================ |
| 21 | |
| 22 | +---------------------------------------+---------------------------------------------------------------+ |
| 23 | | Folder name | Description | |
| 24 | +=======================================+===============================================================+ |
| 25 | | test/bl1 | TF-M bl1 test suites source code. | |
| 26 | +---------------------------------------+---------------------------------------------------------------+ |
| 27 | | test/bl2 | TF-M bL2 test suites source code. | |
| 28 | +---------------------------------------+---------------------------------------------------------------+ |
| 29 | | test/config | The CMAKE test configurations files. | |
| 30 | +---------------------------------------+---------------------------------------------------------------+ |
| 31 | | test/framework | Source code for test framework code, managing test suites. | |
| 32 | +---------------------------------------+---------------------------------------------------------------+ |
| 33 | | test/secure_fw/suites | Test suites divided into subdirectories. | |
| 34 | +---------------------------------------+---------------------------------------------------------------+ |
| 35 | | test/secure_fw/suites/<suite>/service | Test service divided into corresponding suite subdirectories. | |
| 36 | +---------------------------------------+---------------------------------------------------------------+ |
| 37 | | test/secure_fw/common_test_services | Common test services. | |
| 38 | +---------------------------------------+---------------------------------------------------------------+ |
| 39 | |
| 40 | *********************** |
| 41 | Adding a new test suite |
| 42 | *********************** |
| 43 | |
| 44 | This section introduces how to add a new test suite and control its compilation |
David Hu | 945d22d | 2023-11-30 17:49:34 +0800 | [diff] [blame] | 45 | with a test configuration in ``tests_reg/test`` repository. |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 46 | |
| 47 | Source code |
| 48 | =========== |
| 49 | |
| 50 | The test suite example subdirectory named ``<test_name>`` is located under the |
David Hu | 945d22d | 2023-11-30 17:49:34 +0800 | [diff] [blame] | 51 | path ``tests_reg/test/secure_fw/suites``. If the new test suite includes both |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 52 | non-secure and secure parts, the source code shall be divided shared code and |
| 53 | specific code. An example test suite folder can be organized as the figure |
| 54 | below. |
| 55 | |
| 56 | .. code-block:: bash |
| 57 | |
| 58 | . |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 59 | ├── <test_name>_tests_common.c |
| 60 | ├── non_secure |
David Hu | 945d22d | 2023-11-30 17:49:34 +0800 | [diff] [blame] | 61 | | ├── CMakeLists.txt |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 62 | │ ├── <test_name>_ns_interface_testsuite.c |
| 63 | │ └── <test_name>_ns_tests.h |
| 64 | └── secure |
David Hu | 945d22d | 2023-11-30 17:49:34 +0800 | [diff] [blame] | 65 | ├── CMakeLists.txt |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 66 | ├── <test_name>_s_interface_testsuite.c |
| 67 | └── <test_name>_s_tests.h |
| 68 | |
| 69 | Creating test configurations |
| 70 | ============================ |
| 71 | |
| 72 | A test configuration controls whether one or multiple test suites are enabled. |
Elena Uziunaite | 9943817 | 2023-11-13 14:39:29 +0000 | [diff] [blame] | 73 | The doc :doc:`TF-M Build Instructions <TF-M:building/tfm_build_instruction>`. |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 74 | shows some test configurations which are already supported in current TF-M. |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 75 | |
| 76 | Developers shall assign corresponding test configurations to control the test |
| 77 | suites. |
| 78 | |
| 79 | Naming test configurations |
| 80 | -------------------------- |
| 81 | |
| 82 | The test configurations of example test suites are ``TEST_NS_<TEST_NAME>`` |
| 83 | in non-secure and ``TEST_S_<TEST_NAME>`` in secure. |
| 84 | |
| 85 | .. Note:: |
| 86 | The test configurations must be named with the prefixes ``TEST_S_`` and |
| 87 | ``TEST_NS_``, for secure regression tests and non-secure regression tests |
David Hu | 945d22d | 2023-11-30 17:49:34 +0800 | [diff] [blame] | 88 | respectively. Otherwise, tests_reg/test build system may not recognize it. |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 89 | |
| 90 | Setting test configurations |
| 91 | --------------------------- |
| 92 | |
David Hu | 945d22d | 2023-11-30 17:49:34 +0800 | [diff] [blame] | 93 | When the test configurations have dependencies, the default value need to be set. |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 94 | The setting is performed in following four steps. |
| 95 | |
| 96 | #. Command line input: The configuration can be enabled or disabled by the |
| 97 | command ``-DTEST_NS_<TEST_NAME>=ON/OFF -DTEST_S_<TEST_NAME>=ON/OFF``, and |
| 98 | the value cannot be changed throughout the whole compilation of TF-M tests. |
| 99 | |
David Hu | 945d22d | 2023-11-30 17:49:34 +0800 | [diff] [blame] | 100 | #. ``tests_reg/test/config/config.cmake``: The test configurations shall be |
| 101 | ``OFF`` if its dependencies are not supported. The dependencies are probably from: |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 102 | |
| 103 | #. TF-M partitions configurations like ``TFM_PARTITION_CRYPTO``, |
| 104 | ``TFM_PARTITION_INITIAL_ATTESTATION``, etc. |
Summer Qin | ab4e42d | 2022-10-09 17:36:39 +0800 | [diff] [blame] | 105 | #. TF-M build mode configuration like ``CONFIG_TFM_SPM_BACKEND``. |
Mark Horvath | 2f07258 | 2022-09-09 16:15:30 +0200 | [diff] [blame] | 106 | #. TF-M other configurations like ``TFM_PARTITION_FIRMWARE_UPDATE``, etc. |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 107 | |
David Hu | 945d22d | 2023-11-30 17:49:34 +0800 | [diff] [blame] | 108 | #. ``tests_reg/test/config/default_ns_test_config.cmake`` or |
| 109 | ``tests_reg/test/config/default_s_test_config.cmake``: It is required to give |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 110 | the default value of the new test configuration in these two files when |
| 111 | ``TEST_NS`` or ``TEST_S`` is ON. The recommended value is ON unless the |
| 112 | single test's code or data size is very large. |
| 113 | |
David Hu | 945d22d | 2023-11-30 17:49:34 +0800 | [diff] [blame] | 114 | #. ``tests_reg/test/config/default_test_config.cmake``: It is required to give the |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 115 | default value of the new test configuration in the file when both |
| 116 | ``TEST_NS`` and ``TEST_S`` are OFF. The default value must be OFF. |
| 117 | |
| 118 | .. Note:: |
| 119 | The test configurations must be set as CACHE value in CMAKE files. The CACHE |
| 120 | set cannot replace the value from command line, see |
| 121 | `Set Cache Entry <https://cmake.org/cmake/help/latest/command/set.html#set-cache-entry>`_. |
| 122 | |
| 123 | Checking test configurations |
| 124 | ---------------------------- |
| 125 | |
| 126 | The new test configurations must be checked by function ``tfm_invalid_config()`` |
| 127 | if they have any dependence. The value comes from command line may be wrong when |
David Hu | 945d22d | 2023-11-30 17:49:34 +0800 | [diff] [blame] | 128 | the dependencies are conflicting. |
| 129 | |
| 130 | Implement necessary checks in ``tests_reg/test/config/check_config.cmake``. |
| 131 | |
| 132 | Export TF-M configurations |
| 133 | ========================== |
| 134 | |
| 135 | If the new test depends on some TF-M configurations, export their value via |
| 136 | ``tests_reg/test/config/config_ns_tests.cmake.in``. |
| 137 | TF-M secure build will install ``config_ns_tests.cmake`` and export configuration values. |
| 138 | tf-m-tests non-secure build will include ``config_ns_tests.cmake`` and receive TF-M configuration |
| 139 | values. |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 140 | |
BohdanHunko | 48eedb3 | 2022-10-19 19:01:25 +0300 | [diff] [blame] | 141 | Applying test configurations |
| 142 | ============================ |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 143 | |
| 144 | The mission of test configurations is to control the build. They are applied |
| 145 | in ``test/secure_fw/suites/<test_name>/CMakeLists.txt`` like the example below. |
| 146 | |
| 147 | .. code-block:: cmake |
| 148 | |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 149 | if (NOT TEST_NS_<TEST_NAME> AND NOT TEST_S_<TEST_NAME>) |
| 150 | return() |
| 151 | endif() |
| 152 | |
| 153 | ####################### Non Secure ######################################### |
| 154 | |
| 155 | if (TEST_NS_<TEST_NAME>) |
| 156 | add_library(tfm_test_suite_<test_name>_ns STATIC EXCLUDE_FROM_ALL) |
| 157 | # target_sources() |
| 158 | # target_include_directories() |
| 159 | target_compile_definitions(tfm_test_suite_<test_name>_ns |
| 160 | INTERFACE |
| 161 | TEST_NS_<TEST_NAME> |
| 162 | ) |
| 163 | # target_link_libraries() |
| 164 | endif() |
| 165 | |
| 166 | ####################### Secure ############################################# |
| 167 | |
| 168 | if (TEST_S_<TEST_NAME>) |
| 169 | add_library(tfm_test_suite_<test_name>_s STATIC EXCLUDE_FROM_ALL) |
| 170 | # target_sources() |
| 171 | # target_include_directories() |
| 172 | target_compile_definitions(tfm_test_suite_<test_name>_s |
| 173 | INTERFACE |
| 174 | TEST_S_<TEST_NAME> |
| 175 | ) |
| 176 | # target_link_libraries() |
| 177 | endif() |
| 178 | |
| 179 | The function ``target_compile_definitions`` will export the macros |
| 180 | ``TEST_NS_<TEST_NAME>`` or ``TEST_S_<TEST_NAME>`` into source code. and in the |
David Hu | 945d22d | 2023-11-30 17:49:34 +0800 | [diff] [blame] | 181 | file ``tests_reg/test/framework/non_secure_suites.c`` or |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 182 | ``tests/framework/secure_suites.c``, the definitions of these macros will be |
| 183 | checked, and then the head file will be included and test cases will be |
| 184 | registered if the macro is defined. |
| 185 | |
| 186 | .. code-block:: c |
| 187 | |
| 188 | #ifdef TEST_NS_<TEST_NAME> |
| 189 | #include "<test_name>_ns_tests.h" |
| 190 | #endif |
| 191 | |
| 192 | static struct test_suite_t test_suites[] = { |
| 193 | /* Non-secure example test cases */ |
| 194 | // ...... |
| 195 | #ifdef TEST_NS_<TEST_NAME> |
| 196 | {®ister_testsuite_ns_<test_name>_interface, 0, 0, 0}, |
| 197 | #endif |
| 198 | }; |
| 199 | |
| 200 | .. code-block:: c |
| 201 | |
| 202 | #ifdef TEST_S_<TEST_NAME> |
| 203 | #include "<test_name>_s_tests.h" |
| 204 | #endif |
| 205 | |
| 206 | static struct test_suite_t test_suites[] = { |
| 207 | /* Secure example test cases */ |
| 208 | // ...... |
| 209 | #ifdef TEST_S_<TEST_NAME> |
| 210 | {®ister_testsuite_s_<test_name>_interface, 0, 0, 0}, |
| 211 | #endif |
| 212 | }; |
| 213 | |
| 214 | .. Note:: |
| 215 | On most platforms non-secure tests and secure tests run on the same CPU |
| 216 | core, but dual-core platform is an exception. So secure test library and |
BohdanHunko | 48eedb3 | 2022-10-19 19:01:25 +0300 | [diff] [blame] | 217 | secure services shall be linked together in the file |
David Hu | 945d22d | 2023-11-30 17:49:34 +0800 | [diff] [blame] | 218 | ``tests_reg/test/test/secure_fw/secure_tests.cmake``. Thus they can be built on |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 219 | secure CPU core and non-secure tests library and RTOS are built on |
| 220 | non-secure CPU core. |
| 221 | |
| 222 | .. code-block:: cmake |
| 223 | |
David Hu | aecf997 | 2023-04-06 17:41:16 +0800 | [diff] [blame] | 224 | # ... |
| 225 | if (TEST_S_<TEST_NAME>) |
| 226 | add_library(tfm_test_suite_<test_name>_s STATIC EXCLUDE_FROM_ALL) |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 227 | endif() |
| 228 | |
| 229 | ************************************ |
| 230 | Adding a new test case in test suite |
| 231 | ************************************ |
| 232 | |
| 233 | The test cases usually express as a function in source code. They will be added |
| 234 | into an array with structure type called ``test_t`` defined in |
David Hu | 945d22d | 2023-11-30 17:49:34 +0800 | [diff] [blame] | 235 | ``tests_reg/test/test/framework/test_framework.h``. |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 236 | |
| 237 | .. code-block:: c |
| 238 | |
| 239 | struct test_t { |
| 240 | TEST_FUN * const test; /*!< Test function to call */ |
| 241 | const char *name; /*!< Test name */ |
| 242 | const char *desc; /*!< Test description */ |
| 243 | }; |
| 244 | |
| 245 | For example, a new test case called ``TFM_NS_<TEST_NAME>_TEST_1001`` is created |
| 246 | and the function ``tfm_<test_name>_test_1001`` needs to be defined in file |
| 247 | ``<test_name>_ns_interface_testsuite.c``. Then the function shall be appended |
| 248 | into the array which will be quoted in function |
| 249 | ``register_testsuite_ns_<test_name>_interface``. See the reference code below. |
| 250 | |
| 251 | .. code-block:: c |
| 252 | |
| 253 | /* List of test cases */ |
| 254 | static void tfm_<test_name>_test_1001(struct test_result_t *ret); |
| 255 | |
| 256 | /* Append test cases */ |
| 257 | static struct test_t <test_name>_tests[] = { |
| 258 | {&tfm_<test_name>_test_1001, "TFM_NS_<TEST_NAME>_TEST_1001", |
| 259 | "Example test case"}, |
| 260 | }; |
| 261 | |
| 262 | /* Register test case into test suites */ |
| 263 | void register_testsuite_ns_<test_name>_interface(struct test_suite_t *p_test_suite) |
| 264 | { |
| 265 | uint32_t list_size; |
| 266 | |
| 267 | list_size = (sizeof(<test_name>_tests) / sizeof(<test_name>_tests[0])); |
| 268 | |
| 269 | set_testsuite("<TEST_NAME> non-secure interface test (TFM_NS_<TEST_NAME>_TEST_1XXX)", |
| 270 | <test_name>_tests, list_size, p_test_suite); |
| 271 | } |
| 272 | |
| 273 | static void tfm_<test_name>_test_1001(struct test_result_t *ret) |
| 274 | { |
| 275 | /* test case code */ |
| 276 | } |
| 277 | |
| 278 | ******************** |
| 279 | Adding test services |
| 280 | ******************** |
| 281 | |
| 282 | Some test group may need specific test services. These test services may support |
| 283 | one or more groups thus developers shall determine the proper test scope. Refer |
| 284 | to |
Elena Uziunaite | 9943817 | 2023-11-13 14:39:29 +0000 | [diff] [blame] | 285 | :doc:`Adding partitions for regression tests <tfm_test_partitions_addition>` |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 286 | to get more information. |
| 287 | |
| 288 | ********************************** |
| 289 | Out-of-tree regression test suites |
| 290 | ********************************** |
| 291 | |
| 292 | TF-M supports out-of-tree regression test suites build, whose source code |
Raef Coles | b52543f | 2024-05-03 10:38:11 +0100 | [diff] [blame] | 293 | folder is outside tf-m-tests repo. There are four configurations for developers |
Jianliang Shen | b5fd67b | 2022-11-14 14:15:59 +0800 | [diff] [blame] | 294 | to include the source code. |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 295 | |
Jianliang Shen | b5fd67b | 2022-11-14 14:15:59 +0800 | [diff] [blame] | 296 | - ``EXTRA_NS_TEST_SUITE_PATH`` |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 297 | |
Jianliang Shen | b5fd67b | 2022-11-14 14:15:59 +0800 | [diff] [blame] | 298 | An absolute directory of the out-of-tree non-secure test suite |
| 299 | source code folder. TF-M build system searches ``CMakeLists.txt`` of |
| 300 | non-secure test suite in the source code folder. |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 301 | |
Jianliang Shen | b5fd67b | 2022-11-14 14:15:59 +0800 | [diff] [blame] | 302 | - ``EXTRA_S_TEST_SUITE_PATH`` |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 303 | |
Jianliang Shen | b5fd67b | 2022-11-14 14:15:59 +0800 | [diff] [blame] | 304 | An absolute directory of the out-of-tree secure test suite |
| 305 | source code folder. |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 306 | |
Raef Coles | b52543f | 2024-05-03 10:38:11 +0100 | [diff] [blame] | 307 | - ``EXTRA_BL1_1_TEST_SUITE_PATH`` |
| 308 | |
| 309 | An absolute directory of the out-of-tree BL1_1 test suite |
| 310 | source code folder. |
| 311 | |
| 312 | - ``EXTRA_BL1_2_TEST_SUITE_PATH`` |
| 313 | |
| 314 | An absolute directory of the out-of-tree BL1_2 test suite |
| 315 | source code folder. |
| 316 | |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 317 | Example usage |
| 318 | ============= |
| 319 | |
| 320 | Take non-secure test as an example in |
| 321 | `tf-m-extras <https://git.trustedfirmware.org/TF-M/tf-m-extras.git/>`_. |
| 322 | A single out-of-tree test suite folder can be organized as the figure below: |
| 323 | |
| 324 | .. code-block:: bash |
| 325 | |
| 326 | extra_ns |
| 327 | ├── CMakeLists.txt |
| 328 | ├── ns_test.c |
BohdanHunko | ce2e7c9 | 2022-10-21 15:42:39 +0300 | [diff] [blame] | 329 | └── ns_test_config.cmake |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 330 | |
Jianliang Shen | b5fd67b | 2022-11-14 14:15:59 +0800 | [diff] [blame] | 331 | In the example above, ``EXTRA_NS_TEST_SUITE_PATH`` in the build command can be |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 332 | specified as listed below. |
| 333 | |
| 334 | .. code-block:: bash |
| 335 | |
Jianliang Shen | b5fd67b | 2022-11-14 14:15:59 +0800 | [diff] [blame] | 336 | -DEXTRA_NS_TEST_SUITE_PATH=<Absolute-path-extra-test-folder> |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 337 | |
| 338 | Coding instructions |
| 339 | =================== |
| 340 | |
| 341 | This is a demo of source code so the structure has been simplified. Files like |
BohdanHunko | ce2e7c9 | 2022-10-21 15:42:39 +0300 | [diff] [blame] | 342 | ``.c`` and ``.h`` can be expanded to ``src`` and ``include`` folders |
| 343 | respectively. The ``CMakeLists.txt`` is required in the root path and |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 344 | ``ns_test_config.cmake`` is optional. |
| 345 | |
| 346 | Header Files |
| 347 | ------------ |
| 348 | |
| 349 | The header file ``extra_ns_tests.h`` must be included by out-of-tree source |
BohdanHunko | ce2e7c9 | 2022-10-21 15:42:39 +0300 | [diff] [blame] | 350 | code. This file contains the declaration of |
| 351 | ``void register_testsuite_extra_ns_interface(struct test_suite_t *p_test_suite)``. |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 352 | |
| 353 | Source code |
| 354 | ----------- |
| 355 | |
David Hu | 945d22d | 2023-11-30 17:49:34 +0800 | [diff] [blame] | 356 | To connect the out-of-tree source code and regression test framework, the test case |
BohdanHunko | ce2e7c9 | 2022-10-21 15:42:39 +0300 | [diff] [blame] | 357 | function/functions must be defined first. An example format is: |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 358 | |
| 359 | .. code-block:: c |
| 360 | |
BohdanHunko | ce2e7c9 | 2022-10-21 15:42:39 +0300 | [diff] [blame] | 361 | void ns_test(struct test_result_t *ret) |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 362 | { |
| 363 | /* Add platform specific non-secure test suites code here. */ |
| 364 | |
BohdanHunko | ce2e7c9 | 2022-10-21 15:42:39 +0300 | [diff] [blame] | 365 | ret->val = TEST_PASSED; |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 366 | } |
| 367 | |
BohdanHunko | ce2e7c9 | 2022-10-21 15:42:39 +0300 | [diff] [blame] | 368 | This function follows the standard TF-M test case function prototype. |
| 369 | |
| 370 | .. note:: |
| 371 | Extra tests can have one or more test cases. This is simplified example so |
| 372 | only one test case is added. |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 373 | |
| 374 | After ``ns_test()`` is defined, a structure variable need to be created like: |
| 375 | |
| 376 | .. code-block:: c |
| 377 | |
BohdanHunko | ce2e7c9 | 2022-10-21 15:42:39 +0300 | [diff] [blame] | 378 | static struct test_t plat_ns_t[] = { |
| 379 | {&ns_test, "TFM_EXTRA_TEST_1001", |
| 380 | "Extra Non-Secure test"}, |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 381 | }; |
| 382 | |
BohdanHunko | ce2e7c9 | 2022-10-21 15:42:39 +0300 | [diff] [blame] | 383 | It will be used by function ``register_testsuite_extra_ns_interface()`` to |
| 384 | register the test by calling the ``set_testsuite()`` function: |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 385 | |
| 386 | .. code-block:: c |
| 387 | |
BohdanHunko | ce2e7c9 | 2022-10-21 15:42:39 +0300 | [diff] [blame] | 388 | void register_testsuite_extra_ns_interface(struct test_suite_t *p_test_suite) |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 389 | { |
BohdanHunko | ce2e7c9 | 2022-10-21 15:42:39 +0300 | [diff] [blame] | 390 | uint32_t list_size; |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 391 | |
BohdanHunko | ce2e7c9 | 2022-10-21 15:42:39 +0300 | [diff] [blame] | 392 | list_size = (sizeof(plat_ns_t) / |
| 393 | sizeof(plat_ns_t[0])); |
| 394 | |
| 395 | set_testsuite("Extra Non-Secure interface tests" |
| 396 | "(TFM_NS_EXTRA_TEST_1XXX)", |
| 397 | plat_ns_t, list_size, p_test_suite); |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | The platform initialization code can be added in this function because it runs |
| 401 | before ``ns_test()``. |
| 402 | |
| 403 | .. Note:: |
BohdanHunko | ce2e7c9 | 2022-10-21 15:42:39 +0300 | [diff] [blame] | 404 | Function ``register_testsuite_extra_ns_interface()`` is declared in |
| 405 | tf-m-tests repository without definition. It is supplied to out-of-tree |
| 406 | source code and need to be defined with no change of its format, like |
| 407 | returns error code and parameter name. |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 408 | |
| 409 | |
| 410 | CMakeLists.txt |
| 411 | -------------- |
| 412 | |
BohdanHunko | ce2e7c9 | 2022-10-21 15:42:39 +0300 | [diff] [blame] | 413 | After extra test suite file were created they must be linked to |
| 414 | ``tfm_test_suite_extra_ns`` CMAKE target: |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 415 | |
| 416 | .. code-block:: cmake |
| 417 | |
BohdanHunko | ce2e7c9 | 2022-10-21 15:42:39 +0300 | [diff] [blame] | 418 | target_sources(tfm_test_suite_extra_ns |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 419 | PRIVATE |
BohdanHunko | ce2e7c9 | 2022-10-21 15:42:39 +0300 | [diff] [blame] | 420 | ${CMAKE_CURRENT_SOURCE_DIR}/ns_test.c |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 421 | ) |
| 422 | |
Jianliang Shen | 5f7b1b7 | 2022-05-03 19:01:27 +0800 | [diff] [blame] | 423 | ns_test_config.cmake |
| 424 | -------------------- |
| 425 | |
| 426 | The CMAKE configuration file is optional. If out-of-tree source already exists |
| 427 | another configuration file, a new one can be ignored. |
| 428 | |
| 429 | -------------- |
| 430 | |
| 431 | *Copyright (c) 2021-2022, Arm Limited. All rights reserved.* |
BohdanHunko | ce2e7c9 | 2022-10-21 15:42:39 +0300 | [diff] [blame] | 432 | *Copyright (c) 2022 Cypress Semiconductor Corporation (an Infineon company) |
| 433 | or an affiliate of Cypress Semiconductor Corporation. All rights reserved.* |