configure: Add switch for clang's "source-based" code coverage feature

This adds instrumentation to the binaries. At the end of their
execution, these will then write a file containing information which code
was executed. This can be used for code coverage analysis.

[ChangeLog][QtCore][configure] Add switch "-coverage source-based" to
enable clang's "source-based" code coverage feature. This can be used
for code coverage analysis.

Change-Id: If31c6849aa797ff8820e041e85a492a14e2f1a6b
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Robert Loehning 2019-12-19 17:51:21 +01:00
parent a611c632bb
commit 94bc57213f
5 changed files with 24 additions and 5 deletions

View File

@ -137,8 +137,10 @@ Build options:
for example, -sanitize address cannot be combined with
-sanitize thread.
-coverage {trace-pc-guard}
Add code coverage instrumentation (Clang only)
-coverage {trace-pc-guard|source-based}
Specify the 'trace-pc-guard' coverage instrumentation for
sanitizers or generate instrumented code to collect execution
counts and enable code coverage analysis, respectively. (Clang only)
-c++std <edition> .... Select C++ standard <edition> [c++2a/c++17/c++14/c++11]
(Not supported with MSVC 2015)

View File

@ -916,9 +916,14 @@
"autoDetect": false,
"output": [ "publicConfig" ]
},
"coverage_source_based": {
"label": "source-based",
"autoDetect": false,
"output": [ "publicConfig" ]
},
"coverage": {
"label": "Code Coverage Instrumentation",
"condition": "features.coverage_trace_pc_guard",
"condition": "features.coverage_trace_pc_guard || features.coverage_source_based",
"output": [ "publicConfig" ]
},
"GNUmake": {
@ -1612,7 +1617,7 @@ Configure with '-qreal float' to create a build that is binary-compatible with 5
{
"message": "Code Coverage Instrumentation",
"type": "firstAvailableFeature",
"args": "coverage_trace_pc_guard",
"args": "coverage_trace_pc_guard coverage_source_based",
"condition": "features.coverage"
},
{

View File

@ -72,7 +72,9 @@ defineTest(qtConfCommandline_coverage) {
!contains(val, "^-.*"):!isEmpty(val) {
equals(val, "trace-pc-guard") {
qtConfCommandlineSetInput("coverage_trace_pc_guard", "yes")
} else {
} else: equals(val, "source-based") {
qtConfCommandlineSetInput("coverage_source_based", "yes")
} else: {
qtConfAddError("Invalid argument $$val to command line parameter $$arg")
}
} else {

View File

@ -54,3 +54,7 @@ QMAKE_RANLIB_LTCG = true # No need to run, since llvm-ar has "s"
QMAKE_CFLAGS_COVERAGE_TRACE_PC_GUARD = -fsanitize-coverage=trace-pc-guard
QMAKE_CXXFLAGS_COVERAGE_TRACE_PC_GUARD = -fsanitize-coverage=trace-pc-guard
QMAKE_LFLAGS_COVERAGE_TRACE_PC_GUARD = -fsanitize-coverage=trace-pc-guard
QMAKE_CFLAGS_COVERAGE_SOURCE_BASED = -fprofile-instr-generate -fcoverage-mapping
QMAKE_CXXFLAGS_COVERAGE_SOURCE_BASED = -fprofile-instr-generate -fcoverage-mapping
QMAKE_LFLAGS_COVERAGE_SOURCE_BASED = -fprofile-instr-generate -fcoverage-mapping

View File

@ -5,3 +5,9 @@ coverage_trace_pc_guard {
QMAKE_CXXFLAGS += $$QMAKE_CXXFLAGS_COVERAGE_TRACE_PC_GUARD
QMAKE_LFLAGS += $$QMAKE_LFLAGS_COVERAGE_TRACE_PC_GUARD
}
coverage_source_based {
QMAKE_CFLAGS += $$QMAKE_CFLAGS_COVERAGE_SOURCE_BASED
QMAKE_CXXFLAGS += $$QMAKE_CXXFLAGS_COVERAGE_SOURCE_BASED
QMAKE_LFLAGS += $$QMAKE_LFLAGS_COVERAGE_SOURCE_BASED
}