[PATCH 2/4] tests/unit/test-char: Fix qemu_socket(), make_udp_socket() check

Markus Armbruster posted 4 patches 8 months, 2 weeks ago
There is a newer version of this series
[PATCH 2/4] tests/unit/test-char: Fix qemu_socket(), make_udp_socket() check
Posted by Markus Armbruster 8 months, 2 weeks ago
qemu_socket() and make_udp_socket() return a file descriptor on
success, -1 on failure.  The check misinterprets 0 as failure.  Fix
that.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 tests/unit/test-char.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/unit/test-char.c b/tests/unit/test-char.c
index 76946e6f90..e3b783c06b 100644
--- a/tests/unit/test-char.c
+++ b/tests/unit/test-char.c
@@ -556,7 +556,7 @@ static int make_udp_socket(int *port)
     socklen_t alen = sizeof(addr);
     int ret, sock = qemu_socket(PF_INET, SOCK_DGRAM, 0);
 
-    g_assert_cmpint(sock, >, 0);
+    g_assert_cmpint(sock, >=, 0);
     addr.sin_family = AF_INET ;
     addr.sin_addr.s_addr = htonl(INADDR_ANY);
     addr.sin_port = 0;
@@ -1401,7 +1401,7 @@ static void char_hotswap_test(void)
 
     int port;
     int sock = make_udp_socket(&port);
-    g_assert_cmpint(sock, >, 0);
+    g_assert_cmpint(sock, >=, 0);
 
     chr_args = g_strdup_printf("udp:127.0.0.1:%d", port);
 
-- 
2.43.0
Re: [PATCH 2/4] tests/unit/test-char: Fix qemu_socket(), make_udp_socket() check
Posted by Eric Blake 8 months, 1 week ago
On Sat, Feb 03, 2024 at 09:02:26AM +0100, Markus Armbruster wrote:
> qemu_socket() and make_udp_socket() return a file descriptor on
> success, -1 on failure.  The check misinterprets 0 as failure.  Fix
> that.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  tests/unit/test-char.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Eric Blake <eblake@redhat.com>

Might be worth amending the commit message of 1/4 where you called out
this bug to mention it will be fixed in the next patch.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org
Re: [PATCH 2/4] tests/unit/test-char: Fix qemu_socket(), make_udp_socket() check
Posted by Markus Armbruster 8 months, 1 week ago
Eric Blake <eblake@redhat.com> writes:

> On Sat, Feb 03, 2024 at 09:02:26AM +0100, Markus Armbruster wrote:
>> qemu_socket() and make_udp_socket() return a file descriptor on
>> success, -1 on failure.  The check misinterprets 0 as failure.  Fix
>> that.
>> 
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>>  tests/unit/test-char.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> Reviewed-by: Eric Blake <eblake@redhat.com>
>
> Might be worth amending the commit message of 1/4 where you called out
> this bug to mention it will be fixed in the next patch.

Yes.  Thanks!