Bug 1640649 - add --android-timeout r=sparky

This patch surfaces the timeout value for ADBDevice.
It also adds the ability to run a single test with
mach perftest-test and a new --skip-lint option
to skip black/flake8

Differential Revision: https://phabricator.services.mozilla.com/D76791
This commit is contained in:
Tarek Ziadé 2020-05-26 14:42:58 +00:00
Родитель a6ea2774ae
Коммит 92a2c142f7
3 изменённых файлов: 67 добавлений и 12 удалений

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

@ -6,7 +6,7 @@ import sys
from functools import partial
import subprocess
from mach.decorators import CommandProvider, Command
from mach.decorators import CommandProvider, Command, CommandArgument
from mozbuild.base import MachCommandBase, MachCommandConditions as conditions
@ -101,6 +101,16 @@ class PerftestTests(MachCommandBase):
@Command(
"perftest-test", category="testing", description="Run perftest tests",
)
@CommandArgument(
"tests", default=None, nargs="*", help="Tests to run. By default will run all"
)
@CommandArgument(
"-s",
"--skip-linters",
action="store_true",
default=False,
help="Skip flake8 and black",
)
def run_tests(self, **kwargs):
MachCommandBase._activate_virtualenv(self)
@ -108,6 +118,8 @@ class PerftestTests(MachCommandBase):
from mozperftest.runner import _setup_path
from mozperftest.utils import install_package, temporary_env
skip_linters = kwargs.get("skip_linters", False)
# include in sys.path all deps
_setup_path()
try:
@ -115,10 +127,13 @@ class PerftestTests(MachCommandBase):
except ImportError:
pydeps = Path(self.topsrcdir, "third_party", "python")
vendors = ["coverage"]
pypis = ["flake8"]
if skip_linters:
pypis = []
else:
pypis = ["flake8"]
# if we're not on try we want to install black
if not ON_TRY:
if not ON_TRY and not skip_linters:
pypis.append("black")
# these are the deps we are getting from pypi
@ -130,12 +145,12 @@ class PerftestTests(MachCommandBase):
install_package(self.virtualenv_manager, str(Path(pydeps, dep)))
here = Path(__file__).parent.resolve()
if not ON_TRY:
if not ON_TRY and not skip_linters:
# formatting the code with black
assert self._run_python_script("black", str(here))
# checking flake8 correctness
if not (ON_TRY and sys.platform == "darwin"):
if not (ON_TRY and sys.platform == "darwin") and not skip_linters:
assert self._run_python_script("flake8", str(here))
# running pytest with coverage
@ -143,19 +158,36 @@ class PerftestTests(MachCommandBase):
# 1/ coverage erase => erase any previous coverage data
# 2/ coverage run pytest ... => run the tests and collect info
# 3/ coverage report => generate the report
tests = here / "tests"
tests_dir = Path(here, "tests").resolve()
tests = kwargs.get("tests", [])
if tests == []:
tests = str(tests_dir)
run_coverage_check = not skip_linters
else:
run_coverage_check = False
def _get_test(test):
if Path(test).exists():
return str(test)
return str(tests_dir / test)
tests = " ".join([_get_test(test) for test in tests])
import pytest
with temporary_env(COVERAGE_RCFILE=str(here / ".coveragerc")):
assert self._run_python_script(
"coverage", "erase", label="remove old coverage data"
)
if run_coverage_check:
assert self._run_python_script(
"coverage", "erase", label="remove old coverage data"
)
args = [
"run",
pytest.__file__,
"-xs",
str(tests.resolve()),
tests,
]
assert self._run_python_script("coverage", *args, label="running tests")
if not self._run_python_script("coverage", "report", display=True):
if run_coverage_check and not self._run_python_script(
"coverage", "report", display=True
):
raise ValueError("Coverage is too low!")

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

@ -48,6 +48,11 @@ class AndroidDevice(Layer):
"default": "org.mozilla.firefox",
"help": "Android app name",
},
"timeout": {
"type": int,
"default": 30,
"help": "timeout in seconds for adb operations",
},
"intent": {"type": str, "default": None, "help": "Intent to use"},
"activity": {"type": str, "default": None, "help": "Activity to use"},
"install-apk": {
@ -76,7 +81,7 @@ class AndroidDevice(Layer):
self.android_activity = self.get_arg("android-activity")
self.metadata = metadata
try:
self.device = ADBDevice(verbose=True, timeout=30)
self.device = ADBDevice(verbose=True, timeout=self.get_arg("timeout"))
except (ADBError, AttributeError) as e:
self.error("Could not connect to the phone. Is it connected?")
raise DeviceError(str(e))

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

@ -66,5 +66,23 @@ def test_android_apk_alias(device):
assert device.mock_calls[1][1][0].endswith("target.apk")
@mock.patch("mozperftest.utils.requests.get", new=requests_content())
@mock.patch("mozperftest.system.android.ADBDevice")
def test_android_timeout(device):
args = {
"android-install-apk": ["gve_nightly_api16"],
"android": True,
"android-timeout": 60,
"android-app-name": "org.mozilla.geckoview_example",
}
mach_cmd, metadata, env = get_running_env(**args)
system = env.layers[SYSTEM]
with system as android, silence(system):
android(metadata)
options = device.mock_calls[0][-1]
assert options["timeout"] == 60
if __name__ == "__main__":
mozunit.main()