Bug 1732180 - Avoid using mozprofile when target application is non-firefox r=perftest-reviewers,kshampur

mozprofile doesn't work well with apps that are not Firefox and give wrong errors like "Cannot remove mozprofile delimiters". Avoiding to use mozprofile in those cases will stop giving this error or will give the correct error.

Differential Revision: https://phabricator.services.mozilla.com/D182202
This commit is contained in:
Alex Ionescu 2023-09-26 07:44:24 +00:00
Родитель 6b54cf4acc
Коммит c55ad32c25
6 изменённых файлов: 73 добавлений и 44 удалений

Просмотреть файл

@ -4,8 +4,10 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import glob
import os
import shutil
import subprocess
import sys
import tempfile
from subprocess import PIPE
import mozinfo
@ -31,6 +33,12 @@ except Exception:
if os.name == "nt" and "/" in DEFAULT_CERT_PATH:
DEFAULT_CERT_PATH = DEFAULT_CERT_PATH.replace("/", "\\")
FIREFOX_ANDROID_APPS = [
"geckoview",
"refbrow",
"fenix",
]
class MitmproxyAndroid(Mitmproxy):
def setup(self):
@ -118,8 +126,13 @@ class MitmproxyAndroid(Mitmproxy):
2. Import the mitmproxy certificate into the database, i.e.:
`certutil -A -d sql:<path to profile> -n "some nickname" -t TC,, -a -i <path to CA.pem>`
"""
cert_db_location = "sql:%s/" % self.config["local_profile_dir"]
# If the app isn't in FIREFOX_ANDROID_APPS then we have to create the tempdir
# because we don't have it available in the local_profile_dir
if self.config["app"] in FIREFOX_ANDROID_APPS:
tempdir = self.config["local_profile_dir"]
else:
tempdir = tempfile.mkdtemp()
cert_db_location = "sql:%s/" % tempdir
if not self.cert_db_exists(cert_db_location):
self.create_cert_db(cert_db_location)
@ -133,6 +146,11 @@ class MitmproxyAndroid(Mitmproxy):
LOG.error("Aborting: failed to install mitmproxy CA cert into Firefox")
self.stop_mitmproxy_playback()
sys.exit()
if self.config["app"] not in FIREFOX_ANDROID_APPS:
try:
shutil.rmtree(tempdir)
except Exception:
LOG.warning("unable to remove directory: %s" % tempdir)
def import_certificate_in_cert_db(self, cert_db_location, local_cert_path):
# import mitmproxy cert into the db

Просмотреть файл

@ -9,6 +9,7 @@ import shutil
import tempfile
import mozcrash
from cmdline import FIREFOX_ANDROID_APPS
from logger.logger import RaptorLogger
from mozdevice import ADBDeviceFactory
from performance_tuning import tune_performance
@ -44,7 +45,9 @@ class BrowsertimeAndroid(PerftestAndroid, Browsertime):
def __init__(self, app, binary, activity=None, intent=None, **kwargs):
super(BrowsertimeAndroid, self).__init__(
app, binary, profile_class="firefox", **kwargs
app,
binary,
**kwargs,
)
self.config.update({"activity": activity, "intent": intent})
@ -180,18 +183,19 @@ class BrowsertimeAndroid(PerftestAndroid, Browsertime):
def build_browser_profile(self):
super(BrowsertimeAndroid, self).build_browser_profile()
# Merge in the Android profile.
path = os.path.join(self.profile_data_dir, "raptor-android")
LOG.info("Merging profile: {}".format(path))
self.profile.merge(path)
self.profile.set_preferences(
{"browser.tabs.remote.autostart": self.config["e10s"]}
)
if self.config["app"] in FIREFOX_ANDROID_APPS:
# Merge in the Android profile.
path = os.path.join(self.profile_data_dir, "raptor-android")
LOG.info("Merging profile: {}".format(path))
self.profile.merge(path)
self.profile.set_preferences(
{"browser.tabs.remote.autostart": self.config["e10s"]}
)
# There's no great way to have "after" advice in Python, so we do this
# in super and then again here since the profile merging re-introduces
# the "#MozRunner" delimiters.
self.remove_mozprofile_delimiters_from_profile()
# There's no great way to have "after" advice in Python, so we do this
# in super and then again here since the profile merging re-introduces
# the "#MozRunner" delimiters.
self.remove_mozprofile_delimiters_from_profile()
def setup_adb_device(self):
self._initialize_device()
@ -238,9 +242,10 @@ class BrowsertimeAndroid(PerftestAndroid, Browsertime):
self.set_reverse_ports()
if self.playback:
self.turn_on_android_app_proxy()
self.remove_mozprofile_delimiters_from_profile()
if self.config["app"] in FIREFOX_ANDROID_APPS:
if self.playback:
self.turn_on_android_app_proxy()
self.remove_mozprofile_delimiters_from_profile()
def run_tests(self, tests, test_names):
self.setup_adb_device()

Просмотреть файл

@ -15,6 +15,7 @@ from copy import deepcopy
import mozprocess
import six
from benchmark import Benchmark
from cmdline import CHROME_ANDROID_APPS
from logger.logger import RaptorLogger
from manifestparser.util import evaluate_list_from_string
from perftest import GECKO_PROFILER_APPS, TRACE_APPS, Perftest
@ -55,8 +56,16 @@ class Browsertime(Perftest):
)
return BrowsertimeResultsHandler(config, root_results_dir=root_results_dir)
profile_class = "firefox"
if app in CHROME_ANDROID_APPS:
profile_class = "chrome-m"
super(Browsertime, self).__init__(
app, binary, results_handler_class=klass, **kwargs
app,
binary,
profile_class=profile_class,
results_handler_class=klass,
**kwargs,
)
LOG.info("cwd: '{}'".format(os.getcwd()))
self.config["browsertime"] = True

Просмотреть файл

@ -14,12 +14,13 @@ from mozlog.commandline import add_logging_group
"safari",
"custom-car",
]
(GECKOVIEW, REFBROW, FENIX, CHROME_ANDROID) = FIREFOX_ANDROID_APPS = [
(GECKOVIEW, REFBROW, FENIX) = FIREFOX_ANDROID_APPS = [
"geckoview",
"refbrow",
"fenix",
"chrome-m",
]
(CHROME_ANDROID,) = CHROME_ANDROID_APPS = ["chrome-m"]
FIREFOX_APPS = FIREFOX_ANDROID_APPS + [FIREFOX]
CHROMIUM_DISTROS = [CHROME, CHROMIUM]
APPS = {

Просмотреть файл

@ -32,7 +32,7 @@ for path in paths:
sys.path.insert(0, path)
from chrome_trace import ChromeTrace
from cmdline import FIREFOX_ANDROID_APPS, GECKO_PROFILER_APPS, TRACE_APPS
from cmdline import FIREFOX_ANDROID_APPS, FIREFOX_APPS, GECKO_PROFILER_APPS, TRACE_APPS
from condprof.client import ProfileNotFoundError, get_profile
from condprof.util import get_current_platform
from gecko_profile import GeckoProfile
@ -382,19 +382,17 @@ class Perftest(object):
return self.conditioned_profile_copy
def build_browser_profile(self):
if self.config["app"] in ["safari"]:
if self.config["app"] in FIREFOX_APPS:
if self.config.get("conditioned_profile") is None:
self.profile = create_profile(self.profile_class)
else:
# use mozprofile to create a profile for us, from our conditioned profile's path
self.profile = create_profile(
self.profile_class, profile=self.get_conditioned_profile()
)
else:
self.profile = None
return
elif (
self.config["app"] in ["chrome", "chromium", "chrome-m", "custom-car"]
or self.config.get("conditioned_profile") is None
):
self.profile = create_profile(self.profile_class)
else:
# use mozprofile to create a profile for us, from our conditioned profile's path
self.profile = create_profile(
self.profile_class, profile=self.get_conditioned_profile()
)
# Merge extra profile data from testing/profiles
with open(os.path.join(self.profile_data_dir, "profiles.json"), "r") as fh:
base_profiles = json.load(fh)["raptor"]
@ -448,7 +446,7 @@ class Perftest(object):
if test.get("playback") is not None and self.playback is None:
self.start_playback(test)
if test.get("preferences") is not None and self.config["app"] not in "safari":
if test.get("preferences") is not None and self.config["app"] in FIREFOX_APPS:
self.set_browser_test_prefs(test["preferences"])
@abstractmethod
@ -648,8 +646,7 @@ class PerftestAndroid(Perftest):
"Failed to get android browser meta data through mozversion: %s-%s"
% (e.__class__.__name__, e)
)
if self.config["app"] == "chrome-m" or browser_version is None:
elif self.config["app"] == "chrome-m" or browser_version is None:
# We absolutely need to determine the chrome
# version here so that we can select the correct
# chromedriver for browsertime
@ -707,13 +704,14 @@ class PerftestAndroid(Perftest):
def build_browser_profile(self):
super(PerftestAndroid, self).build_browser_profile()
# Merge in the Android profile.
path = os.path.join(self.profile_data_dir, "raptor-android")
LOG.info("Merging profile: {}".format(path))
self.profile.merge(path)
self.profile.set_preferences(
{"browser.tabs.remote.autostart": self.config["e10s"]}
)
if self.config["app"] in FIREFOX_ANDROID_APPS:
# Merge in the Android profile.
path = os.path.join(self.profile_data_dir, "raptor-android")
LOG.info("Merging profile: {}".format(path))
self.profile.merge(path)
self.profile.set_preferences(
{"browser.tabs.remote.autostart": self.config["e10s"]}
)
def clear_app_data(self):
LOG.info("clearing %s app data" % self.config["binary"])

Просмотреть файл

@ -45,8 +45,6 @@ class TestBrowserThread(threading.Thread):
"perftest_class, app_name",
[
[BrowsertimeDesktop, "firefox"],
[BrowsertimeDesktop, "chrome"],
[BrowsertimeDesktop, "chromium"],
[BrowsertimeAndroid, "geckoview"],
],
)