All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] Issue with capture of emulator output in runtime test infra
@ 2021-09-19 12:10 Thomas Petazzoni
  2021-09-19 16:59 ` Edgar Bonet
  2021-10-04 11:52 ` Peter Korsgaard
  0 siblings, 2 replies; 10+ messages in thread
From: Thomas Petazzoni @ 2021-09-19 12:10 UTC (permalink / raw)
  To: buildroot; +Cc: Romain Naour

Hello,

I've been working on some additional test cases in support/testing/,
and stumbled across an issue in the infrastructure, which I thought I
should report before forgetting about it.

The run() method of the Emulator() class captures the output of the
command executed inside the emulated system:

    def run(self, cmd, timeout=-1):
        self.qemu.sendline(cmd)
        if timeout != -1:
            timeout *= self.timeout_multiplier
        self.qemu.expect("# ", timeout=timeout)
        # Remove double carriage return from qemu stdout so str.splitlines()
        # works as expected.
        output = self.qemu.before.replace("\r\r", "\r").splitlines()[1:]

        self.qemu.sendline("echo $?")
        self.qemu.expect("# ")
        exit_code = self.qemu.before.splitlines()[2]
        exit_code = int(exit_code)

As can be seen from the [1:], we remove the first line, because it
contains the command that was executed.

The problem is that when the command is long, for some reason due to
how the emulation works, it gets wrapped on two lines, like this:

# curl -s -o /dev/null -w "%{http_code}\n" -X POST -H "Content-Type: application
/json" -d '{"email": "test", "name": "test"}' http://127.0.0.1:5000
200

(The wrapping above does not come from my e-mail client, it is really
wrapped after "application" and before "/json" in the output).

Due to this, our Emulator.run() logic strips out the "# curl ..." line,
but the output array looks like this:

output[0] = /json" -d '{"email": "test", "name": "test"}' http://127.0.0.1:5000
output[1] = 200

While we would have expected output[] to contain just a single element,
"200", which is really the only output of the command. For now, I've
worked around this by looking at output[-1] in my test case, which is
good enough because I only care about one line of output.

However, I'm not really sure how to fix this in the Emulator.run() core
itself. Perhaps we should not be using the -serial stdio (which
requires interacting on stdin/stdout), but instead use a separate
telnet port (but then there's always the issue of which port to use) ?

Best regards,

Thomas
-- 
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com
_______________________________________________
buildroot mailing list
buildroot@lists.buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-10-05 16:04 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-19 12:10 [Buildroot] Issue with capture of emulator output in runtime test infra Thomas Petazzoni
2021-09-19 16:59 ` Edgar Bonet
2021-09-20  8:55   ` Edgar Bonet
2021-10-04 11:55     ` Peter Korsgaard
2021-10-04 20:46       ` Edgar Bonet
2021-10-05  5:33         ` Yann E. MORIN
2021-10-05  8:54           ` Edgar Bonet
2021-10-05 16:04             ` Yann E. MORIN
2021-10-04 11:52 ` Peter Korsgaard
2021-10-04 12:14   ` Thomas Petazzoni

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.