Bug 550860 - Profile directory for xpcshell based tests needs to be in a predefined, stable, location for at least some tests. r=ted
authorJosh Matthews <josh@joshmatthews.net>
Wed, 28 Apr 2010 03:28:56 +1000
changeset 46203 51bd519736c4e6dffb12d01bfc160036c82f147e
parent 46202 21ee5212a53728c6b443c5e123774455d3064e97
child 46204 c13c4f35a17b8ea2bba25010bfcf1de1a3a9978e
push id14066
push userCallek@gmail.com
push dateFri, 25 Jun 2010 04:15:04 +0000
treeherdermozilla-central@51bd519736c4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs550860
milestone1.9.3a6pre
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 550860 - Profile directory for xpcshell based tests needs to be in a predefined, stable, location for at least some tests. r=ted
config/rules.mk
js/src/config/rules.mk
testing/xpcshell/runxpcshelltests.py
--- a/config/rules.mk
+++ b/config/rules.mk
@@ -175,27 +175,29 @@ xpcshell-tests:
 # start the test. Instead, present the xpcshell prompt so the user can
 # attach a debugger and then start the test.
 check-interactive:
 	$(PYTHON) -u $(topsrcdir)/config/pythonpath.py \
           -I$(topsrcdir)/build \
           $(testxpcsrcdir)/runxpcshelltests.py \
           --symbols-path=$(DIST)/crashreporter-symbols \
           --test-path=$(SOLO_FILE) \
+          --profile-name=$(MOZ_APP_NAME) \
           --interactive \
           $(DIST)/bin/xpcshell \
           $(foreach dir,$(XPCSHELL_TESTS),$(testxpcobjdir)/$(MODULE)/$(dir))
 
 # Execute a single test, specified in $(SOLO_FILE)
 check-one:
 	$(PYTHON) -u $(topsrcdir)/config/pythonpath.py \
           -I$(topsrcdir)/build \
           $(testxpcsrcdir)/runxpcshelltests.py \
           --symbols-path=$(DIST)/crashreporter-symbols \
           --test-path=$(SOLO_FILE) \
+          --profile-name=$(MOZ_APP_NAME) \
           $(DIST)/bin/xpcshell \
           $(foreach dir,$(XPCSHELL_TESTS),$(testxpcobjdir)/$(MODULE)/$(dir))
 
 endif # XPCSHELL_TESTS
 
 ifdef CPP_UNIT_TESTS
 
 # Compile the tests to $(DIST)/bin.  Make lots of niceties available by default
--- a/js/src/config/rules.mk
+++ b/js/src/config/rules.mk
@@ -175,27 +175,29 @@ xpcshell-tests:
 # start the test. Instead, present the xpcshell prompt so the user can
 # attach a debugger and then start the test.
 check-interactive:
 	$(PYTHON) -u $(topsrcdir)/config/pythonpath.py \
           -I$(topsrcdir)/build \
           $(testxpcsrcdir)/runxpcshelltests.py \
           --symbols-path=$(DIST)/crashreporter-symbols \
           --test-path=$(SOLO_FILE) \
+          --profile-name=$(MOZ_APP_NAME) \
           --interactive \
           $(DIST)/bin/xpcshell \
           $(foreach dir,$(XPCSHELL_TESTS),$(testxpcobjdir)/$(MODULE)/$(dir))
 
 # Execute a single test, specified in $(SOLO_FILE)
 check-one:
 	$(PYTHON) -u $(topsrcdir)/config/pythonpath.py \
           -I$(topsrcdir)/build \
           $(testxpcsrcdir)/runxpcshelltests.py \
           --symbols-path=$(DIST)/crashreporter-symbols \
           --test-path=$(SOLO_FILE) \
+          --profile-name=$(MOZ_APP_NAME) \
           $(DIST)/bin/xpcshell \
           $(foreach dir,$(XPCSHELL_TESTS),$(testxpcobjdir)/$(MODULE)/$(dir))
 
 endif # XPCSHELL_TESTS
 
 ifdef CPP_UNIT_TESTS
 
 # Compile the tests to $(DIST)/bin.  Make lots of niceties available by default
--- a/testing/xpcshell/runxpcshelltests.py
+++ b/testing/xpcshell/runxpcshelltests.py
@@ -37,17 +37,17 @@
 # the terms of any one of the MPL, the GPL or the LGPL.
 #
 # ***** END LICENSE BLOCK ***** */
 
 import re, sys, os, os.path, logging, shutil, signal, math
 from glob import glob
 from optparse import OptionParser
 from subprocess import Popen, PIPE, STDOUT
-from tempfile import mkdtemp
+from tempfile import mkdtemp, gettempdir
 
 from automationutils import *
 
 class XPCShellTests(object):
 
   log = logging.getLogger()
   oldcwd = os.getcwd()
 
@@ -265,21 +265,34 @@ class XPCShellTests(object):
       else: # not in this dir? skip it
         return None
             
     return testfiles
 
   def setupProfileDir(self):
     """
       Create a temporary folder for the profile and set appropriate environment variables.
+      When running check-interactive and check-one, the directory is well-defined and
+      retained for inspection once the tests complete.
 
       On a remote system, we overload this to use a remote path structure.
     """
-    profileDir = mkdtemp()
+    if self.interactive or self.singleFile:
+      profileDir = os.path.join(gettempdir(), self.profileName, "xpcshellprofile")
+      try:
+        # This could be left over from previous runs
+        self.removeDir(profileDir)
+      except:
+        pass
+      os.makedirs(profileDir)
+    else:
+      profileDir = mkdtemp()
     self.env["XPCSHELL_TEST_PROFILE_DIR"] = profileDir
+    if self.interactive or self.singleFile:
+      print "TEST-INFO | profile dir is %s" % profileDir
     return profileDir
 
   def setupLeakLogging(self):
     """
       Enable leaks (only) detection to its own log file and set environment variables.
 
       On a remote system, we overload this to use a remote filename and path structure
     """
@@ -358,17 +371,18 @@ class XPCShellTests(object):
             ['-e', 'const _SERVER_ADDR = "localhost"',
              '-e', 'const _HEAD_FILES = [%s];' % cmdH,
              '-e', 'const _TAIL_FILES = [%s];' % cmdT]
 
   def runTests(self, xpcshell, xrePath=None, symbolsPath=None,
                manifest=None, testdirs=[], testPath=None,
                interactive=False, logfiles=True,
                thisChunk=1, totalChunks=1, debugger=None,
-               debuggerArgs=None, debuggerInteractive=False):
+               debuggerArgs=None, debuggerInteractive=False,
+               profileName=None):
     """Run xpcshell tests.
 
     |xpcshell|, is the xpcshell executable to use to run the tests.
     |xrePath|, if provided, is the path to the XRE to use.
     |symbolsPath|, if provided is the path to a directory containing
       breakpad symbols for processing crashes in tests.
     |manifest|, if provided, is a file containing a list of
       test directories to run.
@@ -376,29 +390,32 @@ class XPCShellTests(object):
       No-manifest only option.
     |testPath|, if provided, indicates a single path and/or test to run.
     |interactive|, if set to True, indicates to provide an xpcshell prompt
       instead of automatically executing the test.
     |logfiles|, if set to False, indicates not to save output to log files.
       Non-interactive only option.
     |debuggerInfo|, if set, specifies the debugger and debugger arguments
       that will be used to launch xpcshell.
+    |profileName|, if set, specifies the name of the application for the profile
+      directory if running only a subset of tests
     """
 
     self.xpcshell = xpcshell
     self.xrePath = xrePath
     self.symbolsPath = symbolsPath
     self.manifest = manifest
     self.testdirs = testdirs
     self.testPath = testPath
     self.interactive = interactive
     self.logfiles = logfiles
     self.totalChunks = totalChunks
     self.thisChunk = thisChunk
     self.debuggerInfo = getDebuggerInfo(self.oldcwd, debugger, debuggerArgs, debuggerInteractive)
+    self.profileName = profileName or "xpcshell"
 
     if not testdirs and not manifest:
       # nothing to test!
       print >>sys.stderr, "Error: No test dirs or test manifest specified!"
       return False
 
     passCount = 0
     failCount = 0
@@ -455,17 +472,19 @@ class XPCShellTests(object):
             passCount += 1
 
           checkForCrashes(testdir, self.symbolsPath, testName=test)
           dumpLeakLog(self.leakLogFile, True)
 
           if self.logfiles and stdout:
             self.createLogFile(test, stdout)
         finally:
-          if self.profileDir:
+          # We don't want to delete the profile when running check-interactive
+          # or check-one.
+          if self.profileDir and not self.interactive and not self.singleFile:
             self.removeDir(self.profileDir)
 
     if passCount == 0 and failCount == 0:
       print "TEST-UNEXPECTED-FAIL | runxpcshelltests.py | No tests run. Did you pass an invalid --test-path?"
       failCount = 1
 
     print """INFO | Result summary:
 INFO | Passed: %d
@@ -495,16 +514,19 @@ class XPCShellOptions(OptionParser):
                     type="string", dest="testPath", default=None,
                     help="single path and/or test filename to test")
     self.add_option("--total-chunks",
                     type = "int", dest = "totalChunks", default=1,
                     help = "how many chunks to split the tests up into")
     self.add_option("--this-chunk",
                     type = "int", dest = "thisChunk", default=1,
                     help = "which chunk to run between 1 and --total-chunks")
+    self.add_option("--profile-name",
+                    type = "string", dest="profileName", default=None,
+                    help="name of application profile being tested")
 
 def main():
   parser = XPCShellOptions()
   options, args = parser.parse_args()
 
   if len(args) < 2 and options.manifest is None or \
      (len(args) < 1 and options.manifest is not None):
      print >>sys.stderr, """Usage: %s <path to xpcshell> <test dirs>