Execute a command on the device's shell. Args: target_dir: Parent directory of the executable on the device (relative to devices' base dir for testing). binary: Name of the binary. args: List of arguments to pass to the binary. rel_path: Relative path on device
(self, target_dir, binary, args, rel_path, timeout, env=None,
logcat_file=False)
| 168 | return True |
| 169 | |
| 170 | def run(self, target_dir, binary, args, rel_path, timeout, env=None, |
| 171 | logcat_file=False): |
| 172 | """Execute a command on the device's shell. |
| 173 | |
| 174 | Args: |
| 175 | target_dir: Parent directory of the executable on the device (relative to |
| 176 | devices' base dir for testing). |
| 177 | binary: Name of the binary. |
| 178 | args: List of arguments to pass to the binary. |
| 179 | rel_path: Relative path on device to use as CWD. |
| 180 | timeout: Timeout in seconds. |
| 181 | env: The environment variables with which the command should be run. |
| 182 | logcat_file: File into which to stream adb logcat log. |
| 183 | """ |
| 184 | binary_on_device = os.path.join(DEVICE_DIR, target_dir, binary) |
| 185 | cmd = [binary_on_device] + args |
| 186 | def run_inner(): |
| 187 | try: |
| 188 | output = self.device.RunShellCommand( |
| 189 | cmd, |
| 190 | cwd=os.path.join(DEVICE_DIR, rel_path), |
| 191 | check_return=True, |
| 192 | env=env, |
| 193 | timeout=timeout, |
| 194 | retries=0, |
| 195 | ) |
| 196 | # Return output without linker warnings (https://crbug.com/1454414). |
| 197 | return '\n'.join(filter(self.filter_line, output)) |
| 198 | except device_errors.AdbCommandFailedError as e: |
| 199 | raise CommandFailedException(e.status, e.output) |
| 200 | except device_errors.CommandTimeoutError as e: |
| 201 | raise TimeoutException(timeout, e.output) |
| 202 | |
| 203 | |
| 204 | if logcat_file: |
| 205 | with self.device.GetLogcatMonitor(output_file=logcat_file) as logmon: |
| 206 | result = run_inner() |
| 207 | logmon.Close() |
| 208 | return result |
| 209 | else: |
| 210 | return run_inner() |
| 211 | |
| 212 | def drop_ram_caches(self): |
| 213 | """Drop ran caches on device.""" |