How to use the benchexec.tablegenerator.util function in BenchExec

To help you get started, we’ve selected a few BenchExec examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sosy-lab / benchexec / benchexec / tablegenerator / test_util.py View on Github external
def assertEqualNumberAndUnit(self, value, number, unit):
        self.assertEqual(util.split_number_and_unit(value), (number, unit))
        self.assertEqual(util.split_string_at_suffix(value, False), (number, unit))
github sosy-lab / benchexec / benchexec / tablegenerator / __init__.py View on Github external
def round_to_MHz(value):
                    number, unit = util.split_number_and_unit(value)
                    if unit and unit != "Hz":
                        return value
                    try:
                        return "{:.0f} MHz".format(int(number) / 1000 / 1000)
                    except ValueError:
                        return value

                runSetResult.attributes[key] = util.prettylist(
                    map(round_to_MHz, values)
                )

            elif key == "host":
                runSetResult.attributes[key] = util.prettylist(
                    util.merge_entries_with_common_prefixes(values)
                )

            else:
                runSetResult.attributes[key] = util.prettylist(values)

    # compute nice name of each run set for displaying
    firstBenchmarkName = runSetResults[0].attributes["benchmarkname"]
    allBenchmarkNamesEqual = all(
        r.attributes["benchmarkname"] == firstBenchmarkName for r in runSetResults
    )

    for runSetResult in runSetResults:
        benchmarkName = runSetResult.attributes["benchmarkname"]
        name = runSetResult.attributes["name"]

        if not name:
github sosy-lab / benchexec / benchexec / tablegenerator / __init__.py View on Github external
def round_to_MHz(value):
                    number, unit = util.split_number_and_unit(value)
                    if unit and unit != "Hz":
                        return value
                    try:
                        return "{:.0f} MHz".format(int(number) / 1000 / 1000)
                    except ValueError:
                        return value
github sosy-lab / benchexec / benchexec / tablegenerator / __init__.py View on Github external
if not name:
            name = basename_without_ending(options.xmltablefile)

        if not outputPath:
            outputPath = os.path.dirname(options.xmltablefile)

    else:
        if options.tables:
            inputFiles = options.tables
        else:
            searchDir = outputPath or DEFAULT_OUTPUT_PATH
            logging.info("Searching result files in '%s'...", searchDir)
            inputFiles = [os.path.join(searchDir, "*.results*.xml")]

        inputFiles = util.extend_file_list(inputFiles)  # expand wildcards
        runSetResults = load_results(inputFiles, options)

        if len(inputFiles) == 1:
            if not name:
                name = basename_without_ending(inputFiles[0])
            if not outputFilePattern == "-":
                outputFilePattern = "{name}.{ext}"
        else:
            if not name:
                name = (
                    NAME_START + "." + time.strftime("%Y-%m-%d_%H%M", time.localtime())
                )

        if inputFiles and not outputPath:
            path = os.path.dirname(inputFiles[0])
            if "://" not in path and all(
github sosy-lab / benchexec / benchexec / tablegenerator / columns.py View on Github external
self,
        title,
        pattern=None,
        num_of_digits=None,
        href=None,
        col_type=None,
        unit=None,
        source_unit=None,
        scale_factor=None,
        relevant_for_diff=None,
        display_title=None,
    ):

        # If scaling on the variables is performed, a display unit must be defined, explicitly
        if scale_factor is not None and scale_factor != 1 and unit is None:
            raise util.TableDefinitionError(
                "Scale factor is defined, but display unit is not (in column {})".format(
                    title
                )
            )

        self.title = title
        self.pattern = pattern
        self.number_of_significant_digits = (
            int(num_of_digits) if num_of_digits else None
        )
        self.type = col_type
        self.unit = unit
        self.source_unit = source_unit
        self.scale_factor = float(scale_factor) if scale_factor else scale_factor
        self.href = href
        if relevant_for_diff is None:
github sosy-lab / benchexec / benchexec / tablegenerator / columns.py View on Github external
if value_match is None:
            return ColumnType.text
        else:
            column_has_numbers = True
            curr_column_unit = value_match.group(GROUP_UNIT)

            # If the units in two different rows of the same column differ,
            # 1. Raise an error if an explicit unit is defined by the displayUnit attribute
            #    and the unit in the column cell differs from the defined sourceUnit, or
            # 2. Handle the column as 'text' type, if no displayUnit was defined for the column's values.
            #    In that case, a unit different from the definition of sourceUnit does not lead to an error.
            if curr_column_unit:
                if column_source_unit is None and not explicit_scale_defined:
                    column_source_unit = curr_column_unit
                elif column_source_unit != curr_column_unit:
                    raise util.TableDefinitionError(
                        "Attribute sourceUnit different from real source unit: {} and {} (in column {})".format(
                            column_source_unit, curr_column_unit, column.title
                        )
                    )
                if column_unit and curr_column_unit != column_unit:
                    if explicit_unit_defined:
                        _check_unit_consistency(
                            curr_column_unit, column_source_unit, column
                        )
                    else:
                        return ColumnType.text
                else:
                    column_unit = curr_column_unit

            if column_scale_factor is None:
                column_scale_factor = _get_scale_factor(
github sosy-lab / benchexec / benchexec / tablegenerator / columns.py View on Github external
def _check_unit_consistency(actual_unit, wanted_unit, column):
    if actual_unit and wanted_unit is None:
        raise util.TableDefinitionError(
            "Trying to convert from one unit to another, but source unit not specified"
            " (in column {})".format(column.title)
        )
    elif wanted_unit != actual_unit:
        raise util.TableDefinitionError(
            "Source value of different unit than specified source unit: " + "{} and {}"
            " (in column {})".format(actual_unit, wanted_unit, column.title)
        )
github sosy-lab / benchexec / benchexec / tablegenerator / __init__.py View on Github external
def get_file_list_from_result_tag(result_tag, table_definition_file):
    if "filename" not in result_tag.attrib:
        logging.warning(
            "Result tag without filename attribute in file '%s'.", table_definition_file
        )
        return []
    # expand wildcards
    return util.get_file_list(
        os.path.join(os.path.dirname(table_definition_file), result_tag.get("filename"))
    )
github sosy-lab / benchexec / benchexec / tablegenerator / htmltable.py View on Github external
or ".",
                ),
                (
                    "logfile_path_abs",
                    os.path.dirname(os.path.abspath(runResult.log_file)),
                ),
            ]
            if runResult.log_file
            else []
        )

    source_file = (
        os.path.relpath(runResult.task_id[0], href_base or ".") if runResult else None
    )

    if util.is_url(href):
        # quote special characters only in inserted variable values, not full URL
        if source_file:
            source_file = url_quote(source_file)
            href = benchexec.util.substitute_vars(href, get_replacements(source_file))
        return href

    # quote special characters everywhere (but not twice in source_file!)
    if source_file:
        href = benchexec.util.substitute_vars(href, get_replacements(source_file))
    return url_quote(os.path.relpath(href, base_dir))
github sosy-lab / benchexec / benchexec / tablegenerator / __init__.py View on Github external
def parse_results_file(resultFile, run_set_id=None, ignore_errors=False):
    """
    This function parses an XML file that contains the results of the execution of a run set.
    It returns the "result" XML tag.
    @param resultFile: The file name of the XML file that contains the results.
    @param run_set_id: An optional identifier of this set of results.
    """
    logging.info("    %s", resultFile)
    url = util.make_url(resultFile)

    parse = ElementTree.ElementTree().parse
    try:
        with util.open_url_seekable(url, mode="rb") as f:
            try:
                try:
                    resultElem = parse(gzip.GzipFile(fileobj=f))
                except OSError:
                    f.seek(0)
                    resultElem = parse(bz2.BZ2File(f))
            except OSError:
                f.seek(0)
                resultElem = parse(f)
    except OSError as e:
        handle_error("Could not read result file %s: %s", resultFile, e)
    except ElementTree.ParseError as e: