diff mbox series

[1/7] tests: remotehost: extend proc api

Message ID 20240309194228.4186699-1-janusz.dziedzic@gmail.com
State Accepted
Headers show
Series [1/7] tests: remotehost: extend proc api | expand

Commit Message

Janusz Dziedzic March 9, 2024, 7:42 p.m. UTC
Signed-off-by: Janusz Dziedzic <janusz.dziedzic@gmail.com>
---
 tests/hwsim/remotehost.py | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

Comments

Jouni Malinen March 23, 2024, 8:25 p.m. UTC | #1
I applied patch 1 and 7. There is an open question on patch 2 and it was
not clear which of the patches 3..6 might depend on patch 2, so I
dropped all those from my queue now.
diff mbox series

Patch

diff --git a/tests/hwsim/remotehost.py b/tests/hwsim/remotehost.py
index 9d7c657a1..d0efa210b 100644
--- a/tests/hwsim/remotehost.py
+++ b/tests/hwsim/remotehost.py
@@ -161,8 +161,8 @@  class Host():
         if t.is_alive():
             t.join(wait)
 
-    def pending(self, s, timeout=0):
-        [r, w, e] = select.select([s], [], [], timeout)
+    def proc_pending(self, proc, timeout=0):
+        [r, w, e] = select.select([proc.stdout], [], [], timeout)
         if r:
             return True
         return False
@@ -194,7 +194,7 @@  class Host():
         start = os.times()[4]
         try:
             while True:
-                while self.pending(proc.stdout):
+                while self.proc_pending(proc):
                     line = proc.stdout.readline()
                     if not line:
                         return None
@@ -207,13 +207,26 @@  class Host():
                 remaining = start + timeout - now
                 if remaining <= 0:
                     break
-                if not self.pending(proc.stdout, timeout=remaining):
+                if not self.proc_pending(proc, timeout=remaining):
                     break
         except:
             logger.debug(traceback.format_exc())
             pass
         return None
 
+    def proc_write(self, proc, cmd):
+        return proc.stdout.write(cmd)
+
+    def proc_read(self, proc, timeout=0):
+        if not self.proc_pending(proc):
+            return None
+        res = proc.stdout.read(4094).decode()
+        try:
+            r = str(res)
+        except UnicodeDecodeError as e:
+            r = res
+        return r
+
     def proc_stop(self, proc):
         if not proc:
             return