[tbot] Problem with Linux boot to prompt

Harald Seiler hws at denx.de
Thu Jan 24 08:38:20 UTC 2019


Hi Lukasz,

On Thu, 2019-01-24 at 00:17 +0100, Lukasz Majewski wrote:
> Dear tbot users,
> 
> I'm trying now to boot into Linux prompt (the LinuxStandaloneMachine),
> and then execute 'uname -a'
> 
> The idea is to use boot_to_shell, log in, and execute 'uname -a'
> https://rahix.de/tbot/module-board.html#tbot.machine.board.LinuxStandaloneMachine.boot_to_shell
> 
> Test case:
> 
> @tbot.testcase
> def linux_uname(
>     lab: typing.Optional[linux.LabHost] = None,
>     board_linux: typing.Optional[board.LinuxStandaloneMachine] = None,
> ) -> None:
>     with contextlib.ExitStack() as cx:
>         if board_linux is None:
>             lh  = cx.enter_context(lab or tbot.acquire_lab())
>             b   = cx.enter_context(tbot.acquire_board(lh))
>             lnx = cx.enter_context(tbot.acquire_linux(b))
>         else:
>             lnx = board_linux
> 
>         lnx.boot_to_shell('root at display5:~# ')
>         lnx.exec0("uname", "-a")
> 

Hmm, you are not supposed to call `boot_to_shell` yourself.
This is done internally when you enter the machine context:

	lnx = cx.enter_context(tbot.acquire_linux(b))

Which is equivalent to this:

	with tbot.acquire_linux(b) as lnx:
	    ...

If you are curious, the call happens here:

	https://github.com/Rahix/tbot/blob/master/tbot/machine/board/linux.py#L288

I guess, I should mention this in the docs ...

> (For simplicity I'm using the Linux Standalone Machine).
> 
> The output of -vvv:
> 
> │   │    <> 
> │   │    <> 
> │   ├─> 'root\n'
> │   ├─< 'root\r\n'
> │   │    <> display5 login: root
> │   ├─< '\x1b7\x1b[r\x1b[999;999H\x1b[6n'
> │   ├─< 'root at display5:~# '
> 
> The 'root at display5:~# ' is sent to the "channel", but there is no
> reaction on it (I'm using picocom -b 115200 /dev/ttyUSB0 to handle
> serial console).
> Do I need to use regexp here ?
> 

As stated above, you do not need to do anything.  tbot waits for the
login prompt, send username and optionally a password and then has a
more or less sophisticated way of determining if the shell popped up.
As soon as it has, it will force the shell into a known state and
give control back to your testcase to run commands.  If your config
is correct, simply removing the `boot_to_shell` line should do the trick.

> 
> A side question(s):
> -------------------
> 
> 1. Is it possible to return value from test case to make it fail?
> 
> For example - I do lnx.exec0() then do some work on text received and
> on that basis I would like to make the test pass or fail. Similar use
> case is with parsing 'dmesg' output.
> 

A testcase fails if it raises an Exception.  If you want to manually
create a failure:

	if "bad output" in lnx.exec0("cat", "/var/log/syslog"):
	    raise Exception("Found bad output!")

> 
> 2. Do we have any timeout of booting u-boot/kernel? 
> 
> A very common test case is to check if the board still boots after
> update of SPL/u-boot/linux. I can hack some in-test case timeout (and
> pass with -p the value), but maybe there is a better way?

Sadly not yet.  Normal command execution (like exec(), exec0()) can take
a timeout parameter, but boot does not have this functionality yet.

If you need this right now, you can use this hack:

	import signal

	def handler(_signum, _frame):
	    """ Signal handler for timeout """
	    raise TimeoutError()

	# in your testcase
	signal.signal(signal.SIGALRM, handler)

	# timeout 60 seconds
	signal.alarm(60)
	try:
	    # Do your things here
	    ...
	except TimeoutError:
		tbot.log.message("Aborting run because it took too long.")

> (If anybody has such functionality, please share :-) )
> 
> Thanks in advance for your help.
> 
> Best regards,
> 
> Lukasz Majewski
> 
-- 
Harald

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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://lists.denx.de/pipermail/tbot/attachments/20190124/4e1190d4/attachment.sig>


More information about the tbot mailing list