summaryrefslogtreecommitdiff
path: root/zephyr
diff options
context:
space:
mode:
authorJeremy Bettis <jbettis@google.com>2021-08-30 12:24:04 -0600
committerCommit Bot <commit-bot@chromium.org>2021-08-31 04:21:58 +0000
commit463618c732f55a80ca533cd601ebea8bfef3494c (patch)
treea3aba3e33bad7fa323508dae3f07d49ee9ec096b /zephyr
parent79a2b10cc1588a5b5b0b06b93b7fc67c6759546c (diff)
downloadchrome-ec-463618c732f55a80ca533cd601ebea8bfef3494c.tar.gz
zephyr: Build a script to call gcov
In chroot, you can always use llvm-cov to parse the coverage files, but in zephyr sdk, you have to use the right gcov binary for each toolchain. Use cmake to build a gcov shell script, and call it from zmake coverage. BUG=None TEST=zmake coverage in chroot and gitlab BRANCH=None Signed-off-by: Jeremy Bettis <jbettis@google.com> Change-Id: I6203445f0a412193e8280bb5cdf7994d5346fdbd Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3130622 Tested-by: Jeremy Bettis <jbettis@chromium.org> Auto-Submit: Jeremy Bettis <jbettis@chromium.org> Commit-Queue: Yuval Peress <peress@chromium.org> Reviewed-by: Yuval Peress <peress@chromium.org>
Diffstat (limited to 'zephyr')
-rw-r--r--zephyr/CMakeLists.txt2
-rw-r--r--zephyr/cmake/compiler/clang/generic.cmake1
-rwxr-xr-xzephyr/gcov.tmpl.sh7
-rw-r--r--zephyr/zmake/zmake/zmake.py14
4 files changed, 20 insertions, 4 deletions
diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt
index f2550caf84..75076c6edf 100644
--- a/zephyr/CMakeLists.txt
+++ b/zephyr/CMakeLists.txt
@@ -90,7 +90,9 @@ add_custom_target(
DEPENDS
${ZEPHYR_LIBS_PROPERTY}
kernel
+ ${CMAKE_BINARY_DIR}/gcov.sh
)
+configure_file(gcov.tmpl.sh ${CMAKE_BINARY_DIR}/gcov.sh)
# CONFIG_PLATFORM_EC files that don't relate to something below should be
# included here, sorted by filename. This is common functionality which is
diff --git a/zephyr/cmake/compiler/clang/generic.cmake b/zephyr/cmake/compiler/clang/generic.cmake
index 33d82b38e1..aa3665ad39 100644
--- a/zephyr/cmake/compiler/clang/generic.cmake
+++ b/zephyr/cmake/compiler/clang/generic.cmake
@@ -3,3 +3,4 @@
# found in the LICENSE file.
set(CMAKE_C_COMPILER "/usr/bin/x86_64-pc-linux-gnu-clang")
+set(CMAKE_GCOV "/usr/bin/llvm-cov gcov")
diff --git a/zephyr/gcov.tmpl.sh b/zephyr/gcov.tmpl.sh
new file mode 100755
index 0000000000..96bd82ab51
--- /dev/null
+++ b/zephyr/gcov.tmpl.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+#
+# Copyright 2021 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+exec ${CMAKE_GCOV} "$@"
diff --git a/zephyr/zmake/zmake/zmake.py b/zephyr/zmake/zmake/zmake.py
index 301ee5c431..70f58ed129 100644
--- a/zephyr/zmake/zmake/zmake.py
+++ b/zephyr/zmake/zmake/zmake.py
@@ -513,7 +513,8 @@ class Zmake:
shutil.rmtree(tmpdir)
return rv
- def _run_lcov(self, build_dir, lcov_file, initial=False):
+ def _run_lcov(self, build_dir, lcov_file, initial=False, gcov=""):
+ gcov = os.path.abspath(gcov)
with self.jobserver.get_job():
if initial:
self.logger.info("Running (initial) lcov on %s.", build_dir)
@@ -522,7 +523,7 @@ class Zmake:
cmd = [
"/usr/bin/lcov",
"--gcov-tool",
- self.module_paths["ec"] / "util/llvm-gcov.sh",
+ gcov,
"-q",
"-o",
"-",
@@ -606,9 +607,11 @@ class Zmake:
procs = []
dirs = {}
+ gcov = "gcov.sh-not-found"
for build_name, build_config in build_project.iter_builds():
self.logger.info("Building %s:%s all.libraries.", build_dir, build_name)
dirs[build_name] = build_dir / "build-{}".format(build_name)
+ gcov = dirs[build_name] / "gcov.sh"
proc = self.jobserver.popen(
["/usr/bin/ninja", "-C", dirs[build_name], "all.libraries"],
# Ninja will connect as a job client instead and claim
@@ -638,7 +641,7 @@ class Zmake:
if proc.wait():
raise OSError(get_process_failure_msg(proc))
- return self._run_lcov(build_dir, lcov_file, initial=True)
+ return self._run_lcov(build_dir, lcov_file, initial=True, gcov=gcov)
def _coverage_run_test(self, project, build_dir, lcov_file):
self.logger.info("Running test %s in %s", project.project_dir, build_dir)
@@ -651,7 +654,10 @@ class Zmake:
)
if rv:
return rv
- return self._run_lcov(build_dir, lcov_file, initial=False)
+ gcov = "gcov.sh-not-found"
+ for build_name, build_config in project.iter_builds():
+ gcov = build_dir / "build-{}".format(build_name) / "gcov.sh"
+ return self._run_lcov(build_dir, lcov_file, initial=False, gcov=gcov)
def coverage(self, build_dir):
"""Builds all targets with coverage enabled, and then runs the tests."""