Bug 1344813 - Implement AWSY as a marionette-based mach command. r=jmaher, r=pyang, r=erahm, a=test-only
authorBob Clary <bclary@bclary.com>
Wed, 29 Mar 2017 01:47:46 -0700
changeset 396111 43d6189761c5b3791ab2b87511929b2d1a2e02ae
parent 396110 cc0c7b6cf3427f56591989c17e44a6eed9c2c1a5
child 396112 9d537df8223a1aa20aa31f2ecc9417081d79fcf0
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher, pyang, erahm, test-only
bugs1344813
milestone54.0
Bug 1344813 - Implement AWSY as a marionette-based mach command. r=jmaher, r=pyang, r=erahm, a=test-only usage: mach [global arguments] awsy-test [command arguments] mach awsy-test runs the in-tree version of the Are We Slim Yet (AWSY) tests. awsy-test is implemented as a marionette test and marionette test arguments also apply although they are not necessary since reasonable defaults will be chosen. The AWSY specific arguments can be found in the Command Arguments for AWSY section below. awsy-test will automatically download the tp5n.zip talos pageset from tooltool and install it under topobjdir/_tests/awsy/html. You can specify your own page set by specifying --web-root and --page-manifest. The results of the test will be placed in the results directory specified by the --results argument. Command Arguments for AWSY: --web-root WEBROOTDIR Path to web server root directory. If not specified, defaults to topobjdir/_tests/awsy/html. --page-manifest PAGEMANIFEST Path to page manifest text file containing a list of urls to test. The urls must be served from localhost. If not specified, defaults to page_load_test/tp5b/tp5n.manifest under the web root. --results RESULTSDIR Path to results directory. If not specified, defaults to the parent directory of the web root. --quick Set --entities=3, --iterations=1, --per-tab-pause=1, --settle-wait-time=1 for a quick test. Overrides any explicit argument settings. --entities ENTITIES Number of urls to load. Defaults to the total number of urls. --max-tabs MAXTABS Maximum number of tabs to open. Defaults to 30. --iterations ITERATIONS Number of times to run through the test suite. Defaults to 5. --per-tab-pause PERTABPAUSE Seconds to wait in between opening tabs. Defaults to 10. --settle-wait-time SETTLEWAITTIME Seconds to wait for things to settled down. Defaults to 30.
build/mach_bootstrap.py
testing/awsy/awsy/test_memory_usage.py
testing/awsy/mach_commands.py
--- a/build/mach_bootstrap.py
+++ b/build/mach_bootstrap.py
@@ -114,16 +114,17 @@ MACH_MODULES = [
     'python/compare-locales/mach_commands.py',
     'python/mozboot/mozboot/mach_commands.py',
     'python/mozbuild/mozbuild/mach_commands.py',
     'python/mozbuild/mozbuild/backend/mach_commands.py',
     'python/mozbuild/mozbuild/compilation/codecomplete.py',
     'python/mozbuild/mozbuild/frontend/mach_commands.py',
     'services/common/tests/mach_commands.py',
     'taskcluster/mach_commands.py',
+    'testing/awsy/mach_commands.py',
     'testing/firefox-ui/mach_commands.py',
     'testing/mach_commands.py',
     'testing/marionette/mach_commands.py',
     'testing/mochitest/mach_commands.py',
     'testing/mozharness/mach_commands.py',
     'testing/talos/mach_commands.py',
     'testing/web-platform/mach_commands.py',
     'testing/xpcshell/mach_commands.py',
--- a/testing/awsy/awsy/test_memory_usage.py
+++ b/testing/awsy/awsy/test_memory_usage.py
@@ -39,28 +39,33 @@ class TestMemoryUsage(MarionetteTestCase
         MarionetteTestCase.setUp(self)
         self.logger = mozlog.structured.structuredlog.get_default_logger()
         self.logger.info("setting up!")
 
         self.marionette.set_context('chrome')
 
         self._webroot_dir = self.testvars["webRootDir"]
         self._resultsDir = self.testvars["resultsDir"]
-        for f in glob.glob(os.path.join(self._resultsDir, '*')):
+        # Be conservative in what we delete automatically.
+        for f in glob.glob(os.path.join(self._resultsDir, 'memory-report-*.json.gz')):
             os.unlink(f)
+        for f in glob.glob(os.path.join(self._resultsDir, 'perfherder_data.json')):
+            os.unlink(f)
+
         self._webservers = webservers.WebServers("localhost",
                                                  8001,
                                                  self._webroot_dir,
                                                  100)
         self._webservers.start()
         self._urls = []
 
         urls = None
-        tp5n_manifest = os.path.join(self._webroot_dir, 'page_load_test', 'tp5n',
-                                     'tp5n.manifest')
+        default_tp5n_manifest = os.path.join(self._webroot_dir, 'page_load_test', 'tp5n',
+                                             'tp5n.manifest')
+        tp5n_manifest = self.testvars.get("pageManifest", default_tp5n_manifest)
         with open(tp5n_manifest) as fp:
             urls = fp.readlines()
         if urls:
             urls = map(lambda x:x.replace('localhost', 'localhost:{}'), urls)
         else:
             urls = TEST_SITES_TEMPLATES
 
         for url, server in zip(urls, self._webservers.servers):
@@ -85,17 +90,18 @@ class TestMemoryUsage(MarionetteTestCase
         self._webservers.stop()
 
         self.logger.info("processing data in %s!" % self._resultsDir)
         perf_blob = process_perf_data.create_perf_data(self._resultsDir)
         self.logger.info("PERFHERDER_DATA: %s" % json.dumps(perf_blob))
 
         perf_file = os.path.join(self._resultsDir, "perfherder_data.json")
         with open(perf_file, 'w') as fp:
-            json.dump(perf_blob, fp)
+            json.dump(perf_blob, fp, indent=2)
+        self.logger.info("Perfherder data written to %s" % perf_file)
 
         # copy it to moz upload dir if set
         if 'MOZ_UPLOAD_DIR' in os.environ:
             for file in os.listdir(self._resultsDir):
                 file = os.path.join(self._resultsDir, file)
                 if os.path.isfile(file):
                     shutil.copy2(file, os.environ["MOZ_UPLOAD_DIR"])
 
new file mode 100644
--- /dev/null
+++ b/testing/awsy/mach_commands.py
@@ -0,0 +1,208 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+from __future__ import absolute_import, unicode_literals
+
+import argparse
+import os
+import sys
+
+import mozfile
+
+from mozbuild.base import (
+    MachCommandBase,
+    MachCommandConditions as conditions,
+)
+
+from mach.decorators import (
+    CommandArgument,
+    CommandArgumentGroup,
+    CommandProvider,
+    Command,
+)
+
+def setup_awsy_argument_parser():
+    from marionette_harness.runtests import MarionetteArguments
+    from mozlog.structured import commandline
+
+    parser = MarionetteArguments()
+    commandline.add_logging_group(parser)
+
+    return parser
+
+
+@CommandProvider
+class MachCommands(MachCommandBase):
+    AWSY_PATH = os.path.dirname(os.path.realpath(__file__))
+    if AWSY_PATH not in sys.path:
+        sys.path.append(AWSY_PATH)
+    from awsy import ITERATIONS, PER_TAB_PAUSE, SETTLE_WAIT_TIME, MAX_TABS
+
+    def run_awsy(self, tests, binary=None, **kwargs):
+        import json
+        from mozlog.structured import commandline
+
+        from marionette_harness.runtests import (
+            MarionetteTestRunner,
+            MarionetteHarness
+        )
+
+        parser = setup_awsy_argument_parser()
+
+        if not tests:
+            tests = [os.path.join(self.topsrcdir,
+                                  'testing/awsy/awsy/test_memory_usage.py')]
+
+        args = argparse.Namespace(tests=tests)
+
+        args.binary = binary
+
+        if kwargs['quick']:
+            kwargs['entities'] = 3
+            kwargs['iterations'] = 1
+            kwargs['perTabPause'] = 1
+            kwargs['settleWaitTime'] = 1
+
+        runtime_testvars = {}
+        for arg in ('webRootDir', 'pageManifest', 'resultsDir', 'entities', 'iterations',
+                    'perTabPause', 'settleWaitTime', 'maxTabs'):
+            if kwargs[arg]:
+                runtime_testvars[arg] = kwargs[arg]
+
+        if 'webRootDir' not in runtime_testvars:
+            awsy_tests_dir = os.path.join(self.topobjdir, '_tests', 'awsy')
+            web_root_dir = os.path.join(awsy_tests_dir, 'html')
+            runtime_testvars['webRootDir'] = web_root_dir
+        else:
+            web_root_dir = runtime_testvars['webRootDir']
+            awsy_tests_dir = os.path.dirname(web_root_dir)
+
+        if 'resultsDir' not in runtime_testvars:
+            runtime_testvars['resultsDir'] = os.path.join(awsy_tests_dir,
+                                                          'results')
+        page_load_test_dir = os.path.join(web_root_dir, 'page_load_test')
+        if not os.path.isdir(page_load_test_dir):
+            os.makedirs(page_load_test_dir)
+
+        if not os.path.isdir(runtime_testvars["resultsDir"]):
+            os.makedirs(runtime_testvars["resultsDir"])
+
+        runtime_testvars_path = os.path.join(awsy_tests_dir, 'runtime-testvars.json')
+        if kwargs['testvars']:
+            kwargs['testvars'].append(runtime_testvars_path)
+        else:
+            kwargs['testvars'] = [runtime_testvars_path]
+
+        runtime_testvars_file = open(runtime_testvars_path, 'wb')
+        runtime_testvars_file.write(json.dumps(runtime_testvars, indent=2))
+        runtime_testvars_file.close()
+
+        if not kwargs['webRootDir']:
+            # Populate the Awsy webroot if not specified by the user.
+            manifest_file = os.path.join(self.topsrcdir,
+                                         'testing',
+                                         'awsy',
+                                         'tp5n-pageset.manifest')
+            tooltool_args = {"args": [
+                os.path.join(self.topsrcdir, "taskcluster/docker/recipes/tooltool.py"),
+                "--manifest=%s" % manifest_file,
+                "--unpack",
+                "--cache-folder=%s" % os.path.join(self.topsrcdir, "tooltool-cache"),
+                "fetch"
+            ]}
+
+            self.run_process(cwd=page_load_test_dir, **tooltool_args)
+            tp5nzip = os.path.join(page_load_test_dir, 'tp5n.zip')
+            tp5nmanifest = os.path.join(page_load_test_dir, 'tp5n', 'tp5n.manifest')
+            if not os.path.exists(tp5nmanifest):
+                files = mozfile.extract_zip(tp5nzip, page_load_test_dir)
+
+        for k, v in kwargs.iteritems():
+            setattr(args, k, v)
+
+        parser.verify_usage(args)
+
+        args.logger = commandline.setup_logging("Are We Slim Yet Tests",
+                                                args,
+                                                {"mach": sys.stdout})
+        failed = MarionetteHarness(MarionetteTestRunner, args=vars(args)).run()
+        if failed > 0:
+            return 1
+        else:
+            return 0
+
+    @Command('awsy-test', category='testing',
+        description='Run Are We Slim Yet (AWSY) memory usage testing using marionette.',
+        parser=setup_awsy_argument_parser,
+    )
+    @CommandArgumentGroup('AWSY')
+    @CommandArgument('--web-root', group='AWSY', action='store', type=str,
+                     dest='webRootDir',
+                     help='Path to web server root directory. If not specified, '
+                     'defaults to topobjdir/_tests/awsy/html.')
+    @CommandArgument('--page-manifest', group='AWSY', action='store', type=str,
+                     dest='pageManifest',
+                     help='Path to page manifest text file containing a list '
+                     'of urls to test. The urls must be served from localhost. If not '
+                     'specified, defaults to page_load_test/tp5b/tp5n.manifest under '
+                     'the web root.')
+    @CommandArgument('--results', group='AWSY', action='store', type=str,
+                     dest='resultsDir',
+                     help='Path to results directory. If not specified, defaults '
+                     'to the parent directory of the web root.')
+    @CommandArgument('--quick', group='AWSY', action='store_true',
+                     dest='quick', default=False,
+                     help='Set --entities=3, --iterations=1, --per-tab-pause=1, '
+                     '--settle-wait-time=1 for a quick test. Overrides any explicit '
+                     'argument settings.')
+    @CommandArgument('--entities', group='AWSY', action='store', type=int,
+                     dest='entities',
+                     help='Number of urls to load. Defaults to the total number of '
+                     'urls.')
+    @CommandArgument('--max-tabs', group='AWSY', action='store', type=int,
+                     dest='maxTabs',
+                     help='Maximum number of tabs to open. '
+                     'Defaults to %s.' % MAX_TABS)
+    @CommandArgument('--iterations', group='AWSY', action='store', type=int,
+                     dest='iterations',
+                     help='Number of times to run through the test suite. '
+                     'Defaults to %s.' % ITERATIONS)
+    @CommandArgument('--per-tab-pause', group='AWSY', action='store', type=int,
+                     dest='perTabPause',
+                     help='Seconds to wait in between opening tabs. '
+                     'Defaults to %s.' % PER_TAB_PAUSE)
+    @CommandArgument('--settle-wait-time', group='AWSY', action='store', type=int,
+                     dest='settleWaitTime',
+                     help='Seconds to wait for things to settled down. '
+                     'Defaults to %s.' % SETTLE_WAIT_TIME)
+    def run_awsy_test(self, tests, **kwargs):
+        """mach awsy-test runs the in-tree version of the Are We Slim Yet
+        (AWSY) tests.
+
+        awsy-test is implemented as a marionette test and marionette
+        test arguments also apply although they are not necessary
+        since reasonable defaults will be chosen.
+
+        The AWSY specific arguments can be found in the Command
+        Arguments for AWSY section below.
+
+        awsy-test will automatically download the tp5n.zip talos
+        pageset from tooltool and install it under
+        topobjdir/_tests/awsy/html. You can specify your own page set
+        by specifying --web-root and --page-manifest.
+
+        The results of the test will be placed in the results
+        directory specified by the --results argument.
+
+        """
+        kwargs['logger_name'] = 'Awsy Tests'
+        if 'test_objects' in kwargs:
+            tests = []
+            for obj in kwargs['test_objects']:
+                tests.append(obj['file_relpath'])
+            del kwargs['test_objects']
+
+        if not kwargs.get('binary') and conditions.is_firefox(self):
+            kwargs['binary'] = self.get_binary_path('app')
+        return self.run_awsy(tests, **kwargs)