Skip to content

Commit fca3963

Browse files
andy31415andreilitvinrestyled-commits
authored andcommitted
Add --coverage option for local.py, make clang coverage builds use -fcoverage-mapping/-fprofile-instr-generate (project-chip#37457)
* Add coverage support flags (but no save yet for the flag) * Minor cleanup, save config options when loading variants, so build flags transcend running * Fix yaml content * Restyled by isort * Switch coverage to clang, ensure out dir for config exists * Slight doc update, allow local.py to use ccache * Start adding filter support and comma separation support to local.py * Fix the runner termination logic * gen-coverage works * Restyle * make linter happy * Make it clearer what errors we ignore, add more error logic to make this run on more machines * Restyle * Add more ignores for cleaner results * Restyle * One more ignore * Better organization, make paths consistent * Fix logic. Merged reports now work! * Restyle * fix stderr logging * fix fail dir creation * Make mismatched FIFO pid much easier to investigate * Add hierarchical view by default - it seems easier for us to narrow down coverage * Add coverage support for yaml * Use exec to execute the sub-program * Fix up arguments in local.py to support propper quoting * For chip tool tests also run chip-tool with coverage support * Fix the path-variance runs of unit test, so I can run unit tests with coverage * Updated comment a bit * Increase timeout for test running to cover slow tests, skip slow tests or tests that we know will fail * Also exclude manual tests by default from local runs * match default exclusions ... also flaky excluded * Support keep going for yaml tests, add more ignores * Multiprocessing coverage, coverage now works * Add missing assignment * Restyled by autopep8 --------- Co-authored-by: Andrei Litvin <andreilitvin@google.com> Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 5d94f25 commit fca3963

File tree

6 files changed

+595
-165
lines changed

6 files changed

+595
-165
lines changed

build/config/compiler/BUILD.gn

+12-1
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,18 @@ config("fuzzing_default") {
536536
}
537537

538538
config("coverage") {
539-
cflags = [ "--coverage" ]
539+
if (is_clang) {
540+
cflags = [
541+
# CLANG builds use the clang-specific coverage, so that versions of lcov/gcov
542+
# do not have to match and `llvm-cov export -format=lcov` can be used
543+
#
544+
# Documentation: https://clang.llvm.org/docs/SourceBasedCodeCoverage.html
545+
"-fprofile-instr-generate",
546+
"-fcoverage-mapping",
547+
]
548+
} else {
549+
cflags = [ "--coverage" ]
550+
}
540551
ldflags = cflags
541552
}
542553

scripts/build/build/targets.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def BuildHostFakeTarget():
8080
target.AppendModifier("pw-fuzztest", fuzzing_type=HostFuzzingType.PW_FUZZTEST).OnlyIfRe(
8181
"-clang").ExceptIfRe('-(libfuzzer|ossfuzz|asan)')
8282
target.AppendModifier('coverage', use_coverage=True).OnlyIfRe(
83-
'-(chip-tool|all-clusters)')
83+
'-(chip-tool|all-clusters)').ExceptIfRe('-clang')
8484
target.AppendModifier('dmalloc', use_dmalloc=True)
8585
target.AppendModifier('clang', use_clang=True)
8686

@@ -186,8 +186,7 @@ def BuildHostTarget():
186186
"-clang").ExceptIfRe('-libfuzzer')
187187
target.AppendModifier("pw-fuzztest", fuzzing_type=HostFuzzingType.PW_FUZZTEST).OnlyIfRe(
188188
"-clang").ExceptIfRe('-(libfuzzer|ossfuzz|asan)')
189-
target.AppendModifier('coverage', use_coverage=True).OnlyIfRe(
190-
'-(chip-tool|all-clusters|tests)')
189+
target.AppendModifier('coverage', use_coverage=True)
191190
target.AppendModifier('dmalloc', use_dmalloc=True)
192191
target.AppendModifier('clang', use_clang=True)
193192
target.AppendModifier('test', extra_tests=True)

scripts/build/builders/host.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ def __init__(self, root, runner, app: HostApp, board=HostBoard.NATIVE,
411411
if use_coverage:
412412
self.extra_gn_options.append('use_coverage=true')
413413

414+
self.use_clang = use_clang # for usage in other commands
414415
if use_clang:
415416
self.extra_gn_options.append('is_clang=true')
416417

@@ -586,7 +587,7 @@ def generate(self):
586587
self._Execute(['mkdir', '-p', self.coverage_dir], title="Create coverage output location")
587588

588589
def PreBuildCommand(self):
589-
if self.app == HostApp.TESTS and self.use_coverage:
590+
if self.app == HostApp.TESTS and self.use_coverage and not self.use_clang:
590591
cmd = ['ninja', '-C', self.output_dir]
591592

592593
if self.ninja_jobs is not None:
@@ -604,7 +605,8 @@ def PreBuildCommand(self):
604605
'--output-file', os.path.join(self.coverage_dir, 'lcov_base.info')], title="Initial coverage baseline")
605606

606607
def PostBuildCommand(self):
607-
if self.app == HostApp.TESTS and self.use_coverage:
608+
# TODO: CLANG coverage is not yet implemented, requires different tooling
609+
if self.app == HostApp.TESTS and self.use_coverage and not self.use_clang:
608610
self._Execute(['lcov', '--capture', '--directory', os.path.join(self.output_dir, 'obj'),
609611
'--exclude', os.path.join(self.chip_dir, '**/tests/*'),
610612
'--exclude', os.path.join(self.chip_dir, 'zzz_generated/*'),

scripts/tests/chiptest/test_definition.py

+31-3
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,36 @@ def items(self):
210210
self.microwave_oven_app, self.chip_repl_yaml_tester_cmd,
211211
self.chip_tool_with_python_cmd, self.rvc_app, self.network_manager_app]
212212

213+
def items_with_key(self):
214+
"""
215+
Returns all path items and also the corresponding "Application Key" which
216+
is the typical application name.
217+
218+
This is to provide scripts a consistent way to reference a path, even if
219+
the paths used for individual appplications contain different names
220+
(e.g. they could be wrapper scripts).
221+
"""
222+
return [
223+
(self.chip_tool, "chip-tool"),
224+
(self.all_clusters_app, "chip-all-clusters-app"),
225+
(self.lock_app, "chip-lock-app"),
226+
(self.fabric_bridge_app, "fabric-bridge-app"),
227+
(self.ota_provider_app, "chip-ota-provider-app"),
228+
(self.ota_requestor_app, "chip-ota-requestor-app"),
229+
(self.tv_app, "chip-tv-app"),
230+
(self.bridge_app, "chip-bridge-app"),
231+
(self.lit_icd_app, "lit-icd-app"),
232+
(self.microwave_oven_app, "chip-microwave-oven-app"),
233+
(self.chip_repl_yaml_tester_cmd, "yamltest_with_chip_repl_tester.py"),
234+
(
235+
# This path varies, however it is a fixed python tool so it may be ok
236+
self.chip_tool_with_python_cmd,
237+
os.path.basename(self.chip_tool_with_python_cmd[-1]),
238+
),
239+
(self.rvc_app, "chip-rvc-app"),
240+
(self.network_manager_app, "matter-network-manager-app"),
241+
]
242+
213243

214244
@dataclass
215245
class CaptureLine:
@@ -330,7 +360,7 @@ def Run(self, runner, apps_register, paths: ApplicationPaths, pics_file: str,
330360
"don't know which application to run")
331361

332362
if not dry_run:
333-
for path in paths.items():
363+
for path, key in paths.items_with_key():
334364
# Do not add chip-tool or chip-repl-yaml-tester-cmd to the register
335365
if path == paths.chip_tool or path == paths.chip_repl_yaml_tester_cmd or path == paths.chip_tool_with_python_cmd:
336366
continue
@@ -345,8 +375,6 @@ def Run(self, runner, apps_register, paths: ApplicationPaths, pics_file: str,
345375
# For the app indicated by self.target, give it the 'default' key to add to the register
346376
if path == target_app:
347377
key = 'default'
348-
else:
349-
key = os.path.basename(path[-1])
350378

351379
app = App(runner, path)
352380
# Add the App to the register immediately, so if it fails during

0 commit comments

Comments
 (0)