Пример #1
0
def _create_link(href, base_dir, runResult=None, href_base=None):
    def get_replacements(task_file):
        var_prefix = "taskdef_" if task_file.endswith(".yml") else "inputfile_"
        return [
            (var_prefix + "name", os.path.basename(task_file)),
            (var_prefix + "path", os.path.dirname(task_file) or "."),
            (var_prefix + "path_abs", os.path.dirname(os.path.abspath(task_file))),
        ] + (
            [
                ("logfile_name", os.path.basename(runResult.log_file)),
                (
                    "logfile_path",
                    os.path.dirname(
                        os.path.relpath(runResult.log_file, href_base or ".")
                    )
                    or ".",
                ),
                (
                    "logfile_path_abs",
                    os.path.dirname(os.path.abspath(runResult.log_file)),
                ),
            ]
            if runResult.log_file
            else []
        )

    source_file = (
        # os.path.relpath creates os-dependant paths, so standardize the output between OSs
        util.fix_path_if_on_windows(
            os.path.relpath(runResult.task_id.name, 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))
    # os.path.relpath creates os-dependant paths, so standardize the output between OSs
    return url_quote(util.fix_path_if_on_windows(os.path.relpath(href, base_dir)))
Пример #2
0
 def prepare_column(column):
     result = {k: v for k, v in column.__dict__.items() if v is not None}
     result.pop("scale_factor", None)
     result.pop("source_unit", None)
     if "href" in result:
         # href may contain an url created from an os-dependant path, so standardize it between OSs
         result["href"] = util.fix_path_if_on_windows(result["href"])
     result["display_title"] = column.display_title or column.title
     result["type"] = column.type.type.name
     number_of_significant_digits = column.get_number_of_significant_digits()
     if number_of_significant_digits is not None:
         result["number_of_significant_digits"] = number_of_significant_digits
     return result
Пример #3
0
    def clean_up_row(row):
        result = {}
        result["id"] = [
            str(id_part)
            for id_part, relevant in zip(row.id, relevant_id_columns)
            if id_part and relevant
        ]
        # Replace first part of id (task name, which is always shown) with short name
        assert relevant_id_columns[0]
        # row.short_filename may contain paths, so standardize the output across OSs
        result["id"][0] = util.fix_path_if_on_windows(row.short_filename)

        result["results"] = [clean_up_results(res) for res in row.results]
        if row.has_sourcefile:
            result["href"] = _create_link(row.id.name, base_dir)
        return result
Пример #4
0
def _prepare_benchmark_setup_data(runSetResults, commonFileNamePrefix,
                                  relevant_id_columns):
    # This list contains the number of columns each run set has
    # (the width of a run set in the final table)
    # It is used for calculating the column spans of the header cells.
    runSetWidths = [
        len(runSetResult.columns) for runSetResult in runSetResults
    ]

    def get_row(rowName,
                format_string,
                collapse=False,
                onlyIf=None,
                default="Unknown"):
        def format_cell(attributes):
            if onlyIf and onlyIf not in attributes:
                formatStr = default
            else:
                formatStr = format_string
            return formatStr.format(**attributes)

        values = [
            format_cell(runSetResult.attributes)
            for runSetResult in runSetResults
        ]
        if not any(values):
            return None  # skip row without values completely

        valuesAndWidths = (list(
            util.collapse_equal_values(values, runSetWidths))
                           if collapse else list(zip(values, runSetWidths)))

        return dict(  # noqa: C408
            id=rowName.lower().split(" ")[0],
            name=rowName,
            content=valuesAndWidths)

    titles = [
        column.format_title() for runSetResult in runSetResults
        for column in runSetResult.columns
    ]
    runSetWidths1 = [1] * sum(runSetWidths)
    titleRow = dict(  # noqa: C408
        id="columnTitles",
        # commonFileNamePrefix may contain paths, so standardize the output across OSs
        name=util.fix_path_if_on_windows(commonFileNamePrefix),
        content=list(zip(titles, runSetWidths1)),
    )

    property_row = None
    if not relevant_id_columns[1]:  # property is the same for all tasks
        common_property = runSetResults[0].results[0].task_id[1]
        if common_property:
            property_row = dict(  # noqa: C408
                id="property",
                name="Properties",
                content=[[common_property.name,
                          sum(runSetWidths)]],
            )

    return {
        "tool":
        get_row("Tool", "{tool} {version}", collapse=True),
        "displayName":
        get_row("Benchmark", "{displayName}", collapse=True),
        "limit":
        get_row(
            "Limits",
            "timelimit: {timelimit}, memlimit: {memlimit}, CPU core limit: {cpuCores}",
            collapse=True,
        ),
        "host":
        get_row("Host", "{host}", collapse=True, onlyIf="host"),
        "os":
        get_row("OS", "{os}", collapse=True, onlyIf="os"),
        "system":
        get_row(
            "System",
            "CPU: {cpu}, cores: {cores}, frequency: {freq}{turbo}; RAM: {ram}",
            collapse=True,
            onlyIf="cpu",
        ),
        "date":
        get_row("Date of execution", "{date}", collapse=True),
        "runset":
        get_row("Run set", "{niceName}"),
        "branch":
        get_row("Branch", "{branch}"),
        "options":
        get_row("Options", "{options}"),
        "property":
        property_row,
        "title":
        titleRow,
        "task_id_names": [
            name for name, selected in zip(util.TaskId.field_names,
                                           relevant_id_columns) if selected
        ],
    }