Commit 23513aeb authored by Alexandros Frantzis's avatar Alexandros Frantzis

scripts: Improve logging

Reduce the verbosity of logs in CI, while making all the information
available in the artifacts.
Signed-off-by: Alexandros Frantzis's avatarAlexandros Frantzis <alexandros.frantzis@collabora.com>
parent d600532e
Pipeline #80383 passed with stages
in 15 minutes and 23 seconds
......@@ -50,10 +50,12 @@ rendering under the Xvfb X server.
The [scripts/dump_trace_images.py](scripts/dump_trace_images.py) script replays
traces, dumping the images from calls in the replay that match the expected
reference images. The dumped images are stored in a subdirectory `test` next
to the `references` directory and use the same filename format. The script
accepts either a single trace (.trace or .rdc), or a directory. In the latter
case it recursively walks the directory structure and replays all traces it
finds.
to the `references` directory and use the same filename format. The full log of
any commands used while dumping the images is also saved in a file in the
'test' subdirectory, named after the trace name with '.log' appended. The
script accepts either a single trace (.trace or .rdc), or a directory. In the
latter case it recursively walks the directory structure and replays all traces
it finds.
Examples:
......
......@@ -44,7 +44,7 @@ def find_traces_with_images(directory, device_name):
log("Warning", "%s has reference but no test images, skipping" % str(trace_path))
return traces
def copy_images_to_outputdir(trace, outputdir, device_name):
def copy_artifacts_to_outputdir(trace, outputdir, device_name):
trace_path = Path(trace)
tracedir = str(trace_path.parent.name)
tracename = str(trace_path.name)
......@@ -64,6 +64,10 @@ def copy_images_to_outputdir(trace, outputdir, device_name):
for f in glob.glob(testprefix + '*.png'):
shutil.copy(f, testdest)
log_path = trace_path.parent / "test" / device_name / (tracename + ".log")
if log_path.is_file():
shutil.copy(str(log_path), testdest)
return str(Path(outputdir) / tracedir / tracename)
def diff_images(imagedir, device_name):
......@@ -92,7 +96,7 @@ def main():
failed_diff = False
for trace in traces:
imageout = copy_images_to_outputdir(trace, args.output_dir, args.device_name)
imageout = copy_artifacts_to_outputdir(trace, args.output_dir, args.device_name)
images_match = diff_images(imageout, args.device_name)
if not images_match:
log("Info", "Images differ for %s" % trace)
......
......@@ -30,8 +30,22 @@ from pathlib import Path
from traceutil import iter_trace_paths, trace_has_images, all_trace_type_names
from traceutil import trace_type_from_name, trace_type_from_filename, TraceType
def log(severity, msg):
print("[dump_images] %s: %s" % (severity, msg))
def log(severity, msg, end='\n'):
print("[dump_images] %s: %s" % (severity, msg), flush=True, end=end)
def log_result(msg):
print(msg, flush=True)
def run_logged_command(cmd, log_path):
ret = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
logoutput = ("[dump_images] Running: %s\n" % " ".join(cmd)).encode() + \
ret.stdout
with open(str(log_path), 'wb') as log:
log.write(logoutput)
if ret.returncode:
sys.stdout.buffer.write(logoutput)
# Force an exception
ret.check_returncode()
def get_calls_num(trace, device_name):
tracename = str(Path(trace).name)
......@@ -50,21 +64,19 @@ def dump_with_apitrace(trace, calls, device_name):
outputprefix = str(Path(outputdir) / Path(trace).name) + "-"
cmd = ["apitrace", "dump-images", "--calls=" + ','.join(calls),
"-o", outputprefix, trace]
ret = subprocess.call(cmd)
if ret:
raise RuntimeError("Apitrace dump-images failed!")
log_path = Path(outputdir) / (Path(trace).name + ".log")
run_logged_command(cmd, log_path)
def dump_with_renderdoc(trace, calls, device_name):
outputdir = str(Path(trace).parent / "test" / device_name)
script_path = Path(os.path.dirname(os.path.abspath(__file__)))
cmd = [str(script_path / "renderdoc_dump_images.py"), trace, outputdir]
cmd.extend(calls)
ret = subprocess.call(cmd)
if ret:
raise RuntimeError("Renderdoc dump-images failed!")
log_path = Path(outputdir) / (Path(trace).name + ".log")
run_logged_command(cmd, log_path)
def dump_from_trace(trace, device_name):
log("Info", "Dumping trace %s" % trace)
log("Info", "Dumping trace %s" % trace, end='... ')
calls = get_calls_num(trace, device_name)
trace_type = trace_type_from_filename(trace)
if trace_type == TraceType.APITRACE:
......@@ -73,12 +85,12 @@ def dump_from_trace(trace, device_name):
dump_with_renderdoc(trace, calls, device_name)
else:
raise RuntimeError("Unknown tracefile extension")
log_result("OK")
def find_traces_with_reference_images(directory, device_name, trace_types):
traces = []
for trace_path in iter_trace_paths(directory, trace_types):
if trace_has_images(trace_path, str(Path("references") / device_name)):
log("Info", "Adding %s in list of traces to dump" % str(trace_path))
traces.append(str(trace_path))
else:
log("Warning", "%s has no reference images, skipping" % str(trace_path))
......
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