[Buildroot] Issue with capture of emulator output in runtime test infra

Edgar Bonet bonet at grenoble.cnrs.fr
Mon Sep 20 08:55:30 UTC 2021


Hello!

Yesterday I wrote:
> Is it just a coincidence that the line got wrapped at exactly 80
> columns [...]

I think I found where the spurious line break comes from. Busybox's
lineedit library has a trick to work around the VT100's automargin
feature.[1] When a character is printed on the last column of the
terminal, lineedit adds a carriage return in order to force the cursor
to the next line:

		/* we go to the next line */
#if HACK_FOR_WRONG_WIDTH
		/* This works better if our idea of term width is wrong
		 * and it is actually wider (often happens on serial lines).
		 * Printing CR,LF *forces* cursor to next line.
		 * OTOH if terminal width is correct AND terminal does NOT
		 * have automargin (IOW: it is moving cursor to next line
		 * by itself (which is wrong for VT-10x terminals)),
		 * this will break things: there will be one extra empty line */
		puts("\r"); /* + implicit '\n' */

There doesn't seem to be a way to override this behavior, but we could
make busybox believe our terminal is ultra wide. Busybox gets its idea
of the terminal width from the kernel, via the TIOCGWINSZ ioctl[2]. The
kernel within the emulator may not be able to know the host's terminal
width, in which case setting the dimensions attribute in pexpect.spawn()
may not have any effect. We can, however, override the terminal width
using the "COLUMNS" environment variable[3], but beware that values
larger than 29999 are ignored.

Regards,

Edgar.

[1] https://git.busybox.net/busybox/tree/libbb/lineedit.c?h=1_33_1#n402
[2] https://git.busybox.net/busybox/tree/libbb/xfuncs.c?h=1_33_1#n263
[3] https://git.busybox.net/busybox/tree/libbb/xfuncs.c?h=1_33_1#n235


More information about the buildroot mailing list