[PATCH] tests/qtest: remove unused variables

zhujun2 posted 1 patch 1 year ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20231115080014.12273-1-zhujun2@cmss.chinamobile.com
Maintainers: Zhang Chen <chen.zhang@intel.com>, Li Zhijian <lizhijian@fujitsu.com>, Thomas Huth <thuth@redhat.com>, Laurent Vivier <lvivier@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Jason Wang <jasowang@redhat.com>
tests/qtest/test-filter-mirror.c     | 2 +-
tests/qtest/test-filter-redirector.c | 4 ++--
tests/qtest/virtio-net-test.c        | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
[PATCH] tests/qtest: remove unused variables
Posted by zhujun2 1 year ago
These variables are never referenced in the code, just remove them

Signed-off-by: zhujun2 <zhujun2@cmss.chinamobile.com>
---
 tests/qtest/test-filter-mirror.c     | 2 +-
 tests/qtest/test-filter-redirector.c | 4 ++--
 tests/qtest/virtio-net-test.c        | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/tests/qtest/test-filter-mirror.c b/tests/qtest/test-filter-mirror.c
index adeada3eb8..7aa81daa93 100644
--- a/tests/qtest/test-filter-mirror.c
+++ b/tests/qtest/test-filter-mirror.c
@@ -60,7 +60,7 @@ static void test_mirror(void)
 
     g_assert_cmpint(len, ==, sizeof(send_buf));
     recv_buf = g_malloc(len);
-    ret = recv(recv_sock[0], recv_buf, len, 0);
+    recv(recv_sock[0], recv_buf, len, 0);
     g_assert_cmpstr(recv_buf, ==, send_buf);
 
     g_free(recv_buf);
diff --git a/tests/qtest/test-filter-redirector.c b/tests/qtest/test-filter-redirector.c
index e72e3b7873..e4dfeff2e0 100644
--- a/tests/qtest/test-filter-redirector.c
+++ b/tests/qtest/test-filter-redirector.c
@@ -117,7 +117,7 @@ static void test_redirector_tx(void)
 
     g_assert_cmpint(len, ==, sizeof(send_buf));
     recv_buf = g_malloc(len);
-    ret = recv(recv_sock, recv_buf, len, 0);
+    recv(recv_sock, recv_buf, len, 0);
     g_assert_cmpstr(recv_buf, ==, send_buf);
 
     g_free(recv_buf);
@@ -184,7 +184,7 @@ static void test_redirector_rx(void)
 
     g_assert_cmpint(len, ==, sizeof(send_buf));
     recv_buf = g_malloc(len);
-    ret = recv(backend_sock[0], recv_buf, len, 0);
+    recv(backend_sock[0], recv_buf, len, 0);
     g_assert_cmpstr(recv_buf, ==, send_buf);
 
     close(send_sock);
diff --git a/tests/qtest/virtio-net-test.c b/tests/qtest/virtio-net-test.c
index fab5dd8b05..26df5bbabe 100644
--- a/tests/qtest/virtio-net-test.c
+++ b/tests/qtest/virtio-net-test.c
@@ -90,7 +90,7 @@ static void tx_test(QVirtioDevice *dev,
     g_assert_cmpint(ret, ==, sizeof(len));
     len = ntohl(len);
 
-    ret = recv(socket, buffer, len, 0);
+    recv(socket, buffer, len, 0);
     g_assert_cmpstr(buffer, ==, "TEST");
 }
 
-- 
2.17.1
RE: [PATCH] tests/qtest: remove unused variables
Posted by Zhang, Chen 1 year ago

> -----Original Message-----
> From: qemu-devel-bounces+chen.zhang=intel.com@nongnu.org <qemu-
> devel-bounces+chen.zhang=intel.com@nongnu.org> On Behalf Of zhujun2
> Sent: Wednesday, November 15, 2023 4:00 PM
> To: thuth@redhat.com
> Cc: lvivier@redhat.com; pbonzini@redhat.com; qemu-devel@nongnu.org;
> zhujun2@cmss.chinamobile.com
> Subject: [PATCH] tests/qtest: remove unused variables
> 
> These variables are never referenced in the code, just remove them
> 
> Signed-off-by: zhujun2 <zhujun2@cmss.chinamobile.com>
> ---
>  tests/qtest/test-filter-mirror.c     | 2 +-
>  tests/qtest/test-filter-redirector.c | 4 ++--
>  tests/qtest/virtio-net-test.c        | 2 +-
>  3 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/tests/qtest/test-filter-mirror.c b/tests/qtest/test-filter-mirror.c
> index adeada3eb8..7aa81daa93 100644
> --- a/tests/qtest/test-filter-mirror.c
> +++ b/tests/qtest/test-filter-mirror.c
> @@ -60,7 +60,7 @@ static void test_mirror(void)
> 
>      g_assert_cmpint(len, ==, sizeof(send_buf));
>      recv_buf = g_malloc(len);
> -    ret = recv(recv_sock[0], recv_buf, len, 0);
> +    recv(recv_sock[0], recv_buf, len, 0);
>      g_assert_cmpstr(recv_buf, ==, send_buf);
> 
>      g_free(recv_buf);
> diff --git a/tests/qtest/test-filter-redirector.c b/tests/qtest/test-filter-
> redirector.c
> index e72e3b7873..e4dfeff2e0 100644
> --- a/tests/qtest/test-filter-redirector.c
> +++ b/tests/qtest/test-filter-redirector.c
> @@ -117,7 +117,7 @@ static void test_redirector_tx(void)
> 
>      g_assert_cmpint(len, ==, sizeof(send_buf));
>      recv_buf = g_malloc(len);
> -    ret = recv(recv_sock, recv_buf, len, 0);
> +    recv(recv_sock, recv_buf, len, 0);
>      g_assert_cmpstr(recv_buf, ==, send_buf);
> 
>      g_free(recv_buf);
> @@ -184,7 +184,7 @@ static void test_redirector_rx(void)
> 
>      g_assert_cmpint(len, ==, sizeof(send_buf));
>      recv_buf = g_malloc(len);
> -    ret = recv(backend_sock[0], recv_buf, len, 0);
> +    recv(backend_sock[0], recv_buf, len, 0);

It looks like add more check for the "ret" is better.
For example:
g_assert_cmpint(ret, ==, len);

Thanks
Chen

>      g_assert_cmpstr(recv_buf, ==, send_buf);
> 
>      close(send_sock);
> diff --git a/tests/qtest/virtio-net-test.c b/tests/qtest/virtio-net-test.c index
> fab5dd8b05..26df5bbabe 100644
> --- a/tests/qtest/virtio-net-test.c
> +++ b/tests/qtest/virtio-net-test.c
> @@ -90,7 +90,7 @@ static void tx_test(QVirtioDevice *dev,
>      g_assert_cmpint(ret, ==, sizeof(len));
>      len = ntohl(len);
> 
> -    ret = recv(socket, buffer, len, 0);
> +    recv(socket, buffer, len, 0);
>      g_assert_cmpstr(buffer, ==, "TEST");  }
> 
> --
> 2.17.1
> 
> 
> 
[PATCH] tests/qtest: check the return value
Posted by zhujun2 1 year ago
These variables "ret" are never referenced in the code, that
add check logic for the "ret"

Signed-off-by: zhujun2 <zhujun2@cmss.chinamobile.com>
---
 tests/qtest/test-filter-mirror.c     | 1 +
 tests/qtest/test-filter-redirector.c | 2 ++
 tests/qtest/virtio-net-test.c        | 1 +
 3 files changed, 4 insertions(+)

diff --git a/tests/qtest/test-filter-mirror.c b/tests/qtest/test-filter-mirror.c
index adeada3eb8..f3865f7519 100644
--- a/tests/qtest/test-filter-mirror.c
+++ b/tests/qtest/test-filter-mirror.c
@@ -61,6 +61,7 @@ static void test_mirror(void)
     g_assert_cmpint(len, ==, sizeof(send_buf));
     recv_buf = g_malloc(len);
     ret = recv(recv_sock[0], recv_buf, len, 0);
+    g_assert_cmpint(ret, ==, len);
     g_assert_cmpstr(recv_buf, ==, send_buf);
 
     g_free(recv_buf);
diff --git a/tests/qtest/test-filter-redirector.c b/tests/qtest/test-filter-redirector.c
index e72e3b7873..a77d5fd8ec 100644
--- a/tests/qtest/test-filter-redirector.c
+++ b/tests/qtest/test-filter-redirector.c
@@ -118,6 +118,7 @@ static void test_redirector_tx(void)
     g_assert_cmpint(len, ==, sizeof(send_buf));
     recv_buf = g_malloc(len);
     ret = recv(recv_sock, recv_buf, len, 0);
+    g_assert_cmpint(ret, ==, len);
     g_assert_cmpstr(recv_buf, ==, send_buf);
 
     g_free(recv_buf);
@@ -185,6 +186,7 @@ static void test_redirector_rx(void)
     g_assert_cmpint(len, ==, sizeof(send_buf));
     recv_buf = g_malloc(len);
     ret = recv(backend_sock[0], recv_buf, len, 0);
+    g_assert_cmpint(ret, ==, len);
     g_assert_cmpstr(recv_buf, ==, send_buf);
 
     close(send_sock);
diff --git a/tests/qtest/virtio-net-test.c b/tests/qtest/virtio-net-test.c
index fab5dd8b05..b470d8c6e2 100644
--- a/tests/qtest/virtio-net-test.c
+++ b/tests/qtest/virtio-net-test.c
@@ -92,6 +92,7 @@ static void tx_test(QVirtioDevice *dev,
 
     ret = recv(socket, buffer, len, 0);
     g_assert_cmpstr(buffer, ==, "TEST");
+    g_assert_cmpint(ret, ==, len);
 }
 
 static void rx_stop_cont_test(QVirtioDevice *dev,
-- 
2.17.1
RE: [PATCH] tests/qtest: check the return value
Posted by Zhang, Chen 1 year ago

> -----Original Message-----
> From: zhujun2 <zhujun2@cmss.chinamobile.com>
> Sent: Tuesday, November 21, 2023 2:17 PM
> To: Zhang, Chen <chen.zhang@intel.com>
> Cc: lvivier@redhat.com; pbonzini@redhat.com; qemu-devel@nongnu.org;
> thuth@redhat.com; zhujun2@cmss.chinamobile.com
> Subject: [PATCH] tests/qtest: check the return value
> 
> These variables "ret" are never referenced in the code, that add check logic
> for the "ret"
> 

Just tiny comments, please check the len before str, and add the V2 tag in mail title next time.
After fix my comments and Thomas comments:
Reviewed-by: Zhang Chen <chen.zhang@intel.com>

Thanks
Chen

> Signed-off-by: zhujun2 <zhujun2@cmss.chinamobile.com>
> ---
>  tests/qtest/test-filter-mirror.c     | 1 +
>  tests/qtest/test-filter-redirector.c | 2 ++
>  tests/qtest/virtio-net-test.c        | 1 +
>  3 files changed, 4 insertions(+)
> 
> diff --git a/tests/qtest/test-filter-mirror.c b/tests/qtest/test-filter-mirror.c
> index adeada3eb8..f3865f7519 100644
> --- a/tests/qtest/test-filter-mirror.c
> +++ b/tests/qtest/test-filter-mirror.c
> @@ -61,6 +61,7 @@ static void test_mirror(void)
>      g_assert_cmpint(len, ==, sizeof(send_buf));
>      recv_buf = g_malloc(len);
>      ret = recv(recv_sock[0], recv_buf, len, 0);
> +    g_assert_cmpint(ret, ==, len);
>      g_assert_cmpstr(recv_buf, ==, send_buf);
> 
>      g_free(recv_buf);
> diff --git a/tests/qtest/test-filter-redirector.c b/tests/qtest/test-filter-
> redirector.c
> index e72e3b7873..a77d5fd8ec 100644
> --- a/tests/qtest/test-filter-redirector.c
> +++ b/tests/qtest/test-filter-redirector.c
> @@ -118,6 +118,7 @@ static void test_redirector_tx(void)
>      g_assert_cmpint(len, ==, sizeof(send_buf));
>      recv_buf = g_malloc(len);
>      ret = recv(recv_sock, recv_buf, len, 0);
> +    g_assert_cmpint(ret, ==, len);
>      g_assert_cmpstr(recv_buf, ==, send_buf);
> 
>      g_free(recv_buf);
> @@ -185,6 +186,7 @@ static void test_redirector_rx(void)
>      g_assert_cmpint(len, ==, sizeof(send_buf));
>      recv_buf = g_malloc(len);
>      ret = recv(backend_sock[0], recv_buf, len, 0);
> +    g_assert_cmpint(ret, ==, len);
>      g_assert_cmpstr(recv_buf, ==, send_buf);
> 
>      close(send_sock);
> diff --git a/tests/qtest/virtio-net-test.c b/tests/qtest/virtio-net-test.c index
> fab5dd8b05..b470d8c6e2 100644
> --- a/tests/qtest/virtio-net-test.c
> +++ b/tests/qtest/virtio-net-test.c
> @@ -92,6 +92,7 @@ static void tx_test(QVirtioDevice *dev,
> 
>      ret = recv(socket, buffer, len, 0);
>      g_assert_cmpstr(buffer, ==, "TEST");
> +    g_assert_cmpint(ret, ==, len);

Move it before g_assert_cmpstr().

>  }
> 
>  static void rx_stop_cont_test(QVirtioDevice *dev,
> --
> 2.17.1
> 
> 
Re: [PATCH] tests/qtest: check the return value
Posted by Thomas Huth 1 year ago
Thanks, patch looks better this way, but I'd still like to ask you to fix 
two small issues:

On 21/11/2023 07.16, zhujun2 wrote:
> These variables "ret" are never referenced in the code, that

s/, that/, thus/

> add check logic for the "ret"
> 
> Signed-off-by: zhujun2 <zhujun2@cmss.chinamobile.com>

Could you *please* fix your ~/.gitconfig file, like we asked you last time 
already:

 
https://lore.kernel.org/qemu-devel/27bd1017-fd0a-4e90-ae54-6064b434b9aa@redhat.com/

  https://lore.kernel.org/qemu-devel/87sf5w198d.fsf@pond.sub.org/

  Thanks,
   Thomas


> ---
>   tests/qtest/test-filter-mirror.c     | 1 +
>   tests/qtest/test-filter-redirector.c | 2 ++
>   tests/qtest/virtio-net-test.c        | 1 +
>   3 files changed, 4 insertions(+)
> 
> diff --git a/tests/qtest/test-filter-mirror.c b/tests/qtest/test-filter-mirror.c
> index adeada3eb8..f3865f7519 100644
> --- a/tests/qtest/test-filter-mirror.c
> +++ b/tests/qtest/test-filter-mirror.c
> @@ -61,6 +61,7 @@ static void test_mirror(void)
>       g_assert_cmpint(len, ==, sizeof(send_buf));
>       recv_buf = g_malloc(len);
>       ret = recv(recv_sock[0], recv_buf, len, 0);
> +    g_assert_cmpint(ret, ==, len);
>       g_assert_cmpstr(recv_buf, ==, send_buf);
>   
>       g_free(recv_buf);
> diff --git a/tests/qtest/test-filter-redirector.c b/tests/qtest/test-filter-redirector.c
> index e72e3b7873..a77d5fd8ec 100644
> --- a/tests/qtest/test-filter-redirector.c
> +++ b/tests/qtest/test-filter-redirector.c
> @@ -118,6 +118,7 @@ static void test_redirector_tx(void)
>       g_assert_cmpint(len, ==, sizeof(send_buf));
>       recv_buf = g_malloc(len);
>       ret = recv(recv_sock, recv_buf, len, 0);
> +    g_assert_cmpint(ret, ==, len);
>       g_assert_cmpstr(recv_buf, ==, send_buf);
>   
>       g_free(recv_buf);
> @@ -185,6 +186,7 @@ static void test_redirector_rx(void)
>       g_assert_cmpint(len, ==, sizeof(send_buf));
>       recv_buf = g_malloc(len);
>       ret = recv(backend_sock[0], recv_buf, len, 0);
> +    g_assert_cmpint(ret, ==, len);
>       g_assert_cmpstr(recv_buf, ==, send_buf);
>   
>       close(send_sock);
> diff --git a/tests/qtest/virtio-net-test.c b/tests/qtest/virtio-net-test.c
> index fab5dd8b05..b470d8c6e2 100644
> --- a/tests/qtest/virtio-net-test.c
> +++ b/tests/qtest/virtio-net-test.c
> @@ -92,6 +92,7 @@ static void tx_test(QVirtioDevice *dev,
>   
>       ret = recv(socket, buffer, len, 0);
>       g_assert_cmpstr(buffer, ==, "TEST");
> +    g_assert_cmpint(ret, ==, len);
>   }
>   
>   static void rx_stop_cont_test(QVirtioDevice *dev,
[PATCH] tests/qtest: check the return value
Posted by Zhu Jun 1 year ago
These variables "ret" are never referenced in the code, thus
add check logic for the "ret"

Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
---
 tests/qtest/test-filter-mirror.c     | 1 +
 tests/qtest/test-filter-redirector.c | 2 ++
 tests/qtest/virtio-net-test.c        | 1 +
 3 files changed, 4 insertions(+)

diff --git a/tests/qtest/test-filter-mirror.c b/tests/qtest/test-filter-mirror.c
index adeada3eb8..f3865f7519 100644
--- a/tests/qtest/test-filter-mirror.c
+++ b/tests/qtest/test-filter-mirror.c
@@ -61,6 +61,7 @@ static void test_mirror(void)
     g_assert_cmpint(len, ==, sizeof(send_buf));
     recv_buf = g_malloc(len);
     ret = recv(recv_sock[0], recv_buf, len, 0);
+    g_assert_cmpint(ret, ==, len);
     g_assert_cmpstr(recv_buf, ==, send_buf);
 
     g_free(recv_buf);
diff --git a/tests/qtest/test-filter-redirector.c b/tests/qtest/test-filter-redirector.c
index e72e3b7873..a77d5fd8ec 100644
--- a/tests/qtest/test-filter-redirector.c
+++ b/tests/qtest/test-filter-redirector.c
@@ -118,6 +118,7 @@ static void test_redirector_tx(void)
     g_assert_cmpint(len, ==, sizeof(send_buf));
     recv_buf = g_malloc(len);
     ret = recv(recv_sock, recv_buf, len, 0);
+    g_assert_cmpint(ret, ==, len);
     g_assert_cmpstr(recv_buf, ==, send_buf);
 
     g_free(recv_buf);
@@ -185,6 +186,7 @@ static void test_redirector_rx(void)
     g_assert_cmpint(len, ==, sizeof(send_buf));
     recv_buf = g_malloc(len);
     ret = recv(backend_sock[0], recv_buf, len, 0);
+    g_assert_cmpint(ret, ==, len);
     g_assert_cmpstr(recv_buf, ==, send_buf);
 
     close(send_sock);
diff --git a/tests/qtest/virtio-net-test.c b/tests/qtest/virtio-net-test.c
index fab5dd8b05..2df75c9780 100644
--- a/tests/qtest/virtio-net-test.c
+++ b/tests/qtest/virtio-net-test.c
@@ -91,6 +91,7 @@ static void tx_test(QVirtioDevice *dev,
     len = ntohl(len);
 
     ret = recv(socket, buffer, len, 0);
+    g_assert_cmpint(ret, ==, len);
     g_assert_cmpstr(buffer, ==, "TEST");
 }
 
-- 
2.17.1
Re: [PATCH] tests/qtest: check the return value
Posted by Thomas Huth 1 year ago
On 21/11/2023 09.08, Zhu Jun wrote:
> These variables "ret" are never referenced in the code, thus
> add check logic for the "ret"
> 
> Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>

Thanks!

Reviewed-by: Thomas Huth <thuth@redhat.com>

I'll queue it for my next pull request.
Re: [PATCH] tests/qtest: remove unused variables
Posted by Thomas Huth 1 year ago
On 15/11/2023 09.00, zhujun2 wrote:
> These variables are never referenced in the code, just remove them
> 
> Signed-off-by: zhujun2 <zhujun2@cmss.chinamobile.com>
> ---
>   tests/qtest/test-filter-mirror.c     | 2 +-
>   tests/qtest/test-filter-redirector.c | 4 ++--
>   tests/qtest/virtio-net-test.c        | 2 +-
>   3 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/tests/qtest/test-filter-mirror.c b/tests/qtest/test-filter-mirror.c
> index adeada3eb8..7aa81daa93 100644
> --- a/tests/qtest/test-filter-mirror.c
> +++ b/tests/qtest/test-filter-mirror.c
> @@ -60,7 +60,7 @@ static void test_mirror(void)
>   
>       g_assert_cmpint(len, ==, sizeof(send_buf));
>       recv_buf = g_malloc(len);
> -    ret = recv(recv_sock[0], recv_buf, len, 0);
> +    recv(recv_sock[0], recv_buf, len, 0);
>       g_assert_cmpstr(recv_buf, ==, send_buf);
>   
>       g_free(recv_buf);
> diff --git a/tests/qtest/test-filter-redirector.c b/tests/qtest/test-filter-redirector.c
> index e72e3b7873..e4dfeff2e0 100644
> --- a/tests/qtest/test-filter-redirector.c
> +++ b/tests/qtest/test-filter-redirector.c
> @@ -117,7 +117,7 @@ static void test_redirector_tx(void)
>   
>       g_assert_cmpint(len, ==, sizeof(send_buf));
>       recv_buf = g_malloc(len);
> -    ret = recv(recv_sock, recv_buf, len, 0);
> +    recv(recv_sock, recv_buf, len, 0);
>       g_assert_cmpstr(recv_buf, ==, send_buf);
>   
>       g_free(recv_buf);
> @@ -184,7 +184,7 @@ static void test_redirector_rx(void)
>   
>       g_assert_cmpint(len, ==, sizeof(send_buf));
>       recv_buf = g_malloc(len);
> -    ret = recv(backend_sock[0], recv_buf, len, 0);
> +    recv(backend_sock[0], recv_buf, len, 0);
>       g_assert_cmpstr(recv_buf, ==, send_buf);
>   
>       close(send_sock);
> diff --git a/tests/qtest/virtio-net-test.c b/tests/qtest/virtio-net-test.c
> index fab5dd8b05..26df5bbabe 100644
> --- a/tests/qtest/virtio-net-test.c
> +++ b/tests/qtest/virtio-net-test.c
> @@ -90,7 +90,7 @@ static void tx_test(QVirtioDevice *dev,
>       g_assert_cmpint(ret, ==, sizeof(len));
>       len = ntohl(len);
>   
> -    ret = recv(socket, buffer, len, 0);
> +    recv(socket, buffer, len, 0);
>       g_assert_cmpstr(buffer, ==, "TEST");
>   }

Wouldn't it be better to check the ret value for success?

  Thomas