| 44 | |
| 45 | |
| 46 | class QEMURunner: |
| 47 | def __init__(self) -> None: |
| 48 | |
| 49 | # Properties that can be adjusted by the user or class |
| 50 | self.cmdline: list[str] = [] |
| 51 | self.efi: bool = False |
| 52 | self.gdb: bool = False |
| 53 | self.gdb_bin: str = '' |
| 54 | self.gh_json_file: Path = utils.UNINIT_PATH |
| 55 | self.initrd: Path = utils.UNINIT_PATH |
| 56 | self.interactive: bool = False |
| 57 | self.kernel: Path = utils.UNINIT_PATH |
| 58 | self.kernel_dir: Path = utils.UNINIT_PATH |
| 59 | self.memory: str = '1G' |
| 60 | self.modules: Path = utils.UNINIT_PATH |
| 61 | self.supports_efi: bool = False |
| 62 | # It may be tempting to use self.use_kvm during initialization of |
| 63 | # subclasses to set certain properties but the user can explicitly opt |
| 64 | # out of KVM after instantiation, so any decisions based on it should |
| 65 | # be confined to run(). |
| 66 | self.use_kvm: bool = False |
| 67 | self.smp: int = 0 |
| 68 | self.timeout: str = '' |
| 69 | |
| 70 | self._default_kernel_path: Path = utils.UNINIT_PATH |
| 71 | self._dtbs: list[str] = [] |
| 72 | self._efi_img: Path = utils.UNINIT_PATH |
| 73 | self._efi_vars: Path = utils.UNINIT_PATH |
| 74 | self._initrd_arch: str = '' |
| 75 | self._kvm_cpu: list[str] = ['host'] |
| 76 | self._qemu_arch: str = '' |
| 77 | self._qemu_args: list[Path | str] = [ |
| 78 | '-display', 'none', |
| 79 | '-nodefaults', |
| 80 | ] # fmt: off |
| 81 | self._qemu_path: Path = utils.UNINIT_PATH |
| 82 | |
| 83 | def _find_dtb(self) -> Path: |
| 84 | if not self._dtbs: |
| 85 | msg = 'No dtbs set?' |
| 86 | raise RuntimeError(msg) |
| 87 | if self.kernel == utils.UNINIT_PATH: |
| 88 | msg = 'Cannot locate dtb without kernel' |
| 89 | raise RuntimeError(msg) |
| 90 | |
| 91 | # If we are in a boot folder, look for them in the dts folder in it. |
| 92 | # Otherwise, assume there is a 'dtbs' folder in the same folder as the |
| 93 | # kernel image (tuxmake) |
| 94 | dtb_dir = 'dts' if self.kernel.parent.name == 'boot' else 'dtbs' |
| 95 | for dtb_loc in self._dtbs: |
| 96 | if (dtb := Path(self.kernel.parent, dtb_dir, dtb_loc)).exists(): |
| 97 | return dtb |
| 98 | |
| 99 | msg = f"dtb is required for booting but it could not be found at expected locations ('{self._dtbs}')" |
| 100 | raise FileNotFoundError(msg) |
| 101 | |
| 102 | def _get_default_smp_value(self) -> int: |
| 103 | if self.kernel_dir == utils.UNINIT_PATH: |
nothing calls this directly
no outgoing calls
no test coverage detected