All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tests/unit/test-iov: Fix timeout problem on NetBSD and OpenBSD
@ 2024-01-22 15:33 Thomas Huth
  2024-01-22 15:43 ` Daniel P. Berrangé
  0 siblings, 1 reply; 2+ messages in thread
From: Thomas Huth @ 2024-01-22 15:33 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P . Berrangé,
	Alex Bennée, Peter Maydell, Reinoud Zandijk, Ryo ONODERA,
	Brad Smith

The test-iov code uses usleep() with small values (<= 30) in some
nested loops with many iterations. This causes a small delay on OSes
like Linux that have a precise sleeping mechanism, but on systems
like NetBSD and OpenBSD, each usleep() call takes multiple microseconds,
which then sum up in a total test time of multiple minutes!

Looking at the code, the usleep() does not really seem to be necessary
here - if not enough data could be send, we should simply always use
select() to wait 'til we can send more. Thus remove the usleep() and
re-arrange the code a little bit to make it more clear what is going
on here.

Suggested-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/unit/test-iov.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/tests/unit/test-iov.c b/tests/unit/test-iov.c
index 6f7623d310..75bc3be005 100644
--- a/tests/unit/test-iov.c
+++ b/tests/unit/test-iov.c
@@ -197,15 +197,17 @@ static void test_io(void)
                    s = g_test_rand_int_range(0, j - k + 1);
                    r = iov_send(sv[1], iov, niov, k, s);
                    g_assert(memcmp(iov, siov, sizeof(*iov)*niov) == 0);
-                   if (r >= 0) {
-                       k += r;
-                       usleep(g_test_rand_int_range(0, 30));
-                   } else if (errno == EAGAIN) {
-                       select(sv[1]+1, NULL, &fds, NULL, NULL);
-                       continue;
-                   } else {
-                       perror("send");
-                       exit(1);
+                   if (r < 0) {
+                        if (errno == EAGAIN) {
+                            r = 0;
+                        } else {
+                            perror("send");
+                            exit(1);
+                        }
+                   }
+                   k += r;
+                   if (k < j) {
+                        select(sv[1] + 1, NULL, &fds, NULL, NULL);
                    }
                } while(k < j);
            }
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] tests/unit/test-iov: Fix timeout problem on NetBSD and OpenBSD
  2024-01-22 15:33 [PATCH] tests/unit/test-iov: Fix timeout problem on NetBSD and OpenBSD Thomas Huth
@ 2024-01-22 15:43 ` Daniel P. Berrangé
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel P. Berrangé @ 2024-01-22 15:43 UTC (permalink / raw)
  To: Thomas Huth
  Cc: qemu-devel, Alex Bennée, Peter Maydell, Reinoud Zandijk,
	Ryo ONODERA, Brad Smith

On Mon, Jan 22, 2024 at 04:33:47PM +0100, Thomas Huth wrote:
> The test-iov code uses usleep() with small values (<= 30) in some
> nested loops with many iterations. This causes a small delay on OSes
> like Linux that have a precise sleeping mechanism, but on systems
> like NetBSD and OpenBSD, each usleep() call takes multiple microseconds,
> which then sum up in a total test time of multiple minutes!
> 
> Looking at the code, the usleep() does not really seem to be necessary
> here - if not enough data could be send, we should simply always use
> select() to wait 'til we can send more. Thus remove the usleep() and
> re-arrange the code a little bit to make it more clear what is going
> on here.
> 
> Suggested-by: Daniel P. Berrangé <berrange@redhat.com>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>  tests/unit/test-iov.c | 20 +++++++++++---------
>  1 file changed, 11 insertions(+), 9 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-01-22 15:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-22 15:33 [PATCH] tests/unit/test-iov: Fix timeout problem on NetBSD and OpenBSD Thomas Huth
2024-01-22 15:43 ` Daniel P. Berrangé

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.