Bug 1042979 - Clean up unused imports, variables, and dead code in mochitest. r=ahal
authorAhmed Kachkach <ahmed.kachkach@gmail.com>
Thu, 24 Jul 2014 06:23:00 +0200
changeset 196036 38a505f2bcb10d7f551718da527c93a847a95c4d
parent 196035 dc5dfa48e98d631c314ddfc353ef9207bf2aaeef
child 196037 5342871fa1ccc62f858c3cfd97bec694301c751e
push id46768
push usercbook@mozilla.com
push dateFri, 25 Jul 2014 07:38:08 +0000
treeherdermozilla-inbound@eed7bf748cbd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersahal
bugs1042979
milestone34.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1042979 - Clean up unused imports, variables, and dead code in mochitest. r=ahal
build/automationutils.py
testing/mochitest/Makefile.in
testing/mochitest/bisection.py
testing/mochitest/mach_commands.py
testing/mochitest/runtests.py
testing/mochitest/runtestsvmware.py
--- a/build/automationutils.py
+++ b/build/automationutils.py
@@ -1,21 +1,25 @@
 #
 # 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/.
 
 from __future__ import with_statement
-import glob, logging, os, platform, shutil, subprocess, sys, tempfile, urllib2, zipfile
-import base64
-import re
+import logging
+from operator import itemgetter
 import os
+import platform
+import re
+import signal
+import subprocess
+import sys
+import tempfile
 from urlparse import urlparse
-from operator import itemgetter
-import signal
+import zipfile
 
 try:
   import mozinfo
 except ImportError:
   # Stub out fake mozinfo since this is not importable on Android 4.0 Opt.
   # This should be fixed; see
   # https://bugzilla.mozilla.org/show_bug.cgi?id=650881
   mozinfo = type('mozinfo', (), dict(info={}))()
@@ -552,17 +556,16 @@ def environment(xrePath, env=None, crash
     else:
       log.info(message)
 
   return env
 
 def dumpScreen(utilityPath):
   """dumps a screenshot of the entire screen to a directory specified by
   the MOZ_UPLOAD_DIR environment variable"""
-  import mozfile
 
   # Need to figure out which OS-dependent tool to use
   if mozinfo.isUnix:
     utility = [os.path.join(utilityPath, "screentopng")]
     utilityname = "screentopng"
   elif mozinfo.isMac:
     utility = ['/usr/sbin/screencapture', '-C', '-x', '-t', 'png']
     utilityname = "screencapture"
--- a/testing/mochitest/Makefile.in
+++ b/testing/mochitest/Makefile.in
@@ -12,17 +12,16 @@ USE_EXTENSION_MANIFEST = 1
 
 # files that get copied into $objdir/_tests/
 SERV_FILES = 	\
 		runtests.py \
 		bisection.py \
 		automation.py \
 		runtestsb2g.py \
 		runtestsremote.py \
-		runtestsvmware.py \
 		mochitest_options.py \
 		manifest.webapp \
 		$(topsrcdir)/testing/mozbase/mozdevice/mozdevice/devicemanager.py \
 		$(topsrcdir)/testing/mozbase/mozdevice/mozdevice/devicemanagerADB.py \
 		$(topsrcdir)/testing/mozbase/mozdevice/mozdevice/devicemanagerSUT.py \
 		$(topsrcdir)/testing/mozbase/manifestparser/manifestparser/manifestparser.py \
 		$(topsrcdir)/testing/mozbase/mozdevice/mozdevice/droid.py \
 		$(topsrcdir)/testing/mozbase/mozdevice/mozdevice/Zeroconf.py \
--- a/testing/mochitest/bisection.py
+++ b/testing/mochitest/bisection.py
@@ -1,9 +1,8 @@
-import os
 import math
 import mozinfo
 
 class Bisect(object):
     "Class for creating, bisecting and summarizing for --bisect-chunk option."
 
     def __init__(self, harness):
         super(Bisect, self).__init__()
--- a/testing/mochitest/mach_commands.py
+++ b/testing/mochitest/mach_commands.py
@@ -2,17 +2,16 @@
 # 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/.
 
 from __future__ import unicode_literals
 
 import logging
 import mozpack.path
 import os
-import platform
 import sys
 import warnings
 import which
 
 from mozbuild.base import (
     MachCommandBase,
     MachCommandConditions as conditions,
     MozbuildObject,
@@ -136,24 +135,21 @@ class MochitestRunner(MozbuildObject):
                     ('.py', 'r', imp.PY_SOURCE))
 
             import mochitest
             from mochitest_options import B2GOptions
 
         parser = B2GOptions()
         options = parser.parse_args([])[0]
 
-        test_path_dir = False;
         if test_path:
             test_root_file = mozpack.path.join(self.mochitest_dir, 'tests', test_path)
             if not os.path.exists(test_root_file):
                 print('Specified test path does not exist: %s' % test_root_file)
                 return 1
-            if os.path.isdir(test_root_file):
-                test_path_dir = True;
             options.testPath = test_path
 
         for k, v in kwargs.iteritems():
             setattr(options, k, v)
         options.noWindow = no_window
         options.totalChunks = total_chunks
         options.thisChunk = this_chunk
 
--- a/testing/mochitest/runtests.py
+++ b/testing/mochitest/runtests.py
@@ -215,17 +215,17 @@ def call(*args, **kwargs):
 def killPid(pid):
   # see also https://bugzilla.mozilla.org/show_bug.cgi?id=911249#c58
   try:
     os.kill(pid, getattr(signal, "SIGKILL", signal.SIGTERM))
   except Exception, e:
     log.info("Failed to kill process %d: %s" % (pid, str(e)))
 
 if mozinfo.isWin:
-  import ctypes, ctypes.wintypes, time, msvcrt
+  import ctypes.wintypes
 
   def isPidAlive(pid):
     STILL_ACTIVE = 259
     PROCESS_QUERY_LIMITED_INFORMATION = 0x1000
     pHandle = ctypes.windll.kernel32.OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, 0, pid)
     if not pHandle:
       return False
     pExitCode = ctypes.wintypes.DWORD()
@@ -1317,20 +1317,16 @@ class Mochitest(MochitestUtilsMixin):
     if debuggerInfo:
         interactive = debuggerInfo['interactive']
         debug_args = [debuggerInfo['path']] + debuggerInfo['args']
 
     # fix default timeout
     if timeout == -1:
       timeout = self.DEFAULT_TIMEOUT
 
-    # build parameters
-    is_test_build = mozinfo.info.get('tests_enabled', True)
-    bin_suffix = mozinfo.info.get('bin_suffix', '')
-
     # copy env so we don't munge the caller's environment
     env = env.copy()
 
     # make sure we clean up after ourselves.
     try:
       # set process log environment variable
       tmpfd, processLog = tempfile.mkstemp(suffix='pidlog')
       os.close(tmpfd)
@@ -1964,46 +1960,16 @@ class Mochitest(MochitestUtilsMixin):
 
     d = dict(options.__dict__)
     d['testRoot'] = self.testRoot
     content = json.dumps(d)
 
     with open(os.path.join(options.profilePath, "testConfig.js"), "w") as config:
       config.write(content)
 
-  def installExtensionFromPath(self, options, path, extensionID = None):
-    """install an extension to options.profilePath"""
-
-    # TODO: currently extensionID is unused; see
-    # https://bugzilla.mozilla.org/show_bug.cgi?id=914267
-    # [mozprofile] make extensionID a parameter to install_from_path
-    # https://github.com/mozilla/mozbase/blob/master/mozprofile/mozprofile/addons.py#L169
-
-    extensionPath = self.getFullPath(path)
-
-    log.info("runtests.py | Installing extension at %s to %s." %
-                (extensionPath, options.profilePath))
-
-    addons = AddonManager(options.profilePath)
-
-    # XXX: del the __del__
-    # hack can be removed when mozprofile is mirrored to m-c ; see
-    # https://bugzilla.mozilla.org/show_bug.cgi?id=911218 :
-    # [mozprofile] AddonManager should only cleanup on __del__ optionally:
-    # https://github.com/mozilla/mozbase/blob/master/mozprofile/mozprofile/addons.py#L266
-    if hasattr(addons, '__del__'):
-      del addons.__del__
-
-    addons.install_from_path(path)
-
-  def installExtensionsToProfile(self, options):
-    "Install special testing extensions, application distributed extensions, and specified on the command line ones to testing profile."
-    for path in self.getExtensionsToInstall(options):
-      self.installExtensionFromPath(options, path)
-
   def getTestManifest(self, options):
     if isinstance(options.manifestFile, TestManifest):
         manifest = options.manifestFile
     elif options.manifestFile and os.path.isfile(options.manifestFile):
       manifestFileAbs = os.path.abspath(options.manifestFile)
       assert manifestFileAbs.startswith(SCRIPT_DIR)
       manifest = TestManifest([options.manifestFile], strict=False)
     elif options.manifestFile and os.path.isfile(os.path.join(SCRIPT_DIR, options.manifestFile)):
deleted file mode 100644
--- a/testing/mochitest/runtestsvmware.py
+++ /dev/null
@@ -1,397 +0,0 @@
-#
-# 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 sys
-import os
-import re
-import types
-from optparse import OptionValueError
-from subprocess import PIPE
-from time import sleep
-from tempfile import mkstemp
-
-sys.path.insert(0, os.path.abspath(os.path.realpath(
-  os.path.dirname(sys.argv[0]))))
-
-from automation import Automation
-from runtests import Mochitest, MochitestOptions
-
-class VMwareOptions(MochitestOptions):
-  def __init__(self, automation, mochitest, **kwargs):
-    defaults = {}
-    self._automation = automation or Automation()
-    MochitestOptions.__init__(self, mochitest.SCRIPT_DIRECTORY)
-
-    def checkPathCallback(option, opt_str, value, parser):
-      path = mochitest.getFullPath(value)
-      if not os.path.exists(path):
-        raise OptionValueError("Path %s does not exist for %s option"
-                               % (path, opt_str))
-      setattr(parser.values, option.dest, path)
-
-    self.add_option("--with-vmware-vm",
-                    action = "callback", type = "string", dest = "vmx",
-                    callback = checkPathCallback,
-                    help = "launches the given VM and runs mochitests inside")
-    defaults["vmx"] = None
-
-    self.add_option("--with-vmrun-executable",
-                    action = "callback", type = "string", dest = "vmrun",
-                    callback = checkPathCallback,
-                    help = "specifies the vmrun.exe to use for VMware control")
-    defaults["vmrun"] = None
- 
-    self.add_option("--shutdown-vm-when-done",
-                    action = "store_true", dest = "shutdownVM",
-                    help = "shuts down the VM when mochitests complete")
-    defaults["shutdownVM"] = False
-
-    self.add_option("--repeat-until-failure",
-                    action = "store_true", dest = "repeatUntilFailure",
-                    help = "Runs tests continuously until failure")
-    defaults["repeatUntilFailure"] = False
-
-    self.set_defaults(**defaults)
-
-class VMwareMochitest(Mochitest):
-  _pathFixRegEx = re.compile(r'^[cC](\:[\\\/]+)')
-
-  def convertHostPathsToGuestPaths(self, string):
-    """ converts a path on the host machine to a path on the guest machine """
-    # XXXbent Lame!
-    return self._pathFixRegEx.sub(r'z\1', string)
-
-  def prepareGuestArguments(self, parser, options):
-    """ returns an array of command line arguments needed to replicate the
-        current set of options in the guest """
-    args = []
-    for key in options.__dict__.keys():
-      # Don't send these args to the vm test runner!
-      if key == "vmrun" or key == "vmx" or key == "repeatUntilFailure":
-        continue
-
-      value = options.__dict__[key]
-      valueType = type(value)
-
-      # Find the option in the parser's list.
-      option = None
-      for index in range(len(parser.option_list)):
-        if str(parser.option_list[index].dest) == key:
-          option = parser.option_list[index]
-          break
-      if not option:
-        continue
-
-      # No need to pass args on the command line if they're just going to set
-      # default values. The exception is list values... For some reason the
-      # option parser modifies the defaults as well as the values when using the
-      # "append" action.
-      if value == parser.defaults[option.dest]:
-        if valueType == types.StringType and \
-           value == self.convertHostPathsToGuestPaths(value):
-          continue
-        if valueType != types.ListType:
-          continue
-
-      def getArgString(arg, option):
-        if option.action == "store_true" or option.action == "store_false":
-          return str(option)
-        return "%s=%s" % (str(option),
-                          self.convertHostPathsToGuestPaths(str(arg)))
-
-      if valueType == types.ListType:
-        # Expand lists into separate args.
-        for item in value:
-          args.append(getArgString(item, option))
-      else:
-        args.append(getArgString(value, option))
-
-    return tuple(args)
-
-  def launchVM(self, options):
-    """ launches the VM and enables shared folders """
-    # Launch VM first.
-    self.automation.log.info("INFO | runtests.py | Launching the VM.")
-    (result, stdout) = self.runVMCommand(self.vmrunargs + ("start", self.vmx))
-    if result:
-      return result
-
-    # Make sure that shared folders are enabled.
-    self.automation.log.info("INFO | runtests.py | Enabling shared folders in "
-                             "the VM.")
-    (result, stdout) = self.runVMCommand(self.vmrunargs + \
-                                         ("enableSharedFolders", self.vmx))
-    if result:
-      return result
-
-  def shutdownVM(self):
-    """ shuts down the VM """
-    self.automation.log.info("INFO | runtests.py | Shutting down the VM.")
-    command = self.vmrunargs + ("runProgramInGuest", self.vmx,
-              "c:\\windows\\system32\\shutdown.exe", "/s", "/t", "1")
-    (result, stdout) = self.runVMCommand(command)
-    return result
-
-  def runVMCommand(self, command, expectedErrors=[], silent=False):
-    """ runs a command in the VM using the vmrun.exe helper """
-    commandString = ""
-    for part in command:
-      commandString += str(part) + " "
-    if not silent:
-      self.automation.log.info("INFO | runtests.py | Running command: %s"
-                               % commandString)
-
-    commonErrors = ["Error: Invalid user name or password for the guest OS",
-                    "Unable to connect to host."]
-    expectedErrors.extend(commonErrors)
-
-    # VMware can't run commands until the VM has fully loaded so keep running
-    # this command in a loop until it succeeds or we try 100 times.
-    errorString = ""
-    for i in range(100):
-      process = Automation.Process(command, stdout=PIPE)
-      result = process.wait()
-      if result == 0:
-        break
-
-      for line in process.stdout.readlines():
-        line = line.strip()
-        if not line:
-          continue
-        errorString = line
-        break
-
-      expected = False
-      for error in expectedErrors:
-        if errorString.startswith(error):
-          expected = True
-
-      if not expected:
-        self.automation.log.warning("WARNING | runtests.py | Command \"%s\" "
-                                    "failed with result %d, : %s"
-                                    % (commandString, result, errorString))
-        break
-
-      if not silent:
-        self.automation.log.info("INFO | runtests.py | Running command again.")
-
-    return (result, process.stdout.readlines())
-
-  def monitorVMExecution(self, appname, logfilepath):
-    """ monitors test execution in the VM. Waits for the test process to start,
-        then watches the log file for test failures and checks the status of the
-        process to catch crashes. Returns True if mochitests ran successfully.
-    """
-    success = True
-
-    self.automation.log.info("INFO | runtests.py | Waiting for test process to "
-                             "start.")
-
-    listProcessesCommand = self.vmrunargs + ("listProcessesInGuest", self.vmx)
-    expectedErrors = [ "Error: The virtual machine is not powered on" ]
-
-    running  = False
-    for i in range(100):
-      (result, stdout) = self.runVMCommand(listProcessesCommand, expectedErrors,
-                                           silent=True)
-      if result:
-        self.automation.log.warning("WARNING | runtests.py | Failed to get "
-                                    "list of processes in VM!")
-        return False
-      for line in stdout:
-        line = line.strip()
-        if line.find(appname) != -1:
-          running = True
-          break
-      if running:
-        break
-      sleep(1)
-
-    self.automation.log.info("INFO | runtests.py | Found test process, "
-                             "monitoring log.")
-
-    completed = False
-    nextLine = 0
-    while running:
-      log = open(logfilepath, "rb")
-      lines = log.readlines()
-      if len(lines) > nextLine:
-        linesToPrint = lines[nextLine:]
-        for line in linesToPrint:
-          line = line.strip()
-          if line.find("INFO SimpleTest FINISHED") != -1:
-            completed = True
-            continue
-          if line.find("ERROR TEST-UNEXPECTED-FAIL") != -1:
-            self.automation.log.info("INFO | runtests.py | Detected test "
-                                     "failure: \"%s\"" % line)
-            success = False
-        nextLine = len(lines)
-      log.close()
-
-      (result, stdout) = self.runVMCommand(listProcessesCommand, expectedErrors,
-                                           silent=True)
-      if result:
-        self.automation.log.warning("WARNING | runtests.py | Failed to get "
-                                    "list of processes in VM!")
-        return False
-
-      stillRunning = False
-      for line in stdout:
-        line = line.strip()
-        if line.find(appname) != -1:
-          stillRunning = True
-          break
-      if stillRunning:
-        sleep(5)
-      else:
-        if not completed:
-          self.automation.log.info("INFO | runtests.py | Test process exited "
-                                   "without finishing tests, maybe crashed.")
-          success = False
-        running = stillRunning
-
-    return success
-
-  def getCurentSnapshotList(self):
-    """ gets a list of snapshots from the VM """
-    (result, stdout) = self.runVMCommand(self.vmrunargs + ("listSnapshots",
-                                                           self.vmx))
-    snapshots = []
-    if result != 0:
-      self.automation.log.warning("WARNING | runtests.py | Failed to get list "
-                                  "of snapshots in VM!")
-      return snapshots
-    for line in stdout:
-      if line.startswith("Total snapshots:"):
-        continue
-      snapshots.append(line.strip())
-    return snapshots
-
-  def runTests(self, parser, options):
-    """ runs mochitests in the VM """
-    # Base args that must always be passed to vmrun.
-    self.vmrunargs = (options.vmrun, "-T", "ws", "-gu", "Replay", "-gp",
-                      "mozilla")
-    self.vmrun = options.vmrun
-    self.vmx = options.vmx
-
-    result = self.launchVM(options)
-    if result:
-      return result
-
-    if options.vmwareRecording:
-      snapshots = self.getCurentSnapshotList()
-
-    def innerRun():
-      """ subset of the function that must run every time if we're running until
-          failure """
-      # Make a new shared file for the log file.
-      (logfile, logfilepath) = mkstemp(suffix=".log")
-      os.close(logfile)
-      # Get args to pass to VM process. Make sure we autorun and autoclose.
-      options.autorun = True
-      options.closeWhenDone = True
-      options.logFile = logfilepath
-      self.automation.log.info("INFO | runtests.py | Determining guest "
-                               "arguments.")
-      runtestsArgs = self.prepareGuestArguments(parser, options)
-      runtestsPath = self.convertHostPathsToGuestPaths(self.SCRIPT_DIRECTORY)
-      runtestsPath = os.path.join(runtestsPath, "runtests.py")
-      runtestsCommand = self.vmrunargs + ("runProgramInGuest", self.vmx,
-                        "-activeWindow", "-interactive", "-noWait",
-                        "c:\\mozilla-build\\python25\\python.exe",
-                        runtestsPath) + runtestsArgs
-      expectedErrors = [ "Unable to connect to host.",
-                         "Error: The virtual machine is not powered on" ]
-      self.automation.log.info("INFO | runtests.py | Launching guest test "
-                               "runner.")
-      (result, stdout) = self.runVMCommand(runtestsCommand, expectedErrors)
-      if result:
-        return (result, False)
-      self.automation.log.info("INFO | runtests.py | Waiting for guest test "
-                               "runner to complete.")
-      mochitestsSucceeded = self.monitorVMExecution(
-        os.path.basename(options.app), logfilepath)
-      if mochitestsSucceeded:
-        self.automation.log.info("INFO | runtests.py | Guest tests passed!")
-      else:
-        self.automation.log.info("INFO | runtests.py | Guest tests failed.")
-      if mochitestsSucceeded and options.vmwareRecording:
-        newSnapshots = self.getCurentSnapshotList()
-        if len(newSnapshots) > len(snapshots):
-          self.automation.log.info("INFO | runtests.py | Removing last "
-                                   "recording.")
-          (result, stdout) = self.runVMCommand(self.vmrunargs + \
-                                               ("deleteSnapshot", self.vmx,
-                                                newSnapshots[-1]))
-      self.automation.log.info("INFO | runtests.py | Removing guest log file.")
-      for i in range(30):
-        try:
-          os.remove(logfilepath)
-          break
-        except:
-          sleep(1)
-          self.automation.log.warning("WARNING | runtests.py | Couldn't remove "
-                                      "guest log file, trying again.")
-      return (result, mochitestsSucceeded)
-
-    if options.repeatUntilFailure:
-      succeeded = True
-      result = 0
-      count = 1
-      while result == 0 and succeeded:
-        self.automation.log.info("INFO | runtests.py | Beginning mochitest run "
-                                 "(%d)." % count)
-        count += 1
-        (result, succeeded) = innerRun()
-    else:
-      self.automation.log.info("INFO | runtests.py | Beginning mochitest run.")
-      (result, succeeded) = innerRun()
-
-    if not succeeded and options.vmwareRecording:
-      newSnapshots = self.getCurentSnapshotList()
-      if len(newSnapshots) > len(snapshots):
-        self.automation.log.info("INFO | runtests.py | Failed recording saved "
-                                 "as '%s'." % newSnapshots[-1])
-
-    if result:
-      return result
-
-    if options.shutdownVM:
-      result = self.shutdownVM()
-      if result:
-        return result
-
-    return 0
-
-def main():
-  automation = Automation()
-  mochitest = VMwareMochitest(automation)
-
-  parser = VMwareOptions(automation, mochitest)
-  options, args = parser.parse_args()
-  options = parser.verifyOptions(options, mochitest)
-  if (options == None):
-    sys.exit(1)
-
-  if options.vmx is None:
-    parser.error("A virtual machine must be specified with " +
-                 "--with-vmware-vm")
-
-  if options.vmrun is None:
-    options.vmrun = os.path.join("c:\\", "Program Files", "VMware",
-                                 "VMware VIX", "vmrun.exe")
-    if not os.path.exists(options.vmrun):
-      options.vmrun = os.path.join("c:\\", "Program Files (x86)", "VMware",
-                                   "VMware VIX", "vmrun.exe")
-      if not os.path.exists(options.vmrun):
-        parser.error("Could not locate vmrun.exe, use --with-vmrun-executable" +
-                     " to identify its location")
-
-  sys.exit(mochitest.runTests(parser, options))
-
-if __name__ == "__main__":
-  main()