Exemple #1
0
def _tryone(sco_args, odir):
    """
    Exercise one execution and analysis of the test_ab program
    for stmt+mcdc with the provided `sco_args`, switching to a
    temporary output dir `odir` that we create.
    """

    # Create the output dir and execute the commands from there

    wsd = Wdir(subdir=odir)

    _run_and_cov(pgm='../test_ab', level='stmt+mcdc', sco_args=sco_args)

    # Check report contents

    args = 'stmt+mcdc / ' + ' '.join(sco_args)

    test_xcov = contents_of('test_ab.adb.xcov')
    thistest.fail_if(not re.search(r'\+:    Monitor.Diamond', test_xcov),
                     'failure on check for %s' % args)

    mon_xcov = contents_of('monitor.adb.xcov')
    thistest.fail_if(not re.search(r'\!:.*and then', mon_xcov),
                     'failure on Decision monitor check for %s' % args)
    thistest.fail_if(not re.search(r'\+:.*Hit := Hit \+ 1;', mon_xcov),
                     'failure on Hit monitor check for %s' % args)
    thistest.fail_if(not re.search(r'\+:.*Miss := Miss \+ 1;', mon_xcov),
                     'failure on Miss monitor check for %s' % args)

    wsd.to_homedir()
Exemple #2
0
def try_run(id, gpr):
    """gnatcov run with common set of options & variations via gpr."""
    log = id + '.rlog'
    xrun(['-P%s' % gpr, exe, '-o', '%s.trace' % id],
         out=log,
         register_failure=False)
    return contents_of(log)
Exemple #3
0
    def run(self):
        TestCase.run(self)

        thistest.flush()

        self.reported_diags = [
            HarnessDiagnostic(text=errtext) for errtext in re.findall(
                pattern="^  \* (?:exception|\(.*\)) .*",
                string=contents_of(thistest.report.report_file),
                flags=re.M)
        ]

        [
            self.__count_match_on(reported, expected)
            for reported in self.reported_diags
            for expected in self.expected_diags if expected.match(reported)
        ]

        [
            thistest.fail_if(expected.nmatches != 1,
                             "expectation check failed - %s" % expected.text)
            for expected in self.expected_diags
        ]

        for i in self.reported_diags:
            print i.__dict__

        [
            thistest.fail_if(reported.nmatches != 1,
                             "reporting check failed - %s" % reported.text)
            for reported in self.reported_diags
        ]
Exemple #4
0
def try_cov(id, gpr):
    """
    gnatcov coverage with common set of options & variations via gpr.  Expect
    valid options and check for commonly expected outcome
    """
    log = id + '.clog'
    xcov(['coverage',
          '-P%s' % gpr,
          '%s.trace' % id, '-o',
          rep_for(id)],
         out=log,
         register_failure=False)

    # Check that we get a report with expected contents wrt options
    # eventually. The tag & level checks make sure that
    #
    # * options intended for run do get there and not to coverage
    # * options intended for coverage do get there and not to run
    thistest.fail_if(not empty(log), 'unexpected contents in %s' % log)

    rep = contents_of(rep_for(id))
    thistest.fail_if('level: %s' % lev not in rep,
                     'missing expected level indication in %s' % rep_for(id))

    thistest.fail_if(not re.search('tag.*: %s' % tag_for(id), rep),
                     'missing expected tag indication in %s' % rep_for(id))
Exemple #5
0
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()
Exemple #6
0
def run_list (cmd, dir=None, env=None):
    """Execute the provided CMD command-list (command name + arguments),
    temporarily switching to the DIR directory unless None, dumping a .log
    file tracking the command output in the directory where the command
    executes. ENV, if not none, is expected to hold a dictionary of
    environment variable values to be made visible to the executed command, on
    top of os.environ."""

    oriwd = os.getcwd()
    print "from : %s" % oriwd

    if dir:
        print "hopat : %s" % dir
        os.chdir (dir)

    print "run  : %s" % ' '.join(cmd)

    out = os.path.basename(cmd[0])+".log"
    p = Run (cmd, output=out, env=env, ignore_environ=False)

    fail_if (
        p.status != 0, "execution failed\n"
        + "log was:\n" + contents_of(out))

    os.chdir (oriwd)
Exemple #7
0
def run_test(label, slug, main, helper, recursive, projects=[], units=[],
             projects_warned=[], expected_cov_list=[]):
    """
    Produce a coverage report for the given parameters and check the emitted
    warnings.

    :param str label: Label for this test.
    :param str slug: Unique short string for this test (used to create
        directories).
    :param ProjectConfig main: Configuration for the "main" project.
    :param ProjectConfig helper: Configuration for the "helper" project.
    :param bool recursive: Whether to not pass --no-subprojects.
    :param list[str] projects: List of projects to pass with --projects.
    :param list[str] units: List of units to pass with --units.
    :param list[str] projects_warned: List of projects for which we expected
        warnings.
    :param expected_cov: List of expected coverage reports.
    """
    thistest.log('== [{}] {} =='.format(slug, label))
    tmp.to_subdir('wd_/{}'.format(slug))

    expected_output = '\n'.join(
        'warning: project {} provides no unit of interest'
        .format(project) for project in projects_warned)

    # Generate projects for this test (see below for the description of each
    # project).
    ProjectConfig().generate('empty')
    helper.generate('helper')
    main_prj = main.generate('main', deps=['empty', 'helper'],
                             mains=['main.adb'])
    mkdir('obj-empty')
    mkdir('obj-helper')
    mkdir('obj-main')

    # Generate a coverage report for them
    build_run_and_coverage(
        gprsw=GPRswitches(root_project=main_prj,
                          projects=projects,
                          units=units,
                          no_subprojects=not recursive),
        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')
    thistest.fail_if_not_equal(
        '[{}/{}] gnatcov output'.format(label, slug),
        expected_output,
        contents_of(log_file).strip())

    expected_cov = {}
    for c in expected_cov_list:
        expected_cov.update(c)
    check_xcov_reports('obj-*/*.xcov', expected_cov)
Exemple #8
0
def checked_xcov(args, out_file):
    """
    Run "xcov" and make the testcase fail if the output file is not empty.
    """
    xcov(args, out_file)
    out = contents_of(out_file)
    thistest.fail_if(
        out, 'gnatcov output not empty ({}):\n'
        '   {}\n'
        '{}'.format(out_file, ' '.join(args), out))
Exemple #9
0
def xcov(args,
         out=None,
         err=None,
         inp=None,
         env=None,
         register_failure=True,
         auto_config_args=True,
         auto_target_args=True):
    """
    Run xcov with arguments ARGS, timeout control, valgrind control if
    available and enabled, output directed to OUT and failure registration if
    register_failure is True. Return the process status descriptor. ARGS may be
    a list or a whitespace separated string.

    See xcov_suite_args for the meaning of AUTO_*_ARGS arguments.
    """

    # Make ARGS a list from whatever it is, to allow unified processing.
    # Then fetch the requested command, always first:
    args = to_list(args)
    covcmd = args[0]
    covargs = args[1:]

    covargs = xcov_suite_args(covcmd, covargs, auto_config_args,
                              auto_target_args) + covargs

    # Determine which program we are actually going launch. This is
    # "gnatcov <cmd>" unless we are to execute some designated program
    # for this:
    covpgm = thistest.suite_covpgm_for(covcmd)
    covpgm = ([covpgm] if covpgm is not None else maybe_valgrind([XCOV]) +
              [covcmd])

    # Execute, check status, raise on error and return otherwise.
    #
    # The gprvar options are only needed for the "libsupport" part of our
    # projects. They are pointless wrt coverage run or analysis activities
    # so we don't include them here.
    p = cmdrun(cmd=covpgm + covargs,
               inp=inp,
               out=out,
               err=err,
               env=env,
               register_failure=register_failure)

    if thistest.options.enable_valgrind == 'memcheck':
        memcheck_log = contents_of(MEMCHECK_LOG)
        thistest.fail_if(
            memcheck_log, 'MEMCHECK log not empty'
            '\nFROM "%s":'
            '\n%s' % (' '.join(covpgm + covargs), memcheck_log))

    return p
Exemple #10
0
    def __drivers_from(self, cspec):
        """
        Compute the set of drivers that need to be combined for consolidation
        purposes, extracted from the consolidation spec in CSPEC.
        """

        # Extract the drivers regular expression to match from the
        # consolidation spec file, ...
        drv_expr = re.match("drivers=(.*)", contents_of(cspec)).group(1)

        # ... then construct and return the retricted list of drivers that
        # match this expression
        return [drv for drv in self.all_drivers if re.search(drv_expr, drv)]
Exemple #11
0
    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)))
Exemple #12
0
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:
        runcmd.append(explicit_exe)

    xrun(runcmd)
    xcov(['dump-trace', trace], out=dump)

    thistest.fail_if(
        len(re.findall('t block$', contents_of(dump), flags=re.M)) < 1,
        'with %s, no block trace entry found in %s' % (outbase, trace))
Exemple #13
0
    def __dump_tr_consistency_info (self, log):

        log.write ("\n-- TOR/TR CONSISTENCY LOG:\n")

        tor_tr_logfile = os.path.join (
            self.repodir, "qualification", "qm", "missing_tr_log.txt")

        if not os.path.exists (tor_tr_logfile):
            log.write ("QM log NOT available\n")
            return

        log.write (
            "%s TOR/TR consistency log from QM @ %s :\n" % \
                ("FRESH" if self.do_tor() else "OLD", tor_tr_logfile)
            )
        log.write (contents_of (tor_tr_logfile))
        log.write ("--\n")
Exemple #14
0
def try_one_gpr(gpr, no_such):
    label = os.path.basename(os.getcwd())
    dump = 'xcov.out'

    build_run_and_coverage(
        gprsw=GPRswitches(root_project=gpr),
        covlevel='stmt',
        mains=['p'],
        extra_coverage_args=['-axcov'],
        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))
Exemple #15
0
def host_string_from(host):
    """
    Return a textual version of the relevant info in HOST, a Env().host kind of
    object.
    """

    os_name = host.os.name.capitalize()
    os_version = host.os.version

    # 2008[R2] or 2012[R2] for Windows conveys Server editions
    if os_name == 'Windows' and re.match(os_version, '2008|2012'):
        os_version = 'Server ' + os_version

    # Fetch precise Redhat version
    if os_name == 'Linux' and os_version.startswith('rhES'):
        os_name = ''
        os_version = contents_of('/etc/redhat-release')

    return ' '.join((os_name, os_version)).strip()
Exemple #16
0
def gprdep_for(reldir, wd):
    """
    Quick facility to help tests exercising GPR trees, in a setup like:

    Tree/ component1
                /src
          ...
          componentN   (reldir, Relative Directory from wd)
                /src

          template.gpr
          Test1/       (wd, test Working Directory)
              test.py

    where test.py will construct its own GPR, with dependencies on sub-GPRs
    that it generates for some components.

    Return a fully qualified GPR dependency item.
    """

    # The local project file we create will be named after both the location
    # where it's store (from reldir) and the test that instantiates it (from
    # wd). The test id part is then reused to name the object directory, to
    # make sure that each test operating with a given relative dir has its own
    # object dir there and can run in parallel with others.

    locid = os.path.basename(reldir.rstrip('/'))
    testid = os.path.basename(wd.homedir.rstrip('/'))

    prjname = '%s_%s' % (locid, testid)
    gprdep = os.path.join(wd.homedir, reldir, prjname)

    with open(gprdep + '.gpr', 'w') as gprfile:
        gprfile.write(
            contents_of(os.path.join(wd.homedir, '../template.gpr')) % {
                'prjname': prjname,
                'objdir': 'obj_' + testid,
                'pkg_emulator': gpr_emulator_package(),
            }
        )
    return gprdep
Exemple #17
0
def gprdep_for(reldir, wd):

    # The local project file we create will be named after both the location
    # where it's store (from reldir) and the test that instantiates it (from
    # wd). The test id part is then reused to name the object directory, to
    # make sure that each test operating with a given relative dir has its own
    # object dir there and can run in parallel with others.

    locid = os.path.basename(reldir.rstrip('/'))
    testid = os.path.basename(wd.homedir.rstrip('/'))

    prjname = "%s_%s" % (locid, testid)
    gprdep = os.path.join(wd.homedir, reldir, prjname)

    with open(gprdep + ".gpr", 'w') as gprfile:
        gprfile.write(
            contents_of(os.path.join(wd.homedir, "../template.gpr")) % {
                "prjname": prjname,
                "objdir": "obj_" + testid,
                "pkg_emulator": gpr_emulator_package(),
            })

    return gprdep
Exemple #18
0
    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')
Exemple #19
0
    def gen_one_xcov_report(self, inputs, format, options=""):
        """Helper for gen_xcov_reports, to produce one specific report for a
        particulat FORMAT, from provided INPUTS. The command output is saved
        in a file named FORMAT.out."""

        # Compute the set of arguments we are to pass to gnatcov coverage.

        # When project files are used, force report output in the current
        # directory where it would be without a project file, and which the
        # project file might arbitrarily redirect otherwise. Doing this
        # conditionally prevents the gratuitous addition of command line
        # options which might be absent from the tool qualified interface
        # descriptions.

        covargs = ['--annotate=' + format, inputs
                   ] + (self.covoptions + to_list(options))

        if self.gprmode:
            covargs.append('--output-dir=.')

        # Run, latching standard output in a file so we can check contents on
        # return.

        ofile = format + ".out"
        p = xcov(args=['coverage'] + covargs, out=ofile)

        # Standard output might typically contain labeling warnings issued
        # by the static analysis phase, or error messages issued when a trace
        # indicates that some unlabeled edge was taken.  None of this should
        # happen so we simply fail as soon as the output file is not empty.
        # Note that we do this in qualification mode as well, even though what
        # we're looking at is not stricly part of the qualified interface.

        thistest.fail_if(
            os.path.getsize(ofile) > 0,
            "xcov standard output not empty (%s):\n--\n%s" %
            (ofile, contents_of(ofile)))
Exemple #20
0
    def run(self, discharge_kdict):
        thistest.log("\n~~ processing " + self.report + " ~~\n")

        # For each kind in RELEVANT_XNOTE_KINDS, process discharges of
        # expectations from emitted notes. DISCHARGE_KDICT provides a special
        # set of of emitted note kinds that may discharge a given kind of
        # expected note, when that set is wider than the target kind alone.

        # We have to do this with two distinct loops because there is no
        # guaranteed one to one correspondance between emitted vs expected
        # kinds for discharges.

        # Process expectations first, looking for candidate dischargers and
        # complaining about violation expectations that were not discharged
        # (expected bla missing). Discharges of anti-expectations are also
        # registered here, silently.  Complaints will come out of the emitted
        # notes processing below.

        [
            self.process_xkind(xkind=xkind,
                               ekinds=discharge_kdict.get(xkind, [xkind]))
            for xkind in self.rxp
        ]

        # Then process the relevant emitted notes, complaining about those
        # that don't discharge any expectation as required, or that discharge
        # an anti expectation (unexpected blo).

        [self.process_ekind(ekind) for ekind in self.ren]

        # Dump the report contents in case this check exposed a test failure:

        if thistest.n_failed > self.n_failed_init:
            thistest.log("\nreport contents:\n")
            thistest.log(contents_of(self.report))
        else:
            thistest.log("OK\n")
Exemple #21
0
             srcdirs=['../src'],
             deps=['../App/app'],
             extra=gprcov_for(switches=[
                 Csw('*', ['--level=stmt+decision']),
                 Csw('coverage', ['--annotate=report'])
             ]))
build_run_and_coverage(gprsw=GPRswitches(root_project=gpr,
                                         no_subprojects=False),
                       covlevel=None,
                       mains=[pgm],
                       extra_coverage_args=['-o', 'def.rep'])

# Check that we get results corresponding to the root project file despite
# "overrides" (other Switches) in subprojects.

rep = contents_of('def.rep')

thistest.fail_if(not os.path.exists('def.rep'), "couldn't find default report")

thistest.fail_if(not re.search('statement not executed', rep),
                 'missing expected stmt coverage failure indication')

thistest.fail_if(
    not re.search(r'test.*\.adb:.*: decision outcome .* never exercised', rep),
    'missing expected decision coverage failure indication')

thistest.fail_if(
    not re.search('values.adb:.*: decision outcome .* never exercised', rep),
    'missing expected decision coverage failure indication')

thistest.result()
Exemple #22
0
def check_report(label, filename, pattern, check_present=True):
    report = contents_of(filename)
    matched = re.search(pattern, report)
    thistest.fail_if(not matched if check_present else matched, label)
Exemple #23
0
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'
    ' interest'
    '\nwarning: no unit no_such_unit (from --units) in the projects of'
    ' interest', log_lines)

check_xcov_reports('obj/*.xcov', {'obj/main.adb.xcov': {'+': {5}}})

thistest.result()
Exemple #24
0
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
# from missing command line argument.
trace = 'oops.trace0'
dump = 'oops.dump'
xrun(['-P', gprname, '-o', trace], out=dump, register_failure=False)

thistest.fail_if(
    not match(': Please specify an executable to run', dump),
    'missing expected error diag on main-less invocation of gnatcov run')

thistest.result()
Exemple #25
0
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)


for mode in ('no_arg', 'with_arg'):
    wd = Wdir('wd_{}'.format(mode))

    exe = exepath_to(mainbase)
Exemple #26
0
def xcov_instrument(gprsw,
                    covlevel,
                    extra_args=[],
                    dump_trigger="auto",
                    dump_channel="auto",
                    gpr_obj_dir=None,
                    runtime_project=None,
                    out=None,
                    err=None,
                    warnings_as_errors=True,
                    register_failure=True):
    """
    Run "gnatcov instrument" on a project.

    :param GPRswitches gprsw: Project file command line switches to honor.
    :param None|str covlevel: Coverage level for the instrumentation
        (--level argument). Not passed if None.
    :param list[str] extra_args: Extra arguments to append to the command line.
    :param None|str dump_trigger: If None, do not pass the --dump-trigger
        argument. If "auto", pass the result of default_dump_trigger().
        Otherwise, pass the given value.
    :param None|str dump_channel: If None, do not pass the --dump-channel
        argument. If "auto", pass the result of default_dump_channel().
        Otherwise, pass the given value.
    :param None|str gpr_obj_dir: Optional name of the directory where gprbuild
        will create build artifacts. If left to None, assume they are produced
        in the current directory.
    :param None|str runtime_project: If None, use the default name for the
        instrumentation runtime project. Otherwise, use the name given for this
        option.
    :param bool warnings_as_errors: Whether to make the test fail if there are
        warnings in gnatcov's output.

    See SUITE.tutils.xcov for the other supported options.
    """
    # Create the object directory so that gnatcov does not warn that it
    # does not exist. This is specific to the source trace mode because
    # we run gnatcov before gprbuild.
    if gpr_obj_dir:
        mkdir(gpr_obj_dir)

    covlevel_args = [] if covlevel is None else ['--level', covlevel]

    # We want to get the mains to know which dump-trigger should be passed to
    # the instrumentation command.
    #
    # Capture the list of main file names, double quoted and comma separated.
    m = re.search(pattern=r"for Main use \((?P<mains>.*)\)",
                  string=contents_of(gprsw.root_project))

    # If found, split then remove whitespaces and double quotes
    mains = []
    if m:
        mains = m.group('mains').split(',')
        mains = [main.strip(' "') for main in mains]

    args = ['instrument'] + covlevel_args

    if dump_trigger:
        if dump_trigger == "auto":
            dump_trigger = default_dump_trigger(mains)
        args += ["--dump-trigger", dump_trigger]
    if dump_channel:
        if dump_channel == "auto":
            dump_channel = default_dump_channel()
        args += ["--dump-channel", dump_channel]
    if runtime_project:
        args += ["--runtime-project", runtime_project]

    args += gprsw.cov_switches + extra_args

    if thistest.options.pretty_print:
        args.append('--pretty-print')

    out = out or "instrument.log"
    xcov(args, out=out, err=err, register_failure=register_failure)

    if warnings_as_errors:
        output = contents_of(out)
        thistest.fail_if(
            "!!!" in output,
            f"Warnings detected in the output of 'gnatcov instrument':"
            f"\n{indent(output)}")
Exemple #27
0
"""
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()
Exemple #28
0
def gprfor(mains,
           prjid="gen",
           srcdirs="src",
           objdir=None,
           exedir=".",
           main_cargs=None,
           langs=None,
           deps=(),
           compiler_extra="",
           extra=""):
    """
    Generate a simple PRJID.gpr project file to build executables for each main
    source file in the MAINS list, sources in SRCDIRS. Inexistant directories
    in SRCDIRS are ignored. Assume the set of languages is LANGS when
    specified; infer from the mains otherwise. Add COMPILER_EXTRA, if any, at
    the end of the Compiler package contents. Add EXTRA, if any, at the end of
    the project file contents. Return the gpr file name.
    """
    deps = '\n'.join('with "%s";' % dep for dep in deps)

    mains = to_list(mains)
    srcdirs = to_list(srcdirs)
    langs = to_list(langs)

    # Fetch the support project file template
    template = contents_of(os.path.join(ROOT_DIR, "template.gpr"))

    # Instanciate the template fields.

    # Turn the list of main sources into the proper comma separated sequence
    # of string literals for the Main GPR attribute.
    gprmains = ', '.join('"%s"' % m for m in mains)

    # Likewise for source dirs. Filter on existence, to allow widening the set
    # of tentative dirs while preventing complaints from gprbuild about
    # inexistent ones. Remove a lone trailing comma, which happens when none
    # of the provided dirs exists and would produce an invalid gpr file.
    srcdirs = ', '.join('"%s"' % d for d in srcdirs if os.path.exists(d))
    srcdirs = srcdirs.rstrip(', ')

    # Determine the language(s) from the mains.
    languages_l = langs or set(language_info(main).name for main in mains)
    languages = ', '.join('"%s"' % l for l in languages_l)

    # The base project file we need to extend, and the way to refer to it
    # from the project contents. This provides a default last chance handler
    # on which we rely to detect termination on exception occurrence.
    basegpr = (("%s/support/base" %
                ROOT_DIR) if control.need_libsupport() else None)

    # If we have specific flags for the mains, append them. This is
    # typically something like:
    #
    #    for Switches("test_blob.adb") use
    #      Compiler'Default_Switches("Ada") & ("-fno-inline")

    compswitches = ('\n'.join([
        'for Switches("%s") use \n'
        '  Compiler\'Default_Switches ("%s") & (%s);' %
        (main, language_info(main).name, ','.join(
            ['"%s"' % carg for carg in to_list(main_cargs)])) for main in mains
    ]) + '\n')

    # Now instanciate, dump the contents into the target gpr file and return
    gprtext = template % {
        'prjname': prjid,
        'extends': ('extends "%s"' % basegpr) if basegpr else "",
        'srcdirs': srcdirs,
        'exedir': exedir,
        'objdir': objdir or (exedir + "/obj"),
        'compswitches': compswitches,
        'languages': languages,
        'gprmains': gprmains,
        'deps': deps,
        'compiler_extra': compiler_extra,
        'pkg_emulator': gpr_emulator_package(),
        'extra': extra
    }

    return text_to_file(text=gprtext, filename=prjid + ".gpr")