Imre Kis | 1d2fbdd | 2019-12-13 11:42:08 +0100 | [diff] [blame^] | 1 | User guide
|
Gyorgy Szing | 05ece0e | 2019-10-08 12:56:59 +0200 | [diff] [blame] | 2 | ==========
|
| 3 |
|
Imre Kis | 1d2fbdd | 2019-12-13 11:42:08 +0100 | [diff] [blame^] | 4 | This page describes how to get started with compiling and running unit tests on
|
| 5 | the host machine.
|
| 6 |
|
| 7 | Host machine requirements
|
| 8 | -------------------------
|
| 9 |
|
| 10 | The 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 |
|
| 17 | Tools
|
| 18 | -----
|
| 19 |
|
| 20 | The 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 |
|
| 40 | Ubuntu 19.04
|
| 41 | ^^^^^^^^^^^^
|
| 42 |
|
| 43 | On 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 |
|
| 50 | Ubuntu 18.04
|
| 51 | ^^^^^^^^^^^^
|
| 52 |
|
| 53 | The official Ubuntu 18.04 package repository only contains CMake 3.10 which not
|
| 54 | satisfies the requirements for building unit tests. Fortunately there's an
|
| 55 | official CMake APT repository provided by Kitware: https://apt.kitware.com/ By
|
| 56 | adding this server to the repository list an up-to-date version of CMake can be
|
| 57 | installed 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 |
|
| 68 | Arch Linux
|
| 69 | ^^^^^^^^^^
|
| 70 |
|
| 71 | On 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 |
|
| 78 | MSYS2 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 |
|
| 88 | Getting unit test source code
|
| 89 | -----------------------------
|
| 90 |
|
| 91 | Download 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 |
|
| 98 | Getting Trusted Firmware-A source code
|
| 99 | --------------------------------------
|
| 100 |
|
| 101 | Download 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 |
|
| 108 | Building unit tests
|
| 109 | -------------------
|
| 110 |
|
| 111 | Building unit tests start with running CMake which will check all the
|
| 112 | prerequisites and generate the native build system's input files. This example
|
| 113 | uses Unix Makefiles. Unit tests exercise the code directly by compiling it into
|
| 114 | the same binary as the test code. In this case the tests need to know where to
|
| 115 | find the TF-A source files and this is why the :cmake:variable:`TF_A_PATH` is
|
| 116 | specified.
|
| 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 |
|
| 125 | After running the previous steps the makefiles are generated into the build
|
| 126 | directory so make can build unit tests. During unit test development if only the
|
| 127 | source files have changed it's not necessary to re-run cmake it's only needed to
|
| 128 | run make as shown below.
|
| 129 |
|
| 130 | ::
|
| 131 |
|
| 132 | make -j
|
| 133 |
|
| 134 | For building single unit tests suites the test's name can be used as a makefile
|
| 135 | target. Let's assume there's a test suite called bl1_fwu.
|
| 136 |
|
| 137 | ::
|
| 138 |
|
| 139 | make bl1_fwu
|
| 140 |
|
| 141 |
|
| 142 | Running unit tests
|
| 143 | ------------------
|
| 144 |
|
| 145 | CMake provides a built-in tool called ctest for running all the tests using a
|
| 146 | single command. It is also able to filter tests or run them in parallel for
|
| 147 | speeding up the tests process. Run all the tests using the following command:
|
| 148 |
|
| 149 | ::
|
| 150 |
|
| 151 | ctest
|
| 152 |
|
| 153 | Each unit test suite has its own executable. The easiest way of running single
|
| 154 | test suite is running it as a simple executable.
|
| 155 |
|
| 156 | ::
|
| 157 |
|
| 158 | ./bl1_fwu
|
| 159 |
|
| 160 |
|
| 161 | Debugging unit tests
|
| 162 | --------------------
|
| 163 |
|
| 164 | As it was mentioned in the previous section test suites are basically separate
|
| 165 | executables so they can be debugged as any other native applications on the host
|
| 166 | machine. In a Linux environment gdb or IDE's built-in debugger can be utilized
|
| 167 | for debugging.
|
| 168 |
|
| 169 | ::
|
| 170 |
|
| 171 | gdb ./bl1_fwu
|
| 172 |
|
| 173 |
|
| 174 | Measuring code coverage
|
| 175 | -----------------------
|
| 176 |
|
| 177 | Inspecting code coverage is a useful method for detecting parts of the code
|
| 178 | which is not exercised by tests. The build system includes an option for
|
| 179 | generating 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
|
| 181 | measurement in only available when GCC is used as a compiler.
|
| 182 |
|
| 183 | First of all the :cmake:variable:`COVERAGE` option has to be enabled by using
|
| 184 | the following command line when invoking CMake.
|
| 185 |
|
| 186 | ::
|
| 187 |
|
| 188 | cmake -DTF_A_PATH=../../trusted-firmware-a -DCOVERAGE=ON -G"Unix Makefiles" ..
|
| 189 |
|
| 190 | This makes CMake to build the binaries with coverage information included. The
|
| 191 | rest of the build process works the same way as before.
|
| 192 |
|
| 193 | Before collecting coverage info and generating reports the tests must be run as
|
| 194 | the coverage is a runtime measurement. See section `Running unit tests`_ for
|
| 195 | more information about running unit tests.
|
| 196 |
|
| 197 | The :cmake:variable:`COVERAGE` option adds two new build targets called
|
| 198 | ``coverage`` and ``coverage_report``. They can be used simply by running the
|
| 199 | following commands if ``make`` is used as a build system.
|
| 200 |
|
| 201 | ::
|
| 202 |
|
| 203 | make coverage
|
| 204 | make coverage_report
|
| 205 |
|
| 206 | The ``coverage`` target generates lcov info files for further processing. If
|
| 207 | there are coverage files available from different sources (i.e. coverages of
|
| 208 | other tests) they can be merged with the unit test coverage file and evaluated
|
| 209 | together. Currently two coverage info files are generated during the build. One
|
| 210 | of them contains the coverage of code under test (i.e. Trusted Firmware-A) and
|
| 211 | the other one has the coverage of the unit tests themselves.
|
| 212 |
|
| 213 | The ``coverage_report`` target generates a HTML report from the coverage info
|
| 214 | files. The coverage reports can be found in the build directory's subdirectories
|
| 215 | having ``-coverage`` suffix in their names. The report shows the directory
|
| 216 | structure of the code and each file can be inspected individually. Line,
|
| 217 | function and branch coverage is included.
|
| 218 |
|
Gyorgy Szing | 05ece0e | 2019-10-08 12:56:59 +0200 | [diff] [blame] | 219 |
|
| 220 | --------------
|
| 221 |
|
Imre Kis | 1d2fbdd | 2019-12-13 11:42:08 +0100 | [diff] [blame^] | 222 | *Copyright (c) 2019-2020, Arm Limited. All rights reserved.*
|