tests/qtest/virtio-net-failover: Use g_random_int() instead of g_test_rand_int()
PATCH 1/1 tests/qtest/virtio-net-failover: Use g_random_int() instead of g_test_rand_int()
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.
--- tests/qtest/virtio-net-failover.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qtest/virtio-net-failover.c +1 -1
@@ -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 );
Signature · 1 line
2.27.0
Quoted 19 lines · Thomas Huth
g_test_rand_int()must not be called beforeg_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 theg_testsuite. Thus let's use theg_random_int()function instead.Reported-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Thomas Huth <[email protected]>--- tests/qtest/virtio-net-failover.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/qtest/virtio-net-failover.c +0
-0
tests/qtest/virtio-net-failover.c int main(int argc, char **argv) · line 1314
Quoted 8 lines
tests/qtest/virtio-net-failover.c +1
-1@@ -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 );
Quoted 8 lines · Thomas Huth
g_test_rand_int()must not be called beforeg_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 theg_testsuite. Thus let's use theg_random_int()function instead.
Quoted 5 lines
Reported-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Thomas Huth <[email protected]>--- tests/qtest/virtio-net-failover.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qtest/virtio-net-failover.c int main(int argc, char **argv) · line 1311
Quoted 4 lines · Thomas Huth
const gchar *tmpdir =
g_get_tmp_dir();
gchar *tmpfile = g_strdup_printf("%s/failover_test_migrate-%u-%u",tests/qtest/virtio-net-failover.c +1
-1- 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~
Quoted 11 lines · Richard Henderson
Quoted 5 lines · Thomas Huth
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.
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Richard Henderson
Quoted 5 lines · Thomas Huth
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());
Quoted 7 lines
Quoted 4 lines
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
Quoted 1 line · Thomas Huth
Using
g_file_open_tmpis certainly better ... but the tests are currently written in a way where they require the file name of the temporary file - so switching tog_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~
Quoted 4 lines · Richard Henderson
Quoted 1 line · Thomas Huth
Using
g_file_open_tmpis certainly better ... but the tests are currently written in a way where they require the file name of the temporary file - so switching tog_file_open_tmp()(which only provides a file handle) certainly would need some rewrite here...Incorrect.
g_file_open_tmpreturns the open file handle, but also returns the filename in*name_used.
D'oh - not sure how I missed that yesterday :-/
Quoted 1 line
I should think you can close the file handle straight away and use the filename.
Ok, then let's continue with that approach.
Thomas