| ... |
... |
@@ -7,15 +7,18 @@ import copy |
|
7
|
7
|
import datetime
|
|
8
|
8
|
import json
|
|
9
|
9
|
import os
|
|
|
10
|
+import socket
|
|
10
|
11
|
import subprocess
|
|
11
|
12
|
import sys
|
|
|
13
|
+import tempfile
|
|
|
14
|
+import time
|
|
12
|
15
|
|
|
13
|
16
|
# load modules from parent dir
|
|
14
|
17
|
here = os.path.abspath(os.path.dirname(__file__))
|
|
15
|
18
|
sys.path.insert(1, os.path.dirname(here))
|
|
16
|
19
|
|
|
17
|
20
|
from mozharness.base.log import WARNING
|
|
18
|
|
-from mozharness.base.script import BaseScript, PreScriptAction
|
|
|
21
|
+from mozharness.base.script import BaseScript, PostScriptAction, PreScriptAction
|
|
19
|
22
|
from mozharness.mozilla.automation import TBPL_RETRY
|
|
20
|
23
|
from mozharness.mozilla.mozbase import MozbaseMixin
|
|
21
|
24
|
from mozharness.mozilla.testing.android import AndroidMixin
|
| ... |
... |
@@ -26,7 +29,7 @@ from mozharness.mozilla.testing.codecoverage import ( |
|
26
|
29
|
from mozharness.mozilla.testing.testbase import TestingMixin, testing_config_options
|
|
27
|
30
|
|
|
28
|
31
|
SUITE_DEFAULT_E10S = ["geckoview-junit", "mochitest", "reftest"]
|
|
29
|
|
-SUITE_NO_E10S = ["cppunittest", "gtest", "jittest", "xpcshell"]
|
|
|
32
|
+SUITE_NO_E10S = ["cppunittest", "gtest", "jittest", "xpcshell", "marionette"]
|
|
30
|
33
|
SUITE_REPEATABLE = ["mochitest", "reftest", "xpcshell"]
|
|
31
|
34
|
|
|
32
|
35
|
|
| ... |
... |
@@ -178,6 +181,15 @@ class AndroidEmulatorTest( |
|
178
|
181
|
"times in which case the test must contain at least one of the given tags.",
|
|
179
|
182
|
},
|
|
180
|
183
|
],
|
|
|
184
|
+ [
|
|
|
185
|
+ ["--package-name"],
|
|
|
186
|
+ {
|
|
|
187
|
+ "action": "store",
|
|
|
188
|
+ "default": None,
|
|
|
189
|
+ "dest": "package_name",
|
|
|
190
|
+ "help": "The Android package name for the app being installed.",
|
|
|
191
|
+ },
|
|
|
192
|
+ ],
|
|
181
|
193
|
]
|
|
182
|
194
|
+ copy.deepcopy(testing_config_options)
|
|
183
|
195
|
+ copy.deepcopy(code_coverage_config_options)
|
| ... |
... |
@@ -228,6 +240,7 @@ class AndroidEmulatorTest( |
|
228
|
240
|
self.enable_isolated_zygote_process = c.get("enable_isolated_zygote_process")
|
|
229
|
241
|
self.extra_prefs = c.get("extra_prefs")
|
|
230
|
242
|
self.test_tags = c.get("test_tags")
|
|
|
243
|
+ self.package_name = c.get("package_name") or self.query_package_name()
|
|
231
|
244
|
|
|
232
|
245
|
def query_abs_dirs(self):
|
|
233
|
246
|
if self.abs_dirs:
|
| ... |
... |
@@ -329,6 +342,16 @@ class AndroidEmulatorTest( |
|
329
|
342
|
"error_summary_file": error_summary_file,
|
|
330
|
343
|
"xpcshell_extra": c.get("xpcshell_extra", ""),
|
|
331
|
344
|
"gtest_dir": os.path.join(dirs["abs_test_install_dir"], "gtest"),
|
|
|
345
|
+ "abs_marionette_manifest_dir": os.path.join(
|
|
|
346
|
+ dirs["abs_test_install_dir"],
|
|
|
347
|
+ "marionette",
|
|
|
348
|
+ "tests",
|
|
|
349
|
+ "testing",
|
|
|
350
|
+ "marionette",
|
|
|
351
|
+ "harness",
|
|
|
352
|
+ "marionette_harness",
|
|
|
353
|
+ "tests",
|
|
|
354
|
+ ),
|
|
332
|
355
|
}
|
|
333
|
356
|
|
|
334
|
357
|
user_paths = self._get_mozharness_test_paths(self.test_suite)
|
| ... |
... |
@@ -345,7 +368,7 @@ class AndroidEmulatorTest( |
|
345
|
368
|
|
|
346
|
369
|
if "%(app)" in option:
|
|
347
|
370
|
# only query package name if requested
|
|
348
|
|
- cmd.extend([option % {"app": self.query_package_name()}])
|
|
|
371
|
+ cmd.extend([option % {"app": self.package_name}])
|
|
349
|
372
|
else:
|
|
350
|
373
|
option = option % str_format_values
|
|
351
|
374
|
if option:
|
| ... |
... |
@@ -409,6 +432,7 @@ class AndroidEmulatorTest( |
|
409
|
432
|
self.config["suite_definitions"][self.test_suite].get("tests"),
|
|
410
|
433
|
None,
|
|
411
|
434
|
try_tests,
|
|
|
435
|
+ str_format_values=str_format_values,
|
|
412
|
436
|
)
|
|
413
|
437
|
)
|
|
414
|
438
|
|
| ... |
... |
@@ -449,6 +473,7 @@ class AndroidEmulatorTest( |
|
449
|
473
|
},
|
|
450
|
474
|
),
|
|
451
|
475
|
("xpcshell", {"xpcshell": "xpcshell"}),
|
|
|
476
|
+ ("marionette", {"marionette": "marionette"}),
|
|
452
|
477
|
]
|
|
453
|
478
|
suites = []
|
|
454
|
479
|
for category, all_suites in all:
|
| ... |
... |
@@ -473,6 +498,61 @@ class AndroidEmulatorTest( |
|
473
|
498
|
# in the base class, this checks for mozinstall, but we don't use it
|
|
474
|
499
|
pass
|
|
475
|
500
|
|
|
|
501
|
+ def _configure_marionette_virtualenv(self, action):
|
|
|
502
|
+ dirs = self.query_abs_dirs()
|
|
|
503
|
+ requirements = os.path.join(
|
|
|
504
|
+ dirs["abs_test_install_dir"], "config", "marionette_requirements.txt"
|
|
|
505
|
+ )
|
|
|
506
|
+ if not os.path.isfile(requirements):
|
|
|
507
|
+ self.fatal(f"Could not find marionette requirements file: {requirements}")
|
|
|
508
|
+
|
|
|
509
|
+ self.register_virtualenv_module(requirements=[requirements])
|
|
|
510
|
+
|
|
|
511
|
+ def _marionette_setup(self):
|
|
|
512
|
+ adb = self.query_exe("adb")
|
|
|
513
|
+
|
|
|
514
|
+ self.run_command([adb, "forward", "tcp:2828", "tcp:2828"])
|
|
|
515
|
+
|
|
|
516
|
+ with tempfile.NamedTemporaryFile(suffix=".yaml") as tmp_file:
|
|
|
517
|
+ tmp_file.write(
|
|
|
518
|
+ b"""args:
|
|
|
519
|
+- --marionette
|
|
|
520
|
+- --remote-allow-system-access
|
|
|
521
|
+"""
|
|
|
522
|
+ )
|
|
|
523
|
+ tmp_file.flush()
|
|
|
524
|
+
|
|
|
525
|
+ remote_path = f"/data/local/tmp/{self.package_name}-geckoview-config.yaml"
|
|
|
526
|
+ self.run_command([adb, "push", tmp_file.name, remote_path])
|
|
|
527
|
+
|
|
|
528
|
+ self.run_command([
|
|
|
529
|
+ adb,
|
|
|
530
|
+ "shell",
|
|
|
531
|
+ "am",
|
|
|
532
|
+ "start",
|
|
|
533
|
+ "-S",
|
|
|
534
|
+ "-W",
|
|
|
535
|
+ "-n",
|
|
|
536
|
+ f"{self.package_name}/org.mozilla.gecko.BrowserApp",
|
|
|
537
|
+ ])
|
|
|
538
|
+
|
|
|
539
|
+ # Wait for Marionette to be ready
|
|
|
540
|
+ for attempt in range(5):
|
|
|
541
|
+ try:
|
|
|
542
|
+ self.info(
|
|
|
543
|
+ f"Checking Marionette on 127.0.0.1:2828 (attempt {attempt + 1}/5)"
|
|
|
544
|
+ )
|
|
|
545
|
+ socket.create_connection(("127.0.0.1", 2828), 10).close()
|
|
|
546
|
+ self.info("Marionette is reachable")
|
|
|
547
|
+ break
|
|
|
548
|
+ except OSError:
|
|
|
549
|
+ if attempt == 4:
|
|
|
550
|
+ self.fatal(
|
|
|
551
|
+ "Timed out waiting for 127.0.0.1:2828 to become reachable"
|
|
|
552
|
+ )
|
|
|
553
|
+ self.info("Marionette not reachable yet, retrying in 10s")
|
|
|
554
|
+ time.sleep(10)
|
|
|
555
|
+
|
|
476
|
556
|
@PreScriptAction("create-virtualenv")
|
|
477
|
557
|
def pre_create_virtualenv(self, action):
|
|
478
|
558
|
dirs = self.query_abs_dirs()
|
| ... |
... |
@@ -488,6 +568,9 @@ class AndroidEmulatorTest( |
|
488
|
568
|
if requirements:
|
|
489
|
569
|
self.register_virtualenv_module(requirements=[requirements])
|
|
490
|
570
|
|
|
|
571
|
+ if ("marionette", "marionette") in suites:
|
|
|
572
|
+ self._configure_marionette_virtualenv(action)
|
|
|
573
|
+
|
|
491
|
574
|
def download_and_extract(self):
|
|
492
|
575
|
"""
|
|
493
|
576
|
Download and extract product APK, tests.zip, and host utils.
|
| ... |
... |
@@ -525,6 +608,9 @@ class AndroidEmulatorTest( |
|
525
|
608
|
for per_test_suite, suite in suites:
|
|
526
|
609
|
self.test_suite = suite
|
|
527
|
610
|
|
|
|
611
|
+ if self.test_suite == "marionette":
|
|
|
612
|
+ self._marionette_setup()
|
|
|
613
|
+
|
|
528
|
614
|
try:
|
|
529
|
615
|
cwd = self._query_tests_dir(self.test_suite)
|
|
530
|
616
|
except Exception:
|
| ... |
... |
@@ -594,6 +680,19 @@ class AndroidEmulatorTest( |
|
594
|
680
|
% (suite_category, suite, tbpl_status),
|
|
595
|
681
|
)
|
|
596
|
682
|
|
|
|
683
|
+ @PostScriptAction("run-tests")
|
|
|
684
|
+ def marionette_teardown(self, *args, **kwargs):
|
|
|
685
|
+ if ("marionette", "marionette") in self._query_suites():
|
|
|
686
|
+ adb = self.query_exe("adb")
|
|
|
687
|
+ self.run_command([adb, "shell", "am", "force-stop", self.package_name])
|
|
|
688
|
+ self.run_command([adb, "uninstall", self.package_name])
|
|
|
689
|
+ self.run_command([
|
|
|
690
|
+ adb,
|
|
|
691
|
+ "shell",
|
|
|
692
|
+ "rm",
|
|
|
693
|
+ f"/data/local/tmp/{self.package_name}-geckoview-config.yaml",
|
|
|
694
|
+ ])
|
|
|
695
|
+
|
|
597
|
696
|
|
|
598
|
697
|
if __name__ == "__main__":
|
|
599
|
698
|
test = AndroidEmulatorTest()
|