Bug 949538 - Add mach target for cpp unittests; r=gps
authorDan Minor <dminor@mozilla.com>
Thu, 02 Jan 2014 10:19:35 -0500
changeset 162193 8ffb10cf61383bdda9dad5d70a172a022734396b
parent 162192 71c810816820a0e4a7b6c6f9e80e8e41080268e9
child 162194 343ac499c99319bfc1f2b678db771d555578da17
push id38118
push userdminor@mozilla.com
push dateMon, 06 Jan 2014 17:16:48 +0000
treeherdermozilla-inbound@8ffb10cf6138 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs949538
milestone29.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 949538 - Add mach target for cpp unittests; r=gps
testing/mach_commands.py
testing/runcppunittests.py
--- a/testing/mach_commands.py
+++ b/testing/mach_commands.py
@@ -37,16 +37,21 @@ haven't been told about this test suite 
 please file a bug at https://bugzilla.mozilla.org/enter_bug.cgi?product=Testing&component=General
 and request support be added.
 '''.strip()
 
 MOCHITEST_CHUNK_BY_DIR = 4
 MOCHITEST_TOTAL_CHUNKS = 5
 
 TEST_SUITES = {
+    'cppunittest': {
+        'aliases': ('Cpp', 'cpp'),
+        'mach_command': 'cppunittest',
+        'kwargs': {'test_file': None},
+    },
     'crashtest': {
         'aliases': ('C', 'Rc', 'RC', 'rc'),
         'mach_command': 'crashtest',
         'kwargs': {'test_file': None},
     },
     'crashtest-ipc': {
         'aliases': ('Cipc', 'cipc'),
         'mach_command': 'crashtest-ipc',
@@ -159,8 +164,43 @@ class Test(MachCommandBase):
             return 1
 
         if os.path.isdir(what):
             print(HANDLE_DIR_ERROR % what)
             return 1
 
         print(UNKNOWN_TEST % what)
         return 1
+
+@CommandProvider
+class MachCommands(MachCommandBase):
+    @Command('cppunittest', category='testing',
+        description='Run cpp unit tests.')
+    @CommandArgument('test_files', nargs='*', metavar='N',
+        help='Test to run. Can be specified as one or more files or ' \
+            'directories, or omitted. If omitted, the entire test suite is ' \
+            'executed.')
+
+    def run_cppunit_test(self, **params):
+        import runcppunittests as cppunittests
+        import logging
+
+        if len(params['test_files']) == 0:
+            testdir = os.path.join(self.distdir, 'cppunittests')
+            progs = cppunittests.extract_unittests_from_args([testdir], None)
+        else:
+            progs = cppunittests.extract_unittests_from_args(params['test_files'], None)
+
+        # See if we have crash symbols
+        symbols_path = os.path.join(self.distdir, 'crashreporter-symbols')
+        if not os.path.isdir(symbols_path):
+            symbols_path = None
+
+        tester = cppunittests.CPPUnitTests()
+        try:
+            result = tester.run_tests(progs, self.bindir, symbols_path)
+        except Exception, e:
+            self.log(logging.ERROR, 'cppunittests',
+                {'exception': str(e)},
+                'Caught exception running cpp unit tests: {exception}')
+            result = False
+
+        return 0 if result else 1
--- a/testing/runcppunittests.py
+++ b/testing/runcppunittests.py
@@ -140,35 +140,36 @@ class CPPUnittestOptions(OptionParser):
         self.add_option("--skip-manifest",
                         action = "store", type = "string", dest = "manifest_file",
                         default = None,
                         help = "absolute path to a manifest file")
 
 def extract_unittests_from_args(args, manifest_file):
     """Extract unittests from args, expanding directories as needed"""
     progs = []
-    skipped_progs = set()
+
+    # Known files commonly packaged with the cppunittests that are not tests
+    skipped_progs = set(['.mkdir.done', 'remotecppunittests.py', 'runcppunittests.py', 'runcppunittests.pyc'])
 
     if manifest_file:
         skipped_progs.add(os.path.basename(manifest_file))
         with open(manifest_file) as f:
             for line in f:
                 # strip out comment, if any
                 prog = line.split('#')[0]
                 if prog:
                     skipped_progs.add(prog.strip())
 
     for p in args:
         if os.path.isdir(p):
             progs.extend([os.path.abspath(os.path.join(p, x)) for x in os.listdir(p) if not x in skipped_progs])
         elif p not in skipped_progs:
             progs.append(os.path.abspath(p))
 
-    #filter out python files packaged with the unit tests
-    return filter(lambda x: not x.endswith('.py') and not x.endswith('.pyc'), progs)
+    return progs
 
 def main():
     parser = CPPUnittestOptions()
     options, args = parser.parse_args()
     if not args:
         print >>sys.stderr, """Usage: %s <test binary> [<test binary>...]""" % sys.argv[0]
         sys.exit(1)
     if not options.xre_path: