Skip to content

Commit

Permalink
[cleanup] Log compile errors for AOT tests (#10214)
Browse files Browse the repository at this point in the history
* [cleanup] Log compile errors for AOT tests

See #10213

* Update tests/python/relay/aot/aot_test_utils.py

* removed the encode of msg that is already str

Co-authored-by: lhutton1 <[email protected]>

Co-authored-by: driazati <[email protected]>
Co-authored-by: Manupa Karunaratne <[email protected]>
Co-authored-by: lhutton1 <[email protected]>
  • Loading branch information
4 people authored Mar 2, 2022
1 parent 1df1580 commit 8f6fa8f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
1 change: 1 addition & 0 deletions tests/python/integration/test_arm_mprofile_dsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import numpy as np
import pytest
import tvm
import tvm.testing
from tvm import relay
from tests.python.relay.aot.aot_test_utils import (
AOTTestModel,
Expand Down
45 changes: 28 additions & 17 deletions tests/python/relay/aot/aot_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,35 +225,46 @@ def parametrize_aot_options(test):
)(test)


def subprocess_log_output(cmd, cwd, logfile):
def subprocess_check_log_output(cmd, cwd, logfile):
"""
This method runs a process and logs the output to both a log file and stdout
"""
_LOG.info("Execute (%s): %s", cwd, cmd)
cmd_base = cmd[0] if isinstance(cmd, (list, tuple)) else cmd.split(" ", 1)[0]
proc = subprocess.Popen(
cmd, cwd=cwd, shell=True, bufsize=0, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
cmd,
cwd=cwd,
shell=True,
bufsize=0,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
encoding="utf-8",
)
with open(logfile, "ab") as f:
f.write(
bytes(
"\n"
+ "-" * 80
+ f"{datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}: Execute ({cwd}): {cmd}\n"
+ "-" * 80,
"utf-8",
)
stdout = ""
with open(logfile, "a") as f:
msg = (
"\n"
+ "-" * 80
+ f"{datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}: Execute ({cwd}): {cmd}\n"
+ "-" * 80
)
f.write(msg)
stdout += msg + "\n"
while True:
data = proc.stdout.readline()
_LOG.debug("%s: %s", cmd_base, str(data, "utf-8", "replace").rstrip("\n"))
stdout += data
_LOG.debug("%s: %s", cmd_base, data.rstrip("\n"))
f.write(data)

# process is done if there is no data and the result is valid
if not data: # EOF
break

return proc.wait()
proc.wait()
if proc.returncode != 0:
raise RuntimeError(
f"Subprocess failed: {cmd}\nstdout:\n{stdout}"
)


# TODO: Move to linker script with list of symbols rather than coding into source
Expand Down Expand Up @@ -812,16 +823,16 @@ def run_and_check(
compile_command = f"{make_command} aot_test_runner"
if verbose:
print("Compile command:\n", compile_command)
ret = subprocess_log_output(compile_command, ".", compile_log_path)
assert ret == 0
subprocess_check_log_output(compile_command, ".", compile_log_path)

# Verify that runs fine
run_log_path = os.path.join(build_path, "test_run.log")
run_command = f"{make_command} run"
if verbose:
print("Run command:\n", run_command)
ret = subprocess_log_output(run_command, build_path, run_log_path)
assert ret == 0

subprocess_check_log_output(run_command, build_path, run_log_path)

with open(run_log_path) as run_log:
assert AOT_SUCCESS_TOKEN in run_log.read()

Expand Down

0 comments on commit 8f6fa8f

Please sign in to comment.