Commit a546fdae authored by Johannes Bechberger's avatar Johannes Bechberger

Use process local tmp directories

parent 8fc40c3f
...@@ -5,6 +5,8 @@ import shutil ...@@ -5,6 +5,8 @@ import shutil
import tempfile import tempfile
from datetime import datetime from datetime import datetime
import time import time
from typing import Dict
from mjtest.util.shell import execute from mjtest.util.shell import execute
from mjtest.util.utils import get_mjtest_basedir, force_colored_output from mjtest.util.utils import get_mjtest_basedir, force_colored_output
import mjtest.util.utils import mjtest.util.utils
...@@ -94,6 +96,7 @@ class Environment: ...@@ -94,6 +96,7 @@ class Environment:
self.ci_testing = ci_testing self.ci_testing = ci_testing
self._tmp_file_ctr = 0 self._tmp_file_ctr = 0
self._already_preprocessed_files = set() self._already_preprocessed_files = set()
self._pid_tmpdirs = {} # type: Dict[int, str]
def create_tmpfile(self) -> str: def create_tmpfile(self) -> str:
self._tmp_file_ctr += 1 self._tmp_file_ctr += 1
...@@ -105,6 +108,12 @@ class Environment: ...@@ -105,6 +108,12 @@ class Environment:
os.mkdir(dir) os.mkdir(dir)
return dir return dir
def create_pid_local_tmpdir(self) -> str:
pid = os.getpid()
if pid not in self._pid_tmpdirs:
self._pid_tmpdirs[pid] = self.create_tmpdir()
return self._pid_tmpdirs[pid]
def clean_up(self): def clean_up(self):
if not self.own_tmp_dir: if not self.own_tmp_dir:
shutil.rmtree(self.tmp_dir) shutil.rmtree(self.tmp_dir)
......
...@@ -35,7 +35,7 @@ class JavaExecTest(BasicSyntaxTest): ...@@ -35,7 +35,7 @@ class JavaExecTest(BasicSyntaxTest):
def run(self) -> BasicDiffTestResult: def run(self) -> BasicDiffTestResult:
base_filename = path.basename(self.file).split(".")[0] base_filename = path.basename(self.file).split(".")[0]
tmp_dir = self.env.create_tmpdir() tmp_dir = self.env.create_pid_local_tmpdir()
shutil.copy(self.preprocessed_file, path.join(tmp_dir, base_filename + ".java")) shutil.copy(self.preprocessed_file, path.join(tmp_dir, base_filename + ".java"))
cwd = os.getcwd() cwd = os.getcwd()
os.chdir(tmp_dir) os.chdir(tmp_dir)
...@@ -46,7 +46,6 @@ class JavaExecTest(BasicSyntaxTest): ...@@ -46,7 +46,6 @@ class JavaExecTest(BasicSyntaxTest):
if javac_rtcode != 0: if javac_rtcode != 0:
_LOG.error("File \"{}\" isn't valid Java".format(self.preprocessed_file)) _LOG.error("File \"{}\" isn't valid Java".format(self.preprocessed_file))
os.chdir(cwd) os.chdir(cwd)
shutil.rmtree(tmp_dir)
raise InterruptedError() raise InterruptedError()
exp_out, _, _ = \ exp_out, _, _ = \
self.env.run_command("java", base_filename) self.env.run_command("java", base_filename)
...@@ -62,7 +61,6 @@ class JavaExecTest(BasicSyntaxTest): ...@@ -62,7 +61,6 @@ class JavaExecTest(BasicSyntaxTest):
out, _, _ = self.env.run_command("./" + base_filename) out, _, _ = self.env.run_command("./" + base_filename)
out = out.decode().strip() out = out.decode().strip()
os.chdir(cwd) os.chdir(cwd)
shutil.rmtree(tmp_dir)
if self.type == self.MODE and self.env.mode == self.MODE: if self.type == self.MODE and self.env.mode == self.MODE:
return BasicDiffTestResult(self, rtcode, out, err.decode(), exp_out) return BasicDiffTestResult(self, rtcode, out, err.decode(), exp_out)
return BasicTestResult(self, rtcode, out.decode(), err.decode()) return BasicTestResult(self, rtcode, out.decode(), err.decode())
......
...@@ -39,11 +39,10 @@ class JavaCompileTest(BasicSyntaxTest): ...@@ -39,11 +39,10 @@ class JavaCompileTest(BasicSyntaxTest):
def __init__(self, env: Environment, type: str, file: str, preprocessed_file: str): def __init__(self, env: Environment, type: str, file: str, preprocessed_file: str):
super().__init__(env, type, file, preprocessed_file) super().__init__(env, type, file, preprocessed_file)
tmp_dir = self.env.create_tmpdir() tmp_dir = self.env.create_pid_local_tmpdir()
_, self.javac_err, self.javac_rtcode = \ _, self.javac_err, self.javac_rtcode = \
self.env.run_command("javac", path.relpath(preprocessed_file), "-d", tmp_dir, "-verbose") self.env.run_command("javac", path.relpath(preprocessed_file), "-d", tmp_dir, "-verbose")
self.javac_err = self.javac_err.decode() # type: str self.javac_err = self.javac_err.decode() # type: str
shutil.rmtree(tmp_dir, ignore_errors=True)
self._should_succeed = self._is_file_syntactically_correct() if self.SYNTAX_TEST else self.javac_rtcode == 0 self._should_succeed = self._is_file_syntactically_correct() if self.SYNTAX_TEST else self.javac_rtcode == 0
def _is_file_syntactically_correct(self): def _is_file_syntactically_correct(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment