示例#1
0
def main(argv=None):
    """
    A simple command-line interface to print information provided by a tool info.
    """
    if sys.version_info < (3, ):
        sys.exit("benchexec.test_tool_info needs Python 3 to run.")
    if argv is None:
        argv = sys.argv

    parser = argparse.ArgumentParser(
        fromfile_prefix_chars="@",
        description=
        """Test a tool info for BenchExec and print out all relevant information this tool info provides.
           Part of BenchExec: https://github.com/sosy-lab/benchexec/""",
    )
    parser.add_argument("tool",
                        metavar="TOOL",
                        help="name of tool info to test")
    parser.add_argument(
        "--tool-output",
        metavar="OUTPUT_FILE",
        nargs="+",
        type=argparse.FileType("r"),
        help="optional names of text files with example outputs of a tool run",
    )
    benchexec.benchexec.add_container_args(parser)

    options = parser.parse_args(argv[1:])
    logging.basicConfig(format=COLOR_WARNING + "%(levelname)s: %(message)s" +
                        COLOR_DEFAULT)

    print_value("Name of tool module", options.tool)
    try:
        tool_module, tool = model.load_tool_info(options.tool, options)
        try:
            print_value("Full name of tool module", tool_module)
            print_tool_info(tool)

            if options.tool_output:
                for file in options.tool_output:
                    analyze_tool_output(tool, file)
        finally:
            tool.close()

    except benchexec.BenchExecException as e:
        sys.exit(str(e))
def print_tool_info(name):
    print_value('Name of tool module', name)
    tool_module, tool = model.load_tool_info(name)
    print_value('Full name of tool module', tool_module)

    print_value('Name of tool', tool.name())

    executable = tool.executable()
    print_value('Executable', executable)
    if not os.path.isabs(executable):
        print_value('Executable (absolute path)', os.path.abspath(executable))

    try:
        print_value('Version', tool.version(executable))
    except:
        logging.warning('Determining version failed:', exc_info=1)

    working_directory = tool.working_directory(executable)
    print_value('Working directory', working_directory)
    if not os.path.isabs(working_directory):
        print_value('Working directory (absolute path)', os.path.abspath(working_directory))

    program_files = list(tool.program_files(executable))
    if program_files:
        print_multiline_list('Program files', program_files)
        print_multiline_list('Program files (absolute paths)', map(os.path.abspath, program_files))
    else:
        logging.warning('Tool module specifies no program files.')

    environment = tool.environment(executable)
    new_environment = environment.pop('newEnv', {})
    if new_environment:
        print_multiline_list('Additional environment variables',
                          ('{}={}'.format(variable, value) for (variable, value) in new_environment.items()))
    append_environment = environment.pop('additionalEnv', {})
    if append_environment:
        print_multiline_list('Appended environment variables',
                          ('{}=${{{}}}{}'.format(variable, variable, value) for (variable, value) in append_environment.items()))
    if environment:
        logging.warning(
            'Tool module returned invalid entries for environment, these will be ignored: “%s”',
            environment)

    try:
        cmdline = model.cmdline_for_run(tool, executable, [], ['INPUT.FILE'], None, {})
        print_list('Minimal command line', cmdline)
        if not 'INPUT.FILE' in ' '.join(cmdline):
            logging.warning('Tool module ignores input file.')
    except:
        logging.warning('Tool module does not support tasks without options, '
                        'property file, and resource limits:',
                        exc_info=1)

    try:
        cmdline = model.cmdline_for_run(tool, executable, ['-SOME_OPTION'], ['INPUT.FILE'], None, {})
        print_list('Command line with parameter', cmdline)
        if not '-SOME_OPTION' in cmdline:
            logging.warning('Tool module ignores command-line options.')
    except:
        logging.warning('Tool module does not support tasks with command-line options:',
                        exc_info=1)

    try:
        cmdline = model.cmdline_for_run(tool, executable, [], ['INPUT.FILE'], 'PROPERTY.PRP', {})
        print_list('Command line with property file', cmdline)
        if not 'PROPERTY.PRP' in ' '.join(cmdline):
            logging.warning('Tool module ignores property file.')
    except:
        logging.warning('Tool module does not support tasks with property file:', exc_info=1)

    try:
        cmdline = model.cmdline_for_run(tool, executable, [], ['INPUT1.FILE', 'INPUT2.FILE'], None, {})
        print_list('Command line with multiple input files', cmdline)
        if 'INPUT1.FILE' in ' '.join(cmdline) and not 'INPUT2.FILE' in ' '.join(cmdline):
            logging.warning('Tool module ignores all but first input file.')
    except:
        logging.warning('Tool module does not support tasks with multiple input files:',
                        exc_info=1)

    try:
        cmdline = model.cmdline_for_run(tool, executable, [], ['INPUT.FILE'], None, {model.SOFTTIMELIMIT: 123})
        print_list('Command line CPU-time limit', cmdline)
    except:
        logging.warning('Tool module does not support tasks with CPU-time limit:', exc_info=1)

    return tool
示例#3
0
def main(argv=None):
    """
    A simple command-line interface to print information provided by a tool info.
    """
    if sys.version_info < (3,):
        sys.exit("benchexec.test_tool_info needs Python 3 to run.")
    if argv is None:
        argv = sys.argv

    parser = argparse.ArgumentParser(
        fromfile_prefix_chars="@",
        description="""Test a tool info for BenchExec and print out all relevant information this tool info provides.
           Part of BenchExec: https://github.com/sosy-lab/benchexec/""",
    )
    parser.add_argument("tool", metavar="TOOL", help="name of tool info to test")
    parser.add_argument(
        "--tool-directory",
        help="look for tool in given directory",
        metavar="DIR",
        type=benchexec.util.non_empty_str,
    )
    parser.add_argument(
        "--tool-output",
        metavar="OUTPUT_FILE",
        nargs="+",
        type=argparse.FileType("r"),
        help="optional names of text files with example outputs of a tool run",
    )
    parser.add_argument(
        "--task-definition",
        metavar="TASK_DEF_FILE",
        nargs="+",
        default=[],
        type=argparse.FileType("r"),
        help="optional name of task-definition files to test the module with",
    )
    benchexec.benchexec.add_container_args(parser)

    options = parser.parse_args(argv[1:])
    logging.basicConfig(
        format=COLOR_WARNING + "%(levelname)s: %(message)s" + COLOR_DEFAULT
    )
    tool_locator = tooladapter.create_tool_locator(options)

    print_value("Name of tool module", options.tool)
    try:
        tool_module, tool = model.load_tool_info(options.tool, options)
        try:
            print_value("Full name of tool module", tool_module)
            executable = print_tool_info(tool, tool_locator)
            dummy_cmdline = print_standard_task_cmdlines(tool, executable)
            for task_def_file in options.task_definition:
                print_task_cmdline(tool, executable, task_def_file)

            if options.tool_output:
                for file in options.tool_output:
                    analyze_tool_output(tool, file, dummy_cmdline)
        finally:
            tool.close()

    except benchexec.BenchExecException as e:
        sys.exit("Error: " + str(e))
示例#4
0
def print_tool_info(name):
    print_value('Name of tool module', name)
    tool_module, tool = model.load_tool_info(name)
    print_value('Full name of tool module', tool_module)

    print_value('Name of tool', tool.name())

    executable = tool.executable()
    print_value('Executable', executable)
    if not os.path.isabs(executable):
        print_value('Executable (absolute path)', os.path.abspath(executable))

    try:
        print_value('Version', tool.version(executable))
    except:
        logging.warning('Determining version failed:', exc_info=1)

    working_directory = tool.working_directory(executable)
    print_value('Working directory', working_directory)
    if not os.path.isabs(working_directory):
        print_value('Working directory (absolute path)',
                    os.path.abspath(working_directory))

    program_files = list(tool.program_files(executable))
    if program_files:
        print_multiline_list('Program files', program_files)
        print_multiline_list('Program files (absolute paths)',
                             map(os.path.abspath, program_files))
    else:
        logging.warning('Tool module specifies no program files.')

    environment = tool.environment(executable)
    new_environment = environment.pop('newEnv', {})
    if new_environment:
        print_multiline_list(
            'Additional environment variables',
            ('{}={}'.format(variable, value)
             for (variable, value) in new_environment.items()))
    append_environment = environment.pop('additionalEnv', {})
    if append_environment:
        print_multiline_list(
            'Appended environment variables',
            ('{}=${{{}}}{}'.format(variable, variable, value)
             for (variable, value) in append_environment.items()))
    if environment:
        logging.warning(
            'Tool module returned invalid entries for environment, these will be ignored: “%s”',
            environment)

    try:
        cmdline = model.cmdline_for_run(tool, executable, [], ['INPUT.FILE'],
                                        None, {})
        print_list('Minimal command line', cmdline)
        if not 'INPUT.FILE' in ' '.join(cmdline):
            logging.warning('Tool module ignores input file.')
    except:
        logging.warning(
            'Tool module does not support tasks without options, '
            'property file, and resource limits:',
            exc_info=1)

    try:
        cmdline = model.cmdline_for_run(tool, executable, ['-SOME_OPTION'],
                                        ['INPUT.FILE'], None, {})
        print_list('Command line with parameter', cmdline)
        if not '-SOME_OPTION' in cmdline:
            logging.warning('Tool module ignores command-line options.')
    except:
        logging.warning(
            'Tool module does not support tasks with command-line options:',
            exc_info=1)

    try:
        cmdline = model.cmdline_for_run(tool, executable, [], ['INPUT.FILE'],
                                        'PROPERTY.PRP', {})
        print_list('Command line with property file', cmdline)
        if not 'PROPERTY.PRP' in ' '.join(cmdline):
            logging.warning('Tool module ignores property file.')
    except:
        logging.warning(
            'Tool module does not support tasks with property file: %s',
            exc_info=1)

    try:
        cmdline = model.cmdline_for_run(tool, executable, [],
                                        ['INPUT1.FILE', 'INPUT2.FILE'], None,
                                        {})
        print_list('Command line with multiple input files', cmdline)
        if 'INPUT1.FILE' in ' '.join(
                cmdline) and not 'INPUT2.FILE' in ' '.join(cmdline):
            logging.warning('Tool module ignores all but first input file.')
    except:
        logging.warning(
            'Tool module does not support tasks with multiple input files:',
            exc_info=1)

    try:
        cmdline = model.cmdline_for_run(tool, executable, [], ['INPUT.FILE'],
                                        None, {model.SOFTTIMELIMIT: 123})
        print_list('Command line CPU-time limit', cmdline)
    except:
        logging.warning(
            'Tool module does not support tasks with CPU-time limit:',
            exc_info=1)

    return tool
示例#5
0
def print_tool_info(name, config):
    print_value("Name of tool module", name)
    tool_module, tool = model.load_tool_info(name, config)
    print_value("Full name of tool module", tool_module)
    print_multiline_text("Documentation of tool module", inspect.getdoc(tool))

    print_value("Name of tool", tool.name())

    executable = tool.executable()
    print_value("Executable", executable)
    if not os.path.isabs(executable):
        print_value("Executable (absolute path)", os.path.abspath(executable))
    else:
        logging.warning(
            "Path to executable is absolute, this might be problematic "
            "in scenarios where runs are distributed to other machines.")

    try:
        print_value("Version", tool.version(executable))
    except:
        logging.warning("Determining version failed:", exc_info=1)

    working_directory = tool.working_directory(executable)
    print_value("Working directory", working_directory)
    if not os.path.isabs(working_directory):
        print_value("Working directory (absolute path)",
                    os.path.abspath(working_directory))

    program_files = list(tool.program_files(executable))
    if program_files:
        print_multiline_list("Program files", program_files)
        print_multiline_list("Program files (absolute paths)",
                             map(os.path.abspath, program_files))
    else:
        logging.warning("Tool module specifies no program files.")

    environment = tool.environment(executable)
    new_environment = environment.pop("newEnv", {})
    if new_environment:
        print_multiline_list(
            "Additional environment variables",
            ("{}={}".format(variable, value)
             for (variable, value) in new_environment.items()),
        )
    append_environment = environment.pop("additionalEnv", {})
    if append_environment:
        print_multiline_list(
            "Appended environment variables",
            ("{}=${{{}}}{}".format(variable, variable, value)
             for (variable, value) in append_environment.items()),
        )
    if environment:
        logging.warning(
            "Tool module returned invalid entries for environment, these will be ignored: “%s”",
            environment,
        )

    with log_if_unsupported(
            "tasks without options, property file, and resource limits"):
        cmdline = model.cmdline_for_run(tool, executable, [], ["INPUT.FILE"],
                                        None, {})
        print_list("Minimal command line", cmdline)
        if not "INPUT.FILE" in " ".join(cmdline):
            logging.warning("Tool module ignores input file.")

    with log_if_unsupported("tasks with command-line options"):
        cmdline = model.cmdline_for_run(tool, executable, ["-SOME_OPTION"],
                                        ["INPUT.FILE"], None, {})
        print_list("Command line with parameter", cmdline)
        if not "-SOME_OPTION" in cmdline:
            logging.warning("Tool module ignores command-line options.")

    with log_if_unsupported("tasks with property file"):
        cmdline = model.cmdline_for_run(tool, executable, [], ["INPUT.FILE"],
                                        "PROPERTY.PRP", {})
        print_list("Command line with property file", cmdline)
        if not "PROPERTY.PRP" in " ".join(cmdline):
            logging.warning("Tool module ignores property file.")

    with log_if_unsupported("tasks with multiple input files"):
        cmdline = model.cmdline_for_run(tool, executable, [],
                                        ["INPUT1.FILE", "INPUT2.FILE"], None,
                                        {})
        print_list("Command line with multiple input files", cmdline)
        if "INPUT1.FILE" in " ".join(
                cmdline) and not "INPUT2.FILE" in " ".join(cmdline):
            logging.warning("Tool module ignores all but first input file.")

    with log_if_unsupported("tasks with CPU-time limit"):
        cmdline = model.cmdline_for_run(tool, executable, [], ["INPUT.FILE"],
                                        None, {model.SOFTTIMELIMIT: 123})
        print_list("Command line CPU-time limit", cmdline)

    return tool