Skip to content

filter coverage files #1

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

Open
wants to merge 6 commits into
base: mbed-gcov
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 16 additions & 7 deletions tools/build_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ def target_supports_toolchain(target, toolchain_name):
def prepare_toolchain(src_paths, build_dir, target, toolchain_name,
macros=None, clean=False, jobs=1,
notify=None, config=None, app_config=None,
build_profile=None, ignore=None):
build_profile=None, ignore=None,
coverage_patterns=None):
""" Prepares resource related objects - toolchain, target, config

Positional arguments:
Expand Down Expand Up @@ -319,6 +320,8 @@ def prepare_toolchain(src_paths, build_dir, target, toolchain_name,
if (toolchain_name == "ARM" and CORE_ARCH[target.core] == 8):
toolchain_name = "ARMC6"

if coverage_patterns:
target.extra_labels.append(u'COVERAGE')
try:
cur_tc = TOOLCHAIN_CLASSES[toolchain_name]
except KeyError:
Expand All @@ -330,7 +333,8 @@ def prepare_toolchain(src_paths, build_dir, target, toolchain_name,
profile[key].extend(contents[toolchain_name].get(key, []))

toolchain = cur_tc(
target, notify, macros, build_dir=build_dir, build_profile=profile)
target, notify, macros, build_dir=build_dir, build_profile=profile,
coverage_patterns=coverage_patterns)

toolchain.config = config
toolchain.jobs = jobs
Expand Down Expand Up @@ -458,7 +462,8 @@ def build_project(src_paths, build_path, target, toolchain_name,
notify=None, name=None, macros=None, inc_dirs=None, jobs=1,
report=None, properties=None, project_id=None,
project_description=None, config=None,
app_config=None, build_profile=None, stats_depth=None, ignore=None):
app_config=None, build_profile=None, stats_depth=None, ignore=None,
coverage_patterns=None):
""" Build a project. A project may be a test or a user program.

Positional arguments:
Expand Down Expand Up @@ -502,7 +507,8 @@ def build_project(src_paths, build_path, target, toolchain_name,
toolchain = prepare_toolchain(
src_paths, build_path, target, toolchain_name, macros=macros,
clean=clean, jobs=jobs, notify=notify, config=config,
app_config=app_config, build_profile=build_profile, ignore=ignore)
app_config=app_config, build_profile=build_profile, ignore=ignore,
coverage_patterns=coverage_patterns)
toolchain.version_check()

# The first path will give the name to the library
Expand Down Expand Up @@ -535,6 +541,7 @@ def build_project(src_paths, build_path, target, toolchain_name,

# Compile Sources
objects = toolchain.compile_sources(resources, sorted(resources.get_file_paths(FileType.INC_DIR)))

resources.add_files_to_type(FileType.OBJECT, objects)

# Link Program
Expand Down Expand Up @@ -616,7 +623,7 @@ def build_library(src_paths, build_path, target, toolchain_name,
archive=True, notify=None, macros=None, inc_dirs=None, jobs=1,
report=None, properties=None, project_id=None,
remove_config_header_file=False, app_config=None,
build_profile=None, ignore=None):
build_profile=None, ignore=None, coverage_patterns=None):
""" Build a library

Positional arguments:
Expand Down Expand Up @@ -666,7 +673,8 @@ def build_library(src_paths, build_path, target, toolchain_name,
toolchain = prepare_toolchain(
src_paths, build_path, target, toolchain_name, macros=macros,
clean=clean, jobs=jobs, notify=notify, app_config=app_config,
build_profile=build_profile, ignore=ignore)
build_profile=build_profile, ignore=ignore,
coverage_patterns=coverage_patterns)

# The first path will give the name to the library
if name is None:
Expand Down Expand Up @@ -717,10 +725,11 @@ def build_library(src_paths, build_path, target, toolchain_name,
# Compile Sources
objects = toolchain.compile_sources(
res, res.get_file_paths(FileType.INC_DIR))

res.add_files_to_type(FileType.OBJECT, objects)

if archive:
toolchain.build_library(objects, build_path, name)
toolchain.build_library(res.objects, build_path, name)

if remove_config_header_file:
config_header_path = toolchain.get_config_header()
Expand Down
17 changes: 0 additions & 17 deletions tools/profiles/gcov.json

This file was deleted.

19 changes: 14 additions & 5 deletions tools/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from tools.config import ConfigException, Config
from tools.test_api import test_path_to_name, find_tests, get_test_config, print_tests, build_tests, test_spec_from_test_builds
from tools.test_configs import get_default_config
from tools.options import get_default_options_parser, extract_profile, extract_mcus
from tools.options import get_default_options_parser, extract_profile, extract_mcus, argparse_profile_filestring_type
from tools.build_api import build_project, build_library
from tools.build_api import print_build_memory_usage
from tools.build_api import merge_build_data
Expand Down Expand Up @@ -115,6 +115,9 @@
parser.add_argument("--ignore", dest="ignore", type=argparse_many(str),
default=None, help="Comma separated list of patterns to add to mbedignore (eg. ./main.cpp)")

parser.add_argument("--coverage", dest="coverage_patterns", type=argparse_many(str),
default=None, help="Coverage patterns to run")

options = parser.parse_args()

# Filter tests by path if specified
Expand Down Expand Up @@ -156,7 +159,6 @@
if not config:
config = get_default_config(options.source_dir or ['.'], mcu)


# Find all tests in the relevant paths
for path in all_paths:
all_tests.update(find_tests(path, mcu, toolchain,
Expand All @@ -178,7 +180,6 @@
else:
tests = all_tests


if options.list:
# Print available tests in order and exit
print_tests(tests, options.format)
Expand All @@ -194,6 +195,12 @@
if not base_source_paths:
base_source_paths = ['.']

# Coverage requires debug profile
if options.coverage_patterns:
if toolchain != u'GCC_ARM':
raise ToolException('Coverage supports only GCC_ARM toolchain')
options.profile.append(argparse_profile_filestring_type('debug'))

build_report = {}
build_properties = {}

Expand All @@ -210,7 +217,8 @@
notify=notify, archive=False,
app_config=config,
build_profile=profile,
ignore=options.ignore)
ignore=options.ignore,
coverage_patterns=options.coverage_patterns)

library_build_success = True
except ToolException as e:
Expand Down Expand Up @@ -247,7 +255,8 @@
app_config=config,
build_profile=profile,
stats_depth=options.stats_depth,
ignore=options.ignore)
ignore=options.ignore,
coverage_patterns=options.coverage_patterns)

# If a path to a test spec is provided, write it to a file
if options.test_spec:
Expand Down
5 changes: 3 additions & 2 deletions tools/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2197,7 +2197,7 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
clean=False, notify=None, jobs=1, macros=None,
silent=False, report=None, properties=None,
continue_on_build_fail=False, app_config=None,
build_profile=None, stats_depth=None, ignore=None):
build_profile=None, stats_depth=None, ignore=None, coverage_patterns=None):
"""Given the data structure from 'find_tests' and the typical build parameters,
build all the tests

Expand Down Expand Up @@ -2254,7 +2254,8 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
'build_profile': build_profile,
'toolchain_paths': TOOLCHAIN_PATHS,
'stats_depth': stats_depth,
'notify': MockNotifier()
'notify': MockNotifier(),
'coverage_patterns': coverage_patterns
}

results.append(p.apply_async(build_test_worker, args, kwargs))
Expand Down
5 changes: 4 additions & 1 deletion tools/toolchains/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class mbedToolchain:
profile_template = {'common':[], 'c':[], 'cxx':[], 'asm':[], 'ld':[]}

def __init__(self, target, notify=None, macros=None, build_profile=None,
build_dir=None):
build_dir=None, coverage_patterns=None):
self.target = target
self.name = self.__class__.__name__

Expand Down Expand Up @@ -154,6 +154,9 @@ def __init__(self, target, notify=None, macros=None, build_profile=None,
# Used by the mbed Online Build System to build in chrooted environment
self.CHROOT = None

self.coverage_supported = False
self.coverage_patterns = coverage_patterns

# Call post __init__() hooks before the ARM/GCC_ARM/IAR toolchain __init__() takes over
self.init()

Expand Down
35 changes: 32 additions & 3 deletions tools/toolchains/gcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
limitations under the License.
"""
import re
import fnmatch
from os.path import join, basename, splitext, dirname, exists
from os import getenv
from distutils.spawn import find_executable
Expand All @@ -34,10 +35,14 @@ class GCC(mbedToolchain):
GCC_RANGE = (LooseVersion("6.0.0"), LooseVersion("7.0.0"))
GCC_VERSION_RE = re.compile(b"\d+\.\d+\.\d+")

COMMON_COVERAGE_FLAGS = ["-DENABLE_LIBGCOV_PORT=1", "--coverage"]

def __init__(self, target, notify=None, macros=None, build_profile=None,
build_dir=None):
build_dir=None, coverage_patterns=None):
mbedToolchain.__init__(self, target, notify, macros,
build_profile=build_profile, build_dir=build_dir)
build_profile=build_profile,
build_dir=build_dir,
coverage_patterns=coverage_patterns)

tool_path=TOOLCHAIN_PATHS['GCC_ARM']
# Add flags for current size setting
Expand Down Expand Up @@ -103,6 +108,7 @@ def __init__(self, target, notify=None, macros=None, build_profile=None,

main_cc = join(tool_path, "arm-none-eabi-gcc")
main_cppc = join(tool_path, "arm-none-eabi-g++")
self.coverage_supported = True
self.asm = [main_cc] + self.flags['asm'] + self.flags["common"]
self.cc = [main_cc]
self.cppc =[main_cppc]
Expand All @@ -120,6 +126,14 @@ def __init__(self, target, notify=None, macros=None, build_profile=None,
self.use_distcc = (bool(getenv("DISTCC_POTENTIAL_HOSTS", False))
and not getenv("MBED_DISABLE_DISTCC", False))

self.coverage_cc = self.cc + self.COMMON_COVERAGE_FLAGS
self.coverage_cppc = self.cppc + self.COMMON_COVERAGE_FLAGS
self.coverage_ld = self.ld + ["--coverage"]

for flag in ['-Wl,--wrap,exit', '-Wl,--wrap,atexit']:
if flag in self.coverage_ld:
self.coverage_ld.remove(flag)

def version_check(self):
stdout, _, retcode = run_cmd([self.cc[0], "--version"], redirect=True)
msg = None
Expand Down Expand Up @@ -189,6 +203,12 @@ def get_compile_options(self, defines, includes, for_asm=False):
opts = opts + self.get_config_option(config_header)
return opts

def match_coverage_patterns(self, source):
for pattern in self.coverage_patterns:
if fnmatch.fnmatch(source, pattern):
return True
return False

@hook_tool
def assemble(self, source, object, includes):
# Build assemble command
Expand Down Expand Up @@ -217,9 +237,13 @@ def compile(self, cc, source, object, includes):
return [cmd]

def compile_c(self, source, object, includes):
if self.coverage_patterns and self.match_coverage_patterns(source):
return self.compile(self.coverage_cc, source, object, includes)
return self.compile(self.cc, source, object, includes)

def compile_cpp(self, source, object, includes):
if self.coverage_patterns and self.match_coverage_patterns(source):
return self.compile(self.coverage_cppc, source, object, includes)
return self.compile(self.cppc, source, object, includes)

@hook_tool
Expand All @@ -241,7 +265,12 @@ def link(self, output, objects, libraries, lib_dirs, mem_map):

# Build linker command
map_file = splitext(output)[0] + ".map"
cmd = self.ld + ["-o", output, "-Wl,-Map=%s" % map_file] + objects + ["-Wl,--start-group"] + libs + ["-Wl,--end-group"]
if self.coverage_patterns:
cmd = self.coverage_ld
else:
cmd = self.ld

cmd += ["-o", output, "-Wl,-Map=%s" % map_file] + objects + ["-Wl,--start-group"] + libs + ["-Wl,--end-group"]

if mem_map:
cmd.extend(['-T', mem_map])
Expand Down