Skip to content

Commit 3a9676e

Browse files
committed
shelldriver: make run wrapper injecting more reliable
Current fire and forget approach doesn't work reliably in all corner cases for various reasons, like for example serial console bitflip or lost byte issues due to RX fifo overruns. Those issues mostly happen frequently during early boot process, where there is a lot of output going on. So let's make it more reliable by actually checking, if the run wrapper was injected into the target system correctly. Signed-off-by: Petr Štetiar <[email protected]>
1 parent a7f7bda commit 3a9676e

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

doc/usage.rst

+1
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ environment config:
543543
Mock(return_value=(['OK'], [], 0))
544544
).start()
545545
patch.object(ShellDriver, "_silence_kernel", Mock()).start()
546+
patch.object(ShellDriver, "_inject_run", Mock()).start()
546547

547548
.. testcode:: pytest-example
548549
:hide:

labgrid/driver/shelldriver.py

+18-5
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,24 @@ def _check_prompt(self):
239239
self._status = 0
240240
raise
241241

242-
def _inject_run(self):
243-
self.console.sendline(
244-
'''run() { echo -n "$MARKER"; sh -c "$@"; echo "$MARKER $?"; }'''
245-
)
246-
self.console.expect(self.prompt)
242+
def _inject_run(self, inject_timeout=10.0):
243+
"""Tries to inject run() command wrapper into shell on the console."""
244+
timeout = Timeout(inject_timeout)
245+
246+
while True:
247+
self.console.sendline(
248+
'''run() { echo -n "$MARKER"; sh -c "$@"; echo "$MARKER $?"; }'''
249+
)
250+
self.console.expect(self.prompt)
251+
try:
252+
data = self._raw_run("type run")
253+
if data[2] and "function" in data[2]:
254+
return
255+
except TIMEOUT:
256+
pass
257+
258+
if timeout.expired:
259+
raise TIMEOUT(f"Timeout of {inject_timeout} seconds exceeded during waiting for run injection") # pylint: disable=line-too-long
247260

248261
@step(args=['keyfile_path'])
249262
def _put_ssh_key(self, keyfile_path):

0 commit comments

Comments
 (0)