diff mbox series

[v4,05/15] qemu-iotests: delay QMP socket timers

Message ID 20210520075236.44723-6-eesposit@redhat.com (mailing list archive)
State New, archived
Headers show
Series qemu_iotests: improve debugging options | expand

Commit Message

Emanuele Giuseppe Esposito May 20, 2021, 7:52 a.m. UTC
Attaching gdbserver implies that the qmp socket
should wait indefinitely for an answer from QEMU.

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
 tests/qemu-iotests/iotests.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Comments

Vladimir Sementsov-Ogievskiy May 28, 2021, 5:06 p.m. UTC | #1
20.05.2021 10:52, Emanuele Giuseppe Esposito wrote:
> Attaching gdbserver implies that the qmp socket
> should wait indefinitely for an answer from QEMU.
> 
> Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
> ---
>   tests/qemu-iotests/iotests.py | 10 ++++++----
>   1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
> index d667fde6f8..cf1ca60376 100644
> --- a/tests/qemu-iotests/iotests.py
> +++ b/tests/qemu-iotests/iotests.py
> @@ -478,11 +478,13 @@ def __init__(self, seconds, errmsg="Timeout"):
>           self.seconds = seconds
>           self.errmsg = errmsg
>       def __enter__(self):
> -        signal.signal(signal.SIGALRM, self.timeout)
> -        signal.setitimer(signal.ITIMER_REAL, self.seconds)
> +        if not qemu_gdb:
> +            signal.signal(signal.SIGALRM, self.timeout)
> +            signal.setitimer(signal.ITIMER_REAL, self.seconds)
>           return self
>       def __exit__(self, exc_type, value, traceback):
> -        signal.setitimer(signal.ITIMER_REAL, 0)
> +        if not qemu_gdb:
> +            signal.setitimer(signal.ITIMER_REAL, 0)
>           return False
>       def timeout(self, signum, frame):
>           raise Exception(self.errmsg)

So, you just make the class do nothing.. I'd prefer something like this:

@contextmanager
def NoTimeout:
    yield

if qemu_gdb:
   Timeout = NoTimeout


anyway:

Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>


> @@ -576,7 +578,7 @@ class VM(qtest.QEMUQtestMachine):
>   
>       def __init__(self, path_suffix=''):
>           name = "qemu%s-%d" % (path_suffix, os.getpid())
> -        timer = 15.0
> +        timer = 15.0 if not qemu_gdb else None
>           super().__init__(qemu_prog, qemu_opts, name=name,
>                            test_dir=test_dir,
>                            socket_scm_helper=socket_scm_helper,
> 


Still, it's not simple to avoid any kind of timeouts. The most annoying would be timeouts in event_wait() / events_wait()
Emanuele Giuseppe Esposito June 3, 2021, 11:03 a.m. UTC | #2
> 
> So, you just make the class do nothing.. I'd prefer something like this:
> 
> @contextmanager
> def NoTimeout:
>     yield
> 
> if qemu_gdb:
>    Timeout = NoTimeout

I am not sure I understand what you want to do here.
I have a basic understanding of @contextmanager, but can you explain 
more what you want to do?

Alternatively, I send the patch as-is, and then you can send this change.

Thank you,
Emanuele

> 
> 
> anyway:
> 
> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
>
Vladimir Sementsov-Ogievskiy June 3, 2021, 12:25 p.m. UTC | #3
03.06.2021 14:03, Emanuele Giuseppe Esposito wrote:
> 
>>
>> So, you just make the class do nothing.. I'd prefer something like this:
>>
>> @contextmanager
>> def NoTimeout:
>>     yield
>>
>> if qemu_gdb:
>>    Timeout = NoTimeout
> 
> I am not sure I understand what you want to do here.
> I have a basic understanding of @contextmanager, but can you explain more what you want to do?

With qemu_gdb you make the class do absolutely nothing. So, it's just provides an interface of context manager, but does nothing.

>> @contextmanager
>> def NoTimeout:
>>     yield

is the same thing: it's context manager, so you can do

with NoTimeout():
   ....

but that context manager does absolutely nothing.


@contextmanager gives you a simple way to create a context manager. You define a function which has yield point. So, everything before yield is  __enter__, everything after yield is __exit__. And you can return a value by yield, it will be a return value of __enter__.


So, what I meant: keep Timeout class as is and just add code that I suggested after it.


> 
> Alternatively, I send the patch as-is, and then you can send this change.

OK for me.

> 
> Thank you,
> Emanuele
> 
>>
>>
>> anyway:
>>
>> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
>>
>
Emanuele Giuseppe Esposito June 3, 2021, 12:52 p.m. UTC | #4
On 03/06/2021 14:25, Vladimir Sementsov-Ogievskiy wrote:
> 03.06.2021 14:03, Emanuele Giuseppe Esposito wrote:
>>
>>>
>>> So, you just make the class do nothing.. I'd prefer something like this:
>>>
>>> @contextmanager
>>> def NoTimeout:
>>>     yield
>>>
>>> if qemu_gdb:
>>>    Timeout = NoTimeout
>>
>> I am not sure I understand what you want to do here.
>> I have a basic understanding of @contextmanager, but can you explain 
>> more what you want to do?
> 
> With qemu_gdb you make the class do absolutely nothing. So, it's just 
> provides an interface of context manager, but does nothing.
> 
>>> @contextmanager
>>> def NoTimeout:
>>>     yield
> 
> is the same thing: it's context manager, so you can do
> 
> with NoTimeout():
>    ....
> 
> but that context manager does absolutely nothing.
> 
> 
> @contextmanager gives you a simple way to create a context manager. You 
> define a function which has yield point. So, everything before yield is  
> __enter__, everything after yield is __exit__. And you can return a 
> value by yield, it will be a return value of __enter__.
> 
> 
> So, what I meant: keep Timeout class as is and just add code that I 
> suggested after it.

Oh okay. I didn't know Timeout = NoTimeout was possible (and I didn't 
know where to put it anyways). Looks cleaner than the normal ifs, will 
apply this change and send v5.

Thank you,
Emanuele
diff mbox series

Patch

diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index d667fde6f8..cf1ca60376 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -478,11 +478,13 @@  def __init__(self, seconds, errmsg="Timeout"):
         self.seconds = seconds
         self.errmsg = errmsg
     def __enter__(self):
-        signal.signal(signal.SIGALRM, self.timeout)
-        signal.setitimer(signal.ITIMER_REAL, self.seconds)
+        if not qemu_gdb:
+            signal.signal(signal.SIGALRM, self.timeout)
+            signal.setitimer(signal.ITIMER_REAL, self.seconds)
         return self
     def __exit__(self, exc_type, value, traceback):
-        signal.setitimer(signal.ITIMER_REAL, 0)
+        if not qemu_gdb:
+            signal.setitimer(signal.ITIMER_REAL, 0)
         return False
     def timeout(self, signum, frame):
         raise Exception(self.errmsg)
@@ -576,7 +578,7 @@  class VM(qtest.QEMUQtestMachine):
 
     def __init__(self, path_suffix=''):
         name = "qemu%s-%d" % (path_suffix, os.getpid())
-        timer = 15.0
+        timer = 15.0 if not qemu_gdb else None
         super().__init__(qemu_prog, qemu_opts, name=name,
                          test_dir=test_dir,
                          socket_scm_helper=socket_scm_helper,