summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Bettis <jbettis@google.com>2022-02-03 14:35:17 -0700
committerCommit Bot <commit-bot@chromium.org>2022-02-07 19:41:54 +0000
commit55daab4bfd516c59b45cb4d9041e55d810ecbf97 (patch)
tree5e2b198a0bce0cc2f7b8b3d58df51d4e60a7e160
parent0037f74892b3204e12197d6d2bc76fea9a61ecdf (diff)
downloadchrome-ec-55daab4bfd516c59b45cb4d9041e55d810ecbf97.tar.gz
cq: Handle coverage better
Only build/test with coverage if --code-coverage is passed. Change bundle_coverage to merge all lcov files together, and bundle a single lcov.info that includes all boards and all zephyr tests. This is different from what we do on gitlab, but I don't want to build the CROS-EC tests here. For purposes of showing coverage in gerrit, this should be good enough. BRANCH=None BUG=b:156895937 TEST=Ran commands in README.md, and it caught the zmake breakage at tot Change-Id: I517b191d097384da59fee4c27cffcfc58b7d20ec Signed-off-by: Jeremy Bettis <jbettis@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3436693 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Commit-Queue: Jeremy Bettis <jbettis@chromium.org> Tested-by: Jeremy Bettis <jbettis@chromium.org> Auto-Submit: Jeremy Bettis <jbettis@chromium.org>
-rw-r--r--zephyr/README.md32
-rwxr-xr-xzephyr/firmware_builder.py43
2 files changed, 65 insertions, 10 deletions
diff --git a/zephyr/README.md b/zephyr/README.md
index 58e4a13a9a..6ac634ebb2 100644
--- a/zephyr/README.md
+++ b/zephyr/README.md
@@ -19,3 +19,35 @@ is intended to ensure that we have a path to upstreaming our code eventually and
do not rely on Chrome OS-specific tools. It does make use of 'zmake', however.
See the piplines [here](https://gitlab.com/zephyr-ec/ec/-/pipelines).
+
+## CQ builder
+
+To test the cq builder script run these commands:
+
+### firmware-zephyr-cq
+```
+rm -rf /tmp/artifact_bundles /tmp/artifact_bundle_metadata \
+ ~/chromiumos/src/platform/ec/build
+cd ~/chromiumos/src/platform/ec/zephyr
+./firmware_builder.py --metrics /tmp/metrics build && \
+./firmware_builder.py --metrics /tmp/metrics test && \
+./firmware_builder.py --metrics /tmp/metrics bundle && \
+echo PASSED
+cat /tmp/artifact_bundle_metadata
+ls -l /tmp/artifact_bundles/
+```
+
+### firmware-zephyr-cov-cq
+```
+rm -rf /tmp/artifact_bundles-cov /tmp/artifact_bundle_metadata-cov \
+ ~/chromiumos/src/platform/ec/build
+cd ~/chromiumos/src/platform/ec/zephyr
+./firmware_builder.py --metrics /tmp/metrics --code-coverage build && \
+./firmware_builder.py --metrics /tmp/metrics --code-coverage test && \
+./firmware_builder.py --metrics /tmp/metrics --code-coverage \
+ --output-dir=/tmp/artifact_bundles-cov \
+ --metadata=/tmp/artifact_bundle_metadata-cov bundle && \
+echo PASSED
+cat /tmp/artifact_bundle_metadata-cov
+ls -l /tmp/artifact_bundles-cov
+```
diff --git a/zephyr/firmware_builder.py b/zephyr/firmware_builder.py
index 78a202a56e..d31dd720a5 100755
--- a/zephyr/firmware_builder.py
+++ b/zephyr/firmware_builder.py
@@ -37,7 +37,10 @@ def build(opts):
]
for target in targets:
print('Building {}'.format(target))
- cmd = ['zmake', '-D', 'configure', '-b', target]
+ cmd = ['zmake', '-D', 'configure', '-b']
+ if opts.code_coverage:
+ cmd.append('--coverage')
+ cmd.append(target)
rv = subprocess.run(cmd, cwd=pathlib.Path(__file__).parent).returncode
if rv != 0:
return rv
@@ -78,7 +81,27 @@ def bundle_coverage(opts):
bundle_dir = get_bundle_dir(opts)
zephyr_dir = pathlib.Path(__file__).parent
platform_ec = zephyr_dir.resolve().parent
- build_dir = platform_ec / 'build/zephyr-coverage'
+ # Find the zephyr.info for every project and merge them
+ all_lcov_files = [platform_ec / 'build' / 'zephyr-coverage' / 'lcov.info']
+ for project in zmake.project.find_projects(zephyr_dir).values():
+ if not project.config.is_test:
+ build_dir = platform_ec / "build" / "zephyr" / project.config.project_name
+ artifacts_dir = build_dir
+ all_lcov_files.append(artifacts_dir / 'lcov.info')
+ build_dir = platform_ec / "build"
+ print("all_lcov_files = %s" % all_lcov_files)
+ cmd = [
+ "/usr/bin/lcov",
+ "-o",
+ build_dir / "lcov.info",
+ "--rc",
+ "lcov_branch_coverage=1",
+ ]
+ for lcov_file in all_lcov_files:
+ cmd += ["-a", lcov_file]
+ rv = subprocess.run(cmd, cwd=pathlib.Path(__file__).parent).returncode
+ if rv != 0:
+ return rv
tarball_name = 'coverage.tbz2'
tarball_path = bundle_dir / tarball_name
cmd = ['tar', 'cvfj', tarball_path, 'lcov.info']
@@ -136,13 +159,13 @@ def test(opts):
config_files = zephyr_dir.rglob("**/BUILD.py")
subprocess.run(["black", "--diff", "--check", *config_files], check=True)
- subprocess.run(['zmake', '-D', 'testall'], check=True)
-
- # Run the test with coverage also, as sometimes they behave differently.
- platform_ec = zephyr_dir.parent
- build_dir = platform_ec / 'build/zephyr-coverage'
- return subprocess.run(
- ['zmake', '-D', 'coverage', build_dir], cwd=platform_ec).returncode
+ if opts.code_coverage:
+ platform_ec = zephyr_dir.parent
+ build_dir = platform_ec / 'build/zephyr-coverage'
+ return subprocess.run(
+ ['zmake', '-D', 'coverage', build_dir], cwd=platform_ec).returncode
+ else:
+ return subprocess.run(['zmake', '-D', 'testall'], check=True).returncode
def main(args):
@@ -184,7 +207,7 @@ def parse_args(args):
'--output-dir',
required=False,
help=
- 'Full pathanme for the directory in which to bundle build artifacts.',
+ 'Full pathname for the directory in which to bundle build artifacts.',
)
parser.add_argument(