All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tests/qtest/virtio-net-failover: Use g_random_int() instead of g_test_rand_int()
@ 2021-12-20 10:27 Thomas Huth
  2021-12-20 11:54 ` Laurent Vivier
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Thomas Huth @ 2021-12-20 10:27 UTC (permalink / raw)
  To: qemu-devel, Laurent Vivier; +Cc: Paolo Bonzini, Philippe Mathieu-Daudé

g_test_rand_int() must not be called before g_test_init(), otherwise
the glib will show a "g_rand_int: assertion 'rand != NULL' failed"
message in the log. So we could change the order here, but actually,
g_test_rand_int() seems also the wrong choice here, since we're using
it to create a temporary file name, which certainly should not depend
on the "--seed" CLI option of the g_test suite. Thus let's use the
g_random_int() function instead.

Reported-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/qtest/virtio-net-failover.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/qtest/virtio-net-failover.c b/tests/qtest/virtio-net-failover.c
index 4b2ba8a106..70b94bf18f 100644
--- a/tests/qtest/virtio-net-failover.c
+++ b/tests/qtest/virtio-net-failover.c
@@ -1308,7 +1308,7 @@ int main(int argc, char **argv)
 {
     const gchar *tmpdir = g_get_tmp_dir();
     gchar *tmpfile = g_strdup_printf("%s/failover_test_migrate-%u-%u",
-                                     tmpdir, getpid(), g_test_rand_int());
+                                     tmpdir, getpid(), g_random_int());
     int ret;
 
     g_test_init(&argc, &argv, NULL);
-- 
2.27.0



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

* Re: [PATCH] tests/qtest/virtio-net-failover: Use g_random_int() instead of g_test_rand_int()
  2021-12-20 10:27 [PATCH] tests/qtest/virtio-net-failover: Use g_random_int() instead of g_test_rand_int() Thomas Huth
@ 2021-12-20 11:54 ` Laurent Vivier
  2021-12-20 13:16 ` Philippe Mathieu-Daudé
  2021-12-20 19:26 ` Richard Henderson
  2 siblings, 0 replies; 8+ messages in thread
From: Laurent Vivier @ 2021-12-20 11:54 UTC (permalink / raw)
  To: Thomas Huth, qemu-devel; +Cc: Paolo Bonzini, Philippe Mathieu-Daudé

On 20/12/2021 11:27, Thomas Huth wrote:
> g_test_rand_int() must not be called before g_test_init(), otherwise
> the glib will show a "g_rand_int: assertion 'rand != NULL' failed"
> message in the log. So we could change the order here, but actually,
> g_test_rand_int() seems also the wrong choice here, since we're using
> it to create a temporary file name, which certainly should not depend
> on the "--seed" CLI option of the g_test suite. Thus let's use the
> g_random_int() function instead.
>
> Reported-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>   tests/qtest/virtio-net-failover.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tests/qtest/virtio-net-failover.c b/tests/qtest/virtio-net-failover.c
> index 4b2ba8a106..70b94bf18f 100644
> --- a/tests/qtest/virtio-net-failover.c
> +++ b/tests/qtest/virtio-net-failover.c
> @@ -1308,7 +1308,7 @@ int main(int argc, char **argv)
>   {
>       const gchar *tmpdir = g_get_tmp_dir();
>       gchar *tmpfile = g_strdup_printf("%s/failover_test_migrate-%u-%u",
> -                                     tmpdir, getpid(), g_test_rand_int());
> +                                     tmpdir, getpid(), g_random_int());
>       int ret;
>   
>       g_test_init(&argc, &argv, NULL);

Reviewed-by: Laurent Vivier <lvivier@redhat.com>



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

* Re: [PATCH] tests/qtest/virtio-net-failover: Use g_random_int() instead of g_test_rand_int()
  2021-12-20 10:27 [PATCH] tests/qtest/virtio-net-failover: Use g_random_int() instead of g_test_rand_int() Thomas Huth
  2021-12-20 11:54 ` Laurent Vivier
@ 2021-12-20 13:16 ` Philippe Mathieu-Daudé
  2021-12-20 19:26 ` Richard Henderson
  2 siblings, 0 replies; 8+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-12-20 13:16 UTC (permalink / raw)
  To: Thomas Huth, qemu-devel, Laurent Vivier; +Cc: Paolo Bonzini

On 12/20/21 11:27, Thomas Huth wrote:
> g_test_rand_int() must not be called before g_test_init(), otherwise
> the glib will show a "g_rand_int: assertion 'rand != NULL' failed"
> message in the log. So we could change the order here, but actually,
> g_test_rand_int() seems also the wrong choice here, since we're using
> it to create a temporary file name, which certainly should not depend
> on the "--seed" CLI option of the g_test suite. Thus let's use the
> g_random_int() function instead.
> 
> Reported-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>  tests/qtest/virtio-net-failover.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>



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

* Re: [PATCH] tests/qtest/virtio-net-failover: Use g_random_int() instead of g_test_rand_int()
  2021-12-20 10:27 [PATCH] tests/qtest/virtio-net-failover: Use g_random_int() instead of g_test_rand_int() Thomas Huth
  2021-12-20 11:54 ` Laurent Vivier
  2021-12-20 13:16 ` Philippe Mathieu-Daudé
@ 2021-12-20 19:26 ` Richard Henderson
  2021-12-20 20:02   ` Philippe Mathieu-Daudé
  2 siblings, 1 reply; 8+ messages in thread
From: Richard Henderson @ 2021-12-20 19:26 UTC (permalink / raw)
  To: Thomas Huth, qemu-devel, Laurent Vivier
  Cc: Paolo Bonzini, Philippe Mathieu-Daudé

On 12/20/21 2:27 AM, Thomas Huth wrote:
>       const gchar *tmpdir = g_get_tmp_dir();
>       gchar *tmpfile = g_strdup_printf("%s/failover_test_migrate-%u-%u",
> -                                     tmpdir, getpid(), g_test_rand_int());
> +                                     tmpdir, getpid(), g_random_int());

Random numbers plus pid are irrelevant, because you still don't have guaranteed uniqueness 
-- think stale files in /tmp.

Use g_file_open_tmp.


r~


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

* Re: [PATCH] tests/qtest/virtio-net-failover: Use g_random_int() instead of g_test_rand_int()
  2021-12-20 19:26 ` Richard Henderson
@ 2021-12-20 20:02   ` Philippe Mathieu-Daudé
  2021-12-21 10:32     ` Thomas Huth
  0 siblings, 1 reply; 8+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-12-20 20:02 UTC (permalink / raw)
  To: Richard Henderson, Thomas Huth, qemu-devel, Laurent Vivier; +Cc: Paolo Bonzini

On 12/20/21 20:26, Richard Henderson wrote:
> On 12/20/21 2:27 AM, Thomas Huth wrote:
>>       const gchar *tmpdir = g_get_tmp_dir();
>>       gchar *tmpfile = g_strdup_printf("%s/failover_test_migrate-%u-%u",
>> -                                     tmpdir, getpid(),
>> g_test_rand_int());
>> +                                     tmpdir, getpid(), g_random_int());
> 
> Random numbers plus pid are irrelevant, because you still don't have
> guaranteed uniqueness -- think stale files in /tmp.
> 
> Use g_file_open_tmp.

Another use in test_socket_unix_abstract(),
tests/unit/test-util-sockets.c.



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

* Re: [PATCH] tests/qtest/virtio-net-failover: Use g_random_int() instead of g_test_rand_int()
  2021-12-20 20:02   ` Philippe Mathieu-Daudé
@ 2021-12-21 10:32     ` Thomas Huth
  2021-12-21 19:32       ` Richard Henderson
  0 siblings, 1 reply; 8+ messages in thread
From: Thomas Huth @ 2021-12-21 10:32 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé,
	Richard Henderson, qemu-devel, Laurent Vivier
  Cc: Paolo Bonzini

On 20/12/2021 21.02, Philippe Mathieu-Daudé wrote:
> On 12/20/21 20:26, Richard Henderson wrote:
>> On 12/20/21 2:27 AM, Thomas Huth wrote:
>>>        const gchar *tmpdir = g_get_tmp_dir();
>>>        gchar *tmpfile = g_strdup_printf("%s/failover_test_migrate-%u-%u",
>>> -                                     tmpdir, getpid(),
>>> g_test_rand_int());
>>> +                                     tmpdir, getpid(), g_random_int());
>>
>> Random numbers plus pid are irrelevant, because you still don't have
>> guaranteed uniqueness -- think stale files in /tmp.
>>
>> Use g_file_open_tmp.
> 
> Another use in test_socket_unix_abstract(),
> tests/unit/test-util-sockets.c.

Using g_file_open_tmp is certainly better ... but the tests are currently 
written in a way where they require the file name of the temporary file - so 
switching to g_file_open_tmp() (which only provides a file handle) certainly 
would need some rewrite here... Thus I'd suggest to go first with this patch 
to silence the Assert messages, and then to clean this up properly later.

  Thomas



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

* Re: [PATCH] tests/qtest/virtio-net-failover: Use g_random_int() instead of g_test_rand_int()
  2021-12-21 10:32     ` Thomas Huth
@ 2021-12-21 19:32       ` Richard Henderson
  2021-12-22  7:02         ` Thomas Huth
  0 siblings, 1 reply; 8+ messages in thread
From: Richard Henderson @ 2021-12-21 19:32 UTC (permalink / raw)
  To: Thomas Huth, Philippe Mathieu-Daudé, qemu-devel, Laurent Vivier
  Cc: Paolo Bonzini

On 12/21/21 2:32 AM, Thomas Huth wrote:
> Using g_file_open_tmp is certainly better ... but the tests are currently written in a way 
> where they require the file name of the temporary file - so switching to g_file_open_tmp() 
> (which only provides a file handle) certainly would need some rewrite here...

Incorrect.  g_file_open_tmp returns the open file handle, but also returns the filename in 
*name_used.

I should think you can close the file handle straight away and use the filename.


r~


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

* Re: [PATCH] tests/qtest/virtio-net-failover: Use g_random_int() instead of g_test_rand_int()
  2021-12-21 19:32       ` Richard Henderson
@ 2021-12-22  7:02         ` Thomas Huth
  0 siblings, 0 replies; 8+ messages in thread
From: Thomas Huth @ 2021-12-22  7:02 UTC (permalink / raw)
  To: Richard Henderson, Philippe Mathieu-Daudé,
	qemu-devel, Laurent Vivier
  Cc: Paolo Bonzini

On 21/12/2021 20.32, Richard Henderson wrote:
> On 12/21/21 2:32 AM, Thomas Huth wrote:
>> Using g_file_open_tmp is certainly better ... but the tests are currently 
>> written in a way where they require the file name of the temporary file - 
>> so switching to g_file_open_tmp() (which only provides a file handle) 
>> certainly would need some rewrite here...
> 
> Incorrect.  g_file_open_tmp returns the open file handle, but also returns 
> the filename in *name_used.

D'oh - not sure how I missed that yesterday :-/

> I should think you can close the file handle straight away and use the 
> filename.

Ok, then let's continue with that approach.

  Thomas



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

end of thread, other threads:[~2021-12-22  7:44 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-20 10:27 [PATCH] tests/qtest/virtio-net-failover: Use g_random_int() instead of g_test_rand_int() Thomas Huth
2021-12-20 11:54 ` Laurent Vivier
2021-12-20 13:16 ` Philippe Mathieu-Daudé
2021-12-20 19:26 ` Richard Henderson
2021-12-20 20:02   ` Philippe Mathieu-Daudé
2021-12-21 10:32     ` Thomas Huth
2021-12-21 19:32       ` Richard Henderson
2021-12-22  7:02         ` Thomas Huth

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.