Ejemplo n.º 1
0
    def __get_scovdata(self, scov_file):
        """
        Return a list of strings containing the SCOV_data.  To simplify
        parsing, the leading comment markers are stripped.
        """

        # The langinfo corresponding to the language of SCOV_FILE
        lang_info = language_info(scov_file)

        # The scov data begins at the first line that starts with the
        # language's comment marker, followed by a '#'. Any line that
        # starts as a comment after this first '#' comment line is assumed
        # to be part of the scov data.  Build a list of lines containing
        # the scov data stored in scov_file now.
        contents = []
        in_scovdata = False
        for line in lines_of(scov_file):
            # Take care of leading/trailing spaces to give the user
            # more flexibility.  Also take care of the trailing new-line
            # character that we get from lines_of.
            line.strip()
            if line.startswith(lang_info.comment + '#'):
                in_scovdata = True
            if in_scovdata and line.startswith(lang_info.comment):
                # Also take this opportunity to strip the leading comment
                # string as well as any space immediately following it.
                # This will simplify the parsing a little bit.
                contents.append(line[len(lang_info.comment):].lstrip())
        return contents
Ejemplo n.º 2
0
def check(options, xunits):
    """
    Check that running gnatcov coverage with the provided list of
    `options` for project selection yields `xunits` as the set of
    units of interest, conveyed as a list. Verify the list of units
    reported by --dump-units-to and the set of produced .xcov reports.
    """

    # Compute the name of a unique output dir for the reports,
    # based on the options.
    opt_str = ''.join([
        opt.replace('--projects=',
                    '').replace('root', 'r').replace('../', '').replace(
                        '.gpr',
                        '').replace('_X=True',
                                    '').replace('--no-subprojects',
                                                'ns').strip('-')
        for opt in options
    ])

    odir = 'tmp_' + opt_str
    ofile = os.path.join(odir, 'dump-units')

    xcov([
        'coverage', trace, '--level=stmt', '--annotate=xcov',
        '--output-dir={}'.format(odir), '--dump-units-to={}'.format(ofile),
        board_arg
    ] + options,
         out='cov-' + opt_str + '.log')

    # Primary check, from the list of units reported by --dump-units-to

    xunits = set(xunits)
    runits = set(lines_of(ofile))

    thistest.fail_if(
        runits != xunits,
        "for options '{}', reported list of units not as expected:\n"
        "expected: {}\n"
        "obtained: {}".format(' '.join(options), xunits, runits))

    # Secondary check, from the set of generated reports

    # We have a list/set of expected unit names on the one hand, and a set of
    # .xcov files in `odir` on the other hand. In the latter set, we can have
    # multiple files for a unit, for example a spec and a body for a package.
    # Map the report files to a set of units by stripping both the leading
    # subdir part and the extension.

    runits = set(
        os.path.basename(r).split('.')[0]
        for r in e3.fs.ls(os.path.join(odir, '*.xcov')))

    thistest.fail_if(
        runits != xunits,
        "for options '{}', list of units from reports not as expected:\n"
        "expected: {}\n"
        "obtained: {}".format(' '.join(options), xunits, runits))
Ejemplo n.º 3
0
    def __cmdline_options(self):
        """Return an options object to represent the command line options"""
        main = Main(require_docstring=False, add_targets_options=True)
        main.add_option('--timeout', dest='timeout', type=int, default=None)
        main.add_option('--trace_dir',
                        dest='trace_dir',
                        metavar='DIR',
                        help='Traces location. No bootstrap if not specified.',
                        default=None)
        main.add_option('--report-file',
                        dest='report_file',
                        metavar='FILE',
                        help='The filename where to store the test report '
                        '[required]')
        main.add_option('--qualif-level',
                        dest='qualif_level',
                        metavar='QUALIF_LEVEL',
                        help='The target qualification level when we are '
                        'running in qualification mode.')

        main.add_option('--xcov-level',
                        dest='xcov_level',
                        help='Force the --level argument passed to xcov '
                        'instead of deducing it from the test category '
                        'when that normally happens.')

        main.add_option('--tags', dest='tags', default="")

        control.add_shared_options_to(main, toplevel=False)

        main.parse_args()
        if main.options.report_file is None:
            # This is a required "option" which is a bit self-contradictory,
            # but it's easy to do it that way.
            main.error("The report file must be specified with --report-file")

        # Get our tags set as a list. Fetch contents from file if needed
        # first:

        if main.options.tags and main.options.tags.startswith('@'):
            main.options.tags = ' '.join(lines_of(main.options.tags[1:]))
        if main.options.tags:
            main.options.tags = main.options.tags.split()

        return main.options
Ejemplo n.º 4
0
    def __cmdline_options(self):
        """Return an options object to represent the command line options"""
        main = Main(platform_args=True)
        parser = main.argument_parser
        parser.add_argument('--timeout', type=int, default=None)
        parser.add_argument('--report-file',
                            metavar='FILE',
                            help='The filename where to store the test report'
                            ' [required]')
        parser.add_argument('--qualif-level',
                            metavar='QUALIF_LEVEL',
                            help='The target qualification level when we are'
                            ' running in qualification mode.')

        parser.add_argument('--xcov-level',
                            help='Force the --level argument passed to xcov'
                            'instead of deducing it from the test'
                            ' category when that normally happens.')

        parser.add_argument('--tags', default="")

        control.add_shared_options_to(parser, toplevel=False)

        main.parse_args()

        # "--report-file" is a required "option" which is a bit
        # self-contradictory, but it's easy to do it that way.
        exit_if(main.args.report_file is None,
                "The report file must be specified with --report-file")

        # Get our tags set as a list. Fetch contents from file if needed
        # first:
        if main.args.tags and main.args.tags.startswith('@'):
            main.args.tags = ' '.join(lines_of(main.args.tags[1:]))
        if main.args.tags:
            main.args.tags = main.args.tags.split()

        return main.args