Bug 1291335 - Check mozconfig for --disable-tests when running mach test commands r=gbrown
authorEdwin Gao <egao@mozilla.com>
Wed, 03 Oct 2018 15:40:48 +0000
changeset 495154 b58cfd180ba7f5d7daeb419b1c038c7ca182c9a4
parent 495153 32cde67dd330391a0fb6735be8309a64e646a5f7
child 495155 1c7f3cf86aed6b4476ffa66605f373b2ff74f960
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [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 1291335 - Check mozconfig for --disable-tests when running mach test commands r=gbrown Behavior changes: - instead of reading the mozconfig file, it now instantiates an instance of the build object. - safe checking methods are used to access attributes to prevent errors on automation environment. - better mach command parsing is performed with handler category instead of error-prone argv parsing. Other changes: - docstring for testing/xpcshell/runxpcshelltests.py::buildTestList() added and modernized. - added clause that if length of tests gathered is 0, mach exits with an error code of 1. Differential Revision: https://phabricator.services.mozilla.com/D7133
--- a/python/mach/mach/main.py
+++ b/python/mach/mach/main.py
@@ -488,16 +488,37 @@ To see more help for a specific command,
             if debugger:
         if not hasattr(args, 'mach_handler'):
             raise MachError('ArgumentParser result missing mach handler info.')
         handler = getattr(args, 'mach_handler')
+        # if --disable-tests flag was enabled in the mozconfig used to compile
+        # the build, tests will be disabled.
+        # instead of trying to run nonexistent tests then reporting a failure,
+        # this will prevent mach from progressing beyond this point.
+        if handler.category == 'testing':
+            from mozbuild.base import BuildEnvironmentNotFoundException
+            try:
+                from mozbuild.base import MozbuildObject
+                # all environments should have an instance of build object.
+                build = MozbuildObject.from_environment()
+                if build is not None and hasattr(build, 'mozconfig'):
+                    ac_options = build.mozconfig['configure_args']
+                    if ac_options and '--disable-tests' in ac_options:
+                        print('Tests have been disabled by mozconfig with the flag' +
+                              '"ac_add_options --disable-tests".\n' +
+                              'Remove the flag, and re-compile to enable tests.')
+                        return 1
+            except BuildEnvironmentNotFoundException:
+                # likely automation environment, so do nothing.
+                pass
             return Registrar._run_command_handler(handler, context=context,
         except KeyboardInterrupt as ki:
             raise ki
         except FailedCommandError as e:
--- a/testing/xpcshell/runxpcshelltests.py
+++ b/testing/xpcshell/runxpcshelltests.py
@@ -842,23 +842,33 @@ class XPCShellTests(object):
         if os.sep != '/':
             for key in ('id', 'manifest'):
                 test_object[key] = test_object[key].replace(os.sep, '/')
         return test_object
     def buildTestList(self, test_tags=None, test_paths=None, verify=False):
-        """
-          read the xpcshell.ini manifest and set self.alltests to be
-          an array of test objects.
+        """Reads the xpcshell.ini manifest and set self.alltests to an array.
+        Given the parameters, this method compiles a list of tests to be run
+        that matches the criteria set by parameters.
+        If any chunking of tests are to occur, it is also done in this method.
-          if we are chunking tests, it will be done here as well
+        If no tests are added to the list of tests to be run, an error
+        is logged. A sys.exit() signal is sent to the caller.
+        Args:
+            test_tags (list, optional): list of strings.
+            test_paths (list, optional): list of strings derived from the command
+                                         line argument provided by user, specifying
+                                         tests to be run.
+            verify (bool, optional): boolean value.
         if test_paths is None:
             test_paths = []
         if len(test_paths) == 1 and test_paths[0].endswith(".js") and not verify:
             self.singleFile = os.path.basename(test_paths[0])
             self.singleFile = None
@@ -883,16 +893,17 @@ class XPCShellTests(object):
         except TypeError:
             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(
+            sys.exit(1)
         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)