Commit 3040b097 authored by Johannes Bechberger's avatar Johannes Bechberger

Fix `compile-firm` mode (error code) bug

parent 7c898e5c
...@@ -56,22 +56,26 @@ class JavaExecTest(BasicSyntaxTest): ...@@ -56,22 +56,26 @@ 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))
test_result.incorrect_msg = "invalid java code, but output file missing" test_result.incorrect_msg = "invalid java code, but output file missing"
test_result.error_code = javac_rtcode test_result.set_error_code(javac_rtcode)
test_result.add_long_text("Javac error message", err.decode()) test_result.add_long_text("Javac error message", err.decode())
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")
if not main_class:
_LOG.debug("Can't find a main class, using the file name instead")
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"))
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"
test_result.error_code = java_rtcode test_result.set_error_code(java_rtcode)
test_result.add_long_text("Java error message", err.decode()) test_result.add_long_text("Java error message", err.decode())
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
exp_out = exp_out.decode().strip() exp_out = exp_out.decode()
with open(self._prev_out_file, "w") as f: with open(self._prev_out_file, "w") as f:
f.write(exp_out) f.write(exp_out)
...@@ -90,7 +94,7 @@ class JavaExecTest(BasicSyntaxTest): ...@@ -90,7 +94,7 @@ class JavaExecTest(BasicSyntaxTest):
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")
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.error_code = rtcode test_result.set_error_code(rtcode)
test_result.add_long_text("Error output", err.decode()) test_result.add_long_text("Error output", err.decode())
test_result.add_long_text("Output", out.decode()) test_result.add_long_text("Output", out.decode())
test_result.add_file("Source file", self.preprocessed_file) test_result.add_file("Source file", self.preprocessed_file)
...@@ -98,7 +102,7 @@ class JavaExecTest(BasicSyntaxTest): ...@@ -98,7 +102,7 @@ class JavaExecTest(BasicSyntaxTest):
return test_result return test_result
except SigKill as sig: except SigKill as sig:
test_result.incorrect_msg = "file can't be compiled: " + sig.name test_result.incorrect_msg = "file can't be compiled: " + sig.name
test_result.error_code = sig.retcode test_result.set_error_code(sig.retcode)
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
...@@ -106,31 +110,23 @@ class JavaExecTest(BasicSyntaxTest): ...@@ -106,31 +110,23 @@ class JavaExecTest(BasicSyntaxTest):
os.chdir(cwd) os.chdir(cwd)
raise raise
try: try:
out, err, rtcode = self.env.run_command("./" + base_filename) out, err, _ = self.env.run_command("./" + base_filename)
if rtcode != 0:
test_result.incorrect_msg = "file can't be run"
test_result.error_code = rtcode
test_result.add_long_text("Error output", err.decode())
test_result.add_long_text("Output", out.decode())
test_result.add_file("Source file", self.preprocessed_file)
os.chdir(cwd)
return test_result
except SigKill as sig: except SigKill as sig:
test_result.incorrect_msg = "binary can't be run: " + sig.name test_result.incorrect_msg = "binary can't be run: " + sig.name.strip()
test_result.error_code = sig.retcode test_result.set_error_code(sig.retcode)
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
except: except:
os.chdir(cwd) os.chdir(cwd)
raise raise
out = out.decode().strip() out = out.decode()
if self.type == self.MODE and self.env.mode == self.MODE: if self.type == self.MODE and self.env.mode == self.MODE:
test_result.add_long_text("Output", out.decode()) test_result.add_long_text("Output", out)
if exp_out.strip() != out.strip(): if exp_out.strip() != out.strip():
test_result.incorrect_msg = "incorrect output" test_result.incorrect_msg = "incorrect output"
test_result.has_succeeded = False test_result.has_succeeded = False
test_result.add_diff("Output diff [expected <-> actual]", exp_out, out) test_result.add_diff("Output diff [expected <-> actual]", exp_out, out, with_line_numbers=True)
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
...@@ -181,7 +177,7 @@ class JavaInfiniteLoopTest(BasicSyntaxTest): ...@@ -181,7 +177,7 @@ class JavaInfiniteLoopTest(BasicSyntaxTest):
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")
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.error_code = rtcode test_result.set_error_code(rtcode)
test_result.add_long_text("Error output", err.decode()) test_result.add_long_text("Error output", err.decode())
test_result.add_long_text("Output", out.decode()) test_result.add_long_text("Output", out.decode())
test_result.add_file("Source file", self.preprocessed_file) test_result.add_file("Source file", self.preprocessed_file)
...@@ -189,8 +185,8 @@ class JavaInfiniteLoopTest(BasicSyntaxTest): ...@@ -189,8 +185,8 @@ class JavaInfiniteLoopTest(BasicSyntaxTest):
return test_result return test_result
out, err, rtcode = self.env.run_command("./" + base_filename, timeout=timeout) out, err, rtcode = self.env.run_command("./" + base_filename, timeout=timeout)
if rtcode != 0: if rtcode != 0:
test_result.incorrect_msg = "file can't be run" test_result.incorrect_msg = "binary can't be run"
test_result.error_code = rtcode test_result.set_error_code(rtcode)
test_result.add_long_text("Error output", err.decode()) test_result.add_long_text("Error output", err.decode())
test_result.add_long_text("Output", out.decode()) test_result.add_long_text("Output", out.decode())
test_result.add_file("Source file", self.preprocessed_file) test_result.add_file("Source file", self.preprocessed_file)
...@@ -217,7 +213,7 @@ class JavaInfiniteLoopTest(BasicSyntaxTest): ...@@ -217,7 +213,7 @@ class JavaInfiniteLoopTest(BasicSyntaxTest):
return test_result return test_result
else: else:
test_result.incorrect_msg = "binary can't be run: " + sig.name test_result.incorrect_msg = "binary can't be run: " + sig.name
test_result.error_code = sig.retcode test_result.set_error_code(sig.retcode)
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
......
...@@ -367,6 +367,9 @@ class ExtensibleTestResult(TestResult): ...@@ -367,6 +367,9 @@ class ExtensibleTestResult(TestResult):
self.add_long_text(title, "".join(difflib.Differ().compare(first.splitlines(True), second.splitlines(True))), self.add_long_text(title, "".join(difflib.Differ().compare(first.splitlines(True), second.splitlines(True))),
with_line_numbers=with_line_numbers) with_line_numbers=with_line_numbers)
def set_error_code(self, error_code: int):
self.has_succeeded = error_code == 0
self.error_code = error_code
class TestResultMessage: class TestResultMessage:
......
...@@ -87,7 +87,7 @@ class _Execute(object): ...@@ -87,7 +87,7 @@ class _Execute(object):
def run(self): def run(self):
if self.timeout > 0.0: if self.timeout > 0.0:
_LOG.debug("run with timeout %.1f" % float(self.timeout)) _LOG.debug("run with timeout %.1f: %s" % (float(self.timeout), self.cmd))
thread = threading.Thread(target=self._run_process) thread = threading.Thread(target=self._run_process)
thread.start() thread.start()
thread.join(float(self.timeout)) thread.join(float(self.timeout))
......
...@@ -49,8 +49,8 @@ def get_main_class_name(file: str) -> Optional[str]: ...@@ -49,8 +49,8 @@ def get_main_class_name(file: str) -> Optional[str]:
current_class = None current_class = None
with open(file, "r") as f: with open(file, "r") as f:
for line in f: for line in f:
if line.startswith("class "): if line.startswith("class ") or line.startswith("/*public*/ class "):
match = re.search("[A-Za-z_0-9]+", line.replace("class ", "")) match = re.search("[A-Za-z_0-9]+", line.replace("class ", "").replace("/*public*/", ""))
if match: if match:
has_public_class = True has_public_class = True
current_class = match.group(0) current_class = match.group(0)
......
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