• Home
  • Raw
  • Download

Lines Matching refs:self

55     def __init__(self, config=None):  argument
69 self.script_dir = os.path.dirname(os.path.realpath(__file__))
73 return os.path.join(self.script_dir, config_value)
77 self.android = find_android_build_dir(android_path)
79 self.android = None
80 self.linux = abspath("linux")
81 self.linux_arch = config_dict.get("linux_arch")
82 self.atf = abspath("atf")
83 self.qemu = abspath("qemu", "qemu-system-aarch64")
84 self.rpmbd = abspath("rpmbd")
85 self.arch = config_dict.get("arch")
86 self.extra_qemu_flags = config_dict.get("extra_qemu_flags", [])
88 def check_config(self, interactive: bool, boot_tests=(), argument
93 if not self.linux:
95 if not self.android:
113 if self.android:
114 if not self.linux:
160 def __init__(self): argument
162 self.command_dir = tempfile.mkdtemp()
165 self.command_args = [
170 self.com_pipe_in = None
171 self.com_pipe_out = None
173 def open(self): argument
175 self.com_pipe_in = open(f"{self.command_dir}/com.in", "w",
177 self.com_pipe_out = open(f"{self.command_dir}/com.out", "r",
179 self.qmp_command({"execute": "qmp_capabilities"})
181 def close(self): argument
190 try_close(self.com_pipe_in)
191 try_close(self.com_pipe_out)
206 shutil.rmtree(self.command_dir, onerror=cb_handle_error)
208 def qmp_command(self, qmp_command): argument
212 json.dump(qmp_command, self.com_pipe_in)
213 self.com_pipe_in.flush()
214 for line in iter(self.com_pipe_out.readline, ""):
232 def qmp_execute(self, execute, arguments=None): argument
237 return self.qmp_command(cmp_command)
239 def monitor_command(self, monitor_command): argument
242 res = self.qmp_execute("human-monitor-command",
303 def __init__(self): argument
304 self.has_error = False
305 self.command_pipe = None
306 self.qemu_proc = None
307 self.ports = None
309 self.args = []
310 self.temp_files = []
312 def get_qemu_arg_temp_file(self): argument
315 self.temp_files.append(tmp.name)
328 def __init__(self, argument
339 self.config = config
340 self.interactive = interactive
341 self.debug = debug
342 self.verbose = verbose
343 self.adb_transport = None
344 self.use_rpmb = rpmb
345 self.rpmb_proc = None
346 self.rpmb_sock_dir = None
347 self.msg_sock = None
348 self.msg_sock_conn = None
349 self.msg_sock_dir = None
350 self.debug_on_error = debug_on_error
351 self.dump_stdout_on_error = False
352 self.qemu_arch_options = None
353 self.default_timeout = 60 * 10 # 10 Minutes
354 self.session: Optional[RunnerSession] = None
355 self.state = RunnerState.OFF
358 if verbose or self.interactive:
359 self.stdout = None
360 self.stderr = None
362 self.stdout = tempfile.TemporaryFile() # pylint: disable=consider-using-with
363 self.stderr = subprocess.STDOUT
364 self.dump_stdout_on_error = True
367 if self.interactive:
368 self.stdin = None
370 self.stdin = subprocess.DEVNULL
372 if self.config.arch in ("arm64", "arm"):
373 self.qemu_arch_options = qemu_options.QemuArm64Options(self.config)
374 elif self.config.arch == "x86_64":
376 self.qemu_arch_options = qemu_options.QemuX86_64Options(self.config)
380 def error_dump_output(self): argument
381 if self.dump_stdout_on_error:
384 self.stdout.seek(0)
385 sys.stderr.buffer.write(self.stdout.read())
387 def get_qemu_arg_temp_file(self): argument
391 self.session.temp_files.append(tmp.name)
394 def rpmb_up(self): argument
396 rpmb_data = self.qemu_arch_options.rpmb_data_path()
398 self.rpmb_sock_dir = tempfile.mkdtemp()
401 rpmb_proc = subprocess.Popen([self.config.rpmbd,
404 self.rpmb_proc = rpmb_proc
420 return self.qemu_arch_options.rpmb_options(rpmb_sock)
422 def rpmb_down(self): argument
424 if self.rpmb_proc:
425 self.rpmb_proc.kill()
426 self.rpmb_proc = None
427 if self.rpmb_sock_dir:
428 shutil.rmtree(self.rpmb_sock_dir)
429 self.rpmb_sock_dir = None
431 def msg_channel_up(self): argument
441 self.msg_sock_dir = tempfile.mkdtemp()
443 self.msg_sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
444 self.msg_sock.bind(msg_sock_file)
447 self.msg_sock.listen(1)
453 def msg_channel_down(self): argument
454 if self.msg_sock_conn:
455 self.msg_sock_conn.close()
456 self.msg_sock_conn = None
457 if self.msg_sock_dir:
458 shutil.rmtree(self.msg_sock_dir)
459 self.msg_sock_dir = None
461 def msg_channel_wait_for_connection(self): argument
465 self.msg_sock_conn, _ = self.msg_sock.accept()
467 def msg_channel_send_msg(self, msg): argument
477 if self.msg_sock_conn:
478 self.msg_sock_conn.send(msg.encode())
482 def msg_channel_recv(self): argument
483 if self.msg_sock_conn:
484 return self.msg_sock_conn.recv(64)
489 def msg_channel_close(self): argument
490 if self.msg_sock_conn:
491 self.msg_sock_conn.close()
493 def boottest_run(self, boot_tests, timeout=(60 * 2)): argument
495 args = self.session.args
499 if self.debug:
514 if self.interactive:
516 elif self.verbose:
526 cmd = [self.config.qemu] + args
529 qemu_proc = subprocess.Popen(cmd, cwd=self.config.atf)
532 self.msg_channel_wait_for_connection()
535 self.msg_channel_down()
537 debug_on_error=self.debug_on_error)
541 if not self.debug:
546 self.msg_channel_send_msg(testcase)
549 ret = self.msg_channel_recv()
587 self.msg_channel_down()
590 debug_on_error=self.debug_on_error)
597 def androidtest_run(self, cmd, test_timeout=None): argument
599 session: RunnerSession = self.session
604 test_timeout = self.default_timeout
609 debug_on_error=self.debug_on_error)
611 test_result = self.adb(["shell"] + cmd, timeout=test_timeout,
621 def adb_bin(self): argument
625 def adb(self, argument
640 if self.adb_transport:
641 args = ["-t", str(self.adb_transport)] + args
647 stdout = self.stdout
648 stderr = self.stderr
651 [self.adb_bin()] + args, stdin=self.stdin, stdout=stdout,
669 def check_adb(self, args, **kwargs): argument
671 code = self.adb(args, **kwargs)
675 def adb_root(self): argument
681 self.adb(["wait-for-device"])
682 self.check_adb(["root"])
686 self.adb(["wait-for-device"])
689 code = self.adb(["shell",
699 def scan_transport(self, port, expect_none=False): argument
701 output = subprocess.check_output([self.adb_bin(), "devices", "-l"],
706 self.adb_transport = None
710 self.adb_transport = int(match.group(1))
712 def adb_up(self, port): argument
729 self.check_adb(["connect", f"localhost:{port}"])
730 self.scan_transport(port)
737 self.check_adb(["wait-for-device"], timeout=30, on_timeout=None)
746 self.adb_root()
752 userdata = self.qemu_arch_options.android_trusty_user_data()
753 self.check_adb(["push", userdata, "/"])
755 def adb_down(self, port): argument
757 self.check_adb(["disconnect", f"localhost:{port}"])
764 self.scan_transport(port, expect_none=True)
765 if not self.adb_transport:
777 def universal_args(self): argument
779 args = self.qemu_arch_options.basic_options()
780 args += self.qemu_arch_options.bios_options()
782 if self.config.linux:
783 args += self.qemu_arch_options.linux_options()
785 if self.config.android:
786 args += self.qemu_arch_options.android_drives_args()
789 args += self.config.extra_qemu_flags
793 def launch(self, target_state): argument
815 assert self.state == RunnerState.OFF
819 self.session = RunnerSession()
820 args = self.universal_args()
823 if self.use_rpmb:
824 args += self.rpmb_up()
826 if self.config.linux:
827 args += self.qemu_arch_options.gen_dtb(
829 self.session.get_qemu_arg_temp_file())
832 args = self.qemu_arch_options.machine_options() + args
834 if self.debug:
838 args += self.msg_channel_up()
841 self.session.args = args
842 self.state = target_state
852 if not self.interactive:
853 self.session.command_pipe = QEMUCommandPipe()
854 args += self.session.command_pipe.command_args
857 self.session.ports = alloc_ports()
865 args += forward_ports(self.session.ports)
867 qemu_cmd = [self.config.qemu] + args
868 self.session.qemu_proc = subprocess.Popen( # pylint: disable=consider-using-with
870 cwd=self.config.atf,
871 stdin=self.stdin,
872 stdout=self.stdout,
873 stderr=self.stderr)
875 if self.session.command_pipe:
876 self.session.command_pipe.open()
877 self.msg_channel_wait_for_connection()
879 if self.debug:
880 script_dir = self.config.script_dir
887 self.msg_channel_send_msg("Boot Secondary OS")
890 self.adb_up(self.session.ports[1])
892 self.state = target_state
894 self.session.has_error = True
897 def shutdown(self): argument
904 if self.state == RunnerState.OFF:
907 assert self.session is not None
910 for temp_file in self.session.temp_files:
913 if self.session.has_error:
914 self.error_dump_output()
916 unclean_exit = qemu_exit(self.session.command_pipe,
917 self.session.qemu_proc,
918 has_error=self.session.has_error,
919 debug_on_error=self.debug_on_error)
924 self.rpmb_down()
926 self.msg_channel_down()
928 if self.adb_transport:
930 self.adb_down(self.session.ports[1])
932 self.session = None
933 self.state = RunnerState.OFF
938 def reboot(self, target_state): argument
939 self.shutdown()
942 self.launch(target_state)
944 self.shutdown()
947 def run(self, boot_tests: Optional[List] = None, argument
971 assert self.state == RunnerState.OFF
972 self.config.check_config(self.interactive, boot_tests, android_tests)
983 timeout = timeout if timeout else self.default_timeout
985 self.launch(RunnerState.BOOTLOADER if boot_tests else
990 test_results.append(self.boottest_run(boot_tests, timeout))
994 test_result = self.androidtest_run([android_test], timeout)
1003 if self.interactive and self.session:
1005 self.session.qemu_proc.wait()
1006 self.shutdown()