diff --git a/Tools/ardupilotwaf/boards.py b/Tools/ardupilotwaf/boards.py index c94789320a..42a14723f0 100644 --- a/Tools/ardupilotwaf/boards.py +++ b/Tools/ardupilotwaf/boards.py @@ -164,6 +164,19 @@ class Board: env.DEFINES.update( HAL_DEBUG_BUILD = 1, ) + if cfg.env.COVERAGE: + env.CFLAGS += [ + '-fprofile-arcs', + '-ftest-coverage', + ] + env.CXXFLAGS += [ + '-fprofile-arcs', + '-ftest-coverage', + ] + env.LINKFLAGS += [ + '-lgcov', + '-coverage', + ] if cfg.options.bootloader: # don't let bootloaders try and pull scripting in diff --git a/wscript b/wscript index 8fc729d3ac..e4a8f5fb57 100644 --- a/wscript +++ b/wscript @@ -82,6 +82,11 @@ def options(opt): default=False, help='Configure as debug variant.') + g.add_option('--coverage', + action='store_true', + default=False, + help='Configure coverage flags.') + g.add_option('--Werror', action='store_true', default=False, @@ -284,6 +289,7 @@ def configure(cfg): cfg.env.BOARD = cfg.options.board cfg.env.DEBUG = cfg.options.debug + cfg.env.COVERAGE = cfg.options.coverage cfg.env.AUTOCONFIG = cfg.options.autoconfig _set_build_context_variant(cfg.env.BOARD) @@ -291,6 +297,7 @@ def configure(cfg): cfg.env.BOARD = cfg.options.board cfg.env.DEBUG = cfg.options.debug + cfg.env.COVERAGE = cfg.options.coverage cfg.env.ENABLE_ASSERTS = cfg.options.enable_asserts cfg.env.BOOTLOADER = cfg.options.bootloader cfg.env.ENABLE_MALLOC_GUARD = cfg.options.enable_malloc_guard @@ -368,6 +375,12 @@ def configure(cfg): else: cfg.end_msg('disabled', color='YELLOW') + cfg.start_msg('Coverage build') + if cfg.env.COVERAGE: + cfg.end_msg('enabled') + else: + cfg.end_msg('disabled', color='YELLOW') + cfg.env.append_value('GIT_SUBMODULES', 'mavlink') cfg.env.prepend_value('INCLUDES', [