Bug 1856942: part 5) Factor async loading of a sheet out of `Loader::LoadSheet`....
[gecko.git] / testing / performance / hooks_recording.py
blobbfa61469d132df9bd3833d70db1ff6999329fb9e
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 import json
5 import os
6 import platform
7 from pathlib import Path
9 from mozperftest.test.browsertime import add_option, add_options
11 # Uncomment the manual_login line if you need to do a manual login.
12 # The extra browsertime arguments get overwritten below so they
13 # need to be set here. The value is the time you need to do a login.
14 options = [
15 ("pageCompleteWaitTime", "10000"),
16 # ("browsertime.manual_login", 100000),
19 next_site = None
21 RECORDING_LIST = Path(Path(__file__).parent, "pageload_sites.json")
23 SCM_1_LOGIN_SITES = ("facebook", "netflix")
26 def before_iterations(kw):
27 global next_site
28 print("Setting up next site to record.")
30 with RECORDING_LIST.open() as f:
31 site_list = json.load(f)
32 # currently can't record websites that require user interactions(Logins)
33 if kw.get("android"):
34 site_list = site_list["mobile"]
35 else:
36 site_list = site_list["desktop"]
38 def __should_record(test):
39 # If a test page selection was provided, only select those
40 # tests and exclude all the others
41 specified_tests = kw["proxy_perftest_page"]
42 if specified_tests is not None:
43 if test.get("name") in specified_tests:
44 if test.get("login"):
45 print(f"WARNING: You selected a login test: {test.get('name')}")
46 return True
47 else:
48 return False
50 # Only perform login recordings in automation or when
51 # RAPTOR_LOGINS is defined
52 record = False
53 if not test.get("login") or test.get("login-test"):
54 record = True
55 if not (
56 "MOZ_AUTOMATION" in os.environ or "RAPTOR_LOGINS" in os.environ
57 ) and test.get("login-test"):
58 record = False
59 print(
60 f"Skipping login test `{test.get('name')}` "
61 f"because login info cannot be obtained."
64 # When pushing to Try, only attempt login recording using the
65 # taskcluster secrets that are associated with SCM level 1 as defined
66 # in `SCM_LVL_1_SITES`.
67 if test.get("login"):
68 if "MOZ_AUTOMATION" in os.environ.keys():
69 if (
70 os.environ.get("MOZ_SCM_LEVEL") == 1
71 and test.get("name") not in SCM_1_LOGIN_SITES
73 print(
74 f"Skipping login test `{test.get('name')}` "
75 f"Because SCM = `{os.environ.get('MOZ_SCM_LEVEL') }`"
76 f"and there is no secret available at this level"
78 return False
79 return True
80 elif "RAPTOR_LOGINS" in os.environ:
81 # Leave it to the user to have properly set up a local json file with
82 # the login websites of interest
83 return True
85 return record
87 sites = [test_site for test_site in site_list if __should_record(test_site)]
89 if not sites:
90 raise Exception("No tests were selected for recording!")
92 def next_site():
93 for site in sites:
94 yield site
96 next_site = next_site()
98 # Set the number of test-iterations to the number of builds
99 kw["test_iterations"] = len(sites)
100 return kw
103 def before_runs(env):
104 global next_site
105 print("Running before_runs")
106 add_options(env, options)
108 if next_site:
109 test_site = next(next_site)
110 print("Next site: %s" % test_site)
112 if env.get_arg("android"):
113 platform_name = "android"
114 app_name = env.get_arg("android-app-name").split(".")[-1]
115 else:
116 platform_name = platform.system().lower()
117 app_name = "firefox"
119 name = [
120 "mitm8",
121 platform_name,
122 "gve" if app_name == "geckoview_example" else app_name,
123 test_site["name"],
126 recording_file = "%s.zip" % "-".join(name)
128 env.set_arg("proxy-mode", "record")
129 env.set_arg(
130 "proxy-file",
131 recording_file,
134 add_options(env, options, overwrite=True)
135 add_option(env, "browsertime.url", test_site.get("test_url"))
136 add_option(env, "browsertime.screenshot", "true")
137 add_option(env, "browsertime.testName", test_site.get("name"))
138 add_option(env, "browsertime.testType", test_site.get("type", "pageload"))
139 add_option(
140 env, "browsertime.login", "true" if test_site.get("login") else "false"
143 prefs = test_site.get("preferences", {})
144 for pref, val in prefs.items():
145 add_option(env, "firefox.preference", f"{pref}:{val}")
147 second_url = test_site.get("secondary_url", None)
148 if second_url:
149 add_option(env, "browsertime.secondary_url", second_url)
151 inject_deterministic = test_site.get("inject_deterministic", True)
152 env.set_arg("proxy-deterministic", inject_deterministic)
154 dismiss_cookie_prompt = test_site.get("dismiss_cookie_prompt", [])
155 if dismiss_cookie_prompt:
156 parsed_cmds = [
157 ":::".join([str(i) for i in item])
158 for item in dismiss_cookie_prompt
159 if item
161 add_option(
162 env, "browsertime.dismiss_cookie_prompt", ";;;".join(parsed_cmds)
165 cmds = test_site.get("test_cmds", [])
166 if cmds:
167 parsed_cmds = [":::".join([str(i) for i in item]) for item in cmds if item]
168 add_option(env, "browsertime.commands", ";;;".join(parsed_cmds))
170 print("Recording %s to file: %s" % (test_site.get("test_url"), recording_file))