Lines Matching refs:self
139 …def __init__(self, grpc_port: str, grpc_root_server_port: str, signal_port: str, cmd: List[str], l… argument
156 self.verbose_mode = verbose_mode
157 self.grpc_root_server_port = int(grpc_root_server_port)
158 self.grpc_port = int(grpc_port)
159 self.signal_port = int(signal_port)
160 self.name = name
161 self.type_identifier = type_identifier
162 self.label = label
164 self.log_path_base = get_current_context().get_full_output_path()
165 self.test_runner_base_path = \
167 self.backing_process_log_path = os.path.join(self.log_path_base,
168 … '%s_%s_backing_logs.txt' % (self.type_identifier, self.label))
170 … cmd.append("--btsnoop=%s" % os.path.join(self.log_path_base, '%s_btsnoop_hci.log' % self.label))
171 self.cmd = cmd
172 self.environment = os.environ.copy()
173 if "cert" in self.label:
174 self.terminal_color = TerminalColor.BLUE
176 self.terminal_color = TerminalColor.YELLOW
178 def setup(self): argument
187 …make_ports_available([self.signal_port]), "[%s] Failed to make signal port available" % self.label)
192 signal_socket.bind(("localhost", self.signal_port))
196 logging.debug("Running %s" % " ".join(self.cmd))
197 self.backing_process = subprocess.Popen(
198 self.cmd,
200 env=self.environment,
204 …asserts.assert_true(self.backing_process, msg="Cannot start backing_process at " + " ".join(self.c…
206 is_subprocess_alive(self.backing_process),
207 msg="backing_process stopped immediately after running " + " ".join(self.cmd))
212 self.backing_process_logger = AsyncSubprocessLogger(
213 self.backing_process, [self.backing_process_log_path],
214 log_to_stdout=self.verbose_mode,
215 tag=self.label,
216 color=self.terminal_color)
219 … self.grpc_root_server_channel = grpc.insecure_channel("localhost:%d" % self.grpc_root_server_port)
220 self.grpc_channel = grpc.insecure_channel("localhost:%d" % self.grpc_port)
222 if self.verbose_mode:
223 …self.grpc_channel = grpc.intercept_channel(self.grpc_channel, LoggingClientInterceptor(self.label))
226 self.rootservice = facade_rootservice_pb2_grpc.RootFacadeStub(self.grpc_root_server_channel)
227 self.hal = hal_facade_pb2_grpc.HciHalFacadeStub(self.grpc_channel)
228 …self.controller_read_only_property = facade_rootservice_pb2_grpc.ReadOnlyPropertyStub(self.grpc_ch…
229 self.hci = hci_facade_pb2_grpc.HciLayerFacadeStub(self.grpc_channel)
230 self.l2cap = l2cap_facade_pb2_grpc.L2capClassicModuleFacadeStub(self.grpc_channel)
231 self.l2cap_le = l2cap_le_facade_pb2_grpc.L2capLeModuleFacadeStub(self.grpc_channel)
232 self.hci_acl_manager = acl_manager_facade_pb2_grpc.AclManagerFacadeStub(self.grpc_channel)
233 … self.hci_le_acl_manager = le_acl_manager_facade_pb2_grpc.LeAclManagerFacadeStub(self.grpc_channel)
234 … self.hci_le_initiator_address = le_initiator_address_facade_pb2_grpc.LeInitiatorAddressFacadeStub(
235 self.grpc_channel)
236 self.hci_controller = controller_facade_pb2_grpc.ControllerFacadeStub(self.grpc_channel)
237 …self.hci_controller.GetMacAddressSimple = lambda: self.hci_controller.GetMacAddress(empty_proto.Em…
238 …self.hci_controller.GetLocalNameSimple = lambda: self.hci_controller.GetLocalName(empty_proto.Empt…
239 …self.hci_le_advertising_manager = le_advertising_manager_facade_pb2_grpc.LeAdvertisingManagerFacad…
240 self.grpc_channel)
241 … self.hci_le_scanning_manager = le_scanning_manager_facade_pb2_grpc.LeScanningManagerFacadeStub(
242 self.grpc_channel)
243 self.neighbor = neighbor_facade_pb2_grpc.NeighborFacadeStub(self.grpc_channel)
244 self.security = security_facade_pb2_grpc.SecurityModuleFacadeStub(self.grpc_channel)
245 self.shim = shim_facade_pb2_grpc.ShimFacadeStub(self.grpc_channel)
247 def get_crash_snippet_and_log_tail(self): argument
248 if is_subprocess_alive(self.backing_process):
251 return read_crash_snippet_and_log_tail(self.backing_process_log_path)
253 def teardown(self): argument
259 self.grpc_channel.close()
260 self.grpc_root_server_channel.close()
262 self.backing_process.send_signal(stop_signal)
264 return_code = self.backing_process.wait(timeout=self.WAIT_CHANNEL_READY_TIMEOUT_SECONDS)
266 … logging.error("[%s] Failed to interrupt backing process via SIGINT, sending SIGKILL" % self.label)
268 self.backing_process.kill()
270 … return_code = self.backing_process.wait(timeout=self.WAIT_CHANNEL_READY_TIMEOUT_SECONDS)
275 logging.error("backing process %s stopped with code: %d" % (self.label, return_code))
276 self.backing_process_logger.stop()
278 def wait_channel_ready(self): argument
279 future = grpc.channel_ready_future(self.grpc_channel)
281 future.result(timeout=self.WAIT_CHANNEL_READY_TIMEOUT_SECONDS)
283 asserts.fail("[%s] wait channel ready timeout" % self.label)
291 …def __init__(self, grpc_port: str, grpc_root_server_port: str, signal_port: str, cmd: List[str], l… argument
296 self.backing_process_profraw_path = pathlib.Path(self.log_path_base).joinpath(
297 "%s_%s_backing_coverage.profraw" % (self.type_identifier, self.label))
298 self.environment["LLVM_PROFILE_FILE"] = str(self.backing_process_profraw_path)
300 def teardown(self): argument
302 self.generate_coverage_report()
304 def generate_coverage_report(self): argument
305 if not self.backing_process_profraw_path.is_file():
307 (self.label, str(self.backing_process_profraw_path)))
310 if self.backing_process_profraw_path.stat().st_size <= 0:
312 (self.label, str(self.backing_process_profraw_path)))
316 (self.label, str(self.backing_process_profraw_path)))
322 …"[%s] Skip coverage report as llvm-profdata is not found at %s" % (self.label, str(llvm_profdata)))
326 …logging.info("[%s] Skip coverage report as llvm-cov is not found at %s" % (self.label, str(llvm_co…
328 logging.info("[%s] Generating coverage report" % self.label)
329 profdata_path = pathlib.Path(self.test_runner_base_path).joinpath(
330 "%s_%s_backing_process_coverage.profdata" % (self.type_identifier, self.label))
331 profdata_path_tmp = pathlib.Path(self.test_runner_base_path).joinpath(
332 "%s_%s_backing_process_coverage_tmp.profdata" % (self.type_identifier, self.label))
334 … profdata_cmd = [str(llvm_profdata), "merge", "-sparse", str(self.backing_process_profraw_path)]
340 logging.warning("[%s] Failed to index profdata, cmd result: %r" % (self.label, result))
344 coverage_result_path = pathlib.Path(self.test_runner_base_path).joinpath(
345 "%s_%s_backing_process_coverage.json" % (self.type_identifier, self.label))
348 … [str(llvm_cov), "export", "--format=text", "--instr-profile", profdata_path, self.cmd[0]],
353 … logging.warning("[%s] Failed to generated coverage report, cmd result: %r" % (self.label, result))
356 coverage_summary_path = pathlib.Path(self.test_runner_base_path).joinpath(
357 "%s_%s_backing_process_coverage_summary.txt" % (self.type_identifier, self.label))
360 [llvm_cov, "report", "--instr-profile", profdata_path, self.cmd[0]],
365 …logging.warning("[%s] Failed to generated coverage summary, cmd result: %r" % (self.label, result))
368 def setup(self): argument
374 make_ports_available((self.grpc_port, self.grpc_root_server_port)),
375 "[%s] Failed to make backing process ports available" % self.label)
385 …def __init__(self, grpc_port: str, grpc_root_server_port: str, signal_port: str, cmd: List[str], l… argument
389 self.serial_number = serial_number
390 self.adb = AdbProxy(serial_number)
392 def setup(self): argument
393 logging.info("Setting up device %s %s" % (self.label, self.serial_number))
394 … asserts.assert_true(self.adb.ensure_root(), "device %s cannot run as root", self.serial_number)
397 self.cleanup_port_forwarding()
398 self.sync_device_time()
401 self.tcp_forward_or_die(self.grpc_port, self.grpc_port)
402 self.tcp_forward_or_die(self.grpc_root_server_port, self.grpc_root_server_port)
403 self.tcp_reverse_or_die(self.signal_port, self.signal_port)
406 self.ensure_verity_disabled()
407 …self.push_or_die(os.path.join(get_gd_root(), "target", "bluetooth_stack_with_facade"), "system/bin…
408 … self.push_or_die(os.path.join(get_gd_root(), "target", "libbluetooth_gd.so"), "system/lib64")
409 … self.push_or_die(os.path.join(get_gd_root(), "target", "libgrpc++_unsecure.so"), "system/lib64")
410 self.adb.shell("rm /data/misc/bluetooth/logs/btsnoop_hci.log")
411 self.ensure_no_output(self.adb.shell("svc bluetooth disable"))
414 self.logcat_output_path = os.path.join(
415 …self.log_path_base, '%s_%s_%s_logcat_logs.txt' % (self.type_identifier, self.label, self.serial_nu…
416 …self.logcat_cmd = ["adb", "-s", self.serial_number, "logcat", "-T", "1", "-v", "year", "-v", "uid"]
417 logging.debug("Running %s", " ".join(self.logcat_cmd))
418 self.logcat_process = subprocess.Popen(
419 … self.logcat_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
420 …asserts.assert_true(self.logcat_process, msg="Cannot start logcat_process at " + " ".join(self.log…
422 is_subprocess_alive(self.logcat_process),
423 msg="logcat_process stopped immediately after running " + " ".join(self.logcat_cmd))
424 self.logcat_logger = AsyncSubprocessLogger(
425 self.logcat_process, [self.logcat_output_path],
426 log_to_stdout=self.verbose_mode,
427 tag="%s_%s" % (self.label, self.serial_number),
428 color=self.terminal_color)
431 logging.info("Done preparation for %s, starting backing process" % self.serial_number)
434 def teardown(self): argument
437 self.logcat_process.send_signal(stop_signal)
439 return_code = self.logcat_process.wait(timeout=self.WAIT_CHANNEL_READY_TIMEOUT_SECONDS)
442 (self.label, self.serial_number))
444 self.logcat_process.kill()
446 … return_code = self.logcat_process.wait(timeout=self.WAIT_CHANNEL_READY_TIMEOUT_SECONDS)
448 … logging.error("Failed to kill logcat_process %s %s" % (self.label, self.serial_number))
451 …logging.error("logcat_process %s_%s stopped with code: %d" % (self.label, self.serial_number, retu…
452 self.logcat_logger.stop()
453 self.cleanup_port_forwarding()
454 … self.adb.pull("/data/misc/bluetooth/logs/btsnoop_hci.log %s" % os.path.join(self.log_path_base,
455 … "%s_btsnoop_hci.log" % self.label))
457 def cleanup_port_forwarding(self): argument
458 self.adb.remove_tcp_forward(self.grpc_port)
459 self.adb.remove_tcp_forward(self.grpc_root_server_port)
460 self.adb.reverse("--remove tcp:%d" % self.signal_port)
470 def sync_device_time(self): argument
471 self.adb.shell("settings put global auto_time 0")
472 self.adb.shell("settings put global auto_time_zone 0")
473 device_tz = self.adb.shell("date +%z")
481 self.adb.shell("setprop persist.sys.timezone %s" % target_timezone)
482 self.reboot()
483 device_tz = self.adb.shell("date +%z")
487 self.adb.shell("date %s" % time.strftime("%m%d%H%M%Y.%S"))
490 … device_time = datetime.strptime(self.adb.shell("date +'%s'" % datetime_format), datetime_format)
504 def push_or_die(self, src_file_path, dst_file_path, push_timeout=300): argument
512 out = self.adb.push('%s %s' % (src_file_path, dst_file_path), timeout=push_timeout)
516 def tcp_forward_or_die(self, host_port, device_port, num_retry=1): argument
524 error_or_port = self.adb.tcp_forward(host_port, device_port)
534 … "device port %d, num_retries left is %d" % (self.label, host_port, device_port, num_retry))
535 self.reboot()
536 return self.tcp_forward_or_die(host_port, device_port, num_retry=num_retry)
541 def tcp_reverse_or_die(self, device_port, host_port, num_retry=1): argument
549 error_or_port = self.adb.reverse("tcp:%d tcp:%d" % (device_port, host_port))
561 … "host port %d, num_retries left is %d" % (self.label, device_port, host_port, num_retry))
562 self.reboot()
563 return self.tcp_reverse_or_die(device_port, host_port, num_retry=num_retry)
568 def ensure_verity_disabled(self): argument
574 logging.debug("Disabling verity and remount for %s", self.serial_number)
576 system_verity = self.adb.getprop('partition.system.verified')
577 vendor_verity = self.adb.getprop('partition.vendor.verified')
579 self.adb.disable_verity()
580 self.reboot()
581 self.adb.remount()
582 self.adb.wait_for_device(timeout=self.WAIT_FOR_DEVICE_TIMEOUT_SECONDS)
584 def reboot(self, timeout_minutes=15.0): argument
589 logging.debug("Rebooting %s", self.serial_number)
590 self.adb.reboot()
600 self.adb.get_state()
608 self.wait_for_boot_completion(timeout_minutes=minutes_left)
609 …asserts.assert_true(self.adb.ensure_root(), "device %s cannot run as root after reboot", self.seri…
611 def wait_for_boot_completion(self, timeout_minutes=15.0): argument
619 self.adb.wait_for_device(timeout=self.WAIT_FOR_DEVICE_TIMEOUT_SECONDS)
622 completed = self.adb.getprop("sys.boot_completed")
630 asserts.fail(msg='Device %s booting process timed out.' % self.serial_number)