summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Bettis <jbettis@google.com>2021-04-06 17:29:52 -0600
committerCommit Bot <commit-bot@chromium.org>2021-04-07 23:58:49 +0000
commit93c2031f3d887e8b221a3b303a73390771793e97 (patch)
treef6388dcde1e0ff8ec7c0efefc22be0179bc4507f
parent0940ca52bde3bbcffd5cc671547fc635026f1f68 (diff)
downloadchrome-ec-93c2031f3d887e8b221a3b303a73390771793e97.tar.gz
zephyr: Bundle a summary code coverage file
Fix zmake coverage, it was still using the removed claim_job flag. Change zmake coverage to output a summary lcov.info file as well. Implement zephyr/firmware_builder.py --code-coverage test. Implement zephyr/firmware_builder.py --code-coverage bundle. BRANCH=none BUG=b:183007888 TEST=cros workon --host start chromeos-base/zephyr-build-tools sudo emerge chromeos-base/zephyr-build-tools zephyr/firmware_builder.py --metrics=/tmp/m --code-coverage test zephyr/firmware_builder.py --metrics=/tmp/m --code-coverage bundle tar tvf /tmp/artifact_bundles/coverage.tbz2 cat /tmp/artifact_bundle_metadata Signed-off-by: Jeremy Bettis <jbettis@google.com> Change-Id: I3fbdc4e57029d23a4d24b7ad6e003ee624c75f37 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2809354 Reviewed-by: Jeremy Bettis <jbettis@chromium.org> Reviewed-by: Kevin Shelton <kmshelton@chromium.org> Commit-Queue: Jeremy Bettis <jbettis@chromium.org> Tested-by: Jeremy Bettis <jbettis@chromium.org>
-rwxr-xr-xzephyr/firmware_builder.py24
-rw-r--r--zephyr/zmake/zmake/zmake.py21
2 files changed, 40 insertions, 5 deletions
diff --git a/zephyr/firmware_builder.py b/zephyr/firmware_builder.py
index 540274105b..79ee6a3201 100755
--- a/zephyr/firmware_builder.py
+++ b/zephyr/firmware_builder.py
@@ -74,7 +74,22 @@ def write_metadata(opts, info):
def bundle_coverage(opts):
"""Bundles the artifacts from code coverage into its own tarball."""
- raise NotImplementedError
+ info = firmware_pb2.FirmwareArtifactInfo()
+ info.bcs_version_info.version_string = opts.bcs_version
+ 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'
+ tarball_name = 'coverage.tbz2'
+ tarball_path = bundle_dir / tarball_name
+ cmd = ['tar', 'cvfj', tarball_path, 'lcov.info']
+ subprocess.run(cmd, cwd=build_dir, check=True)
+ meta = info.objects.add()
+ meta.file_name = tarball_name
+ meta.lcov_info.type = firmware_pb2.FirmwareArtifactInfo.LcovTarballInfo.LcovType.LCOV
+
+ write_metadata(opts, info)
+
def bundle_firmware(opts):
@@ -116,6 +131,13 @@ def test(opts):
with open(opts.metrics, 'w') as f:
f.write(json_format.MessageToJson(metrics))
+ if opts.code_coverage:
+ zephyr_dir = pathlib.Path(__file__).parent
+ platform_ec = zephyr_dir.resolve().parent
+ build_dir = platform_ec / 'build/zephyr-coverage'
+ return subprocess.run(
+ ['zmake', '-D', 'coverage', build_dir], cwd=platform_ec).returncode
+
return subprocess.run(['zmake', '-D', 'testall', '--fail-fast']).returncode
diff --git a/zephyr/zmake/zmake/zmake.py b/zephyr/zmake/zmake/zmake.py
index 0b1a57866c..f341de3030 100644
--- a/zephyr/zmake/zmake/zmake.py
+++ b/zephyr/zmake/zmake/zmake.py
@@ -461,7 +461,6 @@ class Zmake:
if initial:
cmd += ['-i']
proc = self.jobserver.popen(cmd,
- claim_job=False,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding='utf-8',
@@ -506,7 +505,6 @@ class Zmake:
['/usr/bin/ninja', '-C', dirs[build_name], 'all.libraries'],
# Ninja will connect as a job client instead and claim
# many jobs.
- claim_job=False,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding='utf-8',
@@ -574,7 +572,6 @@ class Zmake:
proc = self.jobserver.popen(
[self.module_paths['ec'] /
'util/getversion.sh'],
- claim_job=False,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding='utf-8',
@@ -588,6 +585,23 @@ class Zmake:
if proc.wait():
raise OSError(get_process_failure_msg(proc))
+ # Merge info files into a single lcov.info
+ self.logger.info("Merging coverage data into %s.",
+ build_dir / 'lcov.info')
+ cmd = ['/usr/bin/lcov', '-o', build_dir / 'lcov.info']
+ for info in all_lcov_files:
+ cmd += ['-a', info]
+ proc = self.jobserver.popen(
+ cmd,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ encoding='utf-8',
+ errors='replace')
+ zmake.multiproc.log_output(self.logger, logging.ERROR, proc.stderr)
+ zmake.multiproc.log_output(self.logger, logging.DEBUG, proc.stdout)
+ if proc.wait():
+ raise OSError(get_process_failure_msg(proc))
+
# Merge into a nice html report
self.logger.info("Creating coverage report %s.",
build_dir / 'coverage_rpt')
@@ -596,7 +610,6 @@ class Zmake:
build_dir / 'coverage_rpt', '-t',
"Zephyr EC Unittest {}".format(version), '-p',
self.checkout / 'src', '-s'] + all_lcov_files,
- claim_job=False,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding='utf-8',