Kevin Peng | ee2c3a9 | 2022-12-20 12:12:59 +0800 | [diff] [blame^] | 1 | ############################ |
| 2 | The TF-M eRPC Test Framework |
| 3 | ############################ |
| 4 | |
| 5 | The TF-M eRPC Test Framework is an Remote Procedure Call (RPC) framework for testing purpose. |
| 6 | It's based on the `eRPC <https://github.com/EmbeddedRPC/erpc>`__ system. |
| 7 | It is an additional framework to the existing one for running NS test suites. |
| 8 | It enables you to run test codes on host machines as if they were running on the device. |
| 9 | It has the following advantages. |
| 10 | |
| 11 | - Off-load test codes from device to host |
| 12 | |
| 13 | Arm M-profile devices usually have limited flash storage which can only fit limited test suites. |
| 14 | With test codes running on hosts you can run far more tests than on the devices. |
| 15 | |
| 16 | - Less frequent image downloading for test code development. |
| 17 | |
| 18 | As the test codes run on the host, you don't need to update the image on device when you update |
| 19 | test codes. |
| 20 | |
| 21 | - Host can get test pass or failure directly from the return codes. |
| 22 | |
| 23 | This would be helpful for test automation because you don't need to parse the test logs. |
| 24 | |
| 25 | **************** |
| 26 | How Does It Work |
| 27 | **************** |
| 28 | Originally, the NS tests are executed in the NSPE of the device. |
| 29 | The NS image on the device contains the test codes, which calls into TF-M through the PSA client |
| 30 | APIs. |
| 31 | |
| 32 | With the eRPC test framework, the NS tests code are executed on the host machine. |
| 33 | The NSPE of device side does not run the test codes anymore. |
| 34 | When the tests call the PSA client APIs, they call into the eRPC framework. |
| 35 | The eRPC framework communicates with the NSPE on the device, which calls into TF-M through the PSA |
| 36 | client APIs. |
| 37 | |
| 38 | The prototypes of the PSA client APIs are the same while the implementations are different. |
| 39 | Refer to the following sections for more details. |
| 40 | |
| 41 | The Stucture |
| 42 | ============ |
| 43 | |
| 44 | The following diagram shows the software structure. |
| 45 | |
| 46 | .. figure:: media/erpc_test_framework.svg |
| 47 | |
| 48 | - eRPC Framework |
| 49 | |
| 50 | The eRPC framework system |
| 51 | |
| 52 | - eRPC Client Shim |
| 53 | |
| 54 | The eRPC generated shim layer of remote APIs for clients. |
| 55 | It serializes the identifier of the API and its parameters into a stream of bytes and transports |
| 56 | to the server through a communication channel such as UART and TCP/IP. |
| 57 | The codes are generated by the `erpcgen tool <https://github.com/EmbeddedRPC/erpc/wiki/erpcgen>`_. |
| 58 | |
| 59 | - eRPC Server Shim |
| 60 | |
| 61 | The generated shim layer of the server. |
| 62 | It registers a callback function to the eRPC framework. |
| 63 | When the framework receives any requests from the client, it calls the callback function. |
| 64 | The callback unserializes the bytes streams to determine what API to call and then invoke it with |
| 65 | the corresponding parameters from the bytes streams. |
| 66 | And then it returns the results to the client in the reverse routine. |
| 67 | |
| 68 | - API Wrapper |
| 69 | |
| 70 | Part of the parameters of ``psa_call`` API is not supported by eRPC directly, thus an API wrapper |
| 71 | is required to transform the ``in_vec/out_vec`` structures to the eRPC supported data types. |
| 72 | The wrapper API is named as ``erpc_psa_call``. |
| 73 | |
| 74 | On the client side, the wrapper implements the ``psa_call`` which calls the ``erpc_psa_call`` in |
| 75 | the client shim layer. |
| 76 | On the server side, the wrapper implements the ``erpc_psa_call`` which is called by the shim layer. |
| 77 | The ``erpc_psa_call`` then calls the ``psa_call``. |
| 78 | |
| 79 | - Test Suites |
| 80 | |
| 81 | Can be the existing TF-M regression tests or any other tests that interact with TF-M using the |
| 82 | PSA Client APIs. |
| 83 | |
| 84 | - Host App |
| 85 | |
| 86 | Initializes the eRPC client and starts test suites. |
| 87 | |
| 88 | - Target App |
| 89 | |
| 90 | Initializes the eRPC server and listens for requests from the client. |
| 91 | |
| 92 | Supported APIs |
| 93 | ============== |
| 94 | |
| 95 | The APIs supported for doing RPC are the PSA Client APIs because they are the lowest level APIs that |
| 96 | interact with TF-M. You can build lots of test suites upon them. |
| 97 | You can also add your own APIs in the ``tfm.erpc`` file. |
| 98 | Please refer to `IDL Reference <https://github.com/EmbeddedRPC/erpc/wiki/IDL-Reference>`_ for the |
| 99 | syntax of the file. |
| 100 | |
| 101 | API Grouping |
| 102 | ************ |
| 103 | |
| 104 | PSA client APIs are categorised into common APIs and connection-based service APIs. |
| 105 | Connection-based APIs are available when there are connection-based services in the TF-M. |
| 106 | So in the eRPC integration, the APIs are also split into two groups so that the shim layer of the |
| 107 | APIs can be separated into different files as well. |
| 108 | Then build systems can decide which source files to build based on the existence of connection-based |
| 109 | services. |
| 110 | |
| 111 | Common APIs: |
| 112 | |
| 113 | - psa_framework_version() |
| 114 | - psa_version() |
| 115 | - psa_call() |
| 116 | |
| 117 | Connection-based specific: |
| 118 | |
| 119 | - psa_connect() |
| 120 | - psa_close() |
| 121 | |
| 122 | Transportation |
| 123 | ============== |
| 124 | |
| 125 | On device side, only UART transportation is supported in NSPE. |
| 126 | For the host side, both UART and TCP are supported. |
| 127 | The TCP transportation support is basically for fast models where UART data are transferred between |
| 128 | a TCP/IP socket on the host and a serial port on the target. |
| 129 | See the |
| 130 | `fast model reference guide <https://developer.arm.com/documentation/100966/1116/Getting-Started-with-Fixed-Virtual-Platforms/Using-a-terminal-with-a-system-model>`_ |
| 131 | for more details. |
| 132 | |
| 133 | ******************** |
| 134 | Platform Integration |
| 135 | ******************** |
| 136 | |
| 137 | First, the UART drivers of platforms shall support TX/RX control feature. |
| 138 | The TF-M build system provides a ``CONFIG_ENABLE_NS_UART_TX_RX_CONTROL`` option to enable or disable |
| 139 | the TX/RX control feature and it is disabled by default. |
| 140 | When the eRPC test framework is enabled, the ``CONFIG_ENABLE_NS_UART_TX_RX_CONTROL`` will be enabled |
| 141 | automatically. |
| 142 | |
| 143 | Secondly, platforms need to specify the UART port and driver for eRPC transportation config via |
| 144 | ``target_cfg.h``. |
| 145 | |
| 146 | .. code-block:: |
| 147 | |
| 148 | #define ERPC_UART Driver_USART0 |
| 149 | |
| 150 | It's recommended to use a different UART to the stdio UART. |
| 151 | If the same UART is used for both, then the TF-M logs (both SPM and Secure Partitions) must be |
| 152 | disabled. |
| 153 | Otherwise, the eRPC transportation might fail. |
| 154 | |
| 155 | *********************** |
| 156 | Application Integration |
| 157 | *********************** |
| 158 | |
| 159 | The TF-M eRPC test framework provides two CMake libraries for integration. |
| 160 | One is the ``erpc_client``, the other is the ``erpc_server``. |
| 161 | Both include the eRPC framework, the shim layers, API wrappers and expose an initialization API |
| 162 | for client and server respectively. |
| 163 | |
| 164 | The initialization does not include the initialization of the transportation layer because it is use |
| 165 | case specific which kind of transportation is used. |
| 166 | So it is the client and server's responsibilities to initialize the transportation layers and pass |
| 167 | them to the ``erpc_client`` and ``erpc_server``. |
| 168 | |
| 169 | TF-M provides a ``app/erpc_app.c`` as the default server application which initializes the UART |
| 170 | transportation and starts the eRPC server. |
| 171 | |
| 172 | A config option ``CONFIG_TFM_ERPC_TEST_FRAMEWORK`` is provided to enable the eRPC framework on |
| 173 | device (server) side. |
| 174 | The default server will be built and developers only need to focus on the client application |
| 175 | developments. |
| 176 | |
| 177 | In summary, on the server side, you only need to build with the ``CONFIG_TFM_ERPC_TEST_FRAMEWORK`` |
| 178 | enabled. |
| 179 | On the client side, you must |
| 180 | |
| 181 | - Initializes the transportation layer using eRPC provided APIs. |
| 182 | - Call the initialization function provided by TF-M eRPC test framework with the transportation |
| 183 | instance initialized above. |
| 184 | - Develop the application code |
| 185 | - Building with CMake |
| 186 | |
| 187 | - ``add_subdirectory`` with the ``erpc/client`` |
| 188 | - link the ``erpc_client`` library |
| 189 | |
| 190 | There is an example at ``erpc/host_example`` for reference. |
| 191 | |
| 192 | -------------- |
| 193 | |
| 194 | *Copyright (c) 2023, Arm Limited. All rights reserved.* |