From b30d702f223341bf87eb8a65adaa670d4bcc9b2a Mon Sep 17 00:00:00 2001
From: Sergei Trofimov <sergei.trofimov@arm.com>
Date: Mon, 11 May 2015 11:53:36 +0100
Subject: [PATCH] minor fixes to cpufreq APIs

- adding missing cpu id conversion to set_cpu_min_freq
- adding "exact" parameter to set_cpu_frequency; only produce an error
  when the specified frequency is not supported by the cpu if "axact"
  is set; (otherwise let cpufreq decide what the actual frequency will
  be).
---
 wlauto/utils/ssh.py | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/wlauto/utils/ssh.py b/wlauto/utils/ssh.py
index 985a17a3..2ca98186 100644
--- a/wlauto/utils/ssh.py
+++ b/wlauto/utils/ssh.py
@@ -134,7 +134,6 @@ class SshShell(object):
         self.conn.logout()
 
     def _execute_and_wait_for_prompt(self, command, timeout=None, as_root=False, strip_colors=True, log=True):
-        timeout = self.timeout if timeout is None else timeout
         self.conn.prompt(0.1)  # clear an existing prompt if there is one.
         if as_root:
             command = "sudo -- sh -c '{}'".format(escape_single_quotes(command))
@@ -144,14 +143,14 @@ class SshShell(object):
             index = self.conn.expect_exact([self.password_prompt, TIMEOUT], timeout=0.5)
             if index == 0:
                 self.conn.sendline(self.password)
-            timed_out = not self.conn.prompt(timeout)
+            timed_out = self._wait_for_prompt(timeout)
             output = re.sub(r'.*?{}'.format(re.escape(command)), '', self.conn.before, 1).strip()
         else:
             if log:
                 logger.debug(command)
             self.conn.sendline(command)
-            timed_out = not self.conn.prompt(timeout)
-            # the regex removes line breaks potentiall introduced when writing
+            timed_out = self._wait_for_prompt(timeout)
+            # the regex removes line breaks potential introduced when writing
             # command to shell.
             output = re.sub(r' \r([^\n])', r'\1', self.conn.before)
             command_index = output.find(command)
@@ -162,6 +161,14 @@ class SshShell(object):
             output = strip_bash_colors(output)
         return output
 
+    def _wait_for_prompt(self, timeout=None):
+        if timeout:
+            return not self.conn.prompt(timeout)
+        else:  # cannot timeout; wait forever
+            while not self.conn.prompt(self.timeout):
+                pass
+            return False
+
     def _scp(self, source, dest, timeout=30):
         # NOTE: the version of scp in Ubuntu 12.04 occasionally (and bizarrely)
         # fails to connect to a device if port is explicitly specified using -P