direct-io.hg

changeset 10453:410c81420109

[XM-TEST] Improve detection of a guest having booted to prompt.

Lots of xm-test tests are failing with console timeouts on some machines
at the moment. I reproduced the problem and found it was due to some
probing activity in the boot process of the -xen kernel. The behaviour
of the current xm-test code is to assume that the boot process has
finished after performing three one-second waits for input---when the
probing activity introduces more than three one-second delays the test
suite breaks.

This patch changes the test suite to wait for the command prompt
before attempting to submit a command. The timeout is increased from 3
seconds to 3 minutes but the wait exits early when the prompt is found
so the test suite doesn't take any longer to run.

Signed-off-by: Harry Butterworth <butterwo@uk.ibm.com>
author kaf24@firebug.cl.cam.ac.uk
date Mon Jun 19 17:43:04 2006 +0100 (2006-06-19)
parents 06afd218b3b7
children 0fe87421cc80
files tools/xm-test/lib/XmTestLib/Console.py
line diff
     1.1 --- a/tools/xm-test/lib/XmTestLib/Console.py	Mon Jun 19 17:26:54 2006 +0100
     1.2 +++ b/tools/xm-test/lib/XmTestLib/Console.py	Mon Jun 19 17:43:04 2006 +0100
     1.3 @@ -82,9 +82,6 @@ class XmConsole:
     1.4  
     1.5          tty.setraw(self.consoleFd, termios.TCSANOW)
     1.6  
     1.7 -        self.__chewall(self.consoleFd)
     1.8 -
     1.9 -
    1.10      def __addToHistory(self, line):
    1.11          self.historyBuffer.append(line)
    1.12          self.historyLines += 1
    1.13 @@ -120,34 +117,47 @@ class XmConsole:
    1.14          output"""
    1.15          self.PROMPT = prompt
    1.16  
    1.17 -
    1.18 -    def __chewall(self, fd):
    1.19 +    def __getprompt(self, fd):
    1.20          timeout = 0
    1.21 -        bytes   = 0
    1.22 -        
    1.23 -        while timeout < 3:
    1.24 -            i, o, e = select.select([fd], [], [], 1)
    1.25 -            if fd in i:
    1.26 -                try:
    1.27 -                    foo = os.read(fd, 1)
    1.28 -                    if self.debugMe:
    1.29 -                        sys.stdout.write(foo)
    1.30 -                    bytes += 1
    1.31 -                except Exception, exn:
    1.32 -                    raise ConsoleError(str(exn))
    1.33 -
    1.34 +        bytes = 0
    1.35 +        while timeout < 180:
    1.36 +            # eat anything while total bytes less than limit else raise RUNAWAY
    1.37 +            while (not self.limit) or (bytes < self.limit):
    1.38 +                i, o, e = select.select([fd], [], [], 1)
    1.39 +                if fd in i:
    1.40 +                    try:
    1.41 +                        foo = os.read(fd, 1)
    1.42 +                        if self.debugMe:
    1.43 +                            sys.stdout.write(foo)
    1.44 +                        bytes += 1
    1.45 +                    except Exception, exn:
    1.46 +                        raise ConsoleError(str(exn))
    1.47 +                else:
    1.48 +                    break
    1.49              else:
    1.50 -                timeout += 1
    1.51 -
    1.52 -            if self.limit and bytes >= self.limit:
    1.53                  raise ConsoleError("Console run-away (exceeded %i bytes)"
    1.54                                     % self.limit, RUNAWAY)
    1.55 -
    1.56 -        if self.debugMe:
    1.57 -            print "Ignored %i bytes of miscellaneous console output" % bytes
    1.58 -        
    1.59 -        return bytes
    1.60 -
    1.61 +            # press enter
    1.62 +            os.write(self.consoleFd, "\n")
    1.63 +            # look for prompt
    1.64 +            for prompt_char in "\r\n" + self.PROMPT:
    1.65 +                i, o, e = select.select([fd], [], [], 1)
    1.66 +                if fd in i:
    1.67 +                    try:
    1.68 +                        foo = os.read(fd, 1)
    1.69 +                        if self.debugMe:
    1.70 +                            sys.stdout.write(foo)
    1.71 +                        if foo != prompt_char:
    1.72 +                            break
    1.73 +                    except Exception, exn:
    1.74 +                        raise ConsoleError(str(exn))
    1.75 +                else:
    1.76 +                    timeout += 1
    1.77 +                    break
    1.78 +            else:
    1.79 +                break
    1.80 +        else:
    1.81 +            raise ConsoleError("Timed out waiting for console prompt")
    1.82  
    1.83      def __runCmd(self, command, saveHistory=True):
    1.84          output = ""
    1.85 @@ -155,7 +165,7 @@ class XmConsole:
    1.86          lines  = 0
    1.87          bytes  = 0
    1.88  
    1.89 -        self.__chewall(self.consoleFd)
    1.90 +        self.__getprompt(self.consoleFd)
    1.91  
    1.92          if verbose:
    1.93              print "[%s] Sending `%s'" % (self.domain, command)
    1.94 @@ -176,7 +186,7 @@ class XmConsole:
    1.95                          "Failed to read from console (fd=%i): %s" %
    1.96                          (self.consoleFd, exn))
    1.97              else:
    1.98 -                raise ConsoleError("Timed out waiting for console")
    1.99 +                raise ConsoleError("Timed out waiting for console command")
   1.100  
   1.101              if self.limit and bytes >= self.limit:
   1.102                  raise ConsoleError("Console run-away (exceeded %i bytes)"