On 04/03/2012 08:08 AM, Jiří Župka wrote:
> Signed-off-by: Jiří Župka<jzu...@redhat.com>
> ---
>   client/tests/kvm/tests/ksm_overcommit.py |    2 +-
>   client/tests/kvm/tests/virtio_console.py |    2 +-
>   client/virt/aexpect.py                   |   28 ++++++++++++++++++----------
>   client/virt/deps/test_cpu_flags/stress.c |    2 +-
>   4 files changed, 21 insertions(+), 13 deletions(-)
>
> diff --git a/client/tests/kvm/tests/ksm_overcommit.py 
> b/client/tests/kvm/tests/ksm_overcommit.py
> index 3614aea..8511818 100644
> --- a/client/tests/kvm/tests/ksm_overcommit.py
> +++ b/client/tests/kvm/tests/ksm_overcommit.py
> @@ -200,7 +200,7 @@ def run_ksm_overcommit(test, params, env):
>                                         free_mem, (i - 1))
>                           last_vm = i
>                           break
> -                    out = session.read_nonblocking(0.1)
> +                    out = session.read_nonblocking(0.1, 1)
>                       time.sleep(2)
>               except OSError:
>                   logging.debug("Only %s host free memory, killing %d guests",
> diff --git a/client/tests/kvm/tests/virtio_console.py 
> b/client/tests/kvm/tests/virtio_console.py
> index a52b9e1..c3395e8 100644
> --- a/client/tests/kvm/tests/virtio_console.py
> +++ b/client/tests/kvm/tests/virtio_console.py
> @@ -598,7 +598,7 @@ def run_virtio_console(test, params, env):
>
>           @return: Kernel crash log or None.
>           """
> -        data = vm_port.read_nonblocking()
> +        data = vm_port.read_nonblocking(0.1, timeout)
>           match = re.search("BUG:", data, re.MULTILINE)
>           if match is None:
>               return None
> diff --git a/client/virt/aexpect.py b/client/virt/aexpect.py
> index d75bbe1..25ec62d 100755
> --- a/client/virt/aexpect.py
> +++ b/client/virt/aexpect.py
> @@ -901,20 +901,25 @@ class Expect(Tail):
>           return Tail.__getinitargs__(self)
>
>
> -    def read_nonblocking(self, timeout=None):
> +    def read_nonblocking(self, internal_timeout=None, timeout=None):
>           """
>           Read from child until there is nothing to read for timeout seconds.
>
> -        @param timeout: Time (seconds) to wait before we give up reading from
> -                the child process, or None to use the default value.
> +        @param internal_timeout: Time (seconds) to wait before we give up
> +                                 reading from the child process, or None to
> +                                 use the default value.
> +        @param timeout: Timeout for reading child process output.
>           """
> -        if timeout is None:
> -            timeout = 0.1
> +        if internal_timeout is None:
> +            internal_timeout = 0.1
> +        end_time = None
> +        if timeout:
> +            end_time = time.time() + timeout
>           fd = self._get_fd("expect")
>           data = ""
>           while True:
>               try:
> -                r, w, x = select.select([fd], [], [], timeout)
> +                r, w, x = select.select([fd], [], [], internal_timeout)
>               except Exception:
>                   return data
>               if fd in r:
> @@ -924,6 +929,8 @@ class Expect(Tail):
>                   data += new_data
>               else:
>                   return data
> +            if end_time and time.time()>  end_time:
> +                return data
>
>
>       def match_patterns(self, str, patterns):
> @@ -980,7 +987,8 @@ class Expect(Tail):
>               if not r:
>                   raise ExpectTimeoutError(patterns, o)
>               # Read data from child
> -            data = self.read_nonblocking(internal_timeout)
> +            data = self.read_nonblocking(internal_timeout,
> +                                         end_time - time.time())
>               if not data:
>                   break
>               # Print it if necessary
> @@ -1157,14 +1165,14 @@ class ShellSession(Expect):
>           """
>           # Read all output that's waiting to be read, to make sure the output
>           # we read next is in response to the newline sent
> -        self.read_nonblocking(timeout=0)
> +        self.read_nonblocking(internal_timeout=0, timeout=timeout)
>           # Send a newline
>           self.sendline()
>           # Wait up to timeout seconds for some output from the child
>           end_time = time.time() + timeout
>           while time.time()<  end_time:
>               time.sleep(0.5)
> -            if self.read_nonblocking(timeout=0).strip():
> +            if self.read_nonblocking(0, end_time-time.time()).strip():
>                   return True
>           # No output -- report unresponsive
>           return False
> @@ -1224,7 +1232,7 @@ class ShellSession(Expect):
>               return "".join(str.rstrip().splitlines(True)[:-1])
>
>           logging.debug("Sending command: %s" % cmd)
> -        self.read_nonblocking(timeout=0)
> +        self.read_nonblocking(0, timeout)
>           self.sendline(cmd)
>           try:
>               o = self.read_up_to_prompt(timeout, internal_timeout, 
> print_func)
> diff --git a/client/virt/deps/test_cpu_flags/stress.c 
> b/client/virt/deps/test_cpu_flags/stress.c
> index 3c35e59..ae424c2 100644
> --- a/client/virt/deps/test_cpu_flags/stress.c
> +++ b/client/virt/deps/test_cpu_flags/stress.c
> @@ -45,7 +45,6 @@ void stress(inst in) {
>               b[i] = rand();
>       }
>       omp_set_num_threads(in.num_threads);
> -     printf("Stress round.\n");
>       #pragma omp parallel
>       while (1){
>               AddTwo(a, b, in.num_threads); // call AddTwo function}
> @@ -69,6 +68,7 @@ void stress(inst in) {
>                       xop();
>               if (in.sse4a)
>                       sse4a();
> +             printf("Stress round.\n");
>       }
>       free(a);
>       free(b);

I'm glad to see some more verbosity in this area and updated comments. 
I looked over the code and it seems reasonable.  Presumably the new 
output in stress.c code slams the aexpect routines enough to exercise 
the timing.  Short of applying the patches and running the tests, it 
looks good to me.

-- 
Chris Evich, RHCA, RHCE, RHCDS, RHCSS
Quality Assurance Engineer
e-mail: cevich + `@' + redhat.com o: 1-888-RED-HAT1 x44214
_______________________________________________
Autotest mailing list
Autotest@test.kernel.org
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to