def init(config, benchmark):
    config.containerargs = {}
    if config.container:
        config.containerargs = containerexecutor.handle_basic_container_args(
            config)
        if config.containerargs["container_tmpfs"] and (
                config.filesCountLimit or config.filesSizeLimit):
            sys.exit(
                "Files-count limit and files-size limit are not supported "
                "if tmpfs is used in container. "
                "Use --no-tmpfs to make these limits work or disable them "
                "(typically they are unnecessary if a tmpfs is used).")
    config.containerargs["use_namespaces"] = config.container

    tool_locator = tooladapter.create_tool_locator(config)
    benchmark.executable = benchmark.tool.executable(tool_locator)
    benchmark.tool_version = benchmark.tool.version(benchmark.executable)
Beispiel #2
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))
Beispiel #3
0
    def init(self, config, benchmark):
        """
        This functions will set up the docker network to execute the test.
        As a result, it needs root permission for the setup part.
        """

        tool_locator = tooladapter.create_tool_locator(config)
        benchmark.executable = benchmark.tool.executable(tool_locator)
        benchmark.tool_version = benchmark.tool.version(benchmark.executable)

        # Read test inputs paths
        (
            self.switch_source_path,
            self.ptf_folder_path,
            self.network_config_path,
        ) = self.read_folder_paths(benchmark)

        if not os.path.isdir(self.switch_source_path):
            logging.critical(
                "Switch folder path not found: %s, {self.switch_source_path}"
            )
            raise BenchExecException(
                "Switch folder path not found. Look over setup definition"
            )
        if not os.path.isdir(self.ptf_folder_path):
            logging.critical(
                "Ptf test folder path not found: %s, {self.ptf_folder_path}"
            )
            raise (
                BenchExecException(
                    f"Ptf test folder path not found: {self.ptf_folder_path}"
                )
            )

        if not self.switch_source_path or not self.ptf_folder_path:
            raise BenchExecException(
                "Switch or Ptf folder path not defined."
                f"Switch path: {self.switch_source_path} Folder path: {self.ptf_folder_path}"
            )

        # Extract network config info
        if not self.network_config_path:
            logging.error("No network config file was defined")
            raise BenchExecException("No network config file was defined")

        with open(self.network_config_path) as json_file:
            self.network_config = json.load(json_file)

        setup_is_valid = self.network_file_isValid()

        if not setup_is_valid:
            raise BenchExecException("Network config file is not valid")

        # Container setup
        self.client = docker.from_env()
        self.switch_target_path = "/app"
        self.nrOfNodes = len(self.network_config["nodes"])

        try:
            # Create the ptf tester container
            mount_ptf_tester = docker.types.Mount(
                "/app", self.ptf_folder_path, type="bind"
            )
            try:
                self.ptf_tester = self.client.containers.create(
                    PTF_IMAGE_NAME,
                    detach=True,
                    name="ptfTester",
                    mounts=[mount_ptf_tester],
                    tty=True,
                )
            except docker.errors.APIError:
                self.ptf_tester = self.client.containers.get("ptfTester")

            # Create node containers
            self.nodes = []

            for node_name in self.network_config["nodes"]:
                try:
                    self.nodes.append(
                        self.client.containers.create(
                            NODE_IMAGE_NAME, detach=True, name=node_name
                        )
                    )
                except docker.errors.APIError:
                    logging.error("Failed to setup node container.")

            self.switches = []

            # Each switch needs their own mount copy
            for switch_info in self.network_config["switches"]:
                mount_path = self.create_switch_mount_copy(switch_info)
                mount_switch = docker.types.Mount(
                    self.switch_target_path, mount_path, type="bind"
                )

                try:
                    self.switches.append(
                        self.client.containers.create(
                            SWITCH_IMAGE_NAME,
                            detach=True,
                            name=switch_info,
                            mounts=[mount_switch],
                        )
                    )
                except docker.errors.APIError:
                    self.switches.append(self.client.containers.get(switch_info))

            logging.info("Setting up network")
            self.setup_network()
            self.connect_nodes_to_switch()

        except docker.errors.APIError as e:
            self.close()
            raise BenchExecException(str(e))