Skip to content

Commit 5578749

Browse files
author
Mohammad Azim Khan
committed
Changed --coverage-filter to accept a list of filter
1 parent d494bfe commit 5578749

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

tools/build_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def prepare_toolchain(src_paths, target, toolchain_name,
280280
notify=None, silent=False, verbose=False,
281281
extra_verbose=False, config=None,
282282
app_config=None, build_profile=None,
283-
coverage_filter=None):
283+
coverage_filter=[]):
284284
""" Prepares resource related objects - toolchain, target, config
285285
286286
Positional arguments:
@@ -371,7 +371,7 @@ def build_project(src_paths, build_path, target, toolchain_name,
371371
macros=None, inc_dirs=None, jobs=1, silent=False,
372372
report=None, properties=None, project_id=None,
373373
project_description=None, extra_verbose=False, config=None,
374-
app_config=None, build_profile=None, coverage_filter=None):
374+
app_config=None, build_profile=None, coverage_filter=[]):
375375
""" Build a project. A project may be a test or a user program.
376376
377377
Positional arguments:

tools/options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def get_default_options_parser(add_clean=True, add_options=True,
8282
parser.add_argument("--app-config", default=None, dest="app_config",
8383
type=argparse_filestring_type,
8484
help="Path of an app configuration file (Default is to look for 'mbed_app.json')")
85-
parser.add_argument("--coverage-filter", default=None, dest="coverage_filter",
85+
parser.add_argument("--coverage-filter", default=[], action="append", dest="coverage_filter",
8686
help="Enable coverage on path that contains filter expression.")
8787

8888
return parser

tools/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2115,7 +2115,7 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
21152115
clean=False, notify=None, verbose=False, jobs=1, macros=None,
21162116
silent=False, report=None, properties=None,
21172117
continue_on_build_fail=False, app_config=None,
2118-
build_profile=None, coverage_filter=None):
2118+
build_profile=None, coverage_filter=[]):
21192119
"""Given the data structure from 'find_tests' and the typical build parameters,
21202120
build all the tests
21212121

tools/toolchains/gcc.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
2121
from tools.hooks import hook_tool
2222

23+
2324
class GCC(mbedToolchain):
2425
LINKER_EXT = '.ld'
2526
LIBRARY_EXT = '.a'
@@ -34,7 +35,7 @@ class GCC(mbedToolchain):
3435

3536
def __init__(self, target, notify=None, macros=None,
3637
silent=False, tool_path="", extra_verbose=False,
37-
build_profile=None, coverage_filter=None):
38+
build_profile=None, coverage_filter=[]):
3839
mbedToolchain.__init__(self, target, notify, macros, silent,
3940
extra_verbose=extra_verbose,
4041
build_profile=build_profile)
@@ -90,6 +91,10 @@ def __init__(self, target, notify=None, macros=None,
9091

9192
self.flags["common"] += self.cpu
9293

94+
if self.coverage_filter:
95+
self.flags["common"].append("-g")
96+
self.flags["common"].append("-O0")
97+
9398
main_cc = join(tool_path, "arm-none-eabi-gcc")
9499
main_cppc = join(tool_path, "arm-none-eabi-g++")
95100
self.asm = [main_cc] + self.flags['asm'] + self.flags["common"]
@@ -185,7 +190,7 @@ def get_compile_options(self, defines, includes, for_asm=False):
185190
@hook_tool
186191
def assemble(self, source, object, includes):
187192
# Build assemble command
188-
if self.coverage_filter and re.search(self.coverage_filter, source):
193+
if self.check_if_coverage_enabled(source):
189194
cmd = self.asm + self.COVERAGE_COMPILE_FLAGS + self.get_compile_options(self.get_symbols(True), includes) + ["-o", object, source]
190195
else:
191196
cmd = self.asm + self.get_compile_options(self.get_symbols(True), includes) + ["-o", object, source]
@@ -199,7 +204,7 @@ def assemble(self, source, object, includes):
199204
@hook_tool
200205
def compile(self, cc, source, object, includes):
201206
# Build compile command
202-
if self.coverage_filter and re.search(self.coverage_filter, source):
207+
if self.check_if_coverage_enabled(source):
203208
cmd = cc + self.COVERAGE_COMPILE_FLAGS + self.get_compile_options(self.get_symbols(), includes)
204209
else:
205210
cmd = cc + self.get_compile_options(self.get_symbols(), includes)
@@ -276,6 +281,18 @@ def binary(self, resources, elf, bin):
276281
self.cc_verbose("FromELF: %s" % ' '.join(cmd))
277282
self.default_cmd(cmd)
278283

284+
def check_if_coverage_enabled(self, src_path):
285+
"""
286+
Checks if coverage is enabled on the source path.
287+
288+
:param src_path:
289+
:return:
290+
"""
291+
for exp in self.coverage_filter:
292+
if re.search(exp, src_path):
293+
return True
294+
return False
295+
279296

280297
class GCC_ARM(GCC):
281298
@staticmethod
@@ -286,7 +303,7 @@ def check_executable():
286303
return mbedToolchain.generic_check_executable("GCC_ARM", 'arm-none-eabi-gcc', 1)
287304

288305
def __init__(self, target, notify=None, macros=None,
289-
silent=False, extra_verbose=False, build_profile=None, coverage_filter=None):
306+
silent=False, extra_verbose=False, build_profile=None, coverage_filter=[]):
290307
GCC.__init__(self, target, notify, macros, silent,
291308
TOOLCHAIN_PATHS['GCC_ARM'], extra_verbose=extra_verbose,
292309
build_profile=build_profile, coverage_filter=coverage_filter)

0 commit comments

Comments
 (0)