DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] autotest: fix pexpect in python3
@ 2020-05-07 12:38 Christian Ehrhardt
  2020-05-07 13:17 ` Luca Boccassi
  0 siblings, 1 reply; 2+ messages in thread
From: Christian Ehrhardt @ 2020-05-07 12:38 UTC (permalink / raw)
  To: dev; +Cc: Luca Boccassi, Christian Ehrhardt

In python3 pexpect wants by default a BytesIO stream as log buffer.
Otherwise it will (silently masked since we just return false)
  File "/usr/share/dpdk/test/autotest_runner.py", line 22, in wait_prompt
    child.sendline()
  File "/usr/lib/python3/dist-packages/pexpect/pty_spawn.py", line 555, in sendline
    return self.send(s + self.linesep)
  File "/usr/lib/python3/dist-packages/pexpect/pty_spawn.py", line 543, in send
    self._log(s, 'send')
  File "/usr/lib/python3/dist-packages/pexpect/spawnbase.py", line 126, in _log
    self.logfile.write(s)

We have plenty of other code writing and using this buffer.
So instead of changing the type and modifying many more places we tell the
spawn [1] method to encode things right away - then the rest behaves as it
did with python2.

[1]: https://pexpect.readthedocs.io/en/stable/api/pexpect.html#spawn-class

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
---
 app/test/autotest_runner.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/app/test/autotest_runner.py b/app/test/autotest_runner.py
index dfa5f2b2dd..92d4e6e41a 100644
--- a/app/test/autotest_runner.py
+++ b/app/test/autotest_runner.py
@@ -84,7 +84,7 @@ def pool_init(queue, result_queue):
         print("\n%s %s\n" % ("=" * 20, prefix), file=startuplog)
         print("\ncmdline=%s" % cmdline, file=startuplog)
 
-        pool_child = pexpect.spawn(cmdline, logfile=startuplog)
+        pool_child = pexpect.spawn(cmdline, logfile=startuplog, encoding='utf-8')
 
         # wait for target to boot
         if not wait_prompt(pool_child):
-- 
2.26.0


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

end of thread, other threads:[~2020-05-07 13:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-07 12:38 [dpdk-dev] [PATCH] autotest: fix pexpect in python3 Christian Ehrhardt
2020-05-07 13:17 ` Luca Boccassi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).