예제 #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()
예제 #2
0
    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()
예제 #3
0
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
예제 #4
0
"""
Check interactions of --units with -P / --projects.
"""

from SUITE.cutils import Wdir, list_to_tmp
from SUITE.context import thistest
from test_support import check

# Create a directory to hold temporary files, so that we do not accumulate
# uncleaned temporary files across testsuite runs.
temp_file_dir = Wdir('tmp_files', clean=True)
temp_file_dir.to_homedir()

# Note that intops involves sub-units while boolops involves child-units,

# Lone unit, with sub units, in closure

check(
    root_project='gen.gpr',
    units=['intops'],
    recurse=True,
    xreports=['intops.ads', 'intops.adb', 'intops-add.adb', 'intops-sub.adb'])

# Lone unit, with child units, in closure

check(root_project='boolops',
      units=['boolops'],
      recurse=True,
      xreports=['boolops.ads', 'boolops.adb'])

# Likewise, using a response file to convey the units.
예제 #5
0
def check(root_project, recurse, projects=None, units=None, xreports=None):
    """
    Check that running our test with

       -P`root_project`
       [--projects=... for `projects`]
       [--units=... for `units`]
       [--no-subprojects] (if `recurse` is False)

    we obtain reports for the units attached to the projects listed
    in `xreports`.

    If not None, `projects` and `xreports` are expected to be lists of
    shortcut names like 'boolops', 'intops' or 'counters'. This function
    takes care of converting them to relative project file names actually
    expected on the command line or in real project file dependencies.

    `root_project` may be either a .gpr filename, in which case it is used
    as-is, or a project short name.

    `recurse` None means "arrange not to pass any option influencing
    recursiveness".
    """

    projects = to_list(projects)
    units = to_list(units)

    # root_project, projects, and units arguments we will provide to the
    # GPRswitches class:
    gprsw_root_project = (root_project if root_project.endswith('.gpr') else
                          _gpr_for(root_project))

    gprsw_projects = [_gpr_for(prj) for prj in projects]

    gprsw_units = units

    # Arrange to execute each check in its own tmp dir and
    # passing a unique --subdirs prevent mixups across test variants
    # within the shared projects.

    # Start with 'wd_foo' from .../.../foo.gpr or a project short
    # name intended for -P.
    tmpdir = 'wd_' + os.path.basename(root_project).split('.')[0]

    # Append the first letter of each project name will pass through
    # --project, if any:
    if projects:
        tmpdir += '-' + ''.join(prj[0] for prj in projects)

    # Append indication on recursion request:
    if recurse:
        tmpdir += '-rt'
    elif recurse is None:
        tmpdir += '-rn'
    else:
        tmpdir += '-rf'

    # For the --subdirs argument, relative to each subproject's object dir,
    # prepend our testcase local directory name:
    gprsw_subdirs = os.path.basename(os.getcwd()) + '_' + tmpdir

    # If a list of expected reports is provided, convert into list of
    # corresponding sources, which the CovControl class expects:

    if xreports is not None:
        ctl_xreports = []
        for xr in xreports:
            ctl_xreports.extend(_xreports[xr] if xr in _xreports else [xr])
    else:
        ctl_xreports = None

    # Getting the default behavior wrt recursiveness consists
    # in requesting not to pass --no-subprojects.
    gprsw_no_subprojects = False if recurse is None else not recurse

    wd = Wdir(clean=True)
    wd.to_subdir(tmpdir)

    TestCase(category=None).run(covcontrol=CovControl(

        # The programs we build and exercise alway depend on
        # the three subprojects:
        deps=[_gpr_for('boolops'),
              _gpr_for('intops'),
              _gpr_for('counters')],

        # What we analyse and check depends on our arguments:
        gprsw=GPRswitches(root_project=gprsw_root_project,
                          projects=gprsw_projects,
                          units=gprsw_units,
                          no_subprojects=gprsw_no_subprojects,
                          subdirs=gprsw_subdirs,
                          xvars=[('BOARD', env.target.machine)]),
        xreports=ctl_xreports,

        # The test driver and the likes are never of interest
        units_in=[]))

    wd.to_homedir()
예제 #6
0
    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)

    dump = 'dump.txt'
    xcov('dump-trace {}'.format(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 {}'.format(trace))

    wd.to_homedir()

thistest.result()