示例#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(self, register_failure=True):
        '''
        Return if "gnatcov coverage" executed properly.
        '''
        Wdir('tmp_')

        # Compile and run separately each test driver.
        for test_driver, switches in self.test_drivers.items():
            self._compile(test_driver, switches)
            self._run(test_driver)

        # Tell to gnatcov which symbols we are interested in (those are symbols
        # that appear in the coverage expectations).
        self._generate_routines_list()

        # Consolidate resulting traces and parse the object coverage results.
        # If consolidation fails, return False.
        if (not self._consolidate_traces(self.RESULT_FILE, register_failure)
                and not register_failure):
            return False

        # We can parse the result only if the output is an annotated ASM.
        if self.annotate == 'asm':
            coverage_result = self._parse_coverage_results(self.RESULT_FILE)

            # Compare results with expectations...
            thistest.fail_if(
                coverage_result != self.coverage_expectations,
                'Coverage result:\n'
                '{}'
                'do not match coverage expectations:\n'
                '{}'.format(self.format_coverage(coverage_result),
                            self.format_coverage(self.coverage_expectations)))
        return True
示例#4
0
    def _compile(self, test_driver, compile_unit_switches):
        test_driver_wd = Wdir('{}-obj'.format(test_driver)).to_homedir()
        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.iteritems()))

        gprbuild(project_file, suitecargs=self.suitecargs)
示例#5
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
示例#6
0
"""
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'
示例#7
0
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)
示例#8
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.
示例#9
0
from SCOV.tc import TestCase
from SCOV.tctl import CovControl
from SUITE.context import thistest
from SUITE.cutils import Wdir

base_out = ['support', 'test_or_ft', 'test_and_tt', 'test_and_tf']
wd = Wdir()

# Check on lone node unit only
wd.to_subdir('wd_1')
TestCase(category=None).run(
    covcontrol=CovControl(units_out=base_out + ['ops'],
                          xreports=['ops-andthen.adb', 'ops-orelse.adb']))

# Check on child units only
wd.to_subdir('wd_2')
TestCase(category=None).run(
    covcontrol=CovControl(units_out=base_out + ['ops.orelse', 'ops.andthen'],
                          xreports=['ops.ads', 'ops.adb']))

# Check on root + child unit
wd.to_subdir('wd_3')
TestCase(category=None).run(covcontrol=CovControl(
    units_out=base_out + ['ops', 'ops.andthen'], xreports=['ops-orelse.adb']))

thistest.result()
示例#10
0
from SCOV.tc import TestCase
from SCOV.tctl import CovControl
from SUITE.context import thistest
from SUITE.cutils import Wdir, list_to_file

wd = Wdir()

# Check on lone node unit only

wd.to_subdir("wd_1")

TestCase(category=None).run(covcontrol=CovControl(
    ulist_in="../" + list_to_file(["ops"]), xreports=["ops.ads", "ops.adb"]))

# Check on lone node + child unit
wd.to_subdir("wd_2")
TestCase(category=None).run(
    covcontrol=CovControl(ulist_in="../" +
                          list_to_file(["ops", "ops.andthen"]),
                          xreports=["ops.ads", "ops.adb", "ops-andthen.adb"]))

# Check on lone child unit only
wd.to_subdir("wd_3")
TestCase(category=None).run(
    covcontrol=CovControl(ulist_in="../" + list_to_file(["ops.andthen"]),
                          xreports=["ops-andthen.adb"]))

thistest.result()
示例#11
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')
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.
示例#12
0
import os.path
import re

from SCOV.minicheck import build_run_and_coverage
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

pgm = 'test_lt0'
wd = Wdir('wd_')

# Build and run the single test program, which volontarily performs stmt and
# decision coverage violations.
#
# Enforce --level=stmt+decision here. Check that Default_Switches in
# subprojects are ignored
gpr = gprfor(mains=[pgm + '.adb'],
             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
示例#13
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()
示例#14
0
from e3.env import Env

from SUITE.context import thistest
from SUITE.cutils import Wdir, contents_of
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)
示例#15
0
Check that gnatcov processes project files with a Source_Files attribute
correctly.
"""

from SCOV.minicheck import build_run_and_coverage, check_xcov_reports
from SUITE.context import thistest
from SUITE.cutils import Wdir, contents_of
from SUITE.gprutils import GPRswitches
from SUITE.tutils import gprfor

# We have a sample "flip" unit-to-test and a simple test driver for it, plus a
# additional flop.ads file. We exercize coverage of the flip unit by the
# driver with a project file which explicitly lists the sources of relevance
# to the test, by way of a Source_Files attribute not including flop.ads.

wd = Wdir()


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(