Bug 1528236 - [raptor] Refactor handling of remote profiles. r=perftest-reviewers,rwood
authorHenrik Skupin <mail@hskupin.info>
Tue, 14 May 2019 19:30:11 +0000
changeset 532638 c6cccc4ebfcc08826c689102546ea05d7ddc660c
parent 532637 22dba7347176f6885c4ee3f978aa13a35fc7862e
child 532639 9eb4d019ee371b8b4d37c6e3f2f6ad582038c1dc
push id11270
push userrgurzau@mozilla.com
push dateWed, 15 May 2019 15:07:19 +0000
treeherdermozilla-beta@571bc76da583 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersperftest-reviewers, rwood
bugs1528236
milestone68.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 1528236 - [raptor] Refactor handling of remote profiles. r=perftest-reviewers,rwood Differential Revision: https://phabricator.services.mozilla.com/D29329
testing/raptor/raptor/raptor.py
--- a/testing/raptor/raptor/raptor.py
+++ b/testing/raptor/raptor/raptor.py
@@ -615,26 +615,30 @@ class RaptorDesktopChrome(RaptorDesktop)
 
         if test.get('playback') is not None:
             self.setup_chrome_desktop_for_playback()
 
         self.start_runner_proc()
 
 
 class RaptorAndroid(Raptor):
+
     def __init__(self, app, binary, activity=None, intent=None, **kwargs):
         super(RaptorAndroid, self).__init__(app, binary, **kwargs)
 
-        # on android, when creating the browser profile, we want to use a 'firefox' type profile
-        self.profile_class = "firefox"
         self.config.update({
             'activity': activity,
             'intent': intent,
         })
 
+        self.profile_class = "firefox"
+
+        self.remote_test_root = os.path.abspath(os.path.join(os.sep, 'sdcard', 'raptor'))
+        self.remote_profile = os.path.join(self.remote_test_root, "profile")
+
     def set_reverse_port(self, port):
         tcp_port = "tcp:{}".format(port)
         self.device.create_socket_connection('reverse', tcp_port, tcp_port)
 
     def serve_benchmark_source(self, *args, **kwargs):
         super(RaptorAndroid, self).serve_benchmark_source(*args, **kwargs)
 
         # for Android we must make the benchmarks server available to the device
@@ -658,17 +662,19 @@ class RaptorAndroid(Raptor):
             self.log.info("making the raptor playback server port available to device")
             self.set_reverse_port(8080)
 
     def create_browser_handler(self):
         # create the android device handler; it gets initiated and sets up adb etc
         self.log.info("creating android device handler using mozdevice")
         self.device = ADBDevice(verbose=True)
         self.device.clear_logcat()
+
         self.clear_app_data()
+        self.create_raptor_sdcard_folder()
 
     def tune_performance(self):
         """Sets various performance-oriented parameters, to reduce jitter.
 
         For more information, see https://bugzilla.mozilla.org/show_bug.cgi?id=1547135.
         """
         self.log.info("tuning android device performance")
         self.set_scheduler()
@@ -833,45 +839,37 @@ class RaptorAndroid(Raptor):
         }
         for key, value in commands.items():
             self._set_value_and_check_exitcode(key, value)
 
     def clear_app_data(self):
         self.log.info("clearing %s app data" % self.config['binary'])
         self.device.shell("pm clear %s" % self.config['binary'])
 
-    def create_raptor_sdcard_folder(self):
-        # for android/geckoview, create a top-level raptor folder on the device
-        # sdcard; if it already exists remove it so we start fresh each time
-        self.device_raptor_dir = "/sdcard/raptor"
-        self.config['device_raptor_dir'] = self.device_raptor_dir
-        if self.device.is_dir(self.device_raptor_dir):
-            self.log.info("deleting existing device raptor dir: %s" % self.device_raptor_dir)
-            self.device.rm(self.device_raptor_dir, recursive=True)
-        self.log.info("creating raptor folder on sdcard: %s" % self.device_raptor_dir)
-        self.device.mkdir(self.device_raptor_dir)
-        self.device.chmod(self.device_raptor_dir, recursive=True)
-
-    def copy_profile_onto_device(self):
-        # for geckoview/fennec we must copy the profile onto the device and set perms
+    def copy_profile_to_device(self):
+        """Copy the profile to the device, and update permissions of all files."""
         if not self.device.is_app_installed(self.config['binary']):
             raise Exception('%s is not installed' % self.config['binary'])
-        self.device_profile = os.path.join(self.device_raptor_dir, "profile")
+
+        try:
+            self.log.info("copying profile to device: %s" % self.remote_profile)
+            self.device.rm(self.remote_profile, force=True, recursive=True)
+            # self.device.mkdir(self.remote_profile)
+            self.device.push(self.profile.profile, self.remote_profile)
+            self.device.chmod(self.remote_profile, recursive=True, root=True)
 
-        if self.device.is_dir(self.device_profile):
-            self.log.info("deleting existing device profile folder: %s" % self.device_profile)
-            self.device.rm(self.device_profile, recursive=True)
-        self.log.info("creating profile folder on device: %s" % self.device_profile)
-        self.device.mkdir(self.device_profile)
+        except Exception:
+            self.log.error("Unable to copy profile to device.")
+            raise
 
-        self.log.info("copying firefox profile onto the device")
-        self.log.info("note: the profile folder being copied is: %s" % self.profile.profile)
-        self.log.info('the adb push cmd copies that profile dir to a new temp dir before copy')
-        self.device.push(self.profile.profile, self.device_profile)
-        self.device.chmod(self.device_profile, recursive=True)
+    def create_raptor_sdcard_folder(self):
+        self.log.info("creating test folder for raptor: %s" % self.remote_test_root)
+        self.device.rm(self.remote_test_root, force=True, recursive=True)
+        self.device.mkdir(self.remote_test_root)
+        self.device.chmod(self.remote_test_root, recursive=True, root=True)
 
     def turn_on_android_app_proxy(self):
         # for geckoview/android pageload playback we can't use a policy to turn on the
         # proxy; we need to set prefs instead; note that the 'host' may be different
         # than '127.0.0.1' so we must set the prefs accordingly
         self.log.info("setting profile prefs to turn on the android app proxy")
         proxy_prefs = {}
         proxy_prefs["network.proxy.type"] = 1
@@ -880,17 +878,17 @@ class RaptorAndroid(Raptor):
         proxy_prefs["network.proxy.ssl"] = self.config['host']
         proxy_prefs["network.proxy.ssl_port"] = 8080
         proxy_prefs["network.proxy.no_proxies_on"] = self.config['host']
         self.profile.set_preferences(proxy_prefs)
 
     def launch_firefox_android_app(self, test_name):
         self.log.info("starting %s" % self.config['app'])
 
-        extra_args = ["-profile", self.device_profile,
+        extra_args = ["-profile", self.remote_profile,
                       "--es", "env0", "LOG_VERBOSE=1",
                       "--es", "env1", "R_LOG_LEVEL=6"]
 
         try:
             # make sure the android app is not already running
             self.device.stop_application(self.config['binary'])
 
             if self.config['app'] == "fennec":
@@ -994,18 +992,16 @@ class RaptorAndroid(Raptor):
         for test['browser_cycle'] in range(1, test['expected_browser_cycles'] + 1):
 
             self.log.info("begin browser cycle %d of %d for test %s"
                           % (test['browser_cycle'], test['expected_browser_cycles'], test['name']))
 
             self.run_test_setup(test)
 
             if test['browser_cycle'] == 1:
-                self.create_raptor_sdcard_folder()
-
                 if test.get('playback') is not None:
                     self.start_playback(test)
 
                     # an ssl cert db has now been created in the profile; copy it out so we
                     # can use the same cert db in future test cycles / browser restarts
                     local_cert_db_dir = tempfile.mkdtemp()
                     self.log.info("backing up browser ssl cert db that was created via certutil")
                     self.copy_cert_db(self.config['local_profile_dir'], local_cert_db_dir)
@@ -1030,17 +1026,17 @@ class RaptorAndroid(Raptor):
                     self.log.info("copying existing ssl cert db into new browser profile")
                     self.copy_cert_db(local_cert_db_dir, self.config['local_profile_dir'])
 
                 self.run_test_setup(test)
 
             if test.get('playback') is not None:
                 self.turn_on_android_app_proxy()
 
-            self.copy_profile_onto_device()
+            self.copy_profile_to_device()
 
             # now start the browser/app under test
             self.launch_firefox_android_app(test['name'])
 
             # set our control server flag to indicate we are running the browser/app
             self.control_server._finished = False
 
             self.wait_for_test_finish(test, timeout)
@@ -1056,29 +1052,28 @@ class RaptorAndroid(Raptor):
 
     def run_test_warm(self, test, timeout=None):
         self.log.info("test %s is running in warm mode; browser will NOT be restarted between "
                       "page cycles" % test['name'])
         if self.config['power_test']:
             init_android_power_test(self)
 
         self.run_test_setup(test)
-        self.create_raptor_sdcard_folder()
 
         if test.get('playback') is not None:
             self.start_playback(test)
 
         if self.config['host'] not in ('localhost', '127.0.0.1'):
             self.delete_proxy_settings_from_profile()
 
         if test.get('playback') is not None:
             self.turn_on_android_app_proxy()
 
         self.clear_app_data()
-        self.copy_profile_onto_device()
+        self.copy_profile_to_device()
 
         # now start the browser/app under test
         self.launch_firefox_android_app(test['name'])
 
         # set our control server flag to indicate we are running the browser/app
         self.control_server._finished = False
 
         self.wait_for_test_finish(test, timeout)
@@ -1094,17 +1089,17 @@ class RaptorAndroid(Raptor):
         self.device._verbose = False
         logcat = self.device.get_logcat()
         self.device._verbose = verbose
         if logcat:
             if mozcrash.check_for_java_exception(logcat, "raptor"):
                 return
         try:
             dump_dir = tempfile.mkdtemp()
-            remote_dir = posixpath.join(self.device_profile, 'minidumps')
+            remote_dir = posixpath.join(self.remote_profile, 'minidumps')
             if not self.device.is_dir(remote_dir):
                 self.log.error("No crash directory (%s) found on remote device" % remote_dir)
                 return
             self.device.pull(remote_dir, dump_dir)
             mozcrash.log_crashes(self.log, dump_dir, self.config['symbols_path'])
         finally:
             try:
                 shutil.rmtree(dump_dir)