Commit b8fdbb2b authored by Johannes Bechberger's avatar Johannes Bechberger

Improve infinite loop test cases runner

parent b8bd79dd
...@@ -17,8 +17,8 @@ class JavaExecTest(BasicSyntaxTest): ...@@ -17,8 +17,8 @@ class JavaExecTest(BasicSyntaxTest):
The MiniJava compiler should behave the same as javac The MiniJava compiler should behave the same as javac
""" """
FILE_ENDINGS = [".java"] FILE_ENDINGS = [".java", ".mj"]
INVALID_FILE_ENDINGS = [".inf.java"] INVALID_FILE_ENDINGS = [".inf.java", ".inf.mj"]
OUTPUT_FILE_ENDING = ".out" OUTPUT_FILE_ENDING = ".out"
MODE = TestMode.compile_firm MODE = TestMode.compile_firm
...@@ -96,11 +96,14 @@ TestCase.TEST_CASE_CLASSES[TestMode.compile_firm].append(JavaExecTest) ...@@ -96,11 +96,14 @@ TestCase.TEST_CASE_CLASSES[TestMode.compile_firm].append(JavaExecTest)
class JavaInfiniteLoopTest(BasicSyntaxTest): class JavaInfiniteLoopTest(BasicSyntaxTest):
FILE_ENDINGS = [".inf.java"] FILE_ENDINGS = [".inf.java", ".inf.mj"]
OUTPUT_FILE_ENDING = ".out"
MODE = TestMode.compile_firm MODE = TestMode.compile_firm
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)
self._output_file = self.file + self.OUTPUT_FILE_ENDING
self._has_output_file = path.exists(self._output_file)
def run(self) -> BasicTestResult: def run(self) -> BasicTestResult:
base_filename = path.basename(self.file).split(".")[0] base_filename = path.basename(self.file).split(".")[0]
...@@ -109,20 +112,31 @@ class JavaInfiniteLoopTest(BasicSyntaxTest): ...@@ -109,20 +112,31 @@ class JavaInfiniteLoopTest(BasicSyntaxTest):
cwd = os.getcwd() cwd = os.getcwd()
os.chdir(tmp_dir) os.chdir(tmp_dir)
timeout = 1 timeout = 1
err = ""
out = ""
out2 = ""
try: try:
_, err, rtcode = self.env.run_mj_command(self.MODE, base_filename + ".java") out2, err, rtcode = self.env.run_mj_command(self.MODE, base_filename + ".java")
out, _, _ = self.env.run_command("./" + base_filename, timeout=timeout) out, _, _ = self.env.run_command("./" + base_filename, timeout=timeout)
except SigKill as kill: except SigKill as kill:
os.chdir(cwd) os.chdir(cwd)
if kill.retcode == signal.SIGXCPU: if kill.retcode == signal.SIGXCPU:
return BasicTestResult(self, err.decode(), 0, out.decode()) if self._has_output_file:
out = out.decode().strip()
exp_out = ""
with open(self._output_file, "r") as f:
exp_out = f.read().strip()
if not out.startswith(exp_out):
return BasicDiffTestResult(self, 1, out, err.decode(), exp_out,
"Output doesn't start like expected")
return BasicTestResult(self, 0, err.decode(), out.decode())
else: else:
return BasicTestResult(self, kill.retcode, "", "", "No timeout, got " + kill.name) return BasicTestResult(self, kill.retcode, "", err.decode(), "No timeout, got " + kill.name)
except: except:
os.chdir(cwd) os.chdir(cwd)
raise raise
os.chdir(cwd) os.chdir(cwd)
return BasicTestResult(self, 1, "", "", "No timeout") return BasicTestResult(self, 1, "", err.decode(), "No timeout")
TestCase.TEST_CASE_CLASSES[TestMode.compile_firm].append(JavaInfiniteLoopTest) TestCase.TEST_CASE_CLASSES[TestMode.compile_firm].append(JavaInfiniteLoopTest)
\ No newline at end of file
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