Imre Kis | ed98e9c | 2019-10-15 16:17:55 +0200 | [diff] [blame] | 1 | # |
Imre Kis | fdaaf8c | 2019-12-16 23:53:41 +0100 | [diff] [blame] | 2 | # Copyright (c) 2019-2020, Arm Limited. All rights reserved. |
Imre Kis | ed98e9c | 2019-10-15 16:17:55 +0200 | [diff] [blame] | 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | |
Imre Kis | 1d2fbdd | 2019-12-13 11:42:08 +0100 | [diff] [blame] | 7 | #[===[.rst: |
| 8 | Processing flow |
| 9 | --------------- |
| 10 | |
| 11 | The following steps show how the CMake based build system works. The first |
| 12 | couple steps are responsible for detecting and checking the environment. The |
| 13 | following steps are the fetching and building phase of CppUTest. Finally it |
| 14 | collects the test cases. |
| 15 | |
| 16 | 1. Checking if :cmake:variable:`TF_A_PATH` is specified |
| 17 | |
| 18 | 2. Checking git |
| 19 | |
| 20 | 3. Fetching CppUTest |
| 21 | |
| 22 | 4. Building CppUTest |
| 23 | |
| 24 | 5. Configuring coverage targets if they are enabled |
| 25 | |
| 26 | 6. Collecting unit test suites |
| 27 | |
| 28 | Note that the included modules can also execute further checks and commands on |
| 29 | init. |
| 30 | |
| 31 | |
| 32 | Variables |
| 33 | --------- |
| 34 | |
| 35 | The following cache entries can be set with the ``-D`` command line option of |
| 36 | CMake when the configuration phase is first run. This allows applying |
| 37 | environment specific configuration to the build. The current values of these |
| 38 | variables can be checked by opening ``CMakeCache.txt`` in the build directory or |
| 39 | by using ``cmake-gui``. |
| 40 | |
| 41 | .. cmake:variable:: TF_A_PATH |
| 42 | |
| 43 | Path of the Trusted Firmware-A source directory. **This needs to be specified |
| 44 | by the developer** to point to a suitable working copy of TF-A. |
| 45 | |
| 46 | .. cmake:variable:: TF_A_UNIT_TESTS_PATH |
| 47 | |
| 48 | Root directory of unit test repository. It can be used to reference source |
| 49 | files from the unit test repository relative to its root directory. |
| 50 | |
| 51 | .. cmake:variable:: CPPUTEST_URL |
| 52 | |
| 53 | URL of the CppUTest git repository. By default it points to the official Github |
| 54 | repository of CppUTest. It can be used to specify a different CppUTest mirror. |
| 55 | |
| 56 | .. cmake:variable:: CPPUTEST_REFSPEC |
| 57 | |
| 58 | CppUTest git refspec. The default value selects the latest release. |
| 59 | |
| 60 | .. cmake:variable:: CPPUTEST_INSTALL_PATH |
| 61 | |
| 62 | Temporary directory used during CppUTest build |
| 63 | |
| 64 | .. cmake:variable:: CPPUTEST_PACKAGE_PATH |
| 65 | |
| 66 | Path of the CppUTest CMake package directory |
| 67 | |
| 68 | .. cmake:variable:: CPICKER_CACHE_PATH |
| 69 | |
| 70 | Directory of c-picker generated files. Subdirectories are added according to |
| 71 | the path of the original source file's path. |
| 72 | |
| 73 | .. cmake:variable:: CLANG_LIBRARY_PATH |
| 74 | |
| 75 | c-picker uses libclang to parse the source files. If defined this variable |
| 76 | specifies the path of the library. |
| 77 | |
| 78 | .. cmake:variable:: COVERAGE |
| 79 | |
| 80 | Adds compiler flags for coverage measurement and enables ``coverage`` and |
| 81 | ``coverage_report`` targets. |
| 82 | |
| 83 | #]===] |
| 84 | |
Imre Kis | ed98e9c | 2019-10-15 16:17:55 +0200 | [diff] [blame] | 85 | cmake_minimum_required(VERSION 3.11...3.15) # TODO: test with ubuntu |
| 86 | project(tf-a-unit-tests) |
| 87 | |
| 88 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake) |
| 89 | |
| 90 | include(CTest) |
| 91 | include(ExternalProject) |
| 92 | include(FetchContent) |
Imre Kis | c625d49 | 2020-02-10 16:36:22 +0100 | [diff] [blame] | 93 | include(UnitTest) |
Imre Kis | ed98e9c | 2019-10-15 16:17:55 +0200 | [diff] [blame] | 94 | |
| 95 | # Configuration variables |
| 96 | set(TF_A_PATH "" CACHE PATH "Path of the Trusted Firmware A directory") |
| 97 | set(TF_A_UNIT_TESTS_PATH ${CMAKE_CURRENT_LIST_DIR} CACHE PATH "Path of root directory of the unit test repository") |
| 98 | set(CPPUTEST_URL "https://github.com/cpputest/cpputest.git" CACHE STRING "CppUTest repository URL") |
| 99 | set(CPPUTEST_REFSPEC "v3.8" CACHE STRING "CppUTest git refspec") |
| 100 | set(CPPUTEST_INSTALL_PATH ${CMAKE_CURRENT_BINARY_DIR}/CppUTest_install CACHE PATH "CppUTest installation directory") |
| 101 | set(CPPUTEST_PACKAGE_PATH ${CPPUTEST_INSTALL_PATH}/lib/CppUTest/cmake CACHE PATH "CppUTest CMake package directory") |
| 102 | set(CPICKER_CACHE_PATH ${CMAKE_CURRENT_BINARY_DIR}/cpicker_cache CACHE PATH "Directory of c-picker generated file") |
| 103 | set(UNIT_TEST_COMMON_SOURCES ${CMAKE_CURRENT_LIST_DIR}/common/main.cpp) |
| 104 | set(CMAKE_CXX_STANDARD 11) |
Imre Kis | e6bf9e6 | 2020-01-20 11:34:24 +0100 | [diff] [blame] | 105 | option(COVERAGE "Enable code coverage measurement" OFF) |
Imre Kis | ed98e9c | 2019-10-15 16:17:55 +0200 | [diff] [blame] | 106 | |
| 107 | # Checking TF-A |
| 108 | if (NOT TF_A_PATH) |
| 109 | message(FATAL_ERROR "TF_A_PATH is not set") |
| 110 | endif() |
| 111 | |
Imre Kis | ed98e9c | 2019-10-15 16:17:55 +0200 | [diff] [blame] | 112 | # Checking git |
| 113 | find_program(GIT_COMMAND "git") |
| 114 | if (NOT GIT_COMMAND) |
| 115 | message(FATAL_ERROR "Please install git") |
| 116 | endif() |
| 117 | |
| 118 | # Fetching CppUTest |
| 119 | FetchContent_Declare( |
| 120 | cpputest |
| 121 | GIT_REPOSITORY ${CPPUTEST_URL} |
| 122 | GIT_TAG ${CPPUTEST_REFSPEC} |
| 123 | GIT_SHALLOW TRUE |
| 124 | PATCH_COMMAND git apply ${CMAKE_CURRENT_LIST_DIR}/common/cpputest-cmake-fix.patch |
| 125 | ) |
| 126 | |
| 127 | # FetchContent_GetProperties exports cpputest_SOURCE_DIR and cpputest_BINARY_DIR variables |
| 128 | FetchContent_GetProperties(cpputest) |
| 129 | if(NOT cpputest_POPULATED) |
| 130 | message(STATUS "Fetching CppUTest") |
| 131 | FetchContent_Populate(cpputest) |
| 132 | endif() |
| 133 | |
| 134 | # Build and install CppUTest in CMake time. This makes us able to use CppUTest as a CMake package later. |
| 135 | # Memory leak detection is turned off to avoid conflict with memcheck. |
| 136 | execute_process(COMMAND |
| 137 | ${CMAKE_COMMAND} |
| 138 | -DMEMORY_LEAK_DETECTION=OFF |
| 139 | -DLONGLONG=ON |
| 140 | -DC++11=ON |
| 141 | -DCMAKE_INSTALL_PREFIX=${CPPUTEST_INSTALL_PATH} |
| 142 | -GUnix\ Makefiles |
| 143 | ${cpputest_SOURCE_DIR} |
| 144 | WORKING_DIRECTORY |
| 145 | ${cpputest_BINARY_DIR} |
| 146 | ) |
| 147 | execute_process(COMMAND ${CMAKE_COMMAND} --build ${cpputest_BINARY_DIR} -- install -j) |
| 148 | |
| 149 | # Finding CppUTest package. CMake will check [package name]_DIR variable. |
| 150 | set(CppUTest_DIR ${CPPUTEST_PACKAGE_PATH} CACHE PATH "Path of CppUTestConfig.cmake") |
| 151 | find_package(CppUTest CONFIG REQUIRED) |
| 152 | |
| 153 | # find_package sets the CppUTest_INCLUDE_DIRS and CppUTest_LIBRARIES variables |
| 154 | include_directories(${CppUTest_INCLUDE_DIRS}) |
| 155 | link_libraries(${CppUTest_LIBRARIES}) |
| 156 | |
Imre Kis | e6bf9e6 | 2020-01-20 11:34:24 +0100 | [diff] [blame] | 157 | # Coverage |
| 158 | if (COVERAGE) |
| 159 | include(Coverage) |
| 160 | |
| 161 | set(COVERAGE_FILE "coverage.info") |
| 162 | set(TF_A_COVERAGE_FILE "trusted-firmware-a-coverage.info") |
| 163 | set(TF_A_UT_COVERAGE_FILE "tf-a-unit-tests-coverage.info") |
| 164 | set(TF_A_COVERAGE_REPORT_DIR "${CMAKE_CURRENT_BINARY_DIR}/trusted-firmware-a-coverage") |
| 165 | set(TF_A_UT_COVERAGE_REPORT_DIR "${CMAKE_CURRENT_BINARY_DIR}/tf-a-unit-tests-coverage") |
| 166 | |
| 167 | # Collecting coverage |
Imre Kis | 335834e | 2020-02-07 15:44:38 +0100 | [diff] [blame] | 168 | coverage_generate( |
| 169 | NAME "Unit test" |
| 170 | SOURCE_DIR ${TF_A_PATH} |
| 171 | BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} |
| 172 | CPICKER_MAPPING_PATH ${CPICKER_CACHE_PATH} |
| 173 | OUTPUT_FILE ${COVERAGE_FILE} |
| 174 | ) |
Imre Kis | e6bf9e6 | 2020-01-20 11:34:24 +0100 | [diff] [blame] | 175 | |
| 176 | # Filtering TF-A and unit test coverage |
| 177 | coverage_filter( |
| 178 | INPUT_FILE ${COVERAGE_FILE} |
| 179 | OUTPUT_FILE ${TF_A_COVERAGE_FILE} |
| 180 | INCLUDE_DIRECTORY ${TF_A_PATH} |
| 181 | ) |
| 182 | coverage_filter( |
| 183 | INPUT_FILE ${COVERAGE_FILE} |
| 184 | OUTPUT_FILE ${TF_A_UT_COVERAGE_FILE} |
| 185 | INCLUDE_DIRECTORY ${TF_A_UNIT_TESTS_PATH} |
| 186 | ) |
| 187 | |
| 188 | # Coverage reports |
| 189 | coverage_generate_report( |
| 190 | INPUT_FILE trusted-firmware-a-coverage.info |
| 191 | OUTPUT_DIRECTORY ${TF_A_COVERAGE_REPORT_DIR} |
| 192 | ) |
| 193 | coverage_generate_report( |
| 194 | INPUT_FILE tf-a-unit-tests-coverage.info |
| 195 | OUTPUT_DIRECTORY ${TF_A_UT_COVERAGE_REPORT_DIR} |
| 196 | ) |
| 197 | endif() |
| 198 | |
Imre Kis | ed98e9c | 2019-10-15 16:17:55 +0200 | [diff] [blame] | 199 | # Project level include directory |
| 200 | include_directories(${CMAKE_CURRENT_LIST_DIR}/include) |
| 201 | |
Imre Kis | a71757b | 2019-12-17 00:19:40 +0100 | [diff] [blame] | 202 | include(tests/bl1/test_bl1_fwu.cmake) |
Imre Kis | ed98e9c | 2019-10-15 16:17:55 +0200 | [diff] [blame] | 203 | include(tests/lib/libc/test_libc.cmake) |
Imre Kis | fdaaf8c | 2019-12-16 23:53:41 +0100 | [diff] [blame] | 204 | include(tests/lib/object_pool/test_object_pool.cmake) |
johpow01 | 7300787 | 2020-07-15 20:01:05 -0500 | [diff] [blame] | 205 | include(tests/lib/fdt/test_fdt.cmake) |