blob: aec9b1d33c66bb71c5678319d9659e260442d352 [file] [log] [blame]
Imre Kis1d2fbdd2019-12-13 11:42:08 +01001User guide
Gyorgy Szing05ece0e2019-10-08 12:56:59 +02002==========
3
Imre Kis1d2fbdd2019-12-13 11:42:08 +01004This page describes how to get started with compiling and running unit tests on
5the host machine.
6
7Host machine requirements
8-------------------------
9
10The system has been successfully tested on the following platforms:
11
12- Ubuntu 19.04
13- Ubuntu 18.04
14- Arch Linux
15- MSYS2 MinGW64
16
17Tools
18-----
19
20The following applications are expected to be installed in the build machine:
21
22- CMake >=3.11
23
24- Python >=3.4
25
26- c-picker
27
28 - pyyaml
29
30 - clang (pip package if not included in libclang)
31
32 - libclang
33
34- git
35
36- Toolchain
37
38- Native build system
39
40Ubuntu 19.04
41^^^^^^^^^^^^
42
43On Ubuntu 19.04 use the following commands to install the required tools:
44
45::
46
47 sudo apt-get install cmake git python3 python3-pip libclang-dev build-essential
48 sudo pip3 install git+https://gerrit.oss.arm.com/iot-sw/shared/c-picker
49
50Ubuntu 18.04
51^^^^^^^^^^^^
52
53The official Ubuntu 18.04 package repository only contains CMake 3.10 which not
54satisfies the requirements for building unit tests. Fortunately there's an
55official CMake APT repository provided by Kitware: https://apt.kitware.com/ By
56adding this server to the repository list an up-to-date version of CMake can be
57installed on Ubuntu 18.04.
58
59::
60
61 wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc \
62 2>/dev/null | sudo apt-key add -
63 sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ bionic main'
64
65 sudo apt-get install cmake git python3 python3-pip libclang-dev build-essential
66 sudo pip3 install git+https://gerrit.oss.arm.com/iot-sw/shared/c-picker
67
68Arch Linux
69^^^^^^^^^^
70
71On Arch Linux use the following commands to install the required tools:
72
73::
74
75 sudo pacman -Sy cmake git python python-pip python-yaml make gcc clang
76 sudo pip install git+https://gerrit.oss.arm.com/iot-sw/shared/c-picker
77
78MSYS2 MinGW64
79^^^^^^^^^^^^^
80
81::
82
83 pacman -Sy mingw-w64-x86_64-cmake git mingw-w64-x86_64-python3 \
84 mingw-w64-x86_64-python3-pip make mingw-w64-x86_64-gcc mingw-w64-x86_64-clang
85 pip install git+https://gerrit.oss.arm.com/iot-sw/shared/c-picker
86
87
88Getting unit test source code
89-----------------------------
90
91Download the unit test source code using the following command:
92
93::
94
95 git clone https://gerrit.oss.arm.com/trusted-firmware/tf-a-unit-tests.git
96
97
98Getting Trusted Firmware-A source code
99--------------------------------------
100
101Download the TF-A source code using the following command:
102
103::
104
105 git clone https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git
106
107
108Building unit tests
109-------------------
110
111Building unit tests start with running CMake which will check all the
112prerequisites and generate the native build system's input files. This example
113uses Unix Makefiles. Unit tests exercise the code directly by compiling it into
114the same binary as the test code. In this case the tests need to know where to
115find the TF-A source files and this is why the :cmake:variable:`TF_A_PATH` is
116specified.
117
118::
119
120 cd tf-a-unit-tests
121 mkdir build
122 cd build
123 cmake -DTF_A_PATH=../../trusted-firmware-a -G"Unix Makefiles" ..
124
125After running the previous steps the makefiles are generated into the build
126directory so make can build unit tests. During unit test development if only the
127source files have changed it's not necessary to re-run cmake it's only needed to
128run make as shown below.
129
130::
131
132 make -j
133
134For building single unit tests suites the test's name can be used as a makefile
135target. Let's assume there's a test suite called bl1_fwu.
136
137::
138
139 make bl1_fwu
140
141
142Running unit tests
143------------------
144
145CMake provides a built-in tool called ctest for running all the tests using a
146single command. It is also able to filter tests or run them in parallel for
147speeding up the tests process. Run all the tests using the following command:
148
149::
150
151 ctest
152
153Each unit test suite has its own executable. The easiest way of running single
154test suite is running it as a simple executable.
155
156::
157
158 ./bl1_fwu
159
160
161Debugging unit tests
162--------------------
163
164As it was mentioned in the previous section test suites are basically separate
165executables so they can be debugged as any other native applications on the host
166machine. In a Linux environment gdb or IDE's built-in debugger can be utilized
167for debugging.
168
169::
170
171 gdb ./bl1_fwu
172
173
174Measuring code coverage
175-----------------------
176
177Inspecting code coverage is a useful method for detecting parts of the code
178which is not exercised by tests. The build system includes an option for
179generating code coverage report of the unit tests. The coverage is processed by
180``lcov`` which needs to be installed for this feature. Also the coverage
181measurement in only available when GCC is used as a compiler.
182
183First of all the :cmake:variable:`COVERAGE` option has to be enabled by using
184the following command line when invoking CMake.
185
186::
187
188 cmake -DTF_A_PATH=../../trusted-firmware-a -DCOVERAGE=ON -G"Unix Makefiles" ..
189
190This makes CMake to build the binaries with coverage information included. The
191rest of the build process works the same way as before.
192
193Before collecting coverage info and generating reports the tests must be run as
194the coverage is a runtime measurement. See section `Running unit tests`_ for
195more information about running unit tests.
196
197The :cmake:variable:`COVERAGE` option adds two new build targets called
198``coverage`` and ``coverage_report``. They can be used simply by running the
199following commands if ``make`` is used as a build system.
200
201::
202
203 make coverage
204 make coverage_report
205
206The ``coverage`` target generates lcov info files for further processing. If
207there are coverage files available from different sources (i.e. coverages of
208other tests) they can be merged with the unit test coverage file and evaluated
209together. Currently two coverage info files are generated during the build. One
210of them contains the coverage of code under test (i.e. Trusted Firmware-A) and
211the other one has the coverage of the unit tests themselves.
212
213The ``coverage_report`` target generates a HTML report from the coverage info
214files. The coverage reports can be found in the build directory's subdirectories
215having ``-coverage`` suffix in their names. The report shows the directory
216structure of the code and each file can be inspected individually. Line,
217function and branch coverage is included.
218
Gyorgy Szing05ece0e2019-10-08 12:56:59 +0200219
220--------------
221
Imre Kis1d2fbdd2019-12-13 11:42:08 +0100222*Copyright (c) 2019-2020, Arm Limited. All rights reserved.*