mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-14 03:15:47 +00:00
validate: launcher: Introduce new parameter for log file redirecting
Allow log file redirection through the new --redirect-logs parameter. Keep the old --logs-dir stdout/stderr parameter, but reset to the default logs directory in that case, and set redirect_logs internally. This also prevents the creation of an stdout/stderr directory for writing xunit.xml. https://bugzilla.gnome.org/show_bug.cgi?id=742973
This commit is contained in:
parent
10fe72aa52
commit
4e0388c631
4 changed files with 28 additions and 20 deletions
|
@ -86,7 +86,7 @@ class Test(Loggable):
|
|||
" You can reproduce with: %s %s\n" \
|
||||
% (self.message, self._env_variable, self.command)
|
||||
|
||||
if not self.reporter.uses_standard_output():
|
||||
if not self.options.redirect_logs:
|
||||
string += " You can find logs in:\n" \
|
||||
" - %s" % (self.logfile)
|
||||
for log in self.extra_logfiles:
|
||||
|
@ -244,7 +244,7 @@ class Test(Loggable):
|
|||
message = "Launching: %s%s\n" \
|
||||
" Command: '%s %s'\n" % (Colors.ENDC, self.classname,
|
||||
self._env_variable, self.command)
|
||||
if not self.reporter.uses_standard_output():
|
||||
if not self.options.redirect_logs:
|
||||
message += " Logs:\n" \
|
||||
" - %s" % (self.logfile)
|
||||
for log in self.extra_logfiles:
|
||||
|
@ -266,7 +266,7 @@ class Test(Loggable):
|
|||
self._kill_subprocess()
|
||||
self.time_taken = time.time() - self._starting_time
|
||||
|
||||
if not self.reporter.uses_standard_output():
|
||||
if not self.options.redirect_logs:
|
||||
self.reporter.out.seek(0)
|
||||
self.reporter.out.write("=================\n"
|
||||
"Test name: %s\n"
|
||||
|
@ -320,7 +320,7 @@ class GstValidateTest(Test):
|
|||
self.scenario = scenario
|
||||
|
||||
def get_subproc_env(self):
|
||||
if self.reporter.uses_standard_output():
|
||||
if self.options.redirect_logs:
|
||||
self.validatelogs = os.path.join(
|
||||
tempfile.gettempdir(), 'tmp.validate.logs')
|
||||
logfiles = self.validatelogs
|
||||
|
@ -337,7 +337,7 @@ class GstValidateTest(Test):
|
|||
self.extra_logfiles.append(self.validatelogs)
|
||||
|
||||
if 'GST_DEBUG' in os.environ and \
|
||||
not self.reporter.uses_standard_output():
|
||||
not self.options.redirect_logs:
|
||||
gstlogsfile = self.logfile + '.gstdebug'
|
||||
self.extra_logfiles.append(gstlogsfile)
|
||||
subproc_env["GST_DEBUG_FILE"] = gstlogsfile
|
||||
|
@ -348,7 +348,7 @@ class GstValidateTest(Test):
|
|||
|
||||
def clean(self, full=True):
|
||||
Test.clean(self, full=full)
|
||||
if self.reporter.uses_standard_output():
|
||||
if hasattr(self, 'validatelogs') and not self.options.redirect_logs:
|
||||
try:
|
||||
os.remove(self.validatelogs)
|
||||
except OSError:
|
||||
|
@ -921,8 +921,6 @@ class _TestsLauncher(Loggable):
|
|||
|
||||
def set_settings(self, options, args):
|
||||
self.reporter = reporters.XunitReporter(options)
|
||||
if not options.logsdir in[sys.stderr, sys.stdout]:
|
||||
mkdir(options.logsdir)
|
||||
|
||||
self.options = options
|
||||
wanted_testers = None
|
||||
|
@ -1140,7 +1138,7 @@ class ScenarioManager(Loggable):
|
|||
"""
|
||||
scenarios = []
|
||||
scenario_defs = os.path.join(self.config.main_dir, "scenarios.def")
|
||||
if self.config.logsdir in ["stdout", "stderr"]:
|
||||
if self.config.redirect_logs:
|
||||
logs = open(os.devnull)
|
||||
else:
|
||||
logs = open(
|
||||
|
|
|
@ -57,7 +57,7 @@ class HTTPServer(loggable.Loggable):
|
|||
|
||||
def start(self):
|
||||
""" Start the server in a subprocess """
|
||||
if self.options.logsdir in ["stdout", "stderr"]:
|
||||
if self.options.redirect_logs:
|
||||
self.info("Using devnull as HTTP server log file")
|
||||
self._logsfile = tempfile.TemporaryFile()
|
||||
else:
|
||||
|
|
|
@ -208,6 +208,7 @@ class LauncherConfig(Loggable):
|
|||
self.main_dir = utils.DEFAULT_MAIN_DIR
|
||||
self.output_dir = None
|
||||
self.logsdir = None
|
||||
self.redirect_logs = False
|
||||
self.dest = None
|
||||
self._using_default_paths = False
|
||||
self.paths = []
|
||||
|
@ -240,6 +241,10 @@ class LauncherConfig(Loggable):
|
|||
self.output_dir = os.path.abspath(self.output_dir)
|
||||
|
||||
# other output directories
|
||||
if self.logsdir in ['stdout', 'stderr']:
|
||||
# Allow -l stdout/stderr to work like -rl stdout/stderr
|
||||
self.redirect_logs = self.logsdir
|
||||
self.logsdir = None
|
||||
if self.logsdir is None:
|
||||
self.logsdir = os.path.join(self.output_dir, "logs")
|
||||
if self.xunit_file is None:
|
||||
|
@ -249,6 +254,14 @@ class LauncherConfig(Loggable):
|
|||
|
||||
if not os.path.exists(self.dest):
|
||||
os.makedirs(self.dest)
|
||||
if not os.path.exists(self.logsdir):
|
||||
os.makedirs(self.logsdir)
|
||||
|
||||
if not self.redirect_logs in ['stdout', 'stderr', False]:
|
||||
printc("Log redirection (%s) must be either 'stdout' or 'stderr'."
|
||||
% self.redirect_logs, Colors.FAIL, True)
|
||||
return False
|
||||
|
||||
if urlparse.urlparse(self.dest).scheme == "":
|
||||
self.dest = path2url(self.dest)
|
||||
|
||||
|
@ -398,9 +411,7 @@ Note that all testsuite should be inside python modules, so the directory should
|
|||
dir_group.add_argument("-o", "--output-dir", dest="output_dir",
|
||||
help="Directory where to store logs and rendered files. Default is MAIN_DIR")
|
||||
dir_group.add_argument("-l", "--logs-dir", dest="logsdir",
|
||||
help="Directory where to store logs, default is OUTPUT_DIR/logs."
|
||||
" Note that 'stdout' and 'sdterr' are valid values that lets you get all the logs"
|
||||
" printed in the terminal")
|
||||
help="Directory where to store logs, default is OUTPUT_DIR/logs.")
|
||||
dir_group.add_argument("-R", "--render-path", dest="dest",
|
||||
help="Set the path to which projects should be rendered, default is OUTPUT_DIR/rendered")
|
||||
dir_group.add_argument("-p", "--medias-paths", dest="paths", action="append",
|
||||
|
@ -408,6 +419,8 @@ Note that all testsuite should be inside python modules, so the directory should
|
|||
dir_group.add_argument("-a", "--clone-dir", dest="clone_dir",
|
||||
help="Paths where to clone the testuite to run "
|
||||
" default is MAIN_DIR/gst-integration-testsuites")
|
||||
dir_group.add_argument("-rl", "--redirect-logs", dest="redirect_logs",
|
||||
help="Redirect logs to 'stdout' or 'sdterr'.")
|
||||
|
||||
http_server_group = parser.add_argument_group(
|
||||
"Handle the HTTP server to be created")
|
||||
|
|
|
@ -66,15 +66,12 @@ class Reporter(Loggable):
|
|||
}
|
||||
self.results = []
|
||||
|
||||
def uses_standard_output(self):
|
||||
return self.out in [sys.stdout, sys.stderr]
|
||||
|
||||
def before_test(self, test):
|
||||
"""Initialize a timer before starting a test."""
|
||||
if self.options.logsdir == 'stdout':
|
||||
if self.options.redirect_logs == 'stdout':
|
||||
self.out = sys.stdout
|
||||
test.logfile = 'stdout'
|
||||
elif self.options.logsdir == 'stderr':
|
||||
elif self.options.redirect_logs == 'stderr':
|
||||
self.out = sys.stderr
|
||||
test.logfile = 'stderr'
|
||||
else:
|
||||
|
@ -109,7 +106,7 @@ class Reporter(Loggable):
|
|||
self.results.append(self._current_test)
|
||||
|
||||
self.add_results(self._current_test)
|
||||
if not self.uses_standard_output():
|
||||
if not self.options.redirect_logs:
|
||||
self.out.close()
|
||||
|
||||
self.out = None
|
||||
|
@ -164,7 +161,7 @@ class XunitReporter(Reporter):
|
|||
|
||||
def _get_captured(self):
|
||||
captured = ""
|
||||
if self.out and not self.uses_standard_output():
|
||||
if self.out and not self.options.redirect_logs:
|
||||
self.out.seek(0)
|
||||
value = self.out.read()
|
||||
if value:
|
||||
|
|
Loading…
Reference in a new issue