Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --coverage option for local.py, make clang coverage builds use -fcoverage-mapping/-fprofile-instr-generate #37457

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
f60df0f
Add coverage support flags (but no save yet for the flag)
andreilitvin Feb 7, 2025
7b366f5
Minor cleanup, save config options when loading variants, so build fl…
andreilitvin Feb 7, 2025
c9fdf31
Fix yaml content
andreilitvin Feb 7, 2025
678832f
Restyled by isort
restyled-commits Feb 7, 2025
43f94d6
Switch coverage to clang, ensure out dir for config exists
andreilitvin Feb 7, 2025
b839967
Slight doc update, allow local.py to use ccache
andreilitvin Feb 7, 2025
9ab32d0
Start adding filter support and comma separation support to local.py
andreilitvin Feb 7, 2025
fffb0da
Fix the runner termination logic
andreilitvin Feb 7, 2025
4009d04
gen-coverage works
andreilitvin Feb 7, 2025
a18015d
Restyle
andreilitvin Feb 7, 2025
4c507c4
make linter happy
andy31415 Feb 8, 2025
f4e1946
Make it clearer what errors we ignore, add more error logic to make t…
andy31415 Feb 8, 2025
f24932c
Restyle
andy31415 Feb 8, 2025
467647f
Add more ignores for cleaner results
andy31415 Feb 8, 2025
72e42ab
Restyle
andy31415 Feb 8, 2025
7317c8d
One more ignore
andy31415 Feb 8, 2025
aa6a7e8
Better organization, make paths consistent
andy31415 Feb 8, 2025
69dec39
Fix logic. Merged reports now work!
andy31415 Feb 8, 2025
6c8219e
Restyle
andy31415 Feb 8, 2025
96f1443
fix stderr logging
andy31415 Feb 8, 2025
9adddfc
fix fail dir creation
andy31415 Feb 8, 2025
1d15fed
Make mismatched FIFO pid much easier to investigate
andy31415 Feb 8, 2025
4babb19
Add hierarchical view by default - it seems easier for us to narrow d…
andy31415 Feb 10, 2025
206efca
Add coverage support for yaml
andy31415 Feb 10, 2025
dc0ebdc
Use exec to execute the sub-program
andy31415 Feb 10, 2025
bdb8395
Fix up arguments in local.py to support propper quoting
andy31415 Feb 10, 2025
43d9be2
For chip tool tests also run chip-tool with coverage support
andy31415 Feb 10, 2025
8ec302f
Fix the path-variance runs of unit test, so I can run unit tests wit…
andy31415 Feb 10, 2025
ef5cda6
Updated comment a bit
andy31415 Feb 10, 2025
c4b12ab
Increase timeout for test running to cover slow tests, skip slow test…
andy31415 Feb 10, 2025
a41b6a1
Also exclude manual tests by default from local runs
andy31415 Feb 10, 2025
e905ae0
match default exclusions ... also flaky excluded
andy31415 Feb 10, 2025
75c81f4
Support keep going for yaml tests, add more ignores
andy31415 Feb 10, 2025
9c345d6
Multiprocessing coverage, coverage now works
andy31415 Feb 10, 2025
ec5af59
Add missing assignment
andy31415 Feb 10, 2025
81597b6
Merge branch 'master' into add_coverage_to_local_py
andy31415 Feb 10, 2025
b5d22f2
Restyled by autopep8
restyled-commits Feb 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion build/config/compiler/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,18 @@ config("fuzzing_default") {
}

config("coverage") {
cflags = [ "--coverage" ]
if (is_clang) {
cflags = [
# CLANG builds use the clang-specific coverage, so that versions of lcov/gcov
# do not have to match and `llvm-cov export -format=lcov` can be used
#
# Documentation: https://clang.llvm.org/docs/SourceBasedCodeCoverage.html
"-fprofile-instr-generate",
"-fcoverage-mapping",
]
} else {
cflags = [ "--coverage" ]
}
ldflags = cflags
}

Expand Down
5 changes: 2 additions & 3 deletions scripts/build/build/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def BuildHostFakeTarget():
target.AppendModifier("pw-fuzztest", fuzzing_type=HostFuzzingType.PW_FUZZTEST).OnlyIfRe(
"-clang").ExceptIfRe('-(libfuzzer|ossfuzz|asan)')
target.AppendModifier('coverage', use_coverage=True).OnlyIfRe(
'-(chip-tool|all-clusters)')
'-(chip-tool|all-clusters)').ExceptIfRe('-clang')
target.AppendModifier('dmalloc', use_dmalloc=True)
target.AppendModifier('clang', use_clang=True)

Expand Down Expand Up @@ -186,8 +186,7 @@ def BuildHostTarget():
"-clang").ExceptIfRe('-libfuzzer')
target.AppendModifier("pw-fuzztest", fuzzing_type=HostFuzzingType.PW_FUZZTEST).OnlyIfRe(
"-clang").ExceptIfRe('-(libfuzzer|ossfuzz|asan)')
target.AppendModifier('coverage', use_coverage=True).OnlyIfRe(
'-(chip-tool|all-clusters|tests)')
target.AppendModifier('coverage', use_coverage=True)
target.AppendModifier('dmalloc', use_dmalloc=True)
target.AppendModifier('clang', use_clang=True)
target.AppendModifier('test', extra_tests=True)
Expand Down
6 changes: 4 additions & 2 deletions scripts/build/builders/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ def __init__(self, root, runner, app: HostApp, board=HostBoard.NATIVE,
if use_coverage:
self.extra_gn_options.append('use_coverage=true')

self.use_clang = use_clang # for usage in other commands
if use_clang:
self.extra_gn_options.append('is_clang=true')

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

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

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

def PostBuildCommand(self):
if self.app == HostApp.TESTS and self.use_coverage:
# TODO: CLANG coverage is not yet implemented, requires different tooling
if self.app == HostApp.TESTS and self.use_coverage and not self.use_clang:
self._Execute(['lcov', '--capture', '--directory', os.path.join(self.output_dir, 'obj'),
'--exclude', os.path.join(self.chip_dir, '**/tests/*'),
'--exclude', os.path.join(self.chip_dir, 'zzz_generated/*'),
Expand Down
34 changes: 31 additions & 3 deletions scripts/tests/chiptest/test_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,36 @@ def items(self):
self.microwave_oven_app, self.chip_repl_yaml_tester_cmd,
self.chip_tool_with_python_cmd, self.rvc_app, self.network_manager_app]

def items_with_key(self):
"""
Returns all path items and also the corresponding "Application Key" which
is the typical application name.

This is to provide scripts a consistent way to reference a path, even if
the paths used for individual appplications contain different names
(e.g. they could be wrapper scripts).
"""
return [
(self.chip_tool, "chip-tool"),
(self.all_clusters_app, "chip-all-clusters-app"),
(self.lock_app, "chip-lock-app"),
(self.fabric_bridge_app, "fabric-bridge-app"),
(self.ota_provider_app, "chip-ota-provider-app"),
(self.ota_requestor_app, "chip-ota-requestor-app"),
(self.tv_app, "chip-tv-app"),
(self.bridge_app, "chip-bridge-app"),
(self.lit_icd_app, "lit-icd-app"),
(self.microwave_oven_app, "chip-microwave-oven-app"),
(self.chip_repl_yaml_tester_cmd, "yamltest_with_chip_repl_tester.py"),
(
# This path varies, however it is a fixed python tool so it may be ok
self.chip_tool_with_python_cmd,
os.path.basename(self.chip_tool_with_python_cmd[-1]),
),
(self.rvc_app, "chip-rvc-app"),
(self.network_manager_app, "matter-network-manager-app"),
]


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

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

app = App(runner, path)
# Add the App to the register immediately, so if it fails during
Expand Down
Loading
Loading