Backed out changeset 018ee8ea0c12 (bug 972518) for breaking Mnw jobs on a CLOSED TREE
authorWes Kocher <wkocher@mozilla.com>
Tue, 18 Feb 2014 16:47:51 -0800
changeset 169786 d769d6ca70b53d1fe0c20c4ea6edf8e9755fe8e0
parent 169785 bf807de6976a6b094ab0fda08bbe507e11e926c7
child 169801 ae3837d89b5e2a554107d5e476de672cb2aaa0d7
child 169834 bf0e76f2a7d431337f51602bbc5a2f5d3a9d3f5f
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
bugs972518
milestone30.0a1
backs out018ee8ea0c126adef3ba26118b5d43a2580a6095
Backed out changeset 018ee8ea0c12 (bug 972518) for breaking Mnw jobs on a CLOSED TREE
testing/marionette/client/marionette/emulator.py
--- a/testing/marionette/client/marionette/emulator.py
+++ b/testing/marionette/client/marionette/emulator.py
@@ -18,32 +18,26 @@ import tempfile
 import time
 import traceback
 
 from emulator_battery import EmulatorBattery
 from emulator_geo import EmulatorGeo
 from emulator_screen import EmulatorScreen
 
 
-class LogOutputProc(ProcessHandlerMixin):
-    """
-    Process handler for processes which save all output to a logfile.
-    If no logfile is specified, output will still be consumed to prevent
-    the output pipe's from overflowing.
+class LogcatProc(ProcessHandlerMixin):
+    """Process handler for logcat which saves all output to a logfile.
     """
 
-    def __init__(self, cmd, logfile=None,  **kwargs):
+    def __init__(self, logfile, cmd, **kwargs):
         self.logfile = logfile
         kwargs.setdefault('processOutputLine', []).append(self.log_output)
         ProcessHandlerMixin.__init__(self, cmd, **kwargs)
 
     def log_output(self, line):
-        if not self.logfile:
-            return
-
         f = open(self.logfile, 'a')
         f.write(line + "\n")
         f.flush()
 
 
 class Emulator(object):
 
     deviceRe = re.compile(r"^emulator-(\d+)(\s*)(.*)$")
@@ -318,24 +312,19 @@ waitFor(
         if self.copy_userdata:
             # Make a copy of the userdata.img for this instance of the emulator to use.
             self._tmp_userdata = tempfile.mktemp(prefix='marionette')
             shutil.copyfile(self.dataImg, self._tmp_userdata)
             qemu_args[qemu_args.index('-data') + 1] = self._tmp_userdata
 
         original_online, original_offline = self._get_adb_devices()
 
-        filename = None
-        if self.logcat_dir:
-            filename = os.path.join(self.logcat_dir, 'qemu.log')
-            if os.path.isfile(filename):
-                self.rotate_log(filename)
-
-        self.proc = LogOutputProc(qemu_args, filename)
-        self.proc.run()
+        self.proc = subprocess.Popen(qemu_args,
+                                     stdout=subprocess.PIPE,
+                                     stderr=subprocess.PIPE)
 
         online, offline = self._get_adb_devices()
         now = datetime.datetime.now()
         while online - original_online == set([]):
             time.sleep(1)
             if datetime.datetime.now() - now > datetime.timedelta(seconds=60):
                 raise Exception('timed out waiting for emulator to start')
             online, offline = self._get_adb_devices()
@@ -469,39 +458,33 @@ window.addEventListener('mozbrowserloade
         self.dm.pushFile(busybox, remote_file, retryLimit=10)
         self._run_adb(['shell', 'cd /system/bin; chmod 555 busybox; for x in `./busybox --list`; do ln -s ./busybox $x; done'])
         self.dm._verifyZip()
 
     def rotate_log(self, srclog, index=1):
         """ Rotate a logfile, by recursively rotating logs further in the sequence,
             deleting the last file if necessary.
         """
-        basename = os.path.basename(srclog)
-        basename = basename[:-len('.log')]
-        if index > 1:
-            basename = basename[:-len('.1')]
-        basename = '%s.%d.log' % (basename, index)
-
-        destlog = os.path.join(self.logcat_dir, basename)
-        if os.path.isfile(destlog):
+        destlog = os.path.join(self.logcat_dir, 'emulator-%d.%d.log' % (self.port, index))
+        if os.access(destlog, os.F_OK):
             if index == 3:
                 os.remove(destlog)
             else:
                 self.rotate_log(destlog, index+1)
         shutil.move(srclog, destlog)
 
     def save_logcat(self):
         """ Save the output of logcat to a file.
         """
         filename = os.path.join(self.logcat_dir, "emulator-%d.log" % self.port)
-        if os.path.isfile(filename):
+        if os.access(filename, os.F_OK):
             self.rotate_log(filename)
         cmd = [self.adb, '-s', 'emulator-%d' % self.port, 'logcat', '-v', 'threadtime']
 
-        self.logcat_proc = LogOutputProc(cmd, filename)
+        self.logcat_proc = LogcatProc(filename, cmd)
         self.logcat_proc.run()
 
     def setup_port_forwarding(self, remote_port):
         """ Set up TCP port forwarding to the specified port on the device,
             using any availble local port, and return the local port.
         """
         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         s.bind(("",0))