-
Notifications
You must be signed in to change notification settings - Fork 217
/
CMakeLists.txt
97 lines (79 loc) · 4.04 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# CMake build script for OSAL white-box coverage tests
#
# IMPORTANT: This is currently implemented as a completely separate project
# from OSAL itself and it is not connected to the normal OSAL build in any way.
# To run coverage tests this must be built separately. There are several reasons
# for having it this way:
# - Not all targets have coverage testing implemented (yet). Only VxWorks right now.
# - It may use an entirely different toolchain than the actual target build.
# (coverage tests run with the "real" calls stubbed out, so they can be executed
# on any platform/os - case in point, the VxWorks coveraged paths can be analyzed
# by running the code on Linux using the specially-crafted inputs)
# - By definition this MUST completely rebuild OSAL to add the requisite "coverage"
# options so that the binaries include the extra instrumentation.
#
# NO ARTEFACTS FROM THIS BUILD SHOULD EVER INTERMINGLE WITH THE REAL TARGET BUILD
#
project(OSALCOVERAGE C)
# Ask to generate a "make test" target
enable_testing()
# The following logic is borrowed from the real OSAL build
# One difference here is that the UT BSP/framework and target OSTYPE need not "match"
# The following cache variables are recognized:
# OSALCOVERAGE_TARGET_OSTYPE -> the intended OSAL that runs on the actual target
#
# The currently supported setup is to use the configured BSP to execute all available
# code coverage analysis. Because the actual underlying OS calls are stubbed out, there
# is no dependency on the actual underlying OS. Note that RTEMS is not included as the
# coverage test is not implemented at this time.
set(OSALCOVERAGE_TARGET_OSTYPE "vxworks;shared" CACHE STRING "OSAL target(s) to build coverage tests for (default=all)")
# Check that coverage has been implemented for this OSTYPE
foreach(OSTYPE ${OSALCOVERAGE_TARGET_OSTYPE})
if (NOT IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${OSTYPE})
message(FATAL_ERROR "No coverage tests implemented for ${OSTYPE}")
endif (NOT IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${OSTYPE})
endforeach(OSTYPE ${OSALCOVERAGE_TARGET_OSTYPE})
message(STATUS "Coverage Test Target OS: ${OSALCOVERAGE_TARGET_OSTYPE}")
# This unit test is allowed to directly include any internal file in
# the respective set under test.
include_directories(${OSAL_SOURCE_DIR}/src/os/shared/inc)
add_subdirectory(ut-stubs)
# A generic function to add a coverage test case source file
# This combines the following into an executable
# - The test case setup (a C source file starting with "coveragetest" prefix)
# - The object code of the unit under test (special build with instrumentation)
# - Links to the stub libraries of everything else, plus UT assert
function (add_coverage_testrunner TESTNAME FSW_SRCFILE TESTCASE_SRCFILE)
add_library(utobj_${TESTNAME} OBJECT
${FSW_SRCFILE}
)
# both the FSW src file and the adaptor file get compiled with override includes
target_include_directories(utobj_${TESTNAME} BEFORE PRIVATE
${OSALCOVERAGE_SOURCE_DIR}/ut-stubs/override_inc
$<TARGET_PROPERTY:ut_osapi_stub_headers,INTERFACE_INCLUDE_DIRECTORIES>
)
target_compile_options(utobj_${TESTNAME} PRIVATE
$<TARGET_PROPERTY:ut_coverage_compile,INTERFACE_COMPILE_OPTIONS>
)
target_compile_definitions(utobj_${TESTNAME} PRIVATE
$<TARGET_PROPERTY:ut_coverage_compile,INTERFACE_COMPILE_DEFINITIONS>
)
# the testcase is compiled with no special flags or override includes
add_executable(${TESTNAME}-testrunner
${TESTCASE_SRCFILE}
$<TARGET_OBJECTS:utobj_${TESTNAME}>
)
target_link_libraries(${TESTNAME}-testrunner PUBLIC
${ARGN}
osal_public_api
ut_coverage_link
ut_assert
)
add_test(${TESTNAME} ${TESTNAME}-testrunner)
foreach(TGT ${INSTALL_TARGET_LIST})
install(TARGETS ${TESTNAME}-testrunner DESTINATION ${TGT}/${UT_INSTALL_SUBDIR})
endforeach()
endfunction()
foreach(SETNAME ${OSALCOVERAGE_TARGET_OSTYPE})
add_subdirectory(${SETNAME})
endforeach(SETNAME ${OSALCOVERAGE_TARGET_OSTYPE})