blob: 5fa33ee99682d68a2043ebd8d0a36b215b509d5c [file] [log] [blame]
Kevin Pengee2c3a92022-12-20 12:12:59 +08001############################
2The TF-M eRPC Test Framework
3############################
4
5The TF-M eRPC Test Framework is an Remote Procedure Call (RPC) framework for testing purpose.
6It's based on the `eRPC <https://github.com/EmbeddedRPC/erpc>`__ system.
7It is an additional framework to the existing one for running NS test suites.
8It enables you to run test codes on host machines as if they were running on the device.
9It 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****************
26How Does It Work
27****************
28Originally, the NS tests are executed in the NSPE of the device.
29The NS image on the device contains the test codes, which calls into TF-M through the PSA client
30APIs.
31
32With the eRPC test framework, the NS tests code are executed on the host machine.
33The NSPE of device side does not run the test codes anymore.
34When the tests call the PSA client APIs, they call into the eRPC framework.
35The eRPC framework communicates with the NSPE on the device, which calls into TF-M through the PSA
36client APIs.
37
38The prototypes of the PSA client APIs are the same while the implementations are different.
39Refer to the following sections for more details.
40
41The Stucture
42============
43
44The 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
92Supported APIs
93==============
94
95The APIs supported for doing RPC are the PSA Client APIs because they are the lowest level APIs that
96interact with TF-M. You can build lots of test suites upon them.
97You can also add your own APIs in the ``tfm.erpc`` file.
98Please refer to `IDL Reference <https://github.com/EmbeddedRPC/erpc/wiki/IDL-Reference>`_ for the
99syntax of the file.
100
101API Grouping
102************
103
104PSA client APIs are categorised into common APIs and connection-based service APIs.
105Connection-based APIs are available when there are connection-based services in the TF-M.
106So in the eRPC integration, the APIs are also split into two groups so that the shim layer of the
107APIs can be separated into different files as well.
108Then build systems can decide which source files to build based on the existence of connection-based
109services.
110
111Common APIs:
112
113- psa_framework_version()
114- psa_version()
115- psa_call()
116
117Connection-based specific:
118
119- psa_connect()
120- psa_close()
121
122Transportation
123==============
124
125On device side, only UART transportation is supported in NSPE.
126For the host side, both UART and TCP are supported.
127The TCP transportation support is basically for fast models where UART data are transferred between
128a TCP/IP socket on the host and a serial port on the target.
129See 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>`_
131for more details.
132
133********************
134Platform Integration
135********************
136
137First, the UART drivers of platforms shall support TX/RX control feature.
138The TF-M build system provides a ``CONFIG_ENABLE_NS_UART_TX_RX_CONTROL`` option to enable or disable
139the TX/RX control feature and it is disabled by default.
140When the eRPC test framework is enabled, the ``CONFIG_ENABLE_NS_UART_TX_RX_CONTROL`` will be enabled
141automatically.
142
143Secondly, 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
150It's recommended to use a different UART to the stdio UART.
151If the same UART is used for both, then the TF-M logs (both SPM and Secure Partitions) must be
152disabled.
153Otherwise, the eRPC transportation might fail.
154
155***********************
156Application Integration
157***********************
158
159The TF-M eRPC test framework provides two CMake libraries for integration.
160One is the ``erpc_client``, the other is the ``erpc_server``.
161Both include the eRPC framework, the shim layers, API wrappers and expose an initialization API
162for client and server respectively.
163
164The initialization does not include the initialization of the transportation layer because it is use
165case specific which kind of transportation is used.
166So it is the client and server's responsibilities to initialize the transportation layers and pass
167them to the ``erpc_client`` and ``erpc_server``.
168
169TF-M provides a ``app/erpc_app.c`` as the default server application which initializes the UART
170transportation and starts the eRPC server.
171
172A config option ``CONFIG_TFM_ERPC_TEST_FRAMEWORK`` is provided to enable the eRPC framework on
173device (server) side.
174The default server will be built and developers only need to focus on the client application
175developments.
176
177In summary, on the server side, you only need to build with the ``CONFIG_TFM_ERPC_TEST_FRAMEWORK``
178enabled.
179On 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
190There is an example at ``erpc/host_example`` for reference.
191
192--------------
193
194*Copyright (c) 2023, Arm Limited. All rights reserved.*