Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature to use podman container when determining version for vcloud-benchmark #1132

Merged
merged 30 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
db58a2c
wrap the call to the tool to obtain a version inside of a podman cont…
ricffb Dec 3, 2024
d6e65d9
explicitly check for Noneness of tool_base_dir
ricffb Dec 3, 2024
ca7aad9
add setns to libc
ricffb Dec 4, 2024
a2abe90
sort imports
ricffb Dec 4, 2024
6ac1b20
add podman containerized tool
ricffb Dec 4, 2024
a28f1ad
hook into the load toolinfo process
ricffb Dec 4, 2024
6252252
add CustomToolLocator that is used in conjunction with the PodmanCont…
ricffb Dec 4, 2024
dab9a0d
cd into the tool directory in case tools makes calls relative to itself
ricffb Dec 4, 2024
ed499c4
remove erroneous relpath call
ricffb Dec 4, 2024
6a4760b
find the files to upload to vcloud again
ricffb Dec 4, 2024
e673acd
the vcloud executor needs to know about the executable location on th…
ricffb Dec 4, 2024
517fbea
custom tool locator need not now about original tool directory
ricffb Dec 9, 2024
ddecc42
assert tool-directory is set
ricffb Dec 9, 2024
3808261
make it clearer whats the purpose of thee load tool info hook
ricffb Dec 9, 2024
50a7eaf
rename for clarity
ricffb Dec 9, 2024
7a34dd4
use shlex
ricffb Dec 9, 2024
e838dd7
simplify container init
ricffb Dec 9, 2024
a68c0ea
refactor containerized tool info modules for improved code sharing
ricffb Dec 9, 2024
bb2a485
remove wrong initializer
ricffb Dec 9, 2024
5bf07ad
remove config from mk_arg
ricffb Dec 9, 2024
b4a3296
use the defined executable
ricffb Dec 9, 2024
d065835
improve refactoring: keep ContainerizedTool much more like it was bef…
ricffb Dec 9, 2024
dde1397
use podman create, init and rm instead of run and kill
ricffb Dec 9, 2024
374f90b
use Paths, procedual style, and += for list
ricffb Dec 9, 2024
f9ff207
move setup and cleanup specific to ContainerizedTool
ricffb Dec 11, 2024
924e599
report error of missing tool_directory earlier
ricffb Dec 11, 2024
430997f
do not leak a Path instance into benchexec
ricffb Dec 11, 2024
33b0857
add output check to podman inspect call
ricffb Dec 11, 2024
c7c0e54
get rid of custom tool locator
ricffb Dec 11, 2024
195dada
improve checking of valid paths returned from the tool_info_module
ricffb Dec 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions benchexec/libc.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ def _check_errno(result, func, arguments):
unshare.argtypes = [c_int]
unshare.errcheck = _check_errno

setns = _libc.setns
"""Set the current process namespace(s)."""
setns.argtypes = [c_int, c_int]
setns.errcheck = _check_errno

mmap = _libc.mmap
"""Map file into memory."""
Expand Down
48 changes: 45 additions & 3 deletions contrib/vcloud-benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,29 @@

import logging
import os
import subprocess
import sys
import tempfile
import urllib.request
import subprocess

sys.dont_write_bytecode = True # prevent creation of .pyc files
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))

from vcloud.vcloudbenchmarkbase import VcloudBenchmarkBase # noqa E402
from vcloud import vcloudutil # noqa E402
from benchexec import __version__ # noqa E402
from vcloud.vcloudbenchmarkbase import VcloudBenchmarkBase # noqa E402

import benchexec.benchexec # noqa E402
import benchexec.model # noqa E402
import benchexec.tools # noqa E402
from benchexec import __version__ # noqa E402

_ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "vcloud"))
IVY_JAR_NAME = "ivy-2.5.0.jar"
IVY_PATH = os.path.join(_ROOT_DIR, "lib", IVY_JAR_NAME)
IVY_DOWNLOAD_URL = "https://www.sosy-lab.org/ivy/org.apache.ivy/ivy/" + IVY_JAR_NAME

real_load_tool_info = benchexec.model.load_tool_info
PhilippWendler marked this conversation as resolved.
Show resolved Hide resolved


def download_required_jars(config):
# download ivy if needed
Expand Down Expand Up @@ -71,6 +75,44 @@ def download_required_jars(config):
temp_dir.cleanup()


def hook_load_tool_info(tool_name, config):
"""
Load the tool-info class.
@param tool_name: The name of the tool-info module.
Either a full Python package name or a name within the benchexec.tools package.
@return: A tuple of the full name of the used tool-info module and an instance of the tool-info class.
"""
tool_module = tool_name if "." in tool_name else f"benchexec.tools.{tool_name}"
try:
if config.containerImage:
import vcloud.podman_containerized_tool as pod

tool = pod.PodmanContainerizedTool(
tool_module, config, config.containerImage
)
else:
_, tool = real_load_tool_info(tool_module, config)
PhilippWendler marked this conversation as resolved.
Show resolved Hide resolved

except ImportError as ie:
logging.debug(
"Did not find module '%s'. "
"Python probably looked for it in one of the following paths:\n %s",
tool_module,
"\n ".join(path or "." for path in sys.path),
)
sys.exit(f'Unsupported tool "{tool_name}" specified. ImportError: {ie}')
except AttributeError as ae:
sys.exit(
f'Unsupported tool "{tool_name}" specified, class "Tool" is missing: {ae}'
)
except TypeError as te:
sys.exit(f'Unsupported tool "{tool_name}" specified. TypeError: {te}')
return tool_module, tool


benchexec.model.load_tool_info = hook_load_tool_info


class VcloudBenchmark(VcloudBenchmarkBase):
"""
Benchmark class that defines the load_executor function.
Expand Down
91 changes: 88 additions & 3 deletions contrib/vcloud/benchmarkclient_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
import shutil
import subprocess
import sys
from pathlib import Path

import benchexec.tooladapter
import benchexec.util
from benchexec.tools.template import ToolNotFoundException

from . import vcloudutil

Expand All @@ -35,12 +37,95 @@ def set_vcloud_jar_path(p):
vcloud_jar = p


class CustomToolLocator:
def __init__(self, tool_directory=None, container_mount_point=None):
self.tool_directory = tool_directory
self.container_mount_point = container_mount_point

def find_executable(self, executable_name, subdir=""):
logging.debug(
"Using custom tool locator to find executable %s", executable_name
)
assert (
os.path.basename(executable_name) == executable_name
), "Executable needs to be a simple file name"
dirs = []

if not self.tool_directory:
raise ToolNotFoundException(
"Podman containerized tool info module execution is only possible with --tool-directory explicitly set."
)

assert self.container_mount_point is not None, "Container mount point not set"

# At this point we know, that the tool is located at container_mount_point
# as the container as the tool_dir mounted to this location
dirs.append(os.path.join(self.container_mount_point, subdir))
logging.debug("Searching for executable %s in %s", executable_name, dirs)

executable = benchexec.util.find_executable2(executable_name, dirs)
if executable:
return executable

other_file = benchexec.util.find_executable2(executable_name, dirs, os.F_OK)
if other_file:
raise ToolNotFoundException(
f"Could not find executable '{executable_name}', "
f"but found file '{other_file}' that is not executable."
)

msg = (
f"Could not find executable '{executable_name}'. "
f"The searched directories were: " + "".join("\n " + d for d in dirs)
)
if not self.tool_directory:
msg += "\nYou can specify the tool's directory with --tool-directory."

raise ToolNotFoundException(msg)
PhilippWendler marked this conversation as resolved.
Show resolved Hide resolved


def init(config, benchmark):
global _JustReprocessResults
_JustReprocessResults = config.reprocessResults
tool_locator = benchexec.tooladapter.create_tool_locator(config)
benchmark.executable = benchmark.tool.executable(tool_locator)
benchmark.tool_version = benchmark.tool.version(benchmark.executable)

if config.containerImage:
from vcloud.podman_containerized_tool import TOOL_DIRECTORY_MOUNT_POINT

tool_locator = CustomToolLocator(
config.tool_directory, TOOL_DIRECTORY_MOUNT_POINT
)
executable_for_version = benchmark.tool.executable(tool_locator)
benchmark.tool_version = benchmark.tool.version(executable_for_version)

# If the tool info does not call find_executable, we don't know if the
# executable path is containing the mount point.
# In this case we can check whether the path is relative
# and continue with the assumption that it is relative to the provided
# tool directory.
try:
executable_relative_to_mount_point = Path(
executable_for_version
).relative_to(TOOL_DIRECTORY_MOUNT_POINT)
PhilippWendler marked this conversation as resolved.
Show resolved Hide resolved
except ValueError:
if Path(executable_for_version).is_absolute():
raise ValueError(
f"Executable path {executable_for_version} is not relative"
" and is not containing the expected container to the mount point"
" {TOOL_DIRECTORY_MOUNT_POINT}"
) from None
executable_relative_to_mount_point = executable_for_version

# The vcloud uses the tool location later to determine which files need to be uploaded
# So this needs to point to the actual path where the executable is on the host
benchmark.executable = (
Path(config.tool_directory) / executable_relative_to_mount_point
)
PhilippWendler marked this conversation as resolved.
Show resolved Hide resolved

else:
tool_locator = benchexec.tooladapter.create_tool_locator(config)
benchmark.executable = benchmark.tool.executable(tool_locator)
benchmark.tool_version = benchmark.tool.version(executable_for_version)

environment = benchmark.environment()
if environment.get("keepEnv", None) or environment.get("additionalEnv", None):
sys.exit(
Expand Down
Loading
Loading