Commit ffc2cde8 authored by Johannes Bechberger's avatar Johannes Bechberger

Use shorter timeouts and make them adjustable

parent c9d130de
...@@ -88,7 +88,6 @@ class Environment: ...@@ -88,7 +88,6 @@ class Environment:
self.only_incorrect_tests = only_incorrect_tests self.only_incorrect_tests = only_incorrect_tests
self.parallel = parallel self.parallel = parallel
self.timeout = timeout
if not produce_no_reports: if not produce_no_reports:
if report_dir: if report_dir:
self.report_dir = os.path.abspath(os.path.expandvars(report_dir)) self.report_dir = os.path.abspath(os.path.expandvars(report_dir))
...@@ -113,6 +112,9 @@ class Environment: ...@@ -113,6 +112,9 @@ class Environment:
self._pid_tmpdirs = {} # type: Dict[int, str] self._pid_tmpdirs = {} # type: Dict[int, str]
self.only_small_exec_tests = not all_exec_tests self.only_small_exec_tests = not all_exec_tests
self.timeout = float(os.getenv("MJ_TIMEOUT", "5"))
self.big_timeout = float(os.getenv("MJ_BIG_TIMEOUT", "30"))
def create_tmpfile(self) -> str: def create_tmpfile(self) -> str:
self._tmp_file_ctr += 1 self._tmp_file_ctr += 1
return os.path.join(self.tmp_dir, str(round(time.time() * 100000)) return os.path.join(self.tmp_dir, str(round(time.time() * 100000))
......
...@@ -40,6 +40,8 @@ class JavaExecTest(BasicSyntaxTest): ...@@ -40,6 +40,8 @@ class JavaExecTest(BasicSyntaxTest):
self._should_succeed = True self._should_succeed = True
def run(self) -> BasicDiffTestResult: def run(self) -> BasicDiffTestResult:
is_big_testcase = "big" in self.file
timeout = self.env.big_timeout if is_big_testcase else self.env.timeout
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_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"))
...@@ -52,7 +54,7 @@ class JavaExecTest(BasicSyntaxTest): ...@@ -52,7 +54,7 @@ class JavaExecTest(BasicSyntaxTest):
if not self._has_expected_output_file: if not self._has_expected_output_file:
_, err, javac_rtcode = \ _, err, javac_rtcode = \
self.env.run_command("javac", base_filename + ".java") self.env.run_command("javac", base_filename + ".java", timeout=timeout)
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))
test_result.incorrect_msg = "invalid java code, but output file missing" test_result.incorrect_msg = "invalid java code, but output file missing"
...@@ -61,12 +63,12 @@ class JavaExecTest(BasicSyntaxTest): ...@@ -61,12 +63,12 @@ class JavaExecTest(BasicSyntaxTest):
test_result.add_file("Source file", self.preprocessed_file) test_result.add_file("Source file", self.preprocessed_file)
os.chdir(cwd) os.chdir(cwd)
return test_result return test_result
main_class = get_main_class_name(base_filename + ".java") main_class = get_main_class_name(base_filename + ".java", timeout=timeout)
if not main_class: if not main_class:
_LOG.debug("Can't find a main class, using the file name instead") _LOG.debug("Can't find a main class, using the file name instead")
main_class = base_filename main_class = base_filename
exp_out, err, java_rtcode = \ exp_out, err, java_rtcode = \
self.env.run_command("java", get_main_class_name(base_filename + ".java")) self.env.run_command("java", get_main_class_name(base_filename + ".java"), timeout=timeout)
test_result.add_long_text("Java output: ", exp_out.decode()) test_result.add_long_text("Java output: ", exp_out.decode())
if javac_rtcode != 0: if javac_rtcode != 0:
test_result.incorrect_msg = "java runtime error" test_result.incorrect_msg = "java runtime error"
...@@ -91,7 +93,7 @@ class JavaExecTest(BasicSyntaxTest): ...@@ -91,7 +93,7 @@ class JavaExecTest(BasicSyntaxTest):
try: try:
out, err, rtcode = None, None, None out, err, rtcode = None, None, None
try: try:
out, err, rtcode = self.env.run_mj_command(self.MODE, base_filename + ".java") out, err, rtcode = self.env.run_mj_command(self.MODE, base_filename + ".java", timeout=timeout)
if rtcode != 0: if rtcode != 0:
test_result.incorrect_msg = "file can't be compiled" test_result.incorrect_msg = "file can't be compiled"
test_result.set_error_code(rtcode) test_result.set_error_code(rtcode)
...@@ -110,7 +112,7 @@ class JavaExecTest(BasicSyntaxTest): ...@@ -110,7 +112,7 @@ class JavaExecTest(BasicSyntaxTest):
os.chdir(cwd) os.chdir(cwd)
raise raise
try: try:
out, err, rtcode = self.env.run_command("./" + base_filename) out, err, rtcode = self.env.run_command("./" + base_filename, timeout=timeout)
if rtcode != 0: if rtcode != 0:
test_result.incorrect_msg = "binary can't be run, non zero error code" test_result.incorrect_msg = "binary can't be run, non zero error code"
test_result.set_error_code(rtcode) test_result.set_error_code(rtcode)
......
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