def try_one(subdir, extra_covargs, xreports, xwarnings): """ Setup a temp ``subdir`` and perform a build/run/coverage sequence for our example, passing ``extra_covargs`` in addition to gnatcov coverage. Verify that we obtain the reports stated as expected in ``xreports``, and that possible warnings on units-of-interest discrepancies (induced by the extra covargs), stated as expected in ``xwarnings``, are found in the logs. """ wd.to_subdir(subdir) gpr = gprfor(srcdirs="../src", mains="test_t.adb", extra='\n'.join( ['for Source_Files use', ' ("test_t.adb","flip.ads", "flip.adb");'])) build_run_and_coverage( gprsw=GPRswitches(root_project=gpr), covlevel='stmt', mains=['test_t'], extra_coverage_args=['--annotate=xcov'] + extra_covargs) check_xcov_reports('obj/*.xcov', xreports) wlog = contents_of('coverage.log') for xw in xwarnings: thistest.fail_if( xw not in wlog, 'expected warning "%s" not found in log' % xw) wd.to_homedir()
def generate(self, name, deps=(), mains=()): return gprfor( prjid=name, mains=mains, langs=['Ada'], deps=deps, srcdirs=['../../src-{}'.format(name)], objdir='obj-{}'.format(name), extra=gprcov_for(units_in=self.units_in, units_out=self.units_out))
def run(self): tmp = Wdir('tmp_') # Compile all the sources. This method will not work if there are # sources that are not in the "." directory, but since executabes are # processed next, there will be an error if not all sources are # compiled. project = gprfor(self.sources, srcdirs=[".."], main_cargs=self.options) gprbuild(project, gargs=["-bargs", "-z"]) # If requested, check at least one non statement SCO in alis if self.ensure_dcscos: for ali in self.alis: thistest.fail_if(not match('^C[^S ]', ali, re.MULTILINE), "couldn't find non-statement SCO in %s" % ali) # Run xcov map-routines and check absence of errors mapoutput = do( maybe_valgrind([ XCOV, 'map-routines', '-v', '--scos=@{}'.format(list_to_file(self.alis)), ] + self.execs)) maperrors = [ str(m) for m in re.findall(r"(\*\*\*|\!\!\!)(.*)", mapoutput) ] thistest.log('\n'.join(maperrors)) thistest.fail_if( maperrors, "expect no map-routines error for %s" % ", ".join(self.sources)) tmp.to_homedir()
def _compile(self, test_driver, compile_unit_switches): mkdir('{}-obj'.format(test_driver)) project_file = gprfor( mains=[test_driver + '.c'], prjid=test_driver, srcdirs=['..'] + self.extra_sourcedirs, objdir='{}-obj'.format(test_driver), langs=['C', 'ASM'], compiler_extra='\n'.join( ('for Switches("{}") use ' ' Compiler\'Default_Switches ("C") & ({});' ).format(cu, self.fmt_list(switches)) for cu, switches in compile_unit_switches.items())) # We never want the testuite optimization options or source coverage # options to interfere with object coverage testcases as these are very # sensitive to code generation. gprbuild(project_file, scovcargs=False, suitecargs=False)
def run(subdir, extra_args, covlevel=None): """ Build and run the single test program, which volontarily performs stmt and decision coverage violations. """ dirname = f"tmp_{subdir}" wd = Wdir(dirname) gpr = gprfor(mains=[pgm + '.adb'], srcdirs=['../src'], extra=gprcov_for(switches=[ Csw('*', ['--level=stmt']), Csw('coverage', ['--annotate=report']) ])) xcov_args = build_and_run( gprsw=GPRswitches(root_project=gpr), covlevel=covlevel, mains=[pgm], extra_coverage_args=[] if covlevel is None else ['--level', covlevel]) xcov(xcov_args + extra_args) wd.to_homedir() return dirname
""" Check that invalid units passed as project attributes are properly reported. """ from SCOV.minicheck import build_run_and_coverage, check_xcov_reports from SUITE.context import thistest from SUITE.gprutils import GPRswitches, gprcov_for from SUITE.cutils import Wdir, contents_of from SUITE.tutils import gprfor tmp = Wdir('wd_') build_run_and_coverage(gprsw=GPRswitches( root_project=gprfor('main.adb', srcdirs='..', extra=gprcov_for(units_in=['no_such_unit', 'main']))), covlevel='stmt', mains=['main'], extra_coverage_args=['-axcov']) log_file = ('coverage.log' if thistest.options.trace_mode == 'bin' else 'instrument.log') thistest.fail_if_not_equal( 'gnatcov output', 'warning: no unit no_such_unit in project gen (coverage.units attribute)', contents_of(log_file).strip()) check_xcov_reports('obj/*.xcov', {'obj/main.adb.xcov': {'+': {5}}}) thistest.result()
out=dump, register_failure=False) dump = contents_of(dump) expected_warning = ( 'no unit {} in project gen (coverage.units attribute)'.format(no_such) if no_such else 'no unit of interest') thistest.fail_if( expected_warning not in dump, '[{}] missing warning on absence of ALI for unit'.format(label)) # Empty by specifying a single, non-existing unit in only wd.to_subdir("wd_1") try_one_gpr( gpr=gprfor(srcdirs="../src", mains="p.adb", extra=CovControl(units_in=["no_such_unit"]).gpr()), no_such="no_such_unit") # Empty by excluding the only candidate unit wd.to_subdir("wd_2") try_one_gpr(gpr=gprfor(srcdirs="../src", mains="p.adb", extra=CovControl(units_out=["p"]).gpr()), no_such=None) # Empty by including the empty set explicitly wd.to_subdir("wd_3") try_one_gpr( gpr=gprfor( srcdirs="../src", mains="p.adb", extra=CovControl(units_in=[]).gpr()), no_such=None)
from SCOV.minicheck import build_run_and_coverage from SUITE.context import thistest from SUITE.cutils import Wdir from SUITE.gprutils import GPRswitches from SUITE.tutils import gprfor wd = Wdir('wd_', clean=True) gprname = 'p' mainunit = 'foo.adb' subdir = 'gnatcov' mainunit_xcov = os.path.join('obj', subdir, mainunit + '.xcov') # Arrange to build, run and perform coverage analysis passing # --subdirs to all gprbuild and gnatcov commands, then verify that # we find a report in the designated subdir afterwards. build_run_and_coverage(gprsw=GPRswitches(root_project=gprfor(prjid=gprname, mains=[mainunit], srcdirs=['..']), subdirs=subdir), covlevel='stmt', mains=['foo'], extra_coverage_args=['-a', 'xcov']) thistest.fail_if(not os.path.exists(mainunit_xcov), 'The coverage report is missing: {}'.format(mainunit_xcov)) thistest.result()
def gprvariant(id, extra): return gprfor(prjid=id, srcdirs=['../src'], mains=['p.adb'], extra=extra)
""" Check that source files in extended projects are considered when looking for mains. """ from SCOV.minicheck import build_run_and_coverage, check_xcov_reports from SUITE.context import thistest from SUITE.gprutils import GPRswitches from SUITE.cutils import Wdir from SUITE.tutils import gprfor wd = Wdir('wd_', clean=True) # Prepare the two project files p = gprfor(prjid='p', mains=['main1.adb'], srcdirs=['../src'], objdir='obj-p') ext_p = 'ext_p.gpr' with open(ext_p, 'w') as f: f.write(""" project Ext_P extends "{}" is for Source_Dirs use ("../ext-src"); for Object_Dir use "ext-obj"; for Exec_Dir use "."; for Main use ("main1.adb", "main2.adb"); end Ext_P; """.format(p)) build_run_and_coverage( gprsw=GPRswitches(root_project=ext_p), covlevel='stmt', mains=['main1', 'main2'],
from SCOV.minicheck import build_run_and_coverage, check_xcov_reports from SUITE.context import thistest from SUITE.gprutils import GPRswitches from SUITE.cutils import Wdir from SUITE.tutils import gprfor wd = Wdir('wd_', clean=True) build_run_and_coverage(gprsw=GPRswitches(root_project=gprfor( mains=['test_lt0.adb'], srcdirs=['../src'], deps=['../App/app'])), covlevel='stmt', mains=['test_lt0'], extra_args=['--projects=app_base'], extra_coverage_args=['-axcov']) # App_Base is extended by App; App overrides Coverage'Units so that only Values # (not Values.Aux) is selected. check_xcov_reports('obj/*.xcov', { 'obj/values.ads.xcov': {}, 'obj/values.adb.xcov': { '+': {5, 6}, '-': {8} } }) thistest.result()
from SUITE.tutils import (exepath_to, gprbuild, gprfor, tracename_for, xrun, xcov) gprname = 'p' mainbase = 'foo' mainunit = mainbase + '.adb' env = Env() target = env.target.triplet Wdir('wd_') # Get a template for the project file. gpr_filename = gprfor(prjid=gprname, mains=[mainunit], srcdirs=['../..'], langs=["Ada"], extra='for Target use "%TARGET%"; %RUNTIME%') gpr_filename = os.path.abspath(gpr_filename) gpr_basename = os.path.basename(gpr_filename) gpr_content = contents_of(gpr_filename) def instantiate_gpr(target): with open(gpr_basename, 'w') as f: content = gpr_content.replace('%TARGET%', target) content = content.replace( '%RUNTIME%', 'for Runtime ("Ada") use "{}";'.format( thistest.options.RTS) if thistest.options.RTS else '') f.write(content)
import re from e3.fs import mkdir from SCOV.minicheck import build_and_run from SUITE.context import thistest from SUITE.cutils import Wdir, contents_of from SUITE.gprutils import Csw, GPRswitches, gprcov_for from SUITE.tutils import gprfor, xcov pgm = 'test_lt0' wd = Wdir('wd_', clean=True) gpr = gprfor(mains=[pgm + '.adb'], srcdirs=['../src'], extra=gprcov_for(switches=[ Csw('*', ['--level=stmt']), Csw('coverage', ['--annotate=report']) ])) def run(extra_args, covlevel=None): """ Build and run the single test program, which volontarily performs stmt and decision coverage violations. """ xcov_args = build_and_run(gprsw=GPRswitches(root_project=gpr), covlevel=covlevel, mains=[pgm], extra_coverage_args=[]) xcov(xcov_args + extra_args)
from SUITE.context import thistest from SUITE.cutils import Wdir, contents_of, match from SUITE.tutils import exepath_to, gprbuild, gprfor, xcov, xrun wd = Wdir('wd_') # GPR with multiple mains gprname = 'gen' mainbases = ['test_tt', 'test_tf'] mainunits = [base + '.adb' for base in mainbases] gprbuild( gprfor(prjid=gprname, srcdirs=['../../../../src', '../../src'], mains=mainunits)) # We expect this to work. The multiple mains in the gpr file are just ignored # when there is an exe on the command line. exe = exepath_to('test_tt') trace = 'tt.trace0' dump = 'tt.dump0' xrun(['-P', gprname, '-o', trace, exe]) xcov(['dump-trace', trace], out=dump) thistest.fail_if( len(re.findall('t block$', contents_of(dump), flags=re.M)) < 1, 'with exe, no block execution trace found in %s' % trace) # Again, _not_ providing the executable. Expected to fail
def run(self): """Evaluate source coverage as exercised by self.drivers""" self.log() # Whatever the kind of test, we get to a Working Directory and # switch back when done: self.to_workdir(self.rwdir()) # Compute our GPR now, which we will need for build of single tests # and/or analysis later on if in gprmode. Turn inlining off for the # driver unit, so we exercise the functional code as separately # compiled, not as an inlined version of it in a non-representative # driver context. # Most of the tests with coverage control operate within # an extra subdir level this_depth = (thistest.depth + 1 if self.covctl else thistest.depth) self.gpr = gprfor( mains=self.drivers, prjid="gen", srcdirs=["../" * n + "src" for n in range(1, this_depth)], exedir=self.abdir(), main_cargs="-fno-inline", langs=["Ada", "C"], deps=self.covctl.deps if self.covctl else (), extra=self.covctl.gpr() if self.covctl else "") # For single tests (no consolidation), we first need to build, # producing the binary to execute and the ALIs files, then to gnatcov # run to get an execution trace. All these we already have for # consolidation tests, and there's actually no need to build if we # were provided a bin directory to reuse: if self.singletest() and not self.wdctl.reuse_bin: gprbuild(self.gpr, extracargs=self.extracargs) # Compute the gnatcov command line argument we'll pass to convey # the set of scos to operate upon. Note that we need these for # both gnatcov run and gnatcov coverage. thistest.gprmode = (thistest.options.gprmode or (self.covctl and self.covctl.requires_gpr())) self.scoptions = ( to_list(self.covctl.scoptions) if (self.covctl and self.covctl.scoptions) else ["-P%s" % self.gpr] if thistest.gprmode else ["--scos=@%s" % list_to_file(self.ali_list(), "alis.list")]) # Remember which of these indicate the use of project files, which # might influence default output dirs for example. self.gproptions = [ opt for opt in self.scoptions if opt.startswith("-P") ] # Do gnatcov run now unless we're consolidating. We'll just reuse # traces from previous executions in the latter case. if self.singletest(): self.xcov_run(no_ext(self.drivers[0])) # At this point, we have everything we need for the analysis. Either # from the just done build+run in the single test case, or from # previous such sequences in the consolidation case. Run gnatcov # coverage to get actual coverage reports and check against our # Xpectation specs. self.gen_xcov_reports() self.check_expectations() self.to_homedir() thistest.flush() # Let callers retrieve execution data at will return self
from SUITE.context import thistest from SUITE.cutils import Wdir from SUITE.tutils import gprbuild, gprfor from test_support import check wd = Wdir('wd_') gprbuild( gprfor( srcdirs=[ '../src', # For the test sources '../../../../src' ], # For the support sources mains=['test_ab.adb'])) check(test_ali='obj/test_ab.ali', mon_ali='obj/monitor.ali') thistest.result()
from SCOV.minicheck import build_run_and_coverage, check_xcov_reports from SUITE.context import thistest from SUITE.gprutils import GPRswitches from SUITE.cutils import Wdir from SUITE.tutils import gprfor tmp = Wdir('wd_') # The "orig" project contains two units: "main" and "helper". The "ext" project # extends "orig" and overrides only the "helper" unit. # # Previously, gnatcov used to consider that the only unit of interest was # "helper". It now also consider that "main" is a unit of interest. orig_prj = gprfor(prjid='orig', mains=['main.adb'], srcdirs='..') ext_prj = 'ext.gpr' with open(ext_prj, 'w') as f: f.write(""" project Ext extends "{}" is for Source_Dirs use ("../src-ext"); for Object_Dir use "obj-ext"; end Ext; """.format(orig_prj)) build_run_and_coverage( gprsw=GPRswitches(root_project=ext_prj), covlevel='stmt', mains=['main'], extra_coverage_args=['-axcov'], gpr_exe_dir='obj-ext')
from SUITE.context import thistest from SUITE.cutils import Wdir from SUITE.tutils import gprbuild, gprfor from test_support import check wd = Wdir('wd_') gprbuild( gprfor( srcdirs=[ '../src', # For the test sources '../../../../src' ], # For the support sources deps=['../Mon/mon.gpr'], mains=['test_ab.adb'])) check(test_ali='obj/test_ab.ali', mon_ali='../Mon/obj/monitor.ali') thistest.result()
""" from e3.fs import mkdir from SCOV.minicheck import build_run_and_coverage, check_xcov_reports from SUITE.context import thistest from SUITE.gprutils import GPRswitches from SUITE.cutils import Wdir, contents_of from SUITE.tutils import gprfor tmp = Wdir('wd_', clean=True) mkdir('obj-helper') mkdir('obj-main') helper_prj = gprfor(prjid='helper', mains=[], langs=['Ada'], srcdirs='../src-helper', objdir='obj-helper') main_prj = gprfor(prjid='main', mains=['main.adb'], langs=['Ada'], deps=['helper'], srcdirs='../src-main', objdir='obj-main') build_run_and_coverage( gprsw=GPRswitches(root_project=main_prj, projects=['helper'], units=['helper', 'main']), covlevel='stmt', mains=['main'], gpr_obj_dir='obj-main', extra_coverage_args=['-axcov']) log_file = ('coverage.log' if thistest.options.trace_mode == 'bin' else 'instrument.log')
from SUITE.tutils import exepath_to, gprbuild, gprfor, xcov, xrun wd = Wdir('wd_') # We have two candidate main drivers. Craft a gpr # with a Main attribute listing only the first one. mainbase1 = 'test_tt' mainunit1 = mainbase1 + '.adb' exe1 = exepath_to(mainbase1) mainbase2 = 'test_tf' mainunit2 = mainbase2 + '.adb' exe2 = exepath_to(mainbase2) gprname = gprfor(srcdirs=['../../../../src', '../../src'], mains=[mainunit1]) # Build both executables, passing both main unit # names on the command line: gprbuild(project=gprname, gargs=[mainunit1, mainunit2]) # Arrange to gnatcov run providing either exe1, exe2 or # no executable. In all cases, expect to find a trace with # at least an entry showing actual execution of something # for this particular case. def check(explicit_exe): outbase = explicit_exe if explicit_exe else "noexe" trace = '%s.trace' % outbase
""" Check that invalid units passed as --units are properly reported. """ from SCOV.minicheck import build_run_and_coverage, check_xcov_reports from SUITE.context import thistest from SUITE.gprutils import GPRswitches from SUITE.cutils import Wdir, contents_of from SUITE.tutils import gprfor tmp = Wdir('wd_') build_run_and_coverage(gprsw=GPRswitches( root_project=gprfor('main.adb', srcdirs='..'), units=['no_such_unit', 'main', 'helper.say_hello']), covlevel='stmt', mains=['main'], extra_coverage_args=['-axcov']) log_file = ('coverage.log' if thistest.options.trace_mode == 'bin' else 'instrument.log') # Split and re-join lines to avoid spurious CR/LF diffs on Windows. Also sort # lines, as the order in which these warnings is emitted is not deterministic. log_lines = '\n'.join( sorted(line.rstrip() for line in contents_of(log_file).splitlines())).rstrip() thistest.fail_if_not_equal( 'gnatcov output', 'warning: no unit helper.say_hello (from --units) in the projects of'
def run(self): """Evaluate source coverage as exercised by self.drivers""" self.log() # Whatever the kind of test, we get to a Working Directory and # switch back when done: self.to_workdir(self.rwdir()) # If we are requested to convey units of interest through a project # file and don't have a coverage control object to obey, build one to # convey the units of interest: if thistest.options.gprmode and not self.covctl: self.covctl = CovControl(units_in=self.units_of_interest()) # Assess whether we should be using a project file to convey units of # interest, either requested from the command line or for specific # test purposes: self.gprmode = (thistest.options.gprmode or (self.covctl and self.covctl.requires_gpr())) # Compute our GPR now, which we will need for build of single tests # and/or analysis later on if in gprmode. Turn inlining off for the # driver unit, so we exercise the functional code as separately # compiled, not as an inlined version of it in a non-representative # driver context. # Most of the tests with coverage control operate within # an extra subdir level this_depth = (thistest.depth + 1 if self.covctl else thistest.depth) self.gpr_obj_dir = 'obj' self.gpr = gprfor( mains=self.drivers, prjid="gen", objdir=self.gpr_obj_dir, srcdirs=["../" * n + "src" for n in range(1, this_depth)], exedir=self.abdir(), main_cargs="-fno-inline", langs=["Ada", "C"], deps=self.covctl.deps if self.covctl else [], extra=self.covctl.gpr() if self.covctl else "") # For single tests (no consolidation), we first need to build, then # to execute to get an execution trace. All these we already have for # consolidation tests, and there's actually no need to build if we # were provided a bin directory to reuse: if self.singletest() and not self.wdctl.reuse_bin: self.mode_build() # Do gnatcov run now unless we're consolidating. We'll just reuse # traces from previous executions in the latter case. if self.singletest(): self.run_test(main=no_ext(self.drivers[0])) # At this point, we have everything we need for the analysis. Either # from the just done build+run in the single test case, or from # previous such sequences in the consolidation case. Run gnatcov # coverage to get actual coverage reports and check against our # Xpectation specs. self.gen_xcov_reports() self.check_expectations() self.to_homedir() thistest.flush() # Let callers retrieve execution data at will return self