Beispiel #1
0
 def _version_from_tool(self, executable, arg='--version', use_stderr=False):
     """
     Get version of a tool by executing it with argument "--version"
     and returning stdout.
     @param executable: the path to the executable of the tool (typically the result of executable())
     @param arg: an argument to pass to the tool to let it print its version
     @param use_stderr: True if the tool prints version on stderr, False for stdout
     @return a (possibly empty) string of output of the tool
     """
     try:
         process = subprocess.Popen([executable, arg],
                                    stdout=subprocess.PIPE, stderr=subprocess.PIPE)
         (stdout, stderr) = process.communicate()
     except OSError as e:
         logging.warning('Cannot run {0} to determine version: {1}'.
                         format(executable, e.strerror))
         return ''
     if stderr and not use_stderr:
         logging.warning('Cannot determine {0} version, error output: {1}'.
                         format(executable, util.decode_to_string(stderr)))
         return ''
     if process.returncode:
         logging.warning('Cannot determine {0} version, exit code {1}'.
                         format(executable, process.returncode))
         return ''
     return util.decode_to_string(stderr if use_stderr else stdout).strip()
Beispiel #2
0
    def _query_ultimate_version(self, cmd, api):
        try:
            process = subprocess.Popen(cmd,
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE)
            (stdout, stderr) = process.communicate()
        except OSError as e:
            logging.warning(
                'Cannot run Java to determine Ultimate version (API {0}): {1}'.
                format(api, e.strerror))
            return ''
        if stderr:
            logging.warning(
                'Cannot determine Ultimate version (API {0}). Error output: {1}'
                .format(api, util.decode_to_string(stderr)))
            return ''
        if process.returncode:
            logging.warning(
                'Cannot determine Ultimate version (API {0}). Exit code : {1}\nCommand was {2}'
                .format(api, process.returncode, ' '.join(cmd)))
            return ''

        version_ultimate_match = _ULTIMATE_VERSION_REGEX.search(
            util.decode_to_string(stdout))
        if not version_ultimate_match:
            logging.warning(
                'Cannot determine Ultimate version, output (API {0}): {1}'.
                format(api, util.decode_to_string(stdout)))
            return ''
        return version_ultimate_match.group(1)
Beispiel #3
0
 def _version_from_tool(self, executable, arg='--version'):
     """
     Get version of a tool by executing it with argument "--version"
     and returning stdout.
     """
     try:
         process = subprocess.Popen([executable, arg],
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE)
         (stdout, stderr) = process.communicate()
     except OSError as e:
         logging.warning('Cannot run {0} to determine version: {1}'.format(
             executable, e.strerror))
         return ''
     if stderr:
         logging.warning(
             'Cannot determine {0} version, error output: {1}'.format(
                 executable, util.decode_to_string(stderr)))
         return ''
     if process.returncode:
         logging.warning(
             'Cannot determine {0} version, exit code {1}'.format(
                 executable, process.returncode))
         return ''
     return util.decode_to_string(stdout).strip()
    def _ultimate_version(self, executable):
        ultimatedir = os.path.dirname(executable)
        launcher_jar = os.path.join(ultimatedir, _LAUNCHER_JAR)
        data_dir = os.path.join(ultimatedir, 'data')
        if not os.path.isfile(launcher_jar):
            logging.warning('Cannot find {0} to determine Ultimate version'.
                            format(_LAUNCHER_JAR))
            return ''

        try:
            process = subprocess.Popen(["java", "-jar", launcher_jar, "-data", data_dir, "--version"],
                                       stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            (stdout, stderr) = process.communicate()
        except OSError as e:
            logging.warning('Cannot run Java to determine Ultimate version: {0}'.
                            format(e.strerror))
            return ''
        if stderr:
            logging.warning('Cannot determine Ultimate version, error output: {0}'.
                            format(util.decode_to_string(stderr)))
            return ''
        if process.returncode:
            logging.warning('Cannot determine Ultimate version, exit code {0}'.
                            format(process.returncode))
            return ''

        version_ultimate_match = _ULTIMATE_VERSION_REGEX.search(util.decode_to_string(stdout))
        if not version_ultimate_match:
            logging.warning('Cannot determine Ultimate version, output: {0}'.
                            format(util.decode_to_string(stdout)))
            return ''

        return version_ultimate_match.group(1)
Beispiel #5
0
 def _version_from_tool(self,
                        executable,
                        arg='--version',
                        use_stderr=False,
                        ignore_stderr=False):
     """
     Get version of a tool by executing it with argument "--version"
     and returning stdout.
     @param executable: the path to the executable of the tool (typically the result of executable())
     @param arg: an argument to pass to the tool to let it print its version
     @param use_stderr: True if the tool prints version on stderr, False for stdout
     @return a (possibly empty) string of output of the tool
     """
     try:
         process = subprocess.Popen([executable, arg],
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE)
         (stdout, stderr) = process.communicate()
     except OSError as e:
         logging.warning('Cannot run {0} to determine version: {1}'.format(
             executable, e.strerror))
         return ''
     if stderr and not use_stderr and not ignore_stderr:
         logging.warning(
             'Cannot determine {0} version, error output: {1}'.format(
                 executable, util.decode_to_string(stderr)))
         return ''
     if process.returncode:
         logging.warning(
             'Cannot determine {0} version, exit code {1}'.format(
                 executable, process.returncode))
         return ''
     return util.decode_to_string(stderr if use_stderr else stdout).strip()
Beispiel #6
0
    def version(self, executable):
        with tempfile.NamedTemporaryFile(suffix=".c") as trivial_example:
            trivial_example.write(b'int main() { return 0; }\n')
            trivial_example.flush()

            cmd = [executable, trivial_example.name]
            try:
                process = subprocess.Popen(cmd,
                                           stdout=subprocess.PIPE,
                                           stderr=subprocess.PIPE)
                (stdout, stderr) = process.communicate()
            except OSError as e:
                logging.warning(
                    'Unable to determine AProVE version: {0}'.format(
                        e.strerror))
                return ''

            version_aprove_match = re.compile(
                '^# AProVE Commit ID: (.*)',
                re.MULTILINE).search(util.decode_to_string(stdout))
            if not version_aprove_match:
                logging.warning(
                    'Unable to determine AProVE version: {0}'.format(
                        util.decode_to_string(stdout)))
                return ''
            return version_aprove_match.group(1)[:10]
    def _version_from_tool(
        executable,
        arg="--version",
        use_stderr=False,
        ignore_stderr=False,
        line_prefix=None,
    ):
        """
        Get version of a tool by executing it with argument "--version"
        and returning stdout.
        @param executable: the path to the executable of the tool (typically the result of executable())
        @param arg: an argument to pass to the tool to let it print its version
        @param use_stderr: True if the tool prints version on stderr, False for stdout
        @param line_prefix: if given, search line with this prefix and return only the rest of this line
        @return a (possibly empty) string of output of the tool
        """
        try:
            process = subprocess.Popen([executable, arg],
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE)
            (stdout, stderr) = process.communicate()
        except OSError as e:
            logging.warning("Cannot run %s to determine version: %s",
                            executable, e.strerror)
            return ""
        if stderr and not use_stderr and not ignore_stderr:
            logging.warning(
                "Cannot determine %s version, error output: %s",
                executable,
                util.decode_to_string(stderr),
            )
            return ""
        if process.returncode:
            logging.warning(
                "Cannot determine %s version, exit code %s",
                executable,
                process.returncode,
            )
            return ""

        output = util.decode_to_string(
            stderr if use_stderr else stdout).strip()
        if line_prefix:
            matches = (line[len(line_prefix):].strip()
                       for line in output.splitlines()
                       if line.startswith(line_prefix))
            output = next(matches, "")
        return output
Beispiel #8
0
 def version(self, executable):
     stderr = subprocess.Popen(self.cmdline(executable, ['-version'], []),
                               stderr=subprocess.PIPE).communicate()[1]
     stderr = util.decode_to_string(stderr)
     line = next(l for l in stderr.splitlines() if l.startswith('SMTInterpol'))
     line = line.replace('SMTInterpol' , '')
     return line.strip()
Beispiel #9
0
def init(config, benchmark):
    config.containerargs = {}
    if config.container:
        if config.users is not None:
            sys.exit("Cannot use --user in combination with --container.")
        config.containerargs = containerexecutor.handle_basic_container_args(config)
        config.containerargs["use_namespaces"] = True
    else:
        if config.users is not None:
            logging.warning(
                "Executing benchmarks at another user with --user is deprecated and may be removed in the future. "
                "Consider using the container mode instead for isolating runs "
                "(cf. https://github.com/sosy-lab/benchexec/issues/215).")
        elif not config.no_container:
            logging.warning(
                "Neither --container or --no-container was specified, "
                "not using containers for isolation of runs. "
                "Either specify --no-container to silence this warning, "
                "or specify --container to use containers for better isolation of runs "
                "(this will be the default starting with BenchExec 2.0). "
                "Please read https://github.com/sosy-lab/benchexec/blob/master/doc/container.md "
                "for more information.")

    try:
        processes = subprocess.Popen(['ps', '-eo', 'cmd'], stdout=subprocess.PIPE).communicate()[0]
        if len(re.findall("python.*benchmark\.py", util.decode_to_string(processes))) > 1:
            logging.warning("Already running instance of this script detected. "
                            "Please make sure to not interfere with somebody else's benchmarks.")
    except OSError:
        pass # this does not work on Windows

    benchmark.executable = benchmark.tool.executable()
    benchmark.tool_version = benchmark.tool.version(benchmark.executable)
Beispiel #10
0
def init(config, benchmark):
    config.containerargs = {}
    if config.container:
        if config.users is not None:
            sys.exit("Cannot use --user in combination with --container.")
        config.containerargs = containerexecutor.handle_basic_container_args(config)
        config.containerargs["use_namespaces"] = True
    elif not config.no_container:
        logging.warning(
            "Neither --container or --no-container was specified, "
            "not using containers for isolation of runs. "
            "Either specify --no-container to silence this warning, "
            "or specify --container to use containers for better isolation of runs "
            "(this will be the default starting with BenchExec 2.0). "
            "Please read https://github.com/sosy-lab/benchexec/blob/master/doc/container.md "
            "for more information.")

    try:
        processes = subprocess.Popen(['ps', '-eo', 'cmd'], stdout=subprocess.PIPE).communicate()[0]
        if len(re.findall("python.*benchmark\.py", util.decode_to_string(processes))) > 1:
            logging.warning("Already running instance of this script detected. "
                            "Please make sure to not interfere with somebody else's benchmarks.")
    except OSError:
        pass # this does not work on Windows

    benchmark.executable = benchmark.tool.executable()
    benchmark.tool_version = benchmark.tool.version(benchmark.executable)
Beispiel #11
0
    def get_java(self):
        candidates = [
            "java",
            "/usr/bin/java",
            "/opt/oracle-jdk-bin-1.8.0.202/bin/java",
            "/usr/lib/jvm/java-8-openjdk-amd64/bin/java",
        ]
        for c in candidates:
            candidate = self.which(c)
            if not candidate:
                continue
            try:
                process = subprocess.Popen(
                    [candidate, "-version"],
                    stdout=subprocess.PIPE,
                    stderr=subprocess.STDOUT,
                )
                (stdout, stderr) = process.communicate()
            except OSError:
                continue

            stdout = util.decode_to_string(stdout).strip()
            if not stdout:
                continue
            if "1.8" in stdout:
                return candidate
        raise BenchExecException(
            "Could not find a suitable Java version: Need Java 1.8")
Beispiel #12
0
 def version(self, executable):
     stderr = subprocess.Popen(self.cmdline(executable, ['-version'], []),
                               stderr=subprocess.PIPE).communicate()[1]
     stderr = util.decode_to_string(stderr)
     line = next(l for l in stderr.splitlines() if l.startswith('SMTInterpol'))
     line = line.replace('SMTInterpol' , '')
     return line.strip()
Beispiel #13
0
 def _version_from_tool(self, executable, arg='--version'):
     """
     Get version of a tool by executing it with argument "--version"
     and returning stdout.
     """
     stdout = subprocess.Popen([executable, arg],
                               stdout=subprocess.PIPE).communicate()[0]
     return util.decode_to_string(stdout).strip()
Beispiel #14
0
 def version(self, executable):
     """
     Sets the version number for SMACK, which gets displayed in the "Tool" row
     in BenchExec table headers.
     """
     process = subprocess.Popen([executable, "--version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     (stdout, stderr) = process.communicate()
     version = util.decode_to_string(stderr).split(" ")[2]
     return version
Beispiel #15
0
def init(config, benchmark):
    benchmark.executable = benchmark.tool.executable()
    benchmark.tool_version = benchmark.tool.version(benchmark.executable)

    try:
        processes = subprocess.Popen(['ps', '-eo', 'cmd'], stdout=subprocess.PIPE).communicate()[0]
        if len(re.findall("python.*benchmark\.py", util.decode_to_string(processes))) > 1:
            logging.warning("Already running instance of this script detected. "
                            "Please make sure to not interfere with somebody else's benchmarks.")
    except OSError:
        pass # this does not work on Windows
Beispiel #16
0
 def version(self, executable):
     """
     Sets the version number for SMACK, which gets displayed in the "Tool" row
     in BenchExec table headers.
     """
     process = subprocess.Popen([executable, '--version'],
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
     (stdout, stderr) = process.communicate()
     version = util.decode_to_string(stderr).split(' ')[2]
     return version
Beispiel #17
0
    def _ultimate_version(self, executable):
        ultimatedir = os.path.dirname(executable)
        launcher_jar = os.path.join(ultimatedir, _LAUNCHER_JAR)
        data_dir = os.path.join(ultimatedir, 'data')
        if not os.path.isfile(launcher_jar):
            logging.warning(
                'Cannot find {0} to determine Ultimate version'.format(
                    _LAUNCHER_JAR))
            return ''

        try:
            process = subprocess.Popen(
                ["java", "-jar", launcher_jar, "-data", data_dir, "--version"],
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE)
            (stdout, stderr) = process.communicate()
        except OSError as e:
            logging.warning(
                'Cannot run Java to determine Ultimate version: {0}'.format(
                    e.strerror))
            return ''
        if stderr:
            logging.warning(
                'Cannot determine Ultimate version, error output: {0}'.format(
                    util.decode_to_string(stderr)))
            return ''
        if process.returncode:
            logging.warning(
                'Cannot determine Ultimate version, exit code {0}'.format(
                    process.returncode))
            return ''

        version_ultimate_match = _ULTIMATE_VERSION_REGEX.search(
            util.decode_to_string(stdout))
        if not version_ultimate_match:
            logging.warning(
                'Cannot determine Ultimate version, output: {0}'.format(
                    util.decode_to_string(stdout)))
            return ''

        return version_ultimate_match.group(1)
Beispiel #18
0
 def _version_from_tool(self, executable, arg='--version'):
     """
     Get version of a tool by executing it with argument "--version"
     and returning stdout.
     """
     try:
         process = subprocess.Popen([executable, arg],
                                    stdout=subprocess.PIPE, stderr=subprocess.PIPE)
         (stdout, stderr) = process.communicate()
     except OSError as e:
         logging.warning('Cannot run {0} to determine version: {1}'.
                         format(executable, e.strerror))
         return ''
     if stderr:
         logging.warning('Cannot determine {0} version, error output: {1}'.
                         format(executable, util.decode_to_string(stderr)))
         return ''
     if process.returncode:
         logging.warning('Cannot determine {0} version, exit code {1}'.
                         format(executable, process.returncode))
         return ''
     return util.decode_to_string(stdout).strip()
Beispiel #19
0
    def _query_ultimate_version(self, cmd, api):
        try:
            process = subprocess.Popen(cmd,
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE)
            (stdout, stderr) = process.communicate()
        except OSError as e:
            logging.warning(
                "Cannot run Java to determine Ultimate version (API %s): %s",
                api,
                e.strerror,
            )
            return ""
        stdout = util.decode_to_string(stdout).strip()
        if stderr or process.returncode:
            logging.warning(
                "Cannot determine Ultimate version (API %s).\n"
                "Command was:     %s\n"
                "Exit code:       %s\n"
                "Error output:    %s\n"
                "Standard output: %s",
                api,
                " ".join(map(util.escape_string_shell, cmd)),
                process.returncode,
                util.decode_to_string(stderr),
                stdout,
            )
            return ""

        version_ultimate_match = _ULTIMATE_VERSION_REGEX.search(stdout)
        if not version_ultimate_match:
            logging.warning(
                "Cannot determine Ultimate version (API %s), output was: %s",
                api,
                stdout,
            )
            return ""
        return version_ultimate_match.group(1)
Beispiel #20
0
 def version(self, executable):
     try:
         process = subprocess.Popen([executable, '-help'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
         (stdout, stderr) = process.communicate()
     except OSError as e:
         logging.warning('Cannot run CPAchecker to determine version: {0}'.format(e.strerror))
         return ''
     if stderr:
         logging.warning('Cannot determine CPAchecker version, error output: {0}'.format(util.decode_to_string(stderr)))
         return ''
     if process.returncode:
         logging.warning('Cannot determine CPAchecker version, exit code {0}'.format(process.returncode))
         return ''
     stdout = util.decode_to_string(stdout)
     line = next(l for l in stdout.splitlines() if l.startswith('CPAchecker'))
     line = line.replace('CPAchecker' , '')
     line = line.split('(')[0]
     return line.strip()
Beispiel #21
0
 def version(self, executable):
     try:
         process = subprocess.Popen([executable, "--version"],
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.DEVNULL)
         (stdout, _) = process.communicate()
     except OSError as e:
         logging.warning('Cannot run {0} to determine version: {1}'.format(
             executable, e.strerror))
         return ''
     if process.returncode:
         logging.warning(
             'Cannot determine {0} version, exit code {1}'.format(
                 executable, process.returncode))
         return ''
     lns = {}
     for l in util.decode_to_string(stdout).strip().splitlines():
         k, v = l.split(':', maxsplit=1)
         lns[k] = v
     return lns['version']
Beispiel #22
0
def init(config, benchmark):
    config.containerargs = {}
    if config.container:
        config.containerargs = containerexecutor.handle_basic_container_args(
            config)
    config.containerargs["use_namespaces"] = config.container

    try:
        processes = subprocess.Popen(["ps", "-eo", "cmd"],
                                     stdout=subprocess.PIPE).communicate()[0]
        if (len(
                re.findall(r"python.*benchmark\.py",
                           util.decode_to_string(processes))) > 1):
            logging.warning(
                "Already running instance of this script detected. "
                "Please make sure to not interfere with somebody else's benchmarks."
            )
    except OSError:
        pass  # this does not work on Windows

    benchmark.executable = benchmark.tool.executable()
    benchmark.tool_version = benchmark.tool.version(benchmark.executable)
    def get_java_installations(self):
        candidates = [
            "java",
            "/usr/bin/java",
            "/opt/oracle-jdk-bin-*/bin/java",
            "/opt/openjdk-*/bin/java",
            "/usr/lib/jvm/java-*-openjdk-amd64/bin/java",
        ]

        candidates = [c for entry in candidates for c in glob.glob(entry)]
        pattern = r'"(\d+\.\d+).*"'

        rtr = {}
        for c in candidates:
            candidate = shutil.which(c)
            if not candidate:
                continue
            try:
                process = subprocess.Popen(
                    [candidate, "-version"],
                    stdout=subprocess.PIPE,
                    stderr=subprocess.STDOUT,
                )
                (stdout, stderr) = process.communicate()
            except OSError:
                continue

            stdout = util.decode_to_string(stdout).strip()
            if not stdout:
                continue
            version = re.search(pattern, stdout).groups()[0]
            if version not in rtr:
                logging.debug("Found Java installation %s with version %s",
                              candidate, version)
                rtr[version] = candidate
        if not rtr:
            raise ToolNotFoundException("Could not find any Java version")
        return rtr
Beispiel #24
0
 def version(self, executable):
     out = subprocess.Popen(self.cmdline(executable, ['-version'], []),
                               stderr=subprocess.PIPE).communicate()[1]
     out = util.decode_to_string(out)
     return out.strip()