test suite reviews and discussions
 help / color / mirror / Atom feed
From: Lijuan Tu <lijuan.tu@intel.com>
To: reshma.pattan@intel.com
Cc: dts@dpdk.org, Lijuan Tu <lijuan.tu@intel.com>
Subject: [dts] [PATCH] framework: fix session output
Date: Tue,  3 Aug 2021 05:52:04 +0800	[thread overview]
Message-ID: <1627941124-172249-1-git-send-email-lijuan.tu@intel.com> (raw)

* it should flush buffer before getting output
* fix strip space in all session output
* fix some output don't have \r\n before [PEXPECT]

Signed-off-by: Lijuan Tu <lijuan.tu@intel.com>
Reported-by: Reshma Pattan <reshma.pattan@intel.com>
---
 framework/crb.py         |  7 ++++---
 framework/ssh_pexpect.py | 15 +++++++--------
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/framework/crb.py b/framework/crb.py
index 3964e21..e029e71 100644
--- a/framework/crb.py
+++ b/framework/crb.py
@@ -94,10 +94,11 @@ class Crb(object):
 
         # sometimes there will be no alt_session like VM dut
         if alt_session and self.alt_session:
-            return self.alt_session.session.send_expect(cmds, expected,
+            out = self.alt_session.session.send_expect(cmds, expected,
                                                         timeout, verify)
-
-        return self.session.send_expect(cmds, expected, timeout, verify)
+        else:
+            out = self.session.send_expect(cmds, expected, timeout, verify)
+        return out.strip()
 
     def create_session(self, name=""):
         """
diff --git a/framework/ssh_pexpect.py b/framework/ssh_pexpect.py
index fbc7dd4..6fcaa20 100644
--- a/framework/ssh_pexpect.py
+++ b/framework/ssh_pexpect.py
@@ -78,6 +78,8 @@ class SSHPexpect:
         self.clean_session()
         self.session.PROMPT = expected
         self.__sendline(command)
+        # flush buffer before prompt, else buffer may impact output
+        self.__flush()
         self.__prompt(command, timeout)
         aware_keyintr()
 
@@ -127,13 +129,13 @@ class SSHPexpect:
         ignore_keyintr()
         self.session.PROMPT = self.magic_prompt
         try:
+            self.__flush()
             self.session.prompt(timeout)
         except Exception as e:
-            pass
+            raise(e)
 
         aware_keyintr()
         before = self.get_output_all()
-        self.__flush()
 
         return before
 
@@ -159,15 +161,12 @@ class SSHPexpect:
     def get_output_before(self):
         if not self.isalive():
             raise SSHSessionDeadException(self.host)
-        before = self.session.before.rsplit('\r\n', 1)
-        if before[0] == "[PEXPECT]":
-            before[0] = ""
 
-        return before[0]
+        before = self.session.before.strip('[PEXPECT]')
+        return before
 
     def get_output_all(self):
-        output = self.session.before
-        output.replace("[PEXPECT]", "")
+        output = self.session.before.strip('[PEXPECT]')
         return output
 
     def close(self, force=False):
-- 
1.8.3.1


             reply	other threads:[~2021-08-02 14:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-02 21:52 Lijuan Tu [this message]
2022-06-10  9:22 ` Pattan, Reshma

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1627941124-172249-1-git-send-email-lijuan.tu@intel.com \
    --to=lijuan.tu@intel.com \
    --cc=dts@dpdk.org \
    --cc=reshma.pattan@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).