2 # Copyright (c) 2020 Project nlbuild-autotools Authors
3 # Copyright (c) 2020 Google LLC
4 # Copyright 2015-2016 Nest Labs Inc. All Rights Reserved.
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
21 # This file defines automake variables and macros common to all
22 # other automake headers and files for code coverage.
28 # Suffix for the code coverage report "bundle".
30 NL_COVERAGE_BUNDLE_SUFFIX = .lcov
33 # Suffix for the lcov "info" file inside the code coverage report bundle.
35 NL_COVERAGE_INFO_SUFFIX = .info
38 # Verbosity macros and flags
41 NL_V_LCOV = $(nl__v_LCOV_$(V))
42 nl__v_LCOV_ = $(nl__v_LCOV_$(AM_DEFAULT_VERBOSITY))
43 nl__v_LCOV_0 = @echo " LCOV $(@)";
46 NL_V_LCOV_FLAGS = $(nl__v_LCOV_FLAGS_$(V))
47 nl__v_LCOV_FLAGS_ = $(nl__v_LCOV_FLAGS_$(AM_DEFAULT_VERBOSITY))
48 nl__v_LCOV_FLAGS_0 = --quiet
51 NL_V_GENHTML = $(nl__v_GENHTML_$(V))
52 nl__v_GENHTML_ = $(nl__v_GENHTML_$(AM_DEFAULT_VERBOSITY))
53 nl__v_GENHTML_0 = @echo " GENHTML $(@)";
56 NL_V_GENHTML_FLAGS = $(nl__v_GENHTML_FLAGS_$(V))
57 nl__v_GENHTML_FLAGS_ = $(nl__v_GENHTML_FLAGS_$(AM_DEFAULT_VERBOSITY))
58 nl__v_GENHTML_FLAGS_0 = --quiet
59 nl__v_GENHTML_FLAGS_1 =
61 # Ensure that coverage-recursive is included among the list of
62 # recursive targets known by autotools.
64 RECURSIVE_TARGETS += coverage-recursive
67 # generate-coverage-report <directory> [remove_filters]
69 # Capture, using lcov, a coverage report from the specified directory 'directory' and a filter 'remove_filter'
70 # with an final output "info" file as specified by the target variable.
72 # <directory> - The directory from which lcov should search for coverage data (*.gcno & *.gcda)
74 # [remove_filters] - Optional whitespace-separated list of shell wildcard patterns. (note that they may need to be escaped accordingly to prevent
75 # the shell from expanding them first). Every file entry in tracefile which matches at least one of those patterns will be removed.
77 # - create baseline coverage data file (base.info) with '-i|--initial' option
78 # - create test coverage data file (test.info)
79 # - combine baseline and test coverage data to create the final "info" file
80 # - remove particular coverage data specifiled by the remove_filter (no change if remove_filter is null)
82 # Then, on success, generate an HTML-based coverage report using genhtml.
84 define generate-coverage-report
85 $(NL_V_LCOV)$(LCOV) $(NL_V_LCOV_FLAGS) --config-file="$(abs_top_nlbuild_autotools_dir)/etc/lcov.config" --initial --capture --directory "$(1)" --output-file "base.info"
86 $(NL_V_LCOV)$(LCOV) $(NL_V_LCOV_FLAGS) --config-file="$(abs_top_nlbuild_autotools_dir)/etc/lcov.config" --capture --directory "$(1)" --output-file "test.info"
87 $(NL_V_LCOV)$(LCOV) $(NL_V_LCOV_FLAGS) --config-file="$(abs_top_nlbuild_autotools_dir)/etc/lcov.config" --add-tracefile "base.info" --add-tracefile "test.info" --output-file "$(@)"
88 $(NL_V_LCOV)$(LCOV) $(NL_V_LCOV_FLAGS) --config-file="$(abs_top_nlbuild_autotools_dir)/etc/lcov.config" --remove "$(@)" $(foreach pattern,$(2),"$(pattern)") --output-file "$(@)"
89 $(NL_V_GENHTML)$(GENHTML) $(NL_V_GENHTML_FLAGS) --config-file="$(abs_top_nlbuild_autotools_dir)/etc/lcov.config" "$(@)" --output-directory "$(@D)"
90 endef # generate-coverage-report