diff options
author | Paul Fagerburg <pfagerburg@google.com> | 2021-02-05 14:19:36 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-02-06 04:53:08 +0000 |
commit | 85d194abc71e48b048c5255e0d51112966cc1673 (patch) | |
tree | 7c21007eda6aafeb3579e09c74aa7231876550df /firmware_builder.py | |
parent | 943520d37cac1c7f6faa0a1777673873cc5e9564 (diff) | |
download | chrome-ec-85d194abc71e48b048c5255e0d51112966cc1673.tar.gz |
firmware_builder: add --code-coverage option
Added an option flag --code-coverage that will skip the build for EC
hardware targets and build the tests with code coverage enabled.
BUG=b:156895937
BRANCH=None
TEST=Run firmware_builder.py with --code-coverage option. The 'build'
command will do nothing, and the 'test' command will build the host-
based unit test with code coverage.
Signed-off-by: Paul Fagerburg <pfagerburg@google.com>
Change-Id: Ie3786f574e490a5ba6806e518401842bda609e5f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2678937
Tested-by: Paul Fagerburg <pfagerburg@chromium.org>
Reviewed-by: LaMont Jones <lamontjones@chromium.org>
Commit-Queue: Paul Fagerburg <pfagerburg@chromium.org>
Diffstat (limited to 'firmware_builder.py')
-rwxr-xr-x | firmware_builder.py | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/firmware_builder.py b/firmware_builder.py index 243534230a..fc8aa29262 100755 --- a/firmware_builder.py +++ b/firmware_builder.py @@ -24,7 +24,19 @@ DEFAULT_BUNDLE_METADATA_FILE = '/tmp/artifact_bundle_metadata' def build(opts): - """Builds all EC firmware targets""" + """Builds all EC firmware targets + + Note that when we are building unit tests for code coverage, we don't + need this step. It builds EC **firmware** targets, but unit tests with + code coverage are all host-based. So if the --code-coverage flag is set, + we don't need to build the firmware targets and we can return without + doing anything but giving an informational message. + """ + if opts.code_coverage: + print("When --code-coverage is selected, 'build' is a no-op. " + "Run 'test' with --code-coverage instead.") + return + # TODO(b/169178847): Add appropriate metric information metrics = firmware_pb2.FwBuildMetricList() with open(opts.metrics, 'w') as f: @@ -64,8 +76,14 @@ def test(opts): with open(opts.metrics, 'w') as f: f.write(json_format.MessageToJson(metrics)) - # Verify all posix-based unit tests build and pass - subprocess.run(['make', 'runtests', '-j{}'.format(opts.cpus)], + # If building for code coverage, build the 'coverage' target, which + # builds the posix-based unit tests for code coverage and assembles + # the LCOV information. + # + # Otherwise, build the 'runtests' target, which verifies all + # posix-based unit tests build and pass. + target = 'coverage' if opts.code_coverage else 'runtests' + subprocess.run(['make', target, '-j{}'.format(opts.cpus)], cwd=os.path.dirname(__file__), check=True) @@ -125,6 +143,13 @@ def parse_args(args): 'Full pathanme for the directory in which to bundle build artifacts.', ) + parser.add_argument( + '--code-coverage', + required=False, + action='store_true', + help='Build host-based unit tests for code coverage.', + ) + # Would make this required=True, but not available until 3.7 sub_cmds = parser.add_subparsers() |