Commit d11425c1 authored by ufebl's avatar ufebl

Fix BenchTest again

parent 9a532cb6
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
......@@ -57,15 +57,19 @@ class BenchExecTest(BasicSyntaxTest):
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._has_input_file = bool(re.search(self.INPUT_FILE_REGEXP, file))
self._input_file = file if self._has_input_file else None
self._has_character_input = file.endswith("c") if self._has_input_file else False
self._should_succeed = True
def _bench_command(self, cmd: str, *args: Tuple[str], timeout: int, input_str: str) -> _RunResult:
def _bench_command(self, cmd: str, *args: Tuple[str], timeout: int, input_bytes: str) -> _RunResult:
runs = [] # type: List[float]
for i in range(0, self.env.bench_runs):
try:
start = time.time()
self.env.run_command(cmd, *args, timeout=timeout, input_str=input_str)
self.env.run_command(cmd, *args, timeout=timeout, input_bytes=input_bytes)
runs.append((time.time() - start) * 1000)
except subprocess.CalledProcessError:
return _RunResult([-1,0], False);
......@@ -80,24 +84,23 @@ class BenchExecTest(BasicSyntaxTest):
shutil.copy(self.preprocessed_file, path.join(tmp_dir, base_filename + ".java"))
cwd = os.getcwd()
os.chdir(tmp_dir)
input_str = None
input_bytes = None
test_result = ExtensibleTestResult(self)
# read input
if self._has_input_file:
if self._has_character_input:
with open(self._input_file, "r") as f:
input_str = f.read()
with open(self._input_file, "rb") as f:
input_bytes = f.read()
else:
with open(self._input_file, "r") as f:
chars = bytearray('ascii', 'ignore') # type: bytearray
with open(self._input_file, "r", errors="backslashreplace") as f:
input_bytes = bytearray(encoding='ascii', errors='ignore') # type: bytearray
for line in f.readlines():
for part in line.split(" "):
part = part.strip()
if len(part) > 0:
chars.append(int(part))
input_str = chars.decode()
results = [] # type: List[_RunResult]
......@@ -108,30 +111,36 @@ 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", decode(err))
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
results.append(self._bench_command("java", main_class))
#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,0], 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_bytes=input_bytes))
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", 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
#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,0], False));
else:
results.append(self._bench_command("./a.out", timeout=timeout, input_bytes=input_bytes))
except SigKill as sig:
#test_result.incorrect_msg = "file can't be compiled: " + sig.name
#test_result.set_error_code(sig.retcode)
......
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
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