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 gprbuild_wrapper(root_project, gargs): # Honor build relevant switches from gprsw here gprbuild(root_project, gargs=gprsw.build_switches + gargs + extra_gprbuild_args, extracargs=extra_gprbuild_cargs, trace_mode=trace_mode) if check_gprbuild_output: gprbuild_out = contents_of('gprbuild.out') thistest.fail_if( gprbuild_out, "gprbuild's output (gprbuild.out) is not empty:\n{}" .format(indent(gprbuild_out)))
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 mode_build(self): # We first need to instrument, with proper selection of the units of # interest. Expect we are to provide this through a project file as # we have no LI file at hand: assert self.gprmode # If we have a request for specific options, honor that. Otherwise, # use the already computed project file for this test: if self.covctl and self.covctl.gprsw: instrument_gprsw = self.covctl.gprsw else: instrument_gprsw = GPRswitches(root_project=self.gpr) xcov_instrument(covlevel=self.xcovlevel, checkpoint='instr.ckpt', gprsw=instrument_gprsw) # Now we can build, instructing gprbuild to fetch the instrumented # sources in their dedicated subdir: gprbuild(self.gpr, extracargs=self.extracargs, gargs='--src-subdirs=gnatcov-instr')
def mode_build(self): # We first need to instrument, with proper selection of the units of # interest. Expect we are to provide this through a project file as # we have no LI file at hand: assert self.gprmode # If we have a request for specific options, honor that. Otherwise, # use the already computed project file for this test: if self.covctl and self.covctl.gprsw: instrument_gprsw = self.covctl.gprsw else: instrument_gprsw = GPRswitches(root_project=self.gpr) out = 'xinstr.out' xcov_instrument( covlevel=self.xcovlevel, isi_file=self.ISI_FILE, extra_args=to_list(self.covctl.covoptions) if self.covctl else [], gprsw=instrument_gprsw, gpr_obj_dir=self.gpr_obj_dir, out=out) # Standard output might contain warnings indicating instrumentation # issues. This should not happen, so simply fail as soon as the output # file is not empty. thistest.fail_if( os.path.getsize(out) > 0, 'xcov instrument standard output not empty ({}):' '\n--' '\n{}'.format(out, contents_of(out))) # Now we can build, instructing gprbuild to fetch the instrumented # sources in their dedicated subdir: gprbuild(self.gpr, extracargs=self.extracargs, gargs='--src-subdirs=gnatcov-instr')
wd = Wdir('wd_') # We will be exercising combinations of run/coverage operations with option # variations controlled via Coverage attributes in an otherwise common project # file for a simple program. def gprvariant(id, extra): return gprfor(prjid=id, srcdirs=['../src'], mains=['p.adb'], extra=extra) exe = exepath_to('p') # Build once gprbuild(gprvariant(id='bld', extra='')) # ------------------------------------------------ # -- Simple helpers for coverage/run variations -- # ------------------------------------------------ # # --tag, valid only for gnatcov run. # --annotate, valid only for gnatcov coverage. def tag_for(id): return 'tag-%s' % id def tagopt_for(id): return ['--tag=%s' % tag_for(id)]
def mode_build(self): gprbuild(self.gpr, extracargs=self.extracargs)
import re 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
def gprbuild_wrapper(root_project, gargs=[]): gprbuild(root_project, gargs=gargs + extra_gprbuild_args)
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()
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) for mode in ('no_arg', 'with_arg'): wd = Wdir('wd_{}'.format(mode)) exe = exepath_to(mainbase) trace = tracename_for(mainbase) # Build with the real target as the Target attribute. instantiate_gpr(target) gprbuild(os.path.abspath(gpr_basename)) argv = ['-P{}'.format(gprname), '-o', trace, exe] # Run with a bad target as the Target attribute in order to check that the # --target argument actually takes precedence. with_target_arg = mode == 'with_arg' if with_target_arg: instantiate_gpr('this_target_does_not_exist') # Force the passing of --target in the native case, as xrun() does not # pass it when it is the default. if not env.is_cross: argv.append('--target={}'.format(target)) xrun(argv, auto_config_args=False, auto_target_args=with_target_arg)
# 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 dump = '%s.dt' % outbase runcmd = ['-P', gprname, '-o', trace] if explicit_exe:
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()