Skip to content

Commit

Permalink
Add rudimentary build support for code coverage analysis.
Browse files Browse the repository at this point in the history
  • Loading branch information
dvander committed Sep 24, 2019
1 parent d935ec4 commit d2e2579
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
12 changes: 12 additions & 0 deletions AMBuildScript
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class Config(object):
def __init__(self):
super(Config, self).__init__()
self.archs = builder.target.arch.replace('x86_64', 'x64').split(',')
self.enable_coverage = getattr(builder.options, 'enable_coverage', False)

def configure(self):
cxx = builder.DetectCxx()
Expand Down Expand Up @@ -87,6 +88,17 @@ class Config(object):
cxx.cxxflags += ['-Wno-delete-non-virtual-dtor']
cxx.cxxflags += ['-Wno-unused-private-field']

if self.enable_coverage:
if cxx.family == 'clang':
coverage_argv = [
'-fprofile-instr-generate',
'-fcoverage-mapping',
]
cxx.cflags += coverage_argv
cxx.linkflags += coverage_argv
else:
raise Exception('Code coverage support is not implemented for {0}.'.format(cxx.family))

# Disable some stuff we don't use, that gives us better binary
# compatibility on Linux.
cxx.cxxflags += [
Expand Down
4 changes: 3 additions & 1 deletion configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,7 @@ def make_objdir_name(p):
parser.options.add_option('--build', type='string', dest='build', default='all',
help='Build which components (all, spcomp, vm, exp, test, core)')
parser.options.add_option('--enable-spew', action='store_true', default=False, dest='enable_spew',
help='Enable debug spew')
help='Enable debug spew')
parser.options.add_option("--enable-coverage", action='store_true', default=False,
dest='enable_coverage', help='Enable code coverage support.')
parser.Configure()
16 changes: 12 additions & 4 deletions tests/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,24 @@ def main():
help='Show the command-line invocation of each test.')
parser.add_argument('--spcomp2', default=False, action='store_true',
help="Only test using spcomp2.")
parser.add_argument('--compile-only', default=False, action='store_true',
help="Skip execution on tests with runtime components.")
args = parser.parse_args()

if args.test and args.test.startswith('tests/'):
args.test = args.test[6:]

plan = TestPlan(args)
plan.find_compilers()
plan.find_shells()
if not args.compile_only:
plan.find_shells()
plan.find_tests()

if not len(plan.modes):
raise Exception('No compiler binaries were found in {0}'.format(args.objdir))
if not len(plan.tests):
raise Exception('No matching tests were found.')
if not len(plan.shells):
if not len(plan.shells) and not args.compile_only:
raise Exception('No spshell binaries were found in {0}'.format(args.objdir))

with testutil.TempFolder() as tempFolder:
Expand Down Expand Up @@ -373,12 +376,17 @@ def run_mode(self, mode):
if not self.run_test(mode, test):
self.failures_.add(test)

def should_compile_only(self, test):
if test.type == 'compiler-output' or test.type == 'compile-only':
return True
return self.plan.args.compile_only

def run_test(self, mode, test):
self.out('Begin test {0}'.format(test.path))

# First run the compiler.
rc, stdout, stderr = self.run_compiler(mode, test)
if test.type == 'compiler-output' or test.type == 'compile-only':
if self.should_compile_only(test):
if not self.compile_ok(mode, test, rc, stdout, stderr):
self.out_io(stderr, stdout)
return False
Expand Down Expand Up @@ -457,7 +465,7 @@ def run_shell(self, mode, shell, test):
return True

def compile_ok(self, mode, test, rc, stdout, stderr):
if test.type == 'compile-only':
if test.type != 'compiler-output':
return rc == 0

assert test.type == 'compiler-output'
Expand Down

0 comments on commit d2e2579

Please sign in to comment.