Commit e134e8a8 authored by Johannes Bechberger's avatar Johannes Bechberger

Add `--compile-(firm)-only` to compile successful semantic tests

Fix #2 and #1
parent 20bd1041
...@@ -23,7 +23,9 @@ The test cases are divided in 6 'modes': ...@@ -23,7 +23,9 @@ The test cases are divided in 6 'modes':
them. them.
- __ast__: Test cases that check the generated ast by using the pretty printing functionality. - __ast__: Test cases that check the generated ast by using the pretty printing functionality.
- __semantic__: Test cases that check semantic checking of MiniJava programs - __semantic__: Test cases that check semantic checking of MiniJava programs
- __compile-firm-only__: Test cases that check the compilation of MiniJava programs with the libfirm backend.
- __compile-firm__: Test cases that check the correct compilation and execution of MiniJava programs with the libfirm backend. - __compile-firm__: Test cases that check the correct compilation and execution of MiniJava programs with the libfirm backend.
- __compile-only__: Test cases that check the compilation MiniJava programs with the self implemented backend.
- __compile__: Test cases that check the correct compilation and execution of MiniJava programs with the self implemented backend. - __compile__: Test cases that check the correct compilation and execution of MiniJava programs with the self implemented backend.
The test different test cases for each mode are located in a folder with the same name. The test different test cases for each mode are located in a folder with the same name.
...@@ -103,6 +105,19 @@ Test types for the semantic mode ...@@ -103,6 +105,19 @@ Test types for the semantic mode
__All semantic mode tests have to be syntactically correct__ __All semantic mode tests have to be syntactically correct__
Test types for the compile-firm-only and compile-only mode
----------------------------------------------------------
<table>
<tr><th>File ending(s) of test cases</th><th>Expected behaviour to complete a test of this type</th></tr>
<tr>
<td><code>.valid.mj</code> <code>.mj</code> <code>.valid.java</code> <code>.java</code></td>
<td>Return code is <code>0</code> and the compiler produces an `a.out` file, i.e. the MiniJava code can be compiled</td>
</tr>
</table>
__All valid semantic test-cases are also used, the non-semantic compile-(firm)-only
should be placed into the `compile-only` folder__
Test types for the compile-firm and compile mode Test types for the compile-firm and compile mode
------------------------------------------------ ------------------------------------------------
...@@ -171,12 +186,13 @@ usage: mjt.py [-h] [--only_incorrect_tests] [--all_exec_tests] ...@@ -171,12 +186,13 @@ usage: mjt.py [-h] [--only_incorrect_tests] [--all_exec_tests]
[--produce_no_reports] [--produce_all_reports] [--parallel] [--produce_no_reports] [--produce_all_reports] [--parallel]
[--output_no_incorrect_reports] [--color] [--ci_testing] [--output_no_incorrect_reports] [--color] [--ci_testing]
[--log_level LOG_LEVEL] [--log_level LOG_LEVEL]
{all,lexer,syntax,ast,semantic,compile-firm,compile} MJ_RUN {all,lexer,syntax,ast,semantic,compile-firm-only,compile-only,
compile-firm,compile} MJ_RUN
MiniJava test runner MiniJava test runner
positional arguments: positional arguments:
{all,lexer,syntax,ast,semantic,compile-firm,exec} {all,lexer,syntax,ast,semantic,compile-firm-only,compile-only,compile-firm,exec}
What do you want to test? What do you want to test?
MJ_RUN Command to run your MiniJava implementation, e.g. MJ_RUN Command to run your MiniJava implementation, e.g.
`mj/run`, can be omitted by assigning the environment `mj/run`, can be omitted by assigning the environment
......
...@@ -87,6 +87,7 @@ if True:#__name__ == '__main__': ...@@ -87,6 +87,7 @@ if True:#__name__ == '__main__':
if args["mode"] == "all": if args["mode"] == "all":
report_subdir = datetime.now().strftime("%d-%m-%y_%H-%M-%S") report_subdir = datetime.now().strftime("%d-%m-%y_%H-%M-%S")
for mode in [TestMode.lexer, TestMode.syntax, TestMode.ast, TestMode.semantic, for mode in [TestMode.lexer, TestMode.syntax, TestMode.ast, TestMode.semantic,
TestMode.compile_firm_only, TestMode.compile_only,
TestMode.compile_firm, TestMode.compile]: TestMode.compile_firm, TestMode.compile]:
args["all_exec_tests"] = True args["all_exec_tests"] = True
args["report_subdir"] = report_subdir + "_" + mode args["report_subdir"] = report_subdir + "_" + mode
......
...@@ -34,6 +34,10 @@ class TestMode: ...@@ -34,6 +34,10 @@ class TestMode:
compile = "compile" compile = "compile"
compile_firm_only = "compile-firm-only"
compile_only = "compile-only"
exec = "exec" exec = "exec"
bench = "bench" bench = "bench"
...@@ -42,12 +46,14 @@ class TestMode: ...@@ -42,12 +46,14 @@ class TestMode:
ast: [syntax], ast: [syntax],
compile_firm: [exec], compile_firm: [exec],
compile: [exec], compile: [exec],
compile_firm_only: [semantic, compile_only],
compile_only: [semantic],
bench: [exec] bench: [exec]
} }
""" All 'success' tests of the n.th mode can used as 'success' tests for the n-1.th mode""" """ All 'success' tests of the n.th mode can used as 'success' tests for the n-1.th mode"""
TEST_MODES = [TestMode.lexer, TestMode.syntax, TestMode.ast, TestMode.semantic, TestMode.compile_firm, TEST_MODES = [TestMode.lexer, TestMode.syntax, TestMode.ast, TestMode.semantic, TestMode.compile_firm_only,
TestMode.exec, TestMode.bench, TestMode.compile] TestMode.compile_only, TestMode.compile_firm, TestMode.exec, TestMode.bench, TestMode.compile]
def get_test_dirname(mode: str) -> str: def get_test_dirname(mode: str) -> str:
...@@ -163,8 +169,10 @@ class Environment: ...@@ -163,8 +169,10 @@ class Environment:
TestMode.syntax: "--parsetest", TestMode.syntax: "--parsetest",
TestMode.ast: "--print-ast", TestMode.ast: "--print-ast",
TestMode.semantic: "--check", TestMode.semantic: "--check",
TestMode.compile_only: None,
TestMode.compile_firm_only: "--compile-firm",
TestMode.compile_firm: "--compile-firm", TestMode.compile_firm: "--compile-firm",
TestMode.compile: None TestMode.compile: None,
}[mode] }[mode]
cmd = [self.mj_run_cmd] cmd = [self.mj_run_cmd]
if mode_flag: if mode_flag:
......
...@@ -48,6 +48,7 @@ class JavaExecTest(BasicSyntaxTest): ...@@ -48,6 +48,7 @@ class JavaExecTest(BasicSyntaxTest):
self._expected_output_file = self._prev_out_file self._expected_output_file = self._prev_out_file
_LOG.info("Reuse old java output file \"{}\"".format(path.relpath(self._prev_out_file))) _LOG.info("Reuse old java output file \"{}\"".format(path.relpath(self._prev_out_file)))
self._should_succeed = True self._should_succeed = True
self._only_compile = self.MODE.endswith("-only")
def run(self) -> BasicDiffTestResult: def run(self) -> BasicDiffTestResult:
is_big_testcase = "big" in self.file is_big_testcase = "big" in self.file
...@@ -77,7 +78,7 @@ class JavaExecTest(BasicSyntaxTest): ...@@ -77,7 +78,7 @@ class JavaExecTest(BasicSyntaxTest):
chars.append(int(part)) chars.append(int(part))
input_str = chars.decode() input_str = chars.decode()
if not self._has_expected_output_file: if not self._has_expected_output_file and not self._only_compile:
_, err, javac_rtcode = \ _, err, javac_rtcode = \
self.env.run_command("javac", base_filename + ".java", timeout=timeout) self.env.run_command("javac", base_filename + ".java", timeout=timeout)
if javac_rtcode != 0: if javac_rtcode != 0:
...@@ -92,27 +93,29 @@ class JavaExecTest(BasicSyntaxTest): ...@@ -92,27 +93,29 @@ class JavaExecTest(BasicSyntaxTest):
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 = \ if not self._only_compile:
self.env.run_command("java", get_main_class_name(base_filename + ".java"), timeout=timeout, input_str=input_str) exp_out, err, java_rtcode = \
if javac_rtcode != 0: self.env.run_command("java", get_main_class_name(base_filename + ".java"), timeout=timeout, input_str=input_str)
test_result.add_long_text("Java output: ", exp_out.decode()) if javac_rtcode != 0:
test_result.incorrect_msg = "java runtime error" test_result.add_long_text("Java output: ", exp_out.decode())
test_result.set_error_code(java_rtcode) test_result.incorrect_msg = "java runtime error"
test_result.add_long_text("Java error message", err.decode()) test_result.set_error_code(java_rtcode)
test_result.add_file("Source file", self.preprocessed_file) test_result.add_long_text("Java error message", err.decode())
if self._input_file: test_result.add_file("Source file", self.preprocessed_file)
test_result.add_file("Input file", self.file) if self._input_file:
os.chdir(cwd) test_result.add_file("Input file", self.file)
return test_result os.chdir(cwd)
exp_out = exp_out.decode() return test_result
exp_out = exp_out.decode()
with open(self._prev_out_file, "w") as f:
f.write(exp_out) with open(self._prev_out_file, "w") as f:
f.flush() f.write(exp_out)
with open(self._prev_out_hash_file, "w") as f: f.flush()
f.write(self._hash_sum_for_file(base_filename + ".java")) with open(self._prev_out_hash_file, "w") as f:
f.flush() f.write(self._hash_sum_for_file(base_filename + ".java"))
if self._has_expected_output_file and self.type == self.MODE and self.env.mode == self.MODE: f.flush()
if self._has_expected_output_file and self.type == self.MODE and self.env.mode == self.MODE \
and not self._only_compile:
with open(self._expected_output_file, "r") as f: with open(self._expected_output_file, "r") as f:
exp_out = f.read() exp_out = f.read()
...@@ -137,6 +140,12 @@ class JavaExecTest(BasicSyntaxTest): ...@@ -137,6 +140,12 @@ class JavaExecTest(BasicSyntaxTest):
except: except:
os.chdir(cwd) os.chdir(cwd)
raise raise
if self._only_compile:
if not os.path.exists("a.out"):
test_result.incorrect_msg = "binary cannot be found"
test_result.set_error_code(1)
test_result.add_file("Source file", self.preprocessed_file)
return test_result
try: try:
out, err, rtcode = self.env.run_command("./a.out", timeout=timeout, input_str=input_str) out, err, rtcode = self.env.run_command("./a.out", timeout=timeout, input_str=input_str)
if rtcode != 0: if rtcode != 0:
...@@ -228,6 +237,16 @@ class JavaCompileExecTest(JavaExecTest): ...@@ -228,6 +237,16 @@ class JavaCompileExecTest(JavaExecTest):
TestCase.TEST_CASE_CLASSES[TestMode.compile].append(JavaCompileExecTest) TestCase.TEST_CASE_CLASSES[TestMode.compile].append(JavaCompileExecTest)
class JavaCompileOnlyTest(JavaExecTest):
MODE = TestMode.compile_only
TestCase.TEST_CASE_CLASSES[TestMode.compile_only].append(JavaCompileOnlyTest)
class JavaCompileFirmOnlyTest(JavaExecTest):
MODE = TestMode.compile_firm_only
TestCase.TEST_CASE_CLASSES[TestMode.compile_firm_only].append(JavaCompileFirmOnlyTest)
class JavaInfiniteLoopTest(BasicSyntaxTest): class JavaInfiniteLoopTest(BasicSyntaxTest):
FILE_ENDINGS = [".inf.java", ".inf.mj"] FILE_ENDINGS = [".inf.java", ".inf.mj"]
......
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