Bug 1197541 - Add --dump-tests option to mochitest and xpcshell for all tests that will be run. r=ahal
authorVaibhav Agrawal <vaibhavmagarwal@gmail.com>
Fri, 21 Aug 2015 17:16:11 -0700
changeset 292036 bb27412c9a7969f0f13c7cba34f075871de83efb
parent 292035 c1c2b9fbd66fb4261dd6ee9494298e815c830461
child 292037 8ad3f1c2b954255d25c7850cd86a453453143d45
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
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 1197541 - Add --dump-tests option to mochitest and xpcshell for all tests that will be run. r=ahal
--- a/testing/mochitest/mochitest_options.py
+++ b/testing/mochitest/mochitest_options.py
@@ -318,16 +318,22 @@ class MochitestArguments(ArgumentContain
          {"dest": "testRunManifestFile",
           "default": 'tests.json',
           "help": "Overrides the default filename of the tests.json manifest file that is "
                   "generated by the harness and used by SimpleTest. Only useful when running "
                   "multiple test runs simulatenously on the same machine.",
           "suppress": True,
+        [["--dump-tests"],
+         {"dest": "dump_tests",
+          "default": None,
+          "help": "Specify path to a filename to dump all the tests that will be run",
+          "suppress": True,
+          }],
          {"dest": "failureFile",
           "default": None,
           "help": "Filename of the output file where we can store a .json list of failures "
                   "to be run in the future with --run-only-tests.",
           "suppress": True,
--- a/testing/mochitest/runtests.py
+++ b/testing/mochitest/runtests.py
@@ -1973,16 +1973,25 @@ class Mochitest(MochitestUtilsMixin):
         def path_sort(ob1, ob2):
             path1 = ob1['path'].split('/')
             path2 = ob2['path'].split('/')
             return cmp(path1, path2)
         self._active_tests = paths
+        if options.dump_tests:
+            options.dump_tests = os.path.expanduser(options.dump_tests)
+            assert os.path.exists(os.path.dirname(options.dump_tests))
+            with open(options.dump_tests, 'w') as dumpFile:
+                dumpFile.write(json.dumps({'active_tests': self._active_tests}))
+            self.log.info("Dumping active_tests to %s file." % options.dump_tests)
+            sys.exit()
         return self._active_tests
     def logPreamble(self, tests):
         """Logs a suite_start message and test_start/test_end at the beginning of a run.
         self.log.suite_start([t['path'] for t in tests])
         for test in tests:
             if 'disabled' in test:
--- a/testing/xpcshell/mach_commands.py
+++ b/testing/xpcshell/mach_commands.py
@@ -61,17 +61,17 @@ class XPCShellRunner(MozbuildObject):
         return self._run_xpcshell_harness(manifest=manifest, **kwargs)
     def run_test(self, test_paths, interactive=False,
                  keep_going=False, sequential=False, shuffle=False,
                  debugger=None, debuggerArgs=None, debuggerInteractive=None,
                  jsDebugger=False, jsDebuggerPort=None,
                  rerun_failures=False, test_objects=None, verbose=False,
-                 log=None, test_tags=None,
+                 log=None, test_tags=None, dump_tests=None,
                  # ignore parameters from other platforms' options
         """Runs an individual xpcshell test."""
         from mozbuild.testing import TestResolver
         from manifestparser import TestManifest
         # TODO Bug 794506 remove once mach integrates with virtualenv.
         build_path = os.path.join(self.topobjdir, 'build')
@@ -84,17 +84,17 @@ class XPCShellRunner(MozbuildObject):
         if test_paths == 'all':
                            keep_going=keep_going, shuffle=shuffle, sequential=sequential,
                            debugger=debugger, debuggerArgs=debuggerArgs,
                            jsDebugger=jsDebugger, jsDebuggerPort=jsDebuggerPort,
-                           verbose=verbose, log=log, test_tags=test_tags)
+                           verbose=verbose, log=log, test_tags=test_tags, dump_tests=dump_tests)
         elif test_paths:
             test_paths = [self._wrap_path_argument(p).relpath() for p in test_paths]
         if test_objects:
             tests = test_objects
             resolver = self._spawn(TestResolver)
@@ -120,26 +120,28 @@ class XPCShellRunner(MozbuildObject):
             'debuggerInteractive': debuggerInteractive,
             'jsDebugger': jsDebugger,
             'jsDebuggerPort': jsDebuggerPort,
             'rerun_failures': rerun_failures,
             'manifest': manifest,
             'verbose': verbose,
             'log': log,
             'test_tags': test_tags,
+            'dump_tests': dump_tests,
         return self._run_xpcshell_harness(**args)
     def _run_xpcshell_harness(self, manifest,
                               test_path=None, shuffle=False, interactive=False,
                               keep_going=False, sequential=False,
                               debugger=None, debuggerArgs=None, debuggerInteractive=None,
                               jsDebugger=False, jsDebuggerPort=None,
-                              rerun_failures=False, verbose=False, log=None, test_tags=None):
+                              rerun_failures=False, verbose=False, log=None, test_tags=None,
+                              dump_tests=None):
         # Obtain a reference to the xpcshell test runner.
         import runxpcshelltests
         xpcshell = runxpcshelltests.XPCShellTests(log=log)
         tests_dir = os.path.join(self.topobjdir, '_tests', 'xpcshell')
@@ -168,16 +170,17 @@ class XPCShellRunner(MozbuildObject):
             'xunitName': 'xpcshell',
             'pluginsPath': os.path.join(self.distdir, 'plugins'),
             'debugger': debugger,
             'debuggerArgs': debuggerArgs,
             'debuggerInteractive': debuggerInteractive,
             'jsDebugger': jsDebugger,
             'jsDebuggerPort': jsDebuggerPort,
             'test_tags': test_tags,
+            'dump_tests': dump_tests,
             'utility_path': self.bindir,
         if test_path is not None:
             args['testPath'] = test_path
         # A failure manifest is written by default. If --rerun-failures is
         # specified and a prior failure manifest is found, the prior manifest
@@ -442,16 +445,18 @@ class MachCommands(MachCommandBase):
     @CommandArgument('--shuffle', '-s', action='store_true',
         help='Randomize the execution order of tests.')
     @CommandArgument('--rerun-failures', action='store_true',
         help='Reruns failures from last time.')
     @CommandArgument('--tag', action='append', dest='test_tags',
         help='Filter out tests that don\'t have the given tag. Can be used '
              'multiple times in which case the test must contain at least one '
              'of the given tags.')
+    @CommandArgument('--dump-tests', default=None, type=str, dest='dump_tests',
+        help='Specify path to a filename to dump all the tests that will be run')
     @CommandArgument('--devicemanager', default='adb', type=str,
         help='(Android) Type of devicemanager to use for communication: adb or sut')
     @CommandArgument('--ip', type=str, default=None,
         help='(Android) IP address of device')
     @CommandArgument('--port', type=int, default=20701,
         help='(Android) Port of device')
     @CommandArgument('--remote_test_root', type=str, default=None,
         help='(Android) Remote test root such as /mnt/sdcard or /data/local')
--- a/testing/xpcshell/runxpcshelltests.py
+++ b/testing/xpcshell/runxpcshelltests.py
@@ -832,16 +832,25 @@ class XPCShellTests(object):
             sys.stderr.write("*** offending mozinfo.info: %s\n" % repr(mozinfo.info))
         if len(self.alltests) == 0:
             self.log.error("no tests to run using specified "
                            "combination of filters: {}".format(
+        if self.dump_tests:
+            self.dump_tests = os.path.expanduser(self.dump_tests)
+            assert os.path.exists(os.path.dirname(self.dump_tests))
+            with open(self.dump_tests, 'w') as dumpFile:
+                dumpFile.write(json.dumps({'active_tests': self.alltests}))
+            self.log.info("Dumping active_tests to %s file." % self.dump_tests)
+            sys.exit()
     def setAbsPath(self):
           Set the absolute path for xpcshell, httpdjspath and xrepath.
           These 3 variables depend on input from the command line and we need to allow for absolute paths.
           This function is overloaded for a remote solution as os.path* won't work remotely.
         self.testharnessdir = os.path.dirname(os.path.abspath(__file__))
         self.headJSPath = self.testharnessdir.replace("\\", "/") + "/head.js"
@@ -1071,17 +1080,17 @@ class XPCShellTests(object):
                  manifest=None, testdirs=None, testPath=None, mobileArgs=None,
                  interactive=False, verbose=False, keepGoing=False, logfiles=True,
                  thisChunk=1, totalChunks=1, debugger=None,
                  debuggerArgs=None, debuggerInteractive=False,
                  profileName=None, mozInfo=None, sequential=False, shuffle=False,
                  testsRootDir=None, testingModulesDir=None, pluginsPath=None,
                  testClass=XPCShellTestThread, failureManifest=None,
                  log=None, stream=None, jsDebugger=False, jsDebuggerPort=0,
-                 test_tags=None, utility_path=None, **otherOptions):
+                 test_tags=None, dump_tests=None, utility_path=None, **otherOptions):
         """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.
         |appPath|, if provided, is the path to an application directory.
         |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
@@ -1155,16 +1164,17 @@ class XPCShellTests(object):
         self.xpcshell = xpcshell
         self.xrePath = xrePath
         self.appPath = appPath
         self.symbolsPath = symbolsPath
         self.manifest = manifest
         self.testdirs = testdirs
         self.testPath = testPath
+        self.dump_tests = dump_tests
         self.interactive = interactive
         self.verbose = verbose
         self.keepGoing = keepGoing
         self.logfiles = logfiles
         self.totalChunks = totalChunks
         self.thisChunk = thisChunk
         self.profileName = profileName or "xpcshell"
         self.mozInfo = mozInfo
@@ -1468,16 +1478,19 @@ class XPCShellOptions(OptionParser):
                         action="store_true", dest="verbose", default=False,
                         help="always print stdout and stderr from tests")
                         action="store_true", dest="keepGoing", default=False,
                         help="continue running tests after test killed with control-C (SIGINT)")
                         action="store_true", dest="logfiles", default=True,
                         help="create log files (default, only used to override --no-logfiles)")
+        self.add_option("--dump-tests",
+                        type="string", dest="dump_tests", default=None,
+                        help="Specify path to a filename to dump all the tests that will be run")
                         type="string", dest="manifest", default=None,
                         help="Manifest of test directories to use")
                         action="store_false", dest="logfiles",
                         help="don't create log files")
                         action="store_true", dest="sequential", default=False,