Bug 1470266 - [mozharness] Add --setpref argument to main desktop scripts, r=jmaher
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Tue, 02 Oct 2018 13:11:40 +0000
changeset 487544 f251a29c5846f02cbf55d630db8dc724b58882fa
parent 487543 38327e5f0b70c835e117980b9c9cf0e00b4dd19a
child 487545 ec024b2fc13a772ae7a19ebc73a36bb1deca2d5d
push id246
push userfmarier@mozilla.com
push dateSat, 13 Oct 2018 00:15:40 +0000
reviewersjmaher
bugs1470266
milestone64.0a1
Bug 1470266 - [mozharness] Add --setpref argument to main desktop scripts, r=jmaher The mozharness scripts have a lot of special case arguments for one off configurations, stuff like --e10s, --enable-webrender and --gpu-required. Many of these command line args ultimately only end up setting an extra pref in the test harnesses. Instead, let's just give mozharness the ability to set prefs directly via --setpref. This way we can pass them through from taskgraph without needing to add extra configuration to mozharness when making changes like this. Differential Revision: https://phabricator.services.mozilla.com/D7191
testing/mozharness/mozharness/mozilla/testing/talos.py
testing/mozharness/scripts/desktop_unittest.py
testing/mozharness/scripts/web_platform_tests.py
--- a/testing/mozharness/mozharness/mozilla/testing/talos.py
+++ b/testing/mozharness/mozharness/mozilla/testing/talos.py
@@ -151,16 +151,23 @@ class Talos(TestingMixin, MercurialScrip
             "--e10s to help"
         }],
         [["--enable-webrender"], {
             "action": "store_true",
             "dest": "enable_webrender",
             "default": False,
             "help": "Tries to enable the WebRender compositor.",
         }],
+        [["--setpref"], {
+            "action": "append",
+            "metavar": "PREF=VALUE",
+            "dest": "extra_prefs",
+            "default": [],
+            "help": "Defines an extra user preference."}
+         ],
     ] + testing_config_options + copy.deepcopy(code_coverage_config_options)
 
     def __init__(self, **kwargs):
         kwargs.setdefault('config_options', self.config_options)
         kwargs.setdefault('all_actions', ['clobber',
                                           'download-and-extract',
                                           'populate-webroot',
                                           'create-virtualenv',
@@ -351,16 +358,18 @@ class Talos(TestingMixin, MercurialScrip
         options.extend(self.query_gecko_profile_options())
         # extra arguments
         if args is not None:
             options += args
         if 'talos_extra_options' in self.config:
             options += self.config['talos_extra_options']
         if self.config.get('code_coverage', False):
             options.extend(['--code-coverage'])
+        if self.config['extra_prefs']:
+            options.extend(['--setpref={}'.format(p) for p in self.config['extra_prefs']])
         return options
 
     def populate_webroot(self):
         """Populate the production test slaves' webroots"""
         self.talos_path = os.path.join(
             self.query_abs_dirs()['abs_test_install_dir'], 'talos'
         )
 
--- a/testing/mozharness/scripts/desktop_unittest.py
+++ b/testing/mozharness/scripts/desktop_unittest.py
@@ -160,16 +160,23 @@ class DesktopUnittest(TestingMixin, Merc
             "help": "Tries to enable the WebRender compositor."}
          ],
         [["--gpu-required"], {
             "action": "store_true",
             "dest": "gpu_required",
             "default": False,
             "help": "Run additional verification on modified tests using gpu instances."}
          ],
+        [["--setpref"], {
+            "action": "append",
+            "metavar": "PREF=VALUE",
+            "dest": "extra_prefs",
+            "default": [],
+            "help": "Defines an extra user preference."}
+         ],
     ] + copy.deepcopy(testing_config_options) + \
         copy.deepcopy(code_coverage_config_options)
 
     def __init__(self, require_config_file=True):
         # abs_dirs defined already in BaseScript but is here to make pylint happy
         self.abs_dirs = None
         super(DesktopUnittest, self).__init__(
             config_options=self.config_options,
@@ -402,16 +409,19 @@ class DesktopUnittest(TestingMixin, Merc
                     base_cmd.append('--bisect-chunk=default')
                 else:
                     self.warning("--no-random does not currently work with suites other than "
                                  "mochitest.")
 
             if c['headless']:
                 base_cmd.append('--headless')
 
+            if c['extra_prefs']:
+                base_cmd.extend(['--setpref={}'.format(p) for p in c['extra_prefs']])
+
             # set pluginsPath
             abs_res_plugins_dir = os.path.join(abs_res_dir, 'plugins')
             str_format_values['test_plugin_path'] = abs_res_plugins_dir
 
             if suite_category not in c["suite_definitions"]:
                 self.fatal("'%s' not defined in the config!")
 
             if suite in ('browser-chrome-coverage', 'xpcshell-coverage',
--- a/testing/mozharness/scripts/web_platform_tests.py
+++ b/testing/mozharness/scripts/web_platform_tests.py
@@ -84,16 +84,23 @@ class WebPlatformTest(TestingMixin, Merc
             "help": "Specify headless fake screen height (default: 1200)."}
          ],
         [["--single-stylo-traversal"], {
             "action": "store_true",
             "dest": "single_stylo_traversal",
             "default": False,
             "help": "Forcibly enable single thread traversal in Stylo with STYLO_THREADS=1"}
          ],
+        [["--setpref"], {
+            "action": "append",
+            "metavar": "PREF=VALUE",
+            "dest": "extra_prefs",
+            "default": [],
+            "help": "Defines an extra user preference."}
+         ],
     ] + copy.deepcopy(testing_config_options) + \
         copy.deepcopy(code_coverage_config_options)
 
     def __init__(self, require_config_file=True):
         super(WebPlatformTest, self).__init__(
             config_options=self.config_options,
             all_actions=[
                 'clobber',
@@ -200,16 +207,19 @@ class WebPlatformTest(TestingMixin, Merc
                 "--no-pause-after-test"]
 
         if not sys.platform.startswith("linux"):
             cmd += ["--exclude=css"]
 
         for test_type in test_types:
             cmd.append("--test-type=%s" % test_type)
 
+        if c['extra_prefs']:
+            cmd.extend(['--setpref={}'.format(p) for p in c['extra_prefs']])
+
         if not c["e10s"]:
             cmd.append("--disable-e10s")
 
         if c["single_stylo_traversal"]:
             cmd.append("--stylo-threads=1")
         else:
             cmd.append("--stylo-threads=4")