summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLeander Beernaert <leander.beernaert@qt.io>2020-03-17 11:15:10 +0100
committerLeander Beernaert <leander.beernaert@qt.io>2020-03-18 16:28:30 +0100
commitdfd37e27caca37594d43c3b096f711e830c2733d (patch)
treea37f1fe5e922233869d613b1221b0e9dfb53739b /src
parent64bda9d91588c9d8d22a16a41c28d845ab6a935e (diff)
CMake: Enable testlib selftests
This patch adds the equivalent of testlib's selfcover.pri and is enabled for both testlib and the respective selftests test. This patch also fixes the selftests so that they can run without FEATURE_testlib_selfcover enabled. Change-Id: I15913de2d572ac79804ce3e652cee66de74318f8 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/testlib/CMakeLists.txt7
-rw-r--r--src/testlib/selfcover.cmake40
2 files changed, 47 insertions, 0 deletions
diff --git a/src/testlib/CMakeLists.txt b/src/testlib/CMakeLists.txt
index 0f80af42c9..ba3f861549 100644
--- a/src/testlib/CMakeLists.txt
+++ b/src/testlib/CMakeLists.txt
@@ -1,5 +1,9 @@
# Generated from testlib.pro.
+# special case begin
+include(selfcover.cmake)
+# special case end
+
#####################################################################
## Test Module:
#####################################################################
@@ -130,3 +134,6 @@ qt_add_docs(Test
doc/qttestlib.qdocconf
)
+# special case begin
+qt_apply_testlib_coverage_options(Test)
+# special case end
diff --git a/src/testlib/selfcover.cmake b/src/testlib/selfcover.cmake
new file mode 100644
index 0000000000..c04ffa7b01
--- /dev/null
+++ b/src/testlib/selfcover.cmake
@@ -0,0 +1,40 @@
+#
+# Hand crafted file based on selfcover.pri
+#
+
+# Overwrite CMake compiler
+function(__qt_testlib_patch_compiler_name variable)
+ get_filename_component(name ${${variable}} NAME)
+ set(${variable} cs${name} PARENT_SCOPE)
+endfunction()
+
+if (FEATURE_testlib_selfcover)
+ __qt_testlib_patch_compiler_name(CMAKE_C_COMPILER)
+ __qt_testlib_patch_compiler_name(CMAKE_CXX_COMPILER)
+ __qt_testlib_patch_compiler_name(CMAKE_CXX_COMPILER_AR)
+ __qt_testlib_patch_compiler_name(CMAKE_CXX_COMPILER_RANLIB)
+endif()
+
+# This enables verification that testlib itself is adequately tested,
+# as a grounds for trusting that testing with it is useful.
+function(qt_apply_testlib_coverage_options target)
+ if (NOT FEATURE_testlib_selfcover)
+ return()
+ endif()
+ # Exclude all non-testlib source from coverage instrumentation:
+ set(testlib_coverage_options
+ --cs-exclude-file-abs-wildcard="${${CMAKE_PROJECT_NAME}_SOURCE_DIR}/*"
+ --cs-include-file-abs-wildcard="*/src/testlib/*"
+ --cs-mcc # enable Multiple Condition Coverage
+ --cs-mcdc # enable Multiple Condition / Decision Coverage
+ # (recommended for ISO 26262 ASIL A, B and C -- highly recommended for ASIL D)
+ # https://doc.froglogic.com/squish-coco/4.1/codecoverage.html#sec%3Amcdc
+ )
+ target_compile_options(${target} PRIVATE
+ ${testlib_coverage_options}
+ )
+
+ target_link_options(${target} PRIVATE
+ ${testlib_coverage_options}
+ )
+endfunction()