Skip to content
This repository was archived by the owner on Dec 27, 2023. It is now read-only.

Commit dba2d3f

Browse files
committed
Enable auto login for qemu SUT
This patch add the possibility to handle qemu images with auto login and to handle the first PS1 shown after boot. Signed-off-by: Andrea Cervesato <[email protected]>
1 parent 57fa87b commit dba2d3f

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

ltp/qemu_sut.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ def __init__(self) -> None:
3535
self._virtfs = None
3636
self._serial_type = None
3737
self._opts = None
38+
self._user = None
39+
self._prompt = None
3840

3941
@property
4042
def name(self) -> str:
@@ -45,6 +47,7 @@ def config_help(self) -> dict:
4547
return {
4648
"image": "qcow2 image location",
4749
"image_overlay": "image_overlay: image copy location",
50+
"user": "username used to login. If empty, it won't be used (default: 'root')",
4851
"password": "root password (default: root)",
4952
"system": "system architecture (default: x86_64)",
5053
"ram": "RAM of the VM (default: 2G)",
@@ -53,6 +56,7 @@ def config_help(self) -> dict:
5356
"virtfs": "directory to mount inside VM",
5457
"ro_image": "path of the image that will exposed as read only",
5558
"options": "user defined options",
59+
"first_prompt": "first shell prompt string (default: '#')",
5660
}
5761

5862
def _get_transport(self) -> str:
@@ -131,20 +135,21 @@ def _get_command(self) -> str:
131135
return cmd
132136

133137
def _login(self, timeout: float, iobuffer: IOBuffer) -> None:
134-
self._wait_for("login:", timeout, iobuffer)
135-
self._write_stdin("root\n")
138+
if self._user:
139+
self._wait_for("login:", timeout, iobuffer)
140+
self._write_stdin(f"{self._user}\n")
136141

137142
if self._password:
138143
self._wait_for("Password:", 5, iobuffer)
139144
self._write_stdin(f"{self._password}\n")
140145

141146
time.sleep(0.2)
142147

143-
self._wait_for("#", 5, iobuffer)
148+
self._wait_for(self._prompt, timeout, iobuffer)
144149
time.sleep(0.2)
145150

146151
self._write_stdin("stty -echo; stty cols 1024\n")
147-
self._wait_for("#", 5, None)
152+
self._wait_for(self._prompt, 5, None)
148153

149154
_, retcode, _ = self._exec("export PS1=''", 5, None)
150155
if retcode != 0:
@@ -179,12 +184,14 @@ def setup(self, **kwargs: dict) -> None:
179184
self._image = kwargs.get("image", None)
180185
self._image_overlay = kwargs.get("image_overlay", None)
181186
self._ro_image = kwargs.get("ro_image", None)
187+
self._user = kwargs.get("user", "root")
182188
self._password = kwargs.get("password", "root")
183189
self._ram = kwargs.get("ram", "2G")
184190
self._smp = kwargs.get("smp", "2")
185191
self._virtfs = kwargs.get("virtfs", None)
186192
self._serial_type = kwargs.get("serial", "isa")
187193
self._opts = kwargs.get("options", None)
194+
self._prompt = kwargs.get("first_prompt", "#")
188195

189196
system = kwargs.get("system", "x86_64")
190197
self._qemu_cmd = f"qemu-system-{system}"
@@ -216,3 +223,6 @@ def setup(self, **kwargs: dict) -> None:
216223

217224
if self._serial_type not in ["isa", "virtio"]:
218225
raise SUTError("Serial protocol must be isa or virtio")
226+
227+
if not self._prompt:
228+
raise SUTError("first_prompt is not defined")

0 commit comments

Comments
 (0)