Exemplo n.º 1
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()
Exemplo n.º 2
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)
Exemplo n.º 3
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))
Exemplo n.º 4
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'
Exemplo n.º 5
0
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')

check_xcov_reports('obj-ext/*.xcov', {
    'obj-ext/main.adb.xcov': {'+': {5}},
    'obj-ext/helper.ads.xcov': {},
    'obj-ext/helper.adb.xcov': {'+': {4}}})

thistest.result()
Exemplo n.º 6
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()
Exemplo n.º 7
0
# 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
# "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),
Exemplo n.º 8
0
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()
Exemplo n.º 9
0

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'],
    gpr_obj_dir='ext-obj',
    extra_coverage_args=['-axcov'])

check_xcov_reports('ext-obj/*.xcov', {
    'ext-obj/main1.adb.xcov': {'+': {5}},
    'ext-obj/main2.adb.xcov': {'+': {5, 6}}})

thistest.result()
Exemplo n.º 10
0
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()
Exemplo n.º 11
0
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')
thistest.fail_if_not_equal(
    'gnatcov output',
    'warning: no unit main (from --units) in the projects of interest',
    contents_of(log_file).strip())

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

thistest.result()