Bug 873035 - Add a new --gecko-log option to redirect gecko logs to a specified file. r=jgriffin, a=test-only
authorJulien Pagès <jparkouss@gmail.com>
Tue, 16 Sep 2014 17:08:25 -0400
changeset 171622 2bea1fbbcba8a32bad04ae7e7afd126ad9c193a7
parent 171621 59aa7df6904ef725c5c21bb40efdc7bb5f43aab4
child 171623 3a208c39bcb91162bde24669fc09d6cf1b82579a
push id601
push userryanvm@gmail.com
push dateThu, 09 Oct 2014 00:42:11 +0000
reviewersjgriffin, test-only
bugs873035
milestone28.0
Bug 873035 - Add a new --gecko-log option to redirect gecko logs to a specified file. r=jgriffin, a=test-only
testing/marionette/client/marionette/geckoinstance.py
testing/marionette/client/marionette/marionette.py
testing/marionette/client/marionette/runner/base.py
--- a/testing/marionette/client/marionette/geckoinstance.py
+++ b/testing/marionette/client/marionette/geckoinstance.py
@@ -1,48 +1,56 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/
 
 import os
+import time
 
 from mozprofile import Profile
 from mozrunner import Runner
 
 
 class GeckoInstance(object):
 
     required_prefs = {"marionette.defaultPrefs.enabled": True,
                       "marionette.defaultPrefs.port": 2828,
                       "marionette.logging": True,
                       "startup.homepage_welcome_url": "about:blank",
                       "browser.shell.checkDefaultBrowser": False,
                       "browser.startup.page": 0,
                       "browser.sessionstore.resume_from_crash": False,
                       "browser.warnOnQuit": False}
 
-    def __init__(self, host, port, bin, profile, app_args=None):
+    def __init__(self, host, port, bin, profile, app_args=None, gecko_log=None):
         self.marionette_host = host
         self.marionette_port = port
         self.bin = bin
         self.profile = profile
         self.app_args = app_args or []
         self.runner = None
+        self.gecko_log = gecko_log
 
     def start(self):
         profile_path = self.profile
         profile_args = {"preferences": self.required_prefs}
         if not profile_path:
             runner_class = Runner
             profile_args["restore"] = False
         else:
             runner_class = CloneRunner
             profile_args["path_from"] = profile_path
 
-        self.gecko_log = os.path.abspath('gecko.log')
+        if self.gecko_log is None:
+            self.gecko_log = 'gecko.log'
+        elif os.path.isdir(self.gecko_log):
+            fname = "gecko-%d.log" % time.time()
+            self.gecko_log = os.path.join(self.gecko_log, fname)
+
+        self.gecko_log = os.path.realpath(self.gecko_log)
         if os.access(self.gecko_log, os.F_OK):
             os.remove(self.gecko_log)
         self.runner = runner_class.create(
             binary=self.bin,
             profile_args=profile_args,
             cmdargs=['-no-remote', '-marionette'] + self.app_args,
             kp_kwargs={
                 'processOutputLine': [NullOutput()],
--- a/testing/marionette/client/marionette/marionette.py
+++ b/testing/marionette/client/marionette/marionette.py
@@ -437,17 +437,17 @@ class Marionette(object):
                            "portrait-secondary": EmulatorScreen.SO_PORTRAIT_SECONDARY,
                            "landscape-secondary": EmulatorScreen.SO_LANDSCAPE_SECONDARY}
 
     def __init__(self, host='localhost', port=2828, app=None, app_args=None, bin=None,
                  profile=None, emulator=None, sdcard=None, emulatorBinary=None,
                  emulatorImg=None, emulator_res=None, gecko_path=None,
                  connectToRunningEmulator=False, homedir=None, baseurl=None,
                  noWindow=False, logcat_dir=None, busybox=None, symbols_path=None,
-                 timeout=None, device_serial=None):
+                 timeout=None, device_serial=None, gecko_log=None):
         self.host = host
         self.port = self.local_port = port
         self.bin = bin
         self.instance = None
         self.profile = profile
         self.session = None
         self.window = None
         self.emulator = None
@@ -478,17 +478,18 @@ class Marionette(object):
                     config.read(os.path.join(os.path.dirname(bin), 'application.ini'))
                     app = config.get('App', 'Name')
                     instance_class = geckoinstance.apps[app.lower()]
                 except (ConfigParser.NoOptionError,
                         ConfigParser.NoSectionError,
                         KeyError):
                     instance_class = geckoinstance.GeckoInstance
             self.instance = instance_class(host=self.host, port=self.port,
-                                           bin=self.bin, profile=self.profile, app_args=app_args)
+                                           bin=self.bin, profile=self.profile, app_args=app_args,
+                                           gecko_log=gecko_log)
             self.instance.start()
             assert(self.wait_for_port()), "Timed out waiting for port!"
 
         if emulator:
             self.emulator = Emulator(homedir=homedir,
                                      noWindow=self.noWindow,
                                      logcat_dir=self.logcat_dir,
                                      arch=emulator,
--- a/testing/marionette/client/marionette/runner/base.py
+++ b/testing/marionette/client/marionette/runner/base.py
@@ -466,16 +466,24 @@ class BaseMarionetteOptions(OptionParser
                         dest='es_servers',
                         action='append',
                         help='the ElasticSearch server to use for autolog submission')
         self.add_option('--shuffle',
                         action='store_true',
                         dest='shuffle',
                         default=False,
                         help='run tests in a random order')
+        self.add_option('--gecko-log',
+                        dest='gecko_log',
+                        action='store',
+                        help="Define the path to store log file. If the path is"
+                             " a directory, the real log file will be created"
+                             " given the format gecko-(timestamp).log. If it is"
+                             " a file, if will be used directly. Default: 'gecko.log'")
+ 
 
     def parse_args(self, args=None, values=None):
         options, tests = OptionParser.parse_args(self, args, values)
         for handler in self.parse_args_handlers:
             handler(options, tests, args, values)
 
         return (options, tests)
 
@@ -520,17 +528,17 @@ class BaseMarionetteTestRunner(object):
 
     def __init__(self, address=None, emulator=None, emulatorBinary=None,
                  emulatorImg=None, emulator_res='480x800', homedir=None,
                  app=None, app_args=None, bin=None, profile=None, autolog=False,
                  revision=None, logger=None, testgroup="marionette", noWindow=False,
                  logcat_dir=None, xml_output=None, repeat=0, gecko_path=None,
                  testvars=None, tree=None, type=None, device_serial=None,
                  symbols_path=None, timeout=None, es_servers=None, shuffle=False,
-                 sdcard=None, **kwargs):
+                 sdcard=None, gecko_log=None, **kwargs):
         self.address = address
         self.emulator = emulator
         self.emulatorBinary = emulatorBinary
         self.emulatorImg = emulatorImg
         self.emulator_res = emulator_res
         self.homedir = homedir
         self.app = app
         self.app_args = app_args or []
@@ -556,16 +564,17 @@ class BaseMarionetteTestRunner(object):
         self.symbols_path = symbols_path
         self.timeout = timeout
         self._device = None
         self._capabilities = None
         self._appName = None
         self.es_servers = es_servers
         self.shuffle = shuffle
         self.sdcard = sdcard
+        self.gecko_log = gecko_log
         self.mixin_run_tests = []
         self.manifest_skipped_tests = []
 
         if testvars:
             if not os.path.exists(testvars):
                 raise IOError('--testvars file does not exist')
 
             import json
@@ -647,17 +656,17 @@ class BaseMarionetteTestRunner(object):
             self.marionette = Marionette(host=host,
                                          port=int(port),
                                          app=self.app,
                                          app_args=self.app_args,
                                          bin=self.bin,
                                          profile=self.profile,
                                          baseurl=self.baseurl,
                                          timeout=self.timeout,
-                                         device_serial=self.device_serial)
+                                         device_serial=self.device_serial, gecko_log=self.gecko_log)
         elif self.address:
             host, port = self.address.split(':')
             try:
                 #establish a socket connection so we can vertify the data come back
                 connection = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
                 connection.connect((host,int(port)))
                 connection.close()
             except Exception, e: