Use a barebones environment to run benchmarks.
@@ -195,12 +195,19 @@ def _compile_and_run_bitcode_file(
)
assert binary.is_file()
+ # Create a barebones environment to run benchmark in.
+ env = {
+ "TMPDIR": os.environ.get("TMPDIR", ""),
+ "HOME": os.environ.get("HOME", ""),
+ "USER": os.environ.get("USER", ""),
+ }
+
process = subprocess.Popen(
cmd,
shell=True,
stderr=subprocess.STDOUT,
stdout=subprocess.PIPE,
- env=os.environ,
+ env=env,
cwd=cwd,
)
@@ -276,7 +283,6 @@ def _make_cBench_validator(
# directory.
output_paths = [cwd / o for o in output_files]
- with benchmark_execution_environment(os_env):
if pre_execution_callback:
pre_execution_callback(cwd)
@@ -381,27 +387,6 @@ def temporary_environment():
os.environ.update(_environ)
-@contextmanager
-def benchmark_execution_environment(env: Dict[str, str]):
- """Setup the os.environ state for executing benchmarks."""
- with temporary_environment():
- for var in os.environ:
- if not var.startswith("COMPILER_GYM_SITE_DATA") and var not in {
- "PATH",
- "RUNFILES_DIR",
- "RUNFILES_MANIFEST_FILE",
- "USER",
- "SHELL",
- "TERM",
- "TMPDIR",
- "HOME",
- }:
- del os.environ[var]
- for key, val in env.items():
- os.environ[key] = expand_command_vars(val)
- yield
-
-
def expand_command_vars(cmd: str) -> str:
"""Expand shell variables in a command."""
with temporary_environment():
