Commit bcf87cbe authored by ufebl's avatar ufebl

Add infinite loop test for own backend as well

parent 112312f5
......@@ -332,6 +332,88 @@ class JavaInfiniteLoopTest(BasicSyntaxTest):
TestCase.TEST_CASE_CLASSES[TestMode.compile_firm].append(JavaInfiniteLoopTest)
class JavaInfiniteLoopTest2(BasicSyntaxTest):
FILE_ENDINGS = [".inf.java", ".inf.mj"]
OUTPUT_FILE_ENDING = ".out"
MODE = TestMode.compile
def __init__(self, env: Environment, type: str, file: str, preprocessed_file: str, log_file_mode: str):
super().__init__(env, type, file, preprocessed_file, log_file_mode)
self._output_file = self.file + self.OUTPUT_FILE_ENDING
self._has_output_file = path.exists(self._output_file)
def run(self) -> BasicTestResult:
base_filename = path.basename(self.file).split(".")[0]
tmp_dir = self.env.create_pid_local_tmpdir()
shutil.copy(self.preprocessed_file, path.join(tmp_dir, base_filename + ".java"))
cwd = os.getcwd()
os.chdir(tmp_dir)
timeout = 1
err = None
out = None
rtcode = None
test_result = ExtensibleTestResult(self)
try:
out, err, rtcode = self.env.run_mj_command(self.MODE, base_filename + ".java")
if rtcode != 0:
test_result.incorrect_msg = "file can't be compiled"
test_result.set_error_code(rtcode)
test_result.add_long_text("Error output", decode(err))
test_result.add_long_text("Output", decode(out))
test_result.add_file("Source file", self.preprocessed_file)
os.chdir(cwd)
return test_result
out, err, rtcode = self.env.run_command("./a.out", timeout=timeout)
if rtcode != 0:
test_result.incorrect_msg = "binary can't be run, non zero error code"
test_result.set_error_code(rtcode)
test_result.add_long_text("Error output", decode(err))
test_result.add_long_text("Output", decode(out))
test_result.add_file("Source file", self.preprocessed_file)
os.chdir(cwd)
return test_result
except SigKill as sig:
if sig.retcode == signal.SIGXCPU:
out, _, _, _ = self.env.run_command_till_timeout("./a.out", timeout=1)
test_result.add_long_text("Output", decode(out))
if self._has_output_file:
out = decode(out).strip()
exp_out = ""
with open(self._output_file, "r", errors="backslashreplace") as f:
exp_out = f.read().strip()
test_result.add_long_text("Expected output start", exp_out)
if not out.startswith(exp_out):
test_result.incorrect_msg = "incorrect output start"
test_result.has_succeeded = False
test_result.add_file("Source file", self.preprocessed_file)
os.chdir(cwd)
return test_result
else:
test_result.add_file("Source file", self.preprocessed_file)
os.chdir(cwd)
return test_result
else:
test_result.incorrect_msg = "binary can't be run: " + sig.name
test_result.set_error_code(sig.retcode)
test_result.add_file("Source file", self.preprocessed_file)
os.chdir(cwd)
return test_result
except BaseException as e:
os.chdir(cwd)
print(e)
raise
os.chdir(cwd)
test_result.incorrect_msg = "run shorter than one second"
test_result.add_long_text("Output", out)
test_result.has_succeeded = False
test_result.add_file("Source file", self.preprocessed_file)
os.chdir(cwd)
return test_result
TestCase.TEST_CASE_CLASSES[TestMode.compile].append(JavaInfiniteLoopTest2)
class InvalidJavaExecTest(BasicSyntaxTest):
"""
The compiled binary should fail to execute properly
......
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