blob: 6e807c012f61e5ccc21b2b8701d66953677a95dd [file] [log] [blame]
#
# Copyright (c) 2019-2020, Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
#[===[.rst:
Processing flow
---------------
The following steps show how the CMake based build system works. The first
couple steps are responsible for detecting and checking the environment. The
following steps are the fetching and building phase of CppUTest. Finally it
collects the test cases.
1. Checking if :cmake:variable:`TF_A_PATH` is specified
2. Checking git
3. Fetching CppUTest
4. Building CppUTest
5. Configuring coverage targets if they are enabled
6. Collecting unit test suites
Note that the included modules can also execute further checks and commands on
init.
Variables
---------
The following cache entries can be set with the ``-D`` command line option of
CMake when the configuration phase is first run. This allows applying
environment specific configuration to the build. The current values of these
variables can be checked by opening ``CMakeCache.txt`` in the build directory or
by using ``cmake-gui``.
.. cmake:variable:: TF_A_PATH
Path of the Trusted Firmware-A source directory. **This needs to be specified
by the developer** to point to a suitable working copy of TF-A.
.. cmake:variable:: TF_A_UNIT_TESTS_PATH
Root directory of unit test repository. It can be used to reference source
files from the unit test repository relative to its root directory.
.. cmake:variable:: CPPUTEST_URL
URL of the CppUTest git repository. By default it points to the official Github
repository of CppUTest. It can be used to specify a different CppUTest mirror.
.. cmake:variable:: CPPUTEST_REFSPEC
CppUTest git refspec. The default value selects the latest release.
.. cmake:variable:: CPPUTEST_INSTALL_PATH
Temporary directory used during CppUTest build
.. cmake:variable:: CPPUTEST_PACKAGE_PATH
Path of the CppUTest CMake package directory
.. cmake:variable:: CPICKER_CACHE_PATH
Directory of c-picker generated files. Subdirectories are added according to
the path of the original source file's path.
.. cmake:variable:: CLANG_LIBRARY_PATH
c-picker uses libclang to parse the source files. If defined this variable
specifies the path of the library.
.. cmake:variable:: COVERAGE
Adds compiler flags for coverage measurement and enables ``coverage`` and
``coverage_report`` targets.
#]===]
cmake_minimum_required(VERSION 3.11...3.15) # TODO: test with ubuntu
project(tf-a-unit-tests)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
include(CTest)
include(ExternalProject)
include(FetchContent)
include(UnitTest)
# Configuration variables
set(TF_A_PATH "" CACHE PATH "Path of the Trusted Firmware A directory")
set(TF_A_UNIT_TESTS_PATH ${CMAKE_CURRENT_LIST_DIR} CACHE PATH "Path of root directory of the unit test repository")
set(CPPUTEST_URL "https://github.com/cpputest/cpputest.git" CACHE STRING "CppUTest repository URL")
set(CPPUTEST_REFSPEC "v3.8" CACHE STRING "CppUTest git refspec")
set(CPPUTEST_INSTALL_PATH ${CMAKE_CURRENT_BINARY_DIR}/CppUTest_install CACHE PATH "CppUTest installation directory")
set(CPPUTEST_PACKAGE_PATH ${CPPUTEST_INSTALL_PATH}/lib/CppUTest/cmake CACHE PATH "CppUTest CMake package directory")
set(CPICKER_CACHE_PATH ${CMAKE_CURRENT_BINARY_DIR}/cpicker_cache CACHE PATH "Directory of c-picker generated file")
set(UNIT_TEST_COMMON_SOURCES ${CMAKE_CURRENT_LIST_DIR}/common/main.cpp)
set(CMAKE_CXX_STANDARD 11)
option(COVERAGE "Enable code coverage measurement" OFF)
# Checking TF-A
if (NOT TF_A_PATH)
message(FATAL_ERROR "TF_A_PATH is not set")
endif()
# Checking git
find_program(GIT_COMMAND "git")
if (NOT GIT_COMMAND)
message(FATAL_ERROR "Please install git")
endif()
# Fetching CppUTest
FetchContent_Declare(
cpputest
GIT_REPOSITORY ${CPPUTEST_URL}
GIT_TAG ${CPPUTEST_REFSPEC}
GIT_SHALLOW TRUE
PATCH_COMMAND git apply ${CMAKE_CURRENT_LIST_DIR}/common/cpputest-cmake-fix.patch
)
# FetchContent_GetProperties exports cpputest_SOURCE_DIR and cpputest_BINARY_DIR variables
FetchContent_GetProperties(cpputest)
if(NOT cpputest_POPULATED)
message(STATUS "Fetching CppUTest")
FetchContent_Populate(cpputest)
endif()
# Build and install CppUTest in CMake time. This makes us able to use CppUTest as a CMake package later.
# Memory leak detection is turned off to avoid conflict with memcheck.
execute_process(COMMAND
${CMAKE_COMMAND}
-DMEMORY_LEAK_DETECTION=OFF
-DLONGLONG=ON
-DC++11=ON
-DCMAKE_INSTALL_PREFIX=${CPPUTEST_INSTALL_PATH}
-GUnix\ Makefiles
${cpputest_SOURCE_DIR}
WORKING_DIRECTORY
${cpputest_BINARY_DIR}
)
execute_process(COMMAND ${CMAKE_COMMAND} --build ${cpputest_BINARY_DIR} -- install -j)
# Finding CppUTest package. CMake will check [package name]_DIR variable.
set(CppUTest_DIR ${CPPUTEST_PACKAGE_PATH} CACHE PATH "Path of CppUTestConfig.cmake")
find_package(CppUTest CONFIG REQUIRED)
# find_package sets the CppUTest_INCLUDE_DIRS and CppUTest_LIBRARIES variables
include_directories(${CppUTest_INCLUDE_DIRS})
link_libraries(${CppUTest_LIBRARIES})
# Coverage
if (COVERAGE)
include(Coverage)
set(COVERAGE_FILE "coverage.info")
set(TF_A_COVERAGE_FILE "trusted-firmware-a-coverage.info")
set(TF_A_UT_COVERAGE_FILE "tf-a-unit-tests-coverage.info")
set(TF_A_COVERAGE_REPORT_DIR "${CMAKE_CURRENT_BINARY_DIR}/trusted-firmware-a-coverage")
set(TF_A_UT_COVERAGE_REPORT_DIR "${CMAKE_CURRENT_BINARY_DIR}/tf-a-unit-tests-coverage")
# Collecting coverage
coverage_generate(
NAME "Unit test"
SOURCE_DIR ${TF_A_PATH}
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}
CPICKER_MAPPING_PATH ${CPICKER_CACHE_PATH}
OUTPUT_FILE ${COVERAGE_FILE}
)
# Filtering TF-A and unit test coverage
coverage_filter(
INPUT_FILE ${COVERAGE_FILE}
OUTPUT_FILE ${TF_A_COVERAGE_FILE}
INCLUDE_DIRECTORY ${TF_A_PATH}
)
coverage_filter(
INPUT_FILE ${COVERAGE_FILE}
OUTPUT_FILE ${TF_A_UT_COVERAGE_FILE}
INCLUDE_DIRECTORY ${TF_A_UNIT_TESTS_PATH}
)
# Coverage reports
coverage_generate_report(
INPUT_FILE trusted-firmware-a-coverage.info
OUTPUT_DIRECTORY ${TF_A_COVERAGE_REPORT_DIR}
)
coverage_generate_report(
INPUT_FILE tf-a-unit-tests-coverage.info
OUTPUT_DIRECTORY ${TF_A_UT_COVERAGE_REPORT_DIR}
)
endif()
# Project level include directory
include_directories(${CMAKE_CURRENT_LIST_DIR}/include)
include(tests/bl1/test_bl1_fwu.cmake)
include(tests/lib/libc/test_libc.cmake)
include(tests/lib/object_pool/test_object_pool.cmake)
include(tests/lib/fdt/test_fdt.cmake)