From 331aabcde657ec1f1a18fe13852fb6455ad24f0c Mon Sep 17 00:00:00 2001 From: baldurk Date: Tue, 21 Jul 2020 15:16:43 +0100 Subject: [PATCH] Include test process output into test log --- util/test/demos/test_common.cpp | 12 ++++++++++++ util/test/rdtest/capture.py | 11 +++++++++-- util/test/rdtest/logging.py | 10 ++++++++++ util/test/rdtest/testcase.py | 5 ++++- util/test/rdtest/testresults.js | 3 +++ 5 files changed, 38 insertions(+), 3 deletions(-) diff --git a/util/test/demos/test_common.cpp b/util/test/demos/test_common.cpp index 0d3df0b87..6b4ff2506 100644 --- a/util/test/demos/test_common.cpp +++ b/util/test/demos/test_common.cpp @@ -152,6 +152,7 @@ std::string trim(const std::string &str) } static char printBuf[4096] = {}; +static FILE *logFile = NULL; void DebugPrint(const char *fmt, ...) { @@ -165,6 +166,12 @@ void DebugPrint(const char *fmt, ...) fputs(printBuf, stdout); fflush(stdout); + if(logFile) + { + fputs(printBuf, logFile); + fflush(logFile); + } + #if defined(WIN32) OutputDebugStringA(printBuf); #endif @@ -510,6 +517,11 @@ void GraphicsTest::Prepare(int argc, char **argv) maxFrameCount = atoi(argv[i + 1]); } + if(i + 1 < argc && !strcmp(argv[i], "--log")) + { + logFile = fopen(argv[i + 1], "w"); + } + if(i + 1 < argc && (!strcmp(argv[i], "--width") || !strcmp(argv[i], "-w"))) { screenWidth = atoi(argv[i + 1]); diff --git a/util/test/rdtest/capture.py b/util/test/rdtest/capture.py index 9b8e2054a..35fc46186 100644 --- a/util/test/rdtest/capture.py +++ b/util/test/rdtest/capture.py @@ -150,7 +150,8 @@ def run_executable(exe: str, cmdline: str, return res.ident -def run_and_capture(exe: str, cmdline: str, frame: int, capture_name=None, opts=rd.GetDefaultCaptureOptions(), timeout=None): +def run_and_capture(exe: str, cmdline: str, frame: int, *, capture_name=None, opts=rd.GetDefaultCaptureOptions(), + timeout=None, logfile=None): """ Helper function to run an executable with a command line, capture a particular frame, and exit. @@ -161,6 +162,9 @@ def run_and_capture(exe: str, cmdline: str, frame: int, capture_name=None, opts= :param cmdline: The command line to pass. :param frame: The frame to capture. :param capture_name: The name to use creating the captures + :param opts: The capture options to use + :param timeout: The timeout to wait before killing the process if no capture has happened. + :param logfile: The log file output to include in the test log. :return: The path of the generated capture. :rtype: str """ @@ -170,7 +174,7 @@ def run_and_capture(exe: str, cmdline: str, frame: int, capture_name=None, opts= control = TargetControl(run_executable(exe, cmdline, cappath=util.get_tmp_path(capture_name), opts=opts), timeout=timeout) - log.print("Queuing capture of frame {} without timeout of {}".format(frame, "default" if timeout is None else timeout)) + log.print("Queuing capture of frame {} with timeout of {}".format(frame, "default" if timeout is None else timeout)) # Capture frame control.queue_capture(frame) @@ -180,6 +184,9 @@ def run_and_capture(exe: str, cmdline: str, frame: int, capture_name=None, opts= captures = control.captures() + if logfile is not None and os.path.exists(logfile): + log.inline_file('Process output', logfile) + if len(captures) == 0: raise RuntimeError("No capture made") diff --git a/util/test/rdtest/logging.py b/util/test/rdtest/logging.py index 73f0d520e..34288f9b4 100644 --- a/util/test/rdtest/logging.py +++ b/util/test/rdtest/logging.py @@ -90,6 +90,16 @@ class TestLogger: self.dedent() self.rawprint("<< Section {}".format(name)) + def inline_file(self, name: str, path: str): + self.rawprint(">> Raw {}".format(name)) + self.indent() + with open(path) as f: + lines = f.readlines() + for l in lines: + self.rawprint(l.strip()) + self.dedent() + self.rawprint("<< Raw {}".format(name)) + def success(self, message): self.rawprint("** " + message) diff --git a/util/test/rdtest/testcase.py b/util/test/rdtest/testcase.py index 34423d21b..9bb01b40c 100644 --- a/util/test/rdtest/testcase.py +++ b/util/test/rdtest/testcase.py @@ -201,7 +201,10 @@ class TestCase: """ if self.demos_test_name != '': - return capture.run_and_capture(util.get_demos_binary(), self.demos_test_name, self.demos_frame_cap, opts=self.get_capture_options(), timeout=util.get_demos_timeout()) + logfile = os.path.join(util.get_tmp_dir(), 'demos.log') + return capture.run_and_capture(util.get_demos_binary(), self.demos_test_name + " --log " + logfile, + self.demos_frame_cap, logfile=logfile, opts=self.get_capture_options(), + timeout=util.get_demos_timeout()) raise NotImplementedError("If run() is not implemented in a test, then" "get_capture() and check_capture() must be.") diff --git a/util/test/rdtest/testresults.js b/util/test/rdtest/testresults.js index ba5defeab..3c385ff8a 100644 --- a/util/test/rdtest/testresults.js +++ b/util/test/rdtest/testresults.js @@ -166,6 +166,9 @@ document.body.onload = function() { if(words[0] == 'Callstack') { html += start ? ''; instack = start; + } else if(words[0] == 'Raw') { + html += start ? ''; + instack = start; } else if(words[0] == 'Test') { test_name = words[1]; html += start ? '';