[tbot] Problem with context exit (and serial transmission)

Harald Seiler hws at denx.de
Sun Feb 3 21:09:23 UTC 2019

Hi Lukasz,

On Sat, 2019-02-02 at 23:57 +0100, Lukasz Majewski wrote:
> def kernel_active_update(
>     lab: typing.Optional[linux.LabHost] = None,
> ) -> None:
>      linux_falcon_boot(falcon_status="disable")
> # --------- Problem / why do I need this code ?
>      with lab or tbot.acquire_lab() as lh:
>          lh.exec0("pkill", "-9", "picocom")
>          time.sleep(3)
> # ---------
>      uboot_kernel_write(reset=True, serverip="")

Unrelated to your issue I have noticed something:  While your code works,
you have a hidden performance cost:  Each testcase will create its own
connection to the lab-host.  In case of a local lab this will not be
noticeable but with ssh connections it will be a few seconds each time.

You can easily fix this though!  The testcases you listed in the end already
have a `lab` parameter where you can supply an existing lab-host connection:

	def kernel_active_update(
	    lab: typing.Optional[linux.LabHost] = None,
	) -> None:
	    with lab or tbot.acquire_lab() as lh:
	        linux_falcon_boot(lab=lh, falcon_status="disable")

	        uboot_kernel_write(lab=lh, reset=True, serverip="...")

One more note:

> if reset:
>     ub.exec0("reset")

Executing `reset` with `exec0` is not really portable.  If your board has
autoboot enabled, tbot would hang indefinitely waiting for the U-Boot prompt
to reappear.  If you absolutely have to execute reset, I'd do so manually
and then wait for the U-Boot header string to reappear before exiting the
board context (not tested, sorry):

	if reset:
	        # U-Boot Header
	        # Because the header can appear anywhere in the stream
	# Actually power off the board now by exiting its context

> The linux_falcon_boot() and uboot_kernel_write() works without problems
> when executed as standalone tests (and I only expect them to be run one
> by one).
> The question is - why do I need to kill manually the picocom process
> and put some sleep between invocation of those two tests?

It looks like picocom doesn't like the way tbot ends a session.  I found
a workaround:  Add the following function in your board-config (where the
call to picocom is defined):

	def cleanup(self) -> None:
	    # Send ^A^Q to quit picocom
	    if self.channel is not None:

Docs for cleanup can be found here:


> From the doc I thought that when we exit context (from one test with
> disabling power) and start the context again (and power up in another
> test), the "channel" would be put into default state (I mean the picocom
> would be killed and re-spawned accordingly).

Yes, you got that correctly.  Apparently picocom does not exit cleanly by
default ... I'll see if I can somehow fix this without the solution mentioned


DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-62  Fax: +49-8142-66989-80   Email: hws at denx.de 

More information about the tbot mailing list