1#-------------------------------------------------------------------------------
2# Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
7cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
8include(../../deployment.cmake REQUIRED)
9
10#-------------------------------------------------------------------------------
11#  The CMakeLists.txt for building the component-test deployment for linux-pc
12#
13#  Used for building and running component level tests in a native PC enviroment.
14#  Tests can be run by running the built executable called "component-test"
15#-------------------------------------------------------------------------------
16include(${TS_ROOT}/environments/linux-pc/env.cmake)
17project(trusted-services LANGUAGES CXX C)
18
19# Preparing firmware-test-build by including it
20include(${TS_ROOT}/external/firmware_test_builder/FirmwareTestBuilder.cmake)
21
22include(CTest)
23include(UnitTest)
24
25set(COVERAGE FALSE CACHE BOOL "Enable code coverage measurement")
26set(UNIT_TEST_PROJECT_PATH ${TS_ROOT} CACHE PATH "Path of the project directory")
27set(CMAKE_CXX_STANDARD 11)
28
29unit_test_init_cpputest()
30
31if (COVERAGE)
32	include(Coverage)
33
34	set(COVERAGE_FILE "coverage.info")
35	set(COMPONENT_TEST_COVERAGE_FILE "component-test-coverage.info" CACHE PATH "Path of coverage info file")
36	set(COMPONENT_TEST_COVERAGE_REPORT_DIR "${CMAKE_CURRENT_BINARY_DIR}/component-test-coverage-report" CACHE PATH "Directory of coverage report")
37
38	# Collecting coverage
39	coverage_generate(
40		NAME "Component test"
41		SOURCE_DIR ${TS_ROOT}
42		BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}
43		OUTPUT_FILE ${COVERAGE_FILE}
44	)
45
46	# Filtering project file coverage
47	coverage_filter(
48		INPUT_FILE ${COVERAGE_FILE}
49		OUTPUT_FILE ${COMPONENT_TEST_COVERAGE_FILE}
50		INCLUDE_DIRECTORY ${UNIT_TEST_PROJECT_PATH}/components
51	)
52
53	# Coverage report
54	coverage_generate_report(
55		INPUT_FILE ${COMPONENT_TEST_COVERAGE_FILE}
56		OUTPUT_DIRECTORY ${COMPONENT_TEST_COVERAGE_REPORT_DIR}
57	)
58endif()
59
60unit_test_add_suite(
61	NAME component-test
62)
63
64target_include_directories(component-test PRIVATE "${TOP_LEVEL_INCLUDE_DIRS}")
65
66#-------------------------------------------------------------------------------
67#  Components that are specific to deployment in the linux-pc environment.
68#
69#-------------------------------------------------------------------------------
70add_components(
71	TARGET "component-test"
72	BASE_DIR ${TS_ROOT}
73    COMPONENTS
74        "components/service/crypto/backend/mbedcrypto/trng_adapter/linux"
75)
76
77#-------------------------------------------------------------------------------
78#  Extend with components that are common across all deployments of
79#  component-test
80#
81#-------------------------------------------------------------------------------
82include(../component-test.cmake REQUIRED)
83