Bug 548172 - thunderbird mozmill test runner on linux should use Xvnc via vncserver when available. r=Standard8.
authorAndrew Sutherland <asutherland@asutherland.org>
Tue, 16 Mar 2010 15:19:12 -0700
changeset 5187 6e94b4293dd2b6dd40b388a1283018417cbc9ba9
parent 5186 d7c84d29a71a4f62ce5a1e1bb6d4477b9615c930
child 5188 6417f114db07461d35db188054a2f41342f08cfe
push idunknown
push userunknown
push dateunknown
reviewersStandard8
bugs548172
Bug 548172 - thunderbird mozmill test runner on linux should use Xvnc via vncserver when available. r=Standard8.
mail/test/mozmill/runtest.py
--- a/mail/test/mozmill/runtest.py
+++ b/mail/test/mozmill/runtest.py
@@ -40,17 +40,17 @@
 #
 # ***** END LICENSE BLOCK *****
 
 """
 Runs the Bloat test harness
 """
 
 import sys
-import os
+import os, os.path, platform, subprocess, signal
 import shutil
 import mozrunner
 import jsbridge
 import mozmill
 import socket
 import copy
 SCRIPT_DIRECTORY = os.path.abspath(os.path.realpath(os.path.dirname(sys.argv[0])))
 sys.path.append(SCRIPT_DIRECTORY)
@@ -176,31 +176,67 @@ class ThunderTestProfile(mozrunner.Thund
         '''
         Do not cleanup at all.  The next iteration will cleanup for us, but
         until that time it's useful for debugging failures to leave everything
         around.
         '''
         pass
 
 class ThunderTestRunner(mozrunner.ThunderbirdRunner):
+    VNC_SERVER_PATH = '/usr/bin/vncserver'
+    VNC_PASSWD_PATH = '~/.vnc/passwd'
+
     def __init__(self, *args, **kwargs):
         kwargs['env'] = env = dict(os.environ)
         # note, we do NOT want to set NO_EM_RESTART or jsbridge wouldn't work
         # avoid dialogs on windows
         if 'NO_EM_RESTART' in env:
             del env['NO_EM_RESTART']
         if 'XPCOM_DEBUG_BREAK' not in env:
             env['XPCOM_DEBUG_BREAK'] = 'stack'
         # do not reuse an existing instance
         env['MOZ_NO_REMOTE'] = '1'
+
+        # Only use the VNC server if the capability is available and a password
+        # is already defined so this can run without prompting the user.
+        self.use_vnc_server = (
+            platform.system() == 'Linux' and
+            os.path.isfile(self.VNC_SERVER_PATH) and
+            os.path.isfile(os.path.expanduser(self.VNC_PASSWD_PATH)))
+
         mozrunner.Runner.__init__(self, *args, **kwargs)
 
     def find_binary(self):
         return self.profile.app_path
 
+    def start(self):
+        if self.use_vnc_server:
+            subprocess.check_call([self.VNC_SERVER_PATH, ':99'])
+            self.vnc_alive = True
+            self.env['DISPLAY'] = ':99'
+        return mozrunner.ThunderbirdRunner.start(self)
+
+    def wait(self, timeout=None):
+        '''
+        Wrap the call to wait in logic that kills the VNC server when we are
+        done waiting.  During normal operation, wait is the last thing.  In
+        the keyboard interrupt case wait will die due to the interrupt and
+        stop/kill will be killed.  Since we are wrapping wait, we don't need
+        to specialize for stop/kill though.
+        '''
+        try:
+            return mozrunner.ThunderbirdRunner.wait(self, timeout)
+        finally:
+            try:
+                if self.vnc_alive:
+                    subprocess.check_call([self.VNC_SERVER_PATH,
+                                           '-kill', ':99'])
+            except Exception, ex:
+                print '!!! Exception during killing VNC server:', ex
+
 
 class ThunderTestCLI(mozmill.CLI):
 
     profile_class = ThunderTestProfile
     runner_class = ThunderTestRunner
     parser_options = copy.copy(mozmill.CLI.parser_options)
     parser_options[('-m', '--bloat-tests')] = {"default":None, "dest":"created_profile", "help":"Log file name."}
     parser_options[('--symbols-path',)] = {"default": None, "dest": "symbols",