android-env 1.2.1__py3-none-any.whl → 1.2.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- android_env/__init__.py +1 -1
- android_env/components/__init__.py +1 -1
- android_env/components/a11y/__init__.py +15 -0
- android_env/components/a11y/a11y_events.py +118 -0
- android_env/components/a11y/a11y_events_test.py +173 -0
- android_env/components/a11y/a11y_forests.py +128 -0
- android_env/components/a11y/a11y_forests_test.py +237 -0
- android_env/components/a11y/a11y_servicer.py +199 -0
- android_env/components/a11y/a11y_servicer_test.py +224 -0
- android_env/components/action_fns.py +132 -0
- android_env/components/action_fns_test.py +227 -0
- android_env/components/action_type.py +26 -3
- android_env/components/adb_call_parser.py +239 -196
- android_env/components/adb_call_parser_test.py +179 -209
- android_env/components/adb_controller.py +90 -52
- android_env/components/adb_controller_test.py +187 -16
- android_env/components/adb_log_stream.py +17 -5
- android_env/components/adb_log_stream_test.py +17 -3
- android_env/components/app_screen_checker.py +17 -15
- android_env/components/app_screen_checker_test.py +7 -8
- android_env/components/config_classes.py +203 -0
- android_env/components/coordinator.py +102 -338
- android_env/components/coordinator_test.py +59 -199
- android_env/components/device_settings.py +174 -0
- android_env/components/device_settings_test.py +228 -0
- android_env/components/dumpsys_thread.py +3 -4
- android_env/components/dumpsys_thread_test.py +1 -1
- android_env/components/errors.py +52 -10
- android_env/components/errors_test.py +110 -0
- android_env/components/log_stream.py +7 -5
- android_env/components/log_stream_test.py +1 -1
- android_env/components/logcat_thread.py +9 -8
- android_env/components/logcat_thread_test.py +3 -4
- android_env/components/{utils.py → pixel_fns.py} +20 -20
- android_env/components/{utils_test.py → pixel_fns_test.py} +20 -15
- android_env/components/setup_step_interpreter.py +47 -39
- android_env/components/setup_step_interpreter_test.py +4 -4
- android_env/components/simulators/__init__.py +1 -1
- android_env/components/simulators/base_simulator.py +116 -44
- android_env/components/simulators/base_simulator_test.py +131 -9
- android_env/components/simulators/emulator/__init__.py +1 -1
- android_env/components/simulators/emulator/emulator_launcher.py +67 -77
- android_env/components/simulators/emulator/emulator_launcher_test.py +153 -49
- android_env/components/simulators/emulator/emulator_simulator.py +276 -95
- android_env/components/simulators/emulator/emulator_simulator_test.py +314 -89
- android_env/components/simulators/fake/__init__.py +1 -1
- android_env/components/simulators/fake/fake_simulator.py +17 -25
- android_env/components/simulators/fake/fake_simulator_test.py +29 -12
- android_env/components/specs.py +18 -28
- android_env/components/specs_test.py +1 -44
- android_env/components/task_manager.py +48 -48
- android_env/components/task_manager_test.py +71 -60
- android_env/env_interface.py +37 -23
- android_env/environment.py +83 -51
- android_env/environment_test.py +68 -29
- android_env/loader.py +57 -43
- android_env/loader_test.py +115 -35
- android_env/proto/__init__.py +1 -1
- android_env/proto/a11y/__init__.py +15 -0
- android_env/proto/a11y/a11y.proto +75 -0
- android_env/proto/a11y/a11y_pb2.py +54 -0
- android_env/proto/a11y/a11y_pb2.pyi +49 -0
- android_env/proto/a11y/a11y_pb2_grpc.py +202 -0
- android_env/proto/a11y/android_accessibility_action.proto +32 -0
- android_env/proto/a11y/android_accessibility_action_pb2.py +37 -0
- android_env/proto/a11y/android_accessibility_action_pb2.pyi +13 -0
- android_env/proto/a11y/android_accessibility_action_pb2_grpc.py +24 -0
- android_env/proto/a11y/android_accessibility_forest.proto +29 -0
- android_env/proto/a11y/android_accessibility_forest_pb2.py +38 -0
- android_env/proto/a11y/android_accessibility_forest_pb2.pyi +13 -0
- android_env/proto/a11y/android_accessibility_forest_pb2_grpc.py +24 -0
- android_env/proto/a11y/android_accessibility_node_info.proto +122 -0
- android_env/proto/a11y/android_accessibility_node_info_clickable_span.proto +49 -0
- android_env/proto/a11y/android_accessibility_node_info_clickable_span_pb2.py +39 -0
- android_env/proto/a11y/android_accessibility_node_info_clickable_span_pb2.pyi +28 -0
- android_env/proto/a11y/android_accessibility_node_info_clickable_span_pb2_grpc.py +24 -0
- android_env/proto/a11y/android_accessibility_node_info_pb2.py +42 -0
- android_env/proto/a11y/android_accessibility_node_info_pb2.pyi +75 -0
- android_env/proto/a11y/android_accessibility_node_info_pb2_grpc.py +24 -0
- android_env/proto/a11y/android_accessibility_tree.proto +29 -0
- android_env/proto/a11y/android_accessibility_tree_pb2.py +38 -0
- android_env/proto/a11y/android_accessibility_tree_pb2.pyi +13 -0
- android_env/proto/a11y/android_accessibility_tree_pb2_grpc.py +24 -0
- android_env/proto/a11y/android_accessibility_window_info.proto +84 -0
- android_env/proto/a11y/android_accessibility_window_info_pb2.py +41 -0
- android_env/proto/a11y/android_accessibility_window_info_pb2.pyi +48 -0
- android_env/proto/a11y/android_accessibility_window_info_pb2_grpc.py +24 -0
- android_env/proto/a11y/rect.proto +30 -0
- android_env/proto/a11y/rect_pb2.py +37 -0
- android_env/proto/a11y/rect_pb2.pyi +17 -0
- android_env/proto/a11y/rect_pb2_grpc.py +24 -0
- android_env/proto/adb.proto +17 -6
- android_env/proto/adb_pb2.py +120 -107
- android_env/proto/adb_pb2.pyi +396 -0
- android_env/proto/adb_pb2_grpc.py +20 -0
- android_env/proto/emulator_controller.proto +68 -63
- android_env/proto/emulator_controller_pb2.py +142 -131
- android_env/proto/emulator_controller_pb2.pyi +672 -0
- android_env/proto/emulator_controller_pb2_grpc.py +505 -142
- android_env/proto/snapshot.proto +169 -0
- android_env/proto/snapshot_pb2.py +47 -0
- android_env/proto/snapshot_pb2.pyi +117 -0
- android_env/proto/snapshot_pb2_grpc.py +24 -0
- android_env/proto/snapshot_service.proto +289 -0
- android_env/proto/snapshot_service_pb2.py +54 -0
- android_env/proto/snapshot_service_pb2.pyi +86 -0
- android_env/proto/snapshot_service_pb2_grpc.py +487 -0
- android_env/proto/state.proto +63 -0
- android_env/proto/state_pb2.py +63 -0
- android_env/proto/state_pb2.pyi +85 -0
- android_env/proto/state_pb2_grpc.py +24 -0
- android_env/proto/task.proto +5 -1
- android_env/proto/task_pb2.py +42 -31
- android_env/proto/task_pb2.pyi +160 -0
- android_env/proto/task_pb2_grpc.py +20 -0
- android_env/wrappers/__init__.py +1 -1
- android_env/wrappers/a11y_grpc_wrapper.py +500 -0
- android_env/wrappers/a11y_grpc_wrapper_test.py +849 -0
- android_env/wrappers/base_wrapper.py +34 -13
- android_env/wrappers/base_wrapper_test.py +22 -16
- android_env/wrappers/discrete_action_wrapper.py +18 -17
- android_env/wrappers/discrete_action_wrapper_test.py +4 -4
- android_env/wrappers/flat_interface_wrapper.py +5 -5
- android_env/wrappers/flat_interface_wrapper_test.py +7 -11
- android_env/wrappers/float_pixels_wrapper.py +9 -10
- android_env/wrappers/float_pixels_wrapper_test.py +3 -3
- android_env/wrappers/gym_wrapper.py +19 -13
- android_env/wrappers/gym_wrapper_test.py +3 -5
- android_env/wrappers/image_rescale_wrapper.py +18 -21
- android_env/wrappers/image_rescale_wrapper_test.py +25 -37
- android_env/wrappers/last_action_wrapper.py +16 -13
- android_env/wrappers/last_action_wrapper_test.py +44 -51
- android_env/wrappers/rate_limit_wrapper.py +6 -3
- android_env/wrappers/rate_limit_wrapper_test.py +22 -1
- android_env/wrappers/tap_action_wrapper.py +16 -17
- android_env/wrappers/tap_action_wrapper_test.py +51 -16
- {android_env-1.2.1.dist-info → android_env-1.2.3.dist-info}/METADATA +14 -18
- android_env-1.2.3.dist-info/RECORD +141 -0
- {android_env-1.2.1.dist-info → android_env-1.2.3.dist-info}/WHEEL +1 -1
- android_env/proto/raw_observation.proto +0 -39
- android_env/proto/raw_observation_pb2.py +0 -27
- android_env/proto/raw_observation_pb2_grpc.py +0 -4
- android_env-1.2.1.dist-info/RECORD +0 -81
- {android_env-1.2.1.dist-info → android_env-1.2.3.dist-info/licenses}/LICENSE +0 -0
- {android_env-1.2.1.dist-info → android_env-1.2.3.dist-info}/top_level.txt +0 -0
@@ -1,5 +1,5 @@
|
|
1
1
|
# coding=utf-8
|
2
|
-
# Copyright
|
2
|
+
# Copyright 2024 DeepMind Technologies Limited.
|
3
3
|
#
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
5
|
# you may not use this file except in compliance with the License.
|
@@ -15,66 +15,27 @@
|
|
15
15
|
|
16
16
|
"""Prepares and launches an emulator process."""
|
17
17
|
|
18
|
+
import glob
|
18
19
|
import os
|
19
20
|
import subprocess
|
20
21
|
import tempfile
|
21
|
-
from typing import Optional
|
22
22
|
|
23
23
|
from absl import logging
|
24
|
+
from android_env.components import config_classes
|
24
25
|
|
25
26
|
|
26
|
-
class EmulatorLauncher
|
27
|
+
class EmulatorLauncher:
|
27
28
|
"""Handles launching an emulator."""
|
28
29
|
|
29
30
|
def __init__(
|
30
31
|
self,
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
android_avd_home: str = '',
|
39
|
-
run_headless: bool = False,
|
40
|
-
kvm_device: str = '/dev/kvm',
|
41
|
-
gpu_mode: str = 'swiftshader_indirect',
|
42
|
-
tmp_dir: str = '',
|
43
|
-
snapshot_name: str = '',
|
44
|
-
restrict_network: bool = False):
|
45
|
-
"""Launches an emulator.
|
46
|
-
|
47
|
-
Args:
|
48
|
-
adb_port: ADB port for the Android device.
|
49
|
-
adb_server_port: Port of the ADB server deamon.
|
50
|
-
emulator_console_port: Port for telnet communication with the emulator.
|
51
|
-
grpc_port: Port for gRPC communication with the emulator.
|
52
|
-
emulator_path: Path to the emulator binary.
|
53
|
-
android_sdk_root: Root directory of the Android SDK.
|
54
|
-
avd_name: Name of the AVD.
|
55
|
-
android_avd_home: Local directory for AVDs.
|
56
|
-
run_headless: Whether to run in headless mode.
|
57
|
-
kvm_device: Path to the KVM device.
|
58
|
-
gpu_mode: GPU mode override. Supported values are listed at:
|
59
|
-
https://developer.android.com/studio/run/emulator-acceleration#accel-graphics
|
60
|
-
tmp_dir: Path to directory which will hold temporary files.
|
61
|
-
snapshot_name: Name of the snapshot to load.
|
62
|
-
restrict_network: if True, will disable networking on the device. This
|
63
|
-
option is only available for emulator version > 31.3.9 (June 2022).
|
64
|
-
"""
|
65
|
-
self._adb_port = adb_port
|
66
|
-
self._adb_server_port = adb_server_port
|
67
|
-
self._emulator_console_port = emulator_console_port
|
68
|
-
self._grpc_port = grpc_port
|
69
|
-
self._emulator_path = emulator_path
|
70
|
-
self._android_sdk_root = android_sdk_root
|
71
|
-
self._avd_name = avd_name
|
72
|
-
self._android_avd_home = android_avd_home
|
73
|
-
self._run_headless = run_headless
|
74
|
-
self._kvm_device = kvm_device
|
75
|
-
self._gpu_mode = gpu_mode
|
76
|
-
self._snapshot_name = snapshot_name
|
77
|
-
self._restrict_network = restrict_network
|
32
|
+
config: config_classes.EmulatorLauncherConfig,
|
33
|
+
adb_controller_config: config_classes.AdbControllerConfig,
|
34
|
+
):
|
35
|
+
"""Launches an emulator."""
|
36
|
+
|
37
|
+
self._config = config
|
38
|
+
self._adb_controller_config = adb_controller_config
|
78
39
|
|
79
40
|
self._emulator = None
|
80
41
|
self._emulator_output = None
|
@@ -82,9 +43,10 @@ class EmulatorLauncher():
|
|
82
43
|
|
83
44
|
# Create directory for tmp files.
|
84
45
|
# Note: this will be deleted once EmulatorLauncher instance is cleaned up.
|
85
|
-
os.makedirs(tmp_dir, exist_ok=True)
|
46
|
+
os.makedirs(config.tmp_dir, exist_ok=True)
|
86
47
|
self._local_tmp_dir_handle = tempfile.TemporaryDirectory(
|
87
|
-
dir=tmp_dir, prefix='simulator_instance_'
|
48
|
+
dir=config.tmp_dir, prefix='simulator_instance_'
|
49
|
+
)
|
88
50
|
self._local_tmp_dir = self._local_tmp_dir_handle.name
|
89
51
|
self._logfile_path = os.path.join(self._local_tmp_dir, 'emulator_output')
|
90
52
|
logging.info('Simulator local_tmp_dir: %s', self._local_tmp_dir)
|
@@ -95,22 +57,28 @@ class EmulatorLauncher():
|
|
95
57
|
def launch_emulator_process(self) -> None:
|
96
58
|
"""Launches the emulator."""
|
97
59
|
|
98
|
-
logging.info('Booting new emulator
|
60
|
+
logging.info('Booting new emulator: %s', self._config.emulator_path)
|
99
61
|
|
100
62
|
# Set necessary environment variables.
|
101
|
-
base_lib_dir = self.
|
63
|
+
base_lib_dir = self._config.emulator_path[:-8] + 'lib64/'
|
102
64
|
ld_library_path = ':'.join([
|
103
65
|
base_lib_dir + 'x11/', base_lib_dir + 'qt/lib/',
|
104
66
|
base_lib_dir + 'gles_swiftshader/', base_lib_dir
|
105
67
|
])
|
106
68
|
extra_env_vars = {
|
107
69
|
'ANDROID_HOME': '',
|
108
|
-
'ANDROID_SDK_ROOT': self.
|
109
|
-
'ANDROID_AVD_HOME': self.
|
110
|
-
'ANDROID_EMULATOR_KVM_DEVICE': self.
|
111
|
-
'ANDROID_ADB_SERVER_PORT': str(
|
70
|
+
'ANDROID_SDK_ROOT': self._config.android_sdk_root,
|
71
|
+
'ANDROID_AVD_HOME': self._config.android_avd_home,
|
72
|
+
'ANDROID_EMULATOR_KVM_DEVICE': self._config.kvm_device,
|
73
|
+
'ANDROID_ADB_SERVER_PORT': str(
|
74
|
+
self._adb_controller_config.adb_server_port
|
75
|
+
),
|
112
76
|
'LD_LIBRARY_PATH': ld_library_path,
|
113
|
-
'QT_XKB_CONFIG_ROOT': str(
|
77
|
+
'QT_XKB_CONFIG_ROOT': str(
|
78
|
+
self._config.emulator_path[:-8] + 'qt_config/'
|
79
|
+
),
|
80
|
+
'ANDROID_EMU_ENABLE_CRASH_REPORTING': '1',
|
81
|
+
'SHOW_PERF_STATS': str(1 if self._config.show_perf_stats else 0),
|
114
82
|
}
|
115
83
|
logging.info('extra_env_vars: %s',
|
116
84
|
' '.join(f'{k}={v}' for k, v in extra_env_vars.items()))
|
@@ -118,31 +86,52 @@ class EmulatorLauncher():
|
|
118
86
|
env_vars.update(extra_env_vars)
|
119
87
|
|
120
88
|
# Compile command.
|
121
|
-
grpc_port =
|
122
|
-
|
123
|
-
|
89
|
+
grpc_port = (
|
90
|
+
['-grpc', str(self._config.grpc_port)]
|
91
|
+
if self._config.grpc_port >= 0
|
92
|
+
else []
|
93
|
+
)
|
94
|
+
run_headless = (
|
95
|
+
['-no-skin', '-no-window'] if self._config.run_headless else []
|
96
|
+
)
|
97
|
+
ports = [
|
98
|
+
'-ports',
|
99
|
+
'%s,%s' % (self._config.emulator_console_port, self._config.adb_port),
|
100
|
+
]
|
124
101
|
snapshot = [
|
125
|
-
'-snapshot',
|
126
|
-
|
102
|
+
'-snapshot',
|
103
|
+
self._config.snapshot_name,
|
104
|
+
'-feature',
|
105
|
+
'AllowSnapshotMigration,MigratableSnapshotSave',
|
127
106
|
]
|
128
|
-
snapshot = snapshot if self.
|
107
|
+
snapshot = snapshot if self._config.snapshot_name else ['-no-snapshot']
|
129
108
|
restrict_network_args = [
|
130
109
|
'-network-user-mode-options', 'restrict=y', '-wifi-user-mode-options',
|
131
110
|
'restrict=y'
|
132
111
|
]
|
133
|
-
network_args =
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
112
|
+
network_args = (
|
113
|
+
restrict_network_args if self._config.restrict_network else []
|
114
|
+
)
|
115
|
+
command = (
|
116
|
+
[
|
117
|
+
self._config.emulator_path,
|
118
|
+
'-adb-path',
|
119
|
+
self._adb_controller_config.adb_path,
|
120
|
+
'-gpu',
|
121
|
+
self._config.gpu_mode,
|
122
|
+
'-no-audio',
|
123
|
+
'-show-kernel',
|
124
|
+
'-verbose',
|
125
|
+
'-avd',
|
126
|
+
self._config.avd_name,
|
127
|
+
]
|
128
|
+
+ grpc_port
|
129
|
+
+ run_headless
|
130
|
+
+ ports
|
131
|
+
+ snapshot
|
132
|
+
+ network_args
|
133
|
+
)
|
144
134
|
logging.info('Emulator launch command: %s', ' '.join(command))
|
145
|
-
|
146
135
|
# Prepare logfile.
|
147
136
|
self._emulator_output = open(self._logfile_path, 'wb')
|
148
137
|
|
@@ -172,6 +161,7 @@ class EmulatorLauncher():
|
|
172
161
|
def close(self):
|
173
162
|
"""Clean up launcher files and processes."""
|
174
163
|
if not self._is_closed:
|
164
|
+
self._local_tmp_dir_handle.cleanup()
|
175
165
|
self.confirm_shutdown()
|
176
166
|
self._is_closed = True
|
177
167
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# coding=utf-8
|
2
|
-
# Copyright
|
2
|
+
# Copyright 2024 DeepMind Technologies Limited.
|
3
3
|
#
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
5
|
# you may not use this file except in compliance with the License.
|
@@ -22,17 +22,18 @@ import tempfile
|
|
22
22
|
from unittest import mock
|
23
23
|
|
24
24
|
from absl.testing import absltest
|
25
|
+
from absl.testing import parameterized
|
26
|
+
from android_env.components import config_classes
|
25
27
|
from android_env.components.simulators.emulator import emulator_launcher
|
26
28
|
|
27
29
|
|
28
|
-
class EmulatorLauncherTest(
|
30
|
+
class EmulatorLauncherTest(parameterized.TestCase):
|
29
31
|
|
30
32
|
def setUp(self):
|
31
33
|
super().setUp()
|
32
34
|
|
33
|
-
mock.patch.object(os, 'makedirs').start()
|
34
|
-
|
35
35
|
self._emulator_path = 'fake/path/emulator'
|
36
|
+
self._adb_path = 'fake/path/adb'
|
36
37
|
self._adb_port = 5554
|
37
38
|
self._adb_server_port = 1234
|
38
39
|
self._emulator_console_port = 5555
|
@@ -40,14 +41,17 @@ class EmulatorLauncherTest(absltest.TestCase):
|
|
40
41
|
|
41
42
|
self._expected_command = [
|
42
43
|
self._emulator_path,
|
44
|
+
'-adb-path',
|
45
|
+
'fake/path/adb',
|
43
46
|
'-gpu',
|
44
|
-
'
|
47
|
+
'swangle_indirect',
|
45
48
|
'-no-audio',
|
46
49
|
'-show-kernel',
|
47
50
|
'-verbose',
|
48
51
|
'-avd',
|
49
52
|
self._avd_name,
|
50
53
|
]
|
54
|
+
self._headless = ['-no-skin', '-no-window']
|
51
55
|
self._ports = ['-ports', f'{self._emulator_console_port},{self._adb_port}']
|
52
56
|
self._snapshot = ['-no-snapshot']
|
53
57
|
|
@@ -57,116 +61,208 @@ class EmulatorLauncherTest(absltest.TestCase):
|
|
57
61
|
base_lib_dir + 'gles_swiftshader/', base_lib_dir
|
58
62
|
])
|
59
63
|
|
64
|
+
# Instantiate the config to extract default values.
|
65
|
+
config = config_classes.EmulatorLauncherConfig()
|
60
66
|
self._expected_env_vars = {
|
61
67
|
'ANDROID_HOME': '',
|
62
|
-
'ANDROID_SDK_ROOT':
|
63
|
-
'ANDROID_AVD_HOME':
|
68
|
+
'ANDROID_SDK_ROOT': config.android_sdk_root,
|
69
|
+
'ANDROID_AVD_HOME': config.android_avd_home,
|
64
70
|
'ANDROID_EMULATOR_KVM_DEVICE': '/dev/kvm',
|
65
71
|
'ANDROID_ADB_SERVER_PORT': '1234',
|
66
72
|
'LD_LIBRARY_PATH': ld_library_path,
|
67
73
|
'QT_XKB_CONFIG_ROOT': str(self._emulator_path[:-8] + 'qt_config/'),
|
74
|
+
'ANDROID_EMU_ENABLE_CRASH_REPORTING': '1',
|
68
75
|
}
|
69
76
|
|
77
|
+
@parameterized.named_parameters([
|
78
|
+
('hide_perf_stats', False),
|
79
|
+
('show_perf_stats', True),
|
80
|
+
])
|
81
|
+
@mock.patch.object(os, 'makedirs')
|
70
82
|
@mock.patch.object(os, 'environ', autospec=True, return_value=dict())
|
71
83
|
@mock.patch.object(tempfile, 'TemporaryDirectory', instance=True)
|
72
|
-
|
73
|
-
|
74
|
-
|
84
|
+
def test_launch(
|
85
|
+
self,
|
86
|
+
show_perf_stats: bool,
|
87
|
+
mock_tmp_dir,
|
88
|
+
unused_os_environ,
|
89
|
+
unused_os_makedirs,
|
90
|
+
):
|
75
91
|
mock_tmp_dir.return_value.name.return_value = 'local_tmp_dir'
|
76
92
|
|
77
|
-
|
93
|
+
config = config_classes.EmulatorLauncherConfig(
|
78
94
|
adb_port=self._adb_port,
|
79
|
-
adb_server_port=self._adb_server_port,
|
80
95
|
emulator_console_port=self._emulator_console_port,
|
81
96
|
emulator_path=self._emulator_path,
|
82
97
|
avd_name=self._avd_name,
|
83
|
-
grpc_port=-1
|
98
|
+
grpc_port=-1,
|
99
|
+
show_perf_stats=show_perf_stats,
|
100
|
+
)
|
101
|
+
adb_controller_config = config_classes.AdbControllerConfig(
|
102
|
+
adb_path=self._adb_path,
|
103
|
+
adb_server_port=self._adb_server_port,
|
104
|
+
)
|
105
|
+
launcher = emulator_launcher.EmulatorLauncher(
|
106
|
+
config=config, adb_controller_config=adb_controller_config
|
107
|
+
)
|
108
|
+
|
109
|
+
expected_env_vars = self._expected_env_vars
|
110
|
+
expected_env_vars['SHOW_PERF_STATS'] = '1' if show_perf_stats else '0'
|
84
111
|
|
85
112
|
with mock.patch.object(
|
86
|
-
subprocess, 'Popen', autospec=True
|
87
|
-
|
113
|
+
subprocess, 'Popen', autospec=True
|
114
|
+
) as emulator_init, mock.patch.object(builtins, 'open', autospec=True) as f:
|
88
115
|
f.return_value.__enter__ = f()
|
89
116
|
launcher.launch_emulator_process()
|
90
117
|
emulator_init.assert_called_once_with(
|
91
|
-
args=self._expected_command
|
92
|
-
|
118
|
+
args=self._expected_command
|
119
|
+
+ self._headless
|
120
|
+
+ self._ports
|
121
|
+
+ self._snapshot,
|
122
|
+
env=expected_env_vars,
|
93
123
|
stdout=f(),
|
94
|
-
stderr=f()
|
124
|
+
stderr=f(),
|
125
|
+
)
|
95
126
|
|
127
|
+
@parameterized.named_parameters([
|
128
|
+
('hide_perf_stats', False),
|
129
|
+
('show_perf_stats', True),
|
130
|
+
])
|
131
|
+
@mock.patch.object(os, 'makedirs')
|
96
132
|
@mock.patch.object(os, 'environ', autospec=True, return_value=dict())
|
97
133
|
@mock.patch.object(tempfile, 'TemporaryDirectory', instance=True)
|
98
|
-
|
99
|
-
|
100
|
-
|
134
|
+
def test_grpc_port(
|
135
|
+
self,
|
136
|
+
show_perf_stats: bool,
|
137
|
+
mock_tmp_dir,
|
138
|
+
unused_os_environ,
|
139
|
+
unused_os_makedirs,
|
140
|
+
):
|
101
141
|
mock_tmp_dir.return_value.name.return_value = 'local_tmp_dir'
|
102
142
|
|
103
|
-
|
143
|
+
config = config_classes.EmulatorLauncherConfig(
|
104
144
|
adb_port=self._adb_port,
|
105
|
-
adb_server_port=self._adb_server_port,
|
106
145
|
emulator_console_port=self._emulator_console_port,
|
107
146
|
emulator_path=self._emulator_path,
|
108
147
|
avd_name=self._avd_name,
|
109
|
-
grpc_port=8554
|
148
|
+
grpc_port=8554,
|
149
|
+
show_perf_stats=show_perf_stats,
|
150
|
+
)
|
151
|
+
adb_controller_config = config_classes.AdbControllerConfig(
|
152
|
+
adb_path=self._adb_path,
|
153
|
+
adb_server_port=self._adb_server_port,
|
154
|
+
)
|
155
|
+
launcher = emulator_launcher.EmulatorLauncher(
|
156
|
+
config=config, adb_controller_config=adb_controller_config
|
157
|
+
)
|
158
|
+
|
159
|
+
expected_env_vars = self._expected_env_vars
|
160
|
+
expected_env_vars['SHOW_PERF_STATS'] = '1' if show_perf_stats else '0'
|
110
161
|
|
111
162
|
with mock.patch.object(
|
112
|
-
subprocess, 'Popen', autospec=True
|
113
|
-
|
163
|
+
subprocess, 'Popen', autospec=True
|
164
|
+
) as emulator_init, mock.patch.object(builtins, 'open', autospec=True) as f:
|
114
165
|
f.return_value.__enter__ = f()
|
115
166
|
launcher.launch_emulator_process()
|
116
167
|
emulator_init.assert_called_once_with(
|
117
|
-
args=self._expected_command
|
118
|
-
|
119
|
-
|
168
|
+
args=self._expected_command
|
169
|
+
+ ['-grpc', '8554']
|
170
|
+
+ self._headless
|
171
|
+
+ self._ports
|
172
|
+
+ self._snapshot,
|
173
|
+
env=expected_env_vars,
|
120
174
|
stdout=f(),
|
121
|
-
stderr=f()
|
175
|
+
stderr=f(),
|
176
|
+
)
|
122
177
|
|
178
|
+
@parameterized.named_parameters([
|
179
|
+
('hide_perf_stats', False),
|
180
|
+
('show_perf_stats', True),
|
181
|
+
])
|
182
|
+
@mock.patch.object(os, 'makedirs')
|
123
183
|
@mock.patch.object(os, 'environ', autospec=True, return_value=dict())
|
124
184
|
@mock.patch.object(tempfile, 'TemporaryDirectory', instance=True)
|
125
|
-
|
126
|
-
|
127
|
-
|
185
|
+
def test_snapshot(
|
186
|
+
self,
|
187
|
+
show_perf_stats: bool,
|
188
|
+
mock_tmp_dir,
|
189
|
+
unused_os_environ,
|
190
|
+
unused_os_makedirs,
|
191
|
+
):
|
128
192
|
mock_tmp_dir.return_value.name.return_value = 'local_tmp_dir'
|
129
193
|
|
130
|
-
|
194
|
+
config = config_classes.EmulatorLauncherConfig(
|
131
195
|
adb_port=self._adb_port,
|
132
|
-
adb_server_port=self._adb_server_port,
|
133
196
|
emulator_console_port=self._emulator_console_port,
|
134
197
|
emulator_path=self._emulator_path,
|
135
198
|
avd_name=self._avd_name,
|
136
199
|
grpc_port=-1,
|
137
|
-
snapshot_name='my_snapshot'
|
200
|
+
snapshot_name='my_snapshot',
|
201
|
+
show_perf_stats=show_perf_stats,
|
202
|
+
)
|
203
|
+
adb_controller_config = config_classes.AdbControllerConfig(
|
204
|
+
adb_path=self._adb_path,
|
205
|
+
adb_server_port=self._adb_server_port,
|
206
|
+
)
|
207
|
+
launcher = emulator_launcher.EmulatorLauncher(
|
208
|
+
config=config, adb_controller_config=adb_controller_config
|
209
|
+
)
|
138
210
|
|
139
211
|
expected_snapshot = [
|
140
212
|
'-snapshot', 'my_snapshot', '-feature',
|
141
213
|
'AllowSnapshotMigration,MigratableSnapshotSave'
|
142
214
|
]
|
143
215
|
|
216
|
+
expected_env_vars = self._expected_env_vars
|
217
|
+
expected_env_vars['SHOW_PERF_STATS'] = '1' if show_perf_stats else '0'
|
218
|
+
|
144
219
|
with mock.patch.object(
|
145
220
|
subprocess, 'Popen', autospec=True) as emulator_init, \
|
146
221
|
mock.patch.object(builtins, 'open', autospec=True) as f:
|
147
222
|
f.return_value.__enter__ = f()
|
148
223
|
launcher.launch_emulator_process()
|
149
224
|
emulator_init.assert_called_once_with(
|
150
|
-
args=self._expected_command
|
151
|
-
|
225
|
+
args=self._expected_command
|
226
|
+
+ self._headless
|
227
|
+
+ self._ports
|
228
|
+
+ expected_snapshot,
|
229
|
+
env=expected_env_vars,
|
152
230
|
stdout=f(),
|
153
|
-
stderr=f()
|
231
|
+
stderr=f(),
|
232
|
+
)
|
154
233
|
|
234
|
+
@parameterized.named_parameters([
|
235
|
+
('hide_perf_stats', False),
|
236
|
+
('show_perf_stats', True),
|
237
|
+
])
|
238
|
+
@mock.patch.object(os, 'makedirs')
|
155
239
|
@mock.patch.object(os, 'environ', autospec=True, return_value=dict())
|
156
240
|
@mock.patch.object(tempfile, 'TemporaryDirectory', instance=True)
|
157
|
-
|
158
|
-
|
159
|
-
|
241
|
+
def test_network_restrict(
|
242
|
+
self,
|
243
|
+
show_perf_stats: bool,
|
244
|
+
mock_tmp_dir,
|
245
|
+
unused_os_environ,
|
246
|
+
unused_os_makedirs,
|
247
|
+
):
|
160
248
|
mock_tmp_dir.return_value.name.return_value = 'local_tmp_dir'
|
161
249
|
|
162
|
-
|
250
|
+
config = config_classes.EmulatorLauncherConfig(
|
163
251
|
adb_port=self._adb_port,
|
164
|
-
adb_server_port=self._adb_server_port,
|
165
252
|
emulator_console_port=self._emulator_console_port,
|
166
253
|
emulator_path=self._emulator_path,
|
167
254
|
avd_name=self._avd_name,
|
168
255
|
grpc_port=-1,
|
169
|
-
restrict_network=True
|
256
|
+
restrict_network=True,
|
257
|
+
show_perf_stats=show_perf_stats,
|
258
|
+
)
|
259
|
+
adb_controller_config = config_classes.AdbControllerConfig(
|
260
|
+
adb_path=self._adb_path,
|
261
|
+
adb_server_port=self._adb_server_port,
|
262
|
+
)
|
263
|
+
launcher = emulator_launcher.EmulatorLauncher(
|
264
|
+
config=config, adb_controller_config=adb_controller_config
|
265
|
+
)
|
170
266
|
|
171
267
|
expected_snapshot = ['-no-snapshot']
|
172
268
|
expected_network_restrict = [
|
@@ -174,17 +270,25 @@ class EmulatorLauncherTest(absltest.TestCase):
|
|
174
270
|
'restrict=y'
|
175
271
|
]
|
176
272
|
|
273
|
+
expected_env_vars = self._expected_env_vars
|
274
|
+
expected_env_vars['SHOW_PERF_STATS'] = '1' if show_perf_stats else '0'
|
275
|
+
|
177
276
|
with mock.patch.object(
|
178
277
|
subprocess, 'Popen', autospec=True) as emulator_init, \
|
179
278
|
mock.patch.object(builtins, 'open', autospec=True) as f:
|
180
279
|
f.return_value.__enter__ = f()
|
181
280
|
launcher.launch_emulator_process()
|
182
281
|
emulator_init.assert_called_once_with(
|
183
|
-
self._expected_command
|
184
|
-
|
185
|
-
|
282
|
+
self._expected_command
|
283
|
+
+ self._headless
|
284
|
+
+ self._ports
|
285
|
+
+ expected_snapshot
|
286
|
+
+ expected_network_restrict,
|
287
|
+
env=expected_env_vars,
|
186
288
|
stdout=f(),
|
187
|
-
stderr=f()
|
289
|
+
stderr=f(),
|
290
|
+
)
|
291
|
+
|
188
292
|
|
189
293
|
if __name__ == '__main__':
|
190
294
|
absltest.main()
|