Commit e298df34 authored by ufebl's avatar ufebl

Don't crash when compiler fails to compile

parent dc4df6fd
......@@ -71,7 +71,7 @@ class BenchExecTest(BasicSyntaxTest):
self.env.run_command(cmd, *args, timeout=timeout, input_str=input_str)
runs.append((time.time() - start) * 1000)
except subprocess.CalledProcessError:
return _RunResult([], False)
return _RunResult([-1,-1,-1,-1], False);
return _RunResult(runs, True)
......@@ -111,50 +111,63 @@ class BenchExecTest(BasicSyntaxTest):
self.env.run_command("javac", base_filename + ".java", timeout=timeout)
if javac_rtcode != 0:
_LOG.error("File \"{}\" isn't valid Java".format(self.preprocessed_file))
test_result.incorrect_msg = "invalid java code, but output file missing"
test_result.set_error_code(javac_rtcode)
test_result.add_long_text("Javac error message", err.decode())
test_result.add_file("Source file", self.preprocessed_file)
os.chdir(cwd)
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
#test_result.incorrect_msg = "invalid java code, but output file missing"
#test_result.set_error_code(javac_rtcode)
#test_result.add_long_text("Javac error message", err.decode())
#test_result.add_file("Source file", self.preprocessed_file)
#os.chdir(cwd)
#return test_result
results.append(_RunResult([-1,-1,-1,-1], False));
else:
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
results.append(self._bench_command("java", main_class, timeout=timeout, input_str=input_str))
results.append(self._bench_command("java", main_class, timeout=timeout, input_str=input_str))
else:
try:
compiler_flag = compiler_flag.replace("\\-", "-")
out, err, rtcode = self.env.run_command(self.env.mj_run_cmd, *(compiler_flag.split(" ") + [base_filename + ".java"]),
timeout=timeout)
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", 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
#test_result.incorrect_msg = "file can't be compiled"
#test_result.set_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
results.append(_RunResult([-1,-1,-1,-1], False));
else:
results.append(self._bench_command("./a.out", timeout=timeout, input_str=input_str))
except SigKill as sig:
test_result.incorrect_msg = "file can't be compiled: " + sig.name
test_result.set_error_code(sig.retcode)
test_result.add_file("Source file", self.preprocessed_file)
os.chdir(cwd)
return test_result
#test_result.incorrect_msg = "file can't be compiled: " + sig.name
#test_result.set_error_code(sig.retcode)
#test_result.add_file("Source file", self.preprocessed_file)
#os.chdir(cwd)
#return test_result
results.append(_RunResult([-1,-1,-1,-1], False));
except:
os.chdir(cwd)
raise
results.append(self._bench_command("./a.out", timeout=timeout, input_str=input_str))
os.chdir(cwd)
assert len(results) >= 2 # We want to compare the first two, so we need at least two
if not results[0].is_correct or not results[1].is_correct:
incorrect_flags = [self.env.bench_compiler_flags[i] for (i, res) in enumerate(results) if not res.is_correct]
test_result.incorrect_msg = "Running with {} failed".format(", ".join(incorrect_flags))
test_result.has_succeeded = False
return test_result
for (i, res) in enumerate(results):
if not results[i]:
incorrect_flags = [self.env.bench_compiler_flags[i] for (i, res) in enumerate(results) if not res.is_correct]
test_result.incorrect_msg = "Running with {} failed".format(", ".join(incorrect_flags))
test_result.has_succeeded = False
# add negative results
for (i, res) in enumerate(results):
test_result.add_short_text("min({})".format(i), res.min())
test_result.add_short_text("max({})".format(i), res.max())
test_result.add_short_text("mean({})".format(i), res.mean())
test_result.add_short_text("stddev({})".format(i), res.stddev())
return test_result
msg_parts = []
stddev = max(results[0].stddev() / results[0].mean(), results[1].stddev() / results[1].mean())
rel_min = results[0].min() / results[1].min()
......
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