* [PATCH] tests: use g_test_rand_int
@ 2019-12-11 14:23 Paolo Bonzini
2019-12-11 19:25 ` Thomas Huth
0 siblings, 1 reply; 3+ messages in thread
From: Paolo Bonzini @ 2019-12-11 14:23 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial
g_test_rand_int provides a reproducible random integer number, using a
different number seed every time but allowing reproduction using the
--seed command line option. It is thus better suited to tests than
g_random_int or random.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
block/vhdx.c | 2 +-
block/vmdk.c | 4 ++--
tests/ivshmem-test.c | 2 +-
tests/test-bitmap.c | 8 ++++----
tests/test-qga.c | 4 ++--
5 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/block/vhdx.c b/block/vhdx.c
index f02d261..36465d5 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -1504,7 +1504,7 @@ static int vhdx_create_new_headers(BlockBackend *blk, uint64_t image_size,
hdr = g_new0(VHDXHeader, 1);
hdr->signature = VHDX_HEADER_SIGNATURE;
- hdr->sequence_number = g_random_int();
+ hdr->sequence_number = g_test_rand_int();
hdr->log_version = 0;
hdr->version = 1;
hdr->log_length = log_size;
diff --git a/block/vmdk.c b/block/vmdk.c
index 20e909d..eba96bf 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -2037,7 +2037,7 @@ static int vmdk_pwritev(BlockDriverState *bs, uint64_t offset,
/* update CID on the first write every time the virtual disk is
* opened */
if (!s->cid_updated) {
- ret = vmdk_write_cid(bs, g_random_int());
+ ret = vmdk_write_cid(bs, g_test_rand_int());
if (ret < 0) {
return ret;
}
@@ -2499,7 +2499,7 @@ static int coroutine_fn vmdk_co_do_create(int64_t size,
/* generate descriptor file */
desc = g_strdup_printf(desc_template,
- g_random_int(),
+ g_test_rand_int(),
parent_cid,
BlockdevVmdkSubformat_str(subformat),
parent_desc_line,
diff --git a/tests/ivshmem-test.c b/tests/ivshmem-test.c
index be9aa92..ecda256 100644
--- a/tests/ivshmem-test.c
+++ b/tests/ivshmem-test.c
@@ -443,7 +443,7 @@ static gchar *mktempshm(int size, int *fd)
while (true) {
gchar *name;
- name = g_strdup_printf("/qtest-%u-%u", getpid(), g_random_int());
+ name = g_strdup_printf("/qtest-%u-%u", getpid(), g_test_rand_int());
*fd = shm_open(name, O_CREAT|O_RDWR|O_EXCL,
S_IRWXU|S_IRWXG|S_IRWXO);
if (*fd > 0) {
diff --git a/tests/test-bitmap.c b/tests/test-bitmap.c
index 087e02a..2f5b714 100644
--- a/tests/test-bitmap.c
+++ b/tests/test-bitmap.c
@@ -22,10 +22,10 @@ static void check_bitmap_copy_with_offset(void)
bmap2 = bitmap_new(BMAP_SIZE);
bmap3 = bitmap_new(BMAP_SIZE);
- bmap1[0] = random();
- bmap1[1] = random();
- bmap1[2] = random();
- bmap1[3] = random();
+ bmap1[0] = g_test_rand_int();
+ bmap1[1] = g_test_rand_int();
+ bmap1[2] = g_test_rand_int();
+ bmap1[3] = g_test_rand_int();
total = BITS_PER_LONG * 4;
/* Shift 115 bits into bmap2 */
diff --git a/tests/test-qga.c b/tests/test-qga.c
index 1ca49bb..d2b2435 100644
--- a/tests/test-qga.c
+++ b/tests/test-qga.c
@@ -143,7 +143,7 @@ static void qmp_assertion_message_error(const char *domain,
static void test_qga_sync_delimited(gconstpointer fix)
{
const TestFixture *fixture = fix;
- guint32 v, r = g_random_int();
+ guint32 v, r = g_test_rand_int();
unsigned char c;
QDict *ret;
@@ -186,7 +186,7 @@ static void test_qga_sync_delimited(gconstpointer fix)
static void test_qga_sync(gconstpointer fix)
{
const TestFixture *fixture = fix;
- guint32 v, r = g_random_int();
+ guint32 v, r = g_test_rand_int();
QDict *ret;
/*
--
1.8.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] tests: use g_test_rand_int
2019-12-11 14:23 [PATCH] tests: use g_test_rand_int Paolo Bonzini
@ 2019-12-11 19:25 ` Thomas Huth
2019-12-12 1:17 ` Paolo Bonzini
0 siblings, 1 reply; 3+ messages in thread
From: Thomas Huth @ 2019-12-11 19:25 UTC (permalink / raw)
To: qemu-devel
On 11/12/2019 15.23, Paolo Bonzini wrote:
> g_test_rand_int provides a reproducible random integer number, using a
> different number seed every time but allowing reproduction using the
> --seed command line option. It is thus better suited to tests than
> g_random_int or random.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> block/vhdx.c | 2 +-
> block/vmdk.c | 4 ++--
> tests/ivshmem-test.c | 2 +-
> tests/test-bitmap.c | 8 ++++----
> tests/test-qga.c | 4 ++--
> 5 files changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/block/vhdx.c b/block/vhdx.c
> index f02d261..36465d5 100644
> --- a/block/vhdx.c
> +++ b/block/vhdx.c
> @@ -1504,7 +1504,7 @@ static int vhdx_create_new_headers(BlockBackend *blk, uint64_t image_size,
> hdr = g_new0(VHDXHeader, 1);
>
> hdr->signature = VHDX_HEADER_SIGNATURE;
> - hdr->sequence_number = g_random_int();
> + hdr->sequence_number = g_test_rand_int();
> hdr->log_version = 0;
> hdr->version = 1;
> hdr->log_length = log_size;
> diff --git a/block/vmdk.c b/block/vmdk.c
> index 20e909d..eba96bf 100644
> --- a/block/vmdk.c
> +++ b/block/vmdk.c
> @@ -2037,7 +2037,7 @@ static int vmdk_pwritev(BlockDriverState *bs, uint64_t offset,
> /* update CID on the first write every time the virtual disk is
> * opened */
> if (!s->cid_updated) {
> - ret = vmdk_write_cid(bs, g_random_int());
> + ret = vmdk_write_cid(bs, g_test_rand_int());
> if (ret < 0) {
> return ret;
> }
> @@ -2499,7 +2499,7 @@ static int coroutine_fn vmdk_co_do_create(int64_t size,
>
> /* generate descriptor file */
> desc = g_strdup_printf(desc_template,
> - g_random_int(),
> + g_test_rand_int(),
> parent_cid,
> BlockdevVmdkSubformat_str(subformat),
> parent_desc_line,
Why do you also change this in block/ and not only in tests/ ?
Thomas
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] tests: use g_test_rand_int
2019-12-11 19:25 ` Thomas Huth
@ 2019-12-12 1:17 ` Paolo Bonzini
0 siblings, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2019-12-12 1:17 UTC (permalink / raw)
To: Thomas Huth, qemu-devel
On 11/12/19 20:25, Thomas Huth wrote:
> On 11/12/2019 15.23, Paolo Bonzini wrote:
>> g_test_rand_int provides a reproducible random integer number, using a
>> different number seed every time but allowing reproduction using the
>> --seed command line option. It is thus better suited to tests than
>> g_random_int or random.
>>
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>> ---
>> block/vhdx.c | 2 +-
>> block/vmdk.c | 4 ++--
>> tests/ivshmem-test.c | 2 +-
>> tests/test-bitmap.c | 8 ++++----
>> tests/test-qga.c | 4 ++--
>> 5 files changed, 10 insertions(+), 10 deletions(-)
>>
>> diff --git a/block/vhdx.c b/block/vhdx.c
>> index f02d261..36465d5 100644
>> --- a/block/vhdx.c
>> +++ b/block/vhdx.c
>> @@ -1504,7 +1504,7 @@ static int vhdx_create_new_headers(BlockBackend *blk, uint64_t image_size,
>> hdr = g_new0(VHDXHeader, 1);
>>
>> hdr->signature = VHDX_HEADER_SIGNATURE;
>> - hdr->sequence_number = g_random_int();
>> + hdr->sequence_number = g_test_rand_int();
>> hdr->log_version = 0;
>> hdr->version = 1;
>> hdr->log_length = log_size;
>> diff --git a/block/vmdk.c b/block/vmdk.c
>> index 20e909d..eba96bf 100644
>> --- a/block/vmdk.c
>> +++ b/block/vmdk.c
>> @@ -2037,7 +2037,7 @@ static int vmdk_pwritev(BlockDriverState *bs, uint64_t offset,
>> /* update CID on the first write every time the virtual disk is
>> * opened */
>> if (!s->cid_updated) {
>> - ret = vmdk_write_cid(bs, g_random_int());
>> + ret = vmdk_write_cid(bs, g_test_rand_int());
>> if (ret < 0) {
>> return ret;
>> }
>> @@ -2499,7 +2499,7 @@ static int coroutine_fn vmdk_co_do_create(int64_t size,
>>
>> /* generate descriptor file */
>> desc = g_strdup_printf(desc_template,
>> - g_random_int(),
>> + g_test_rand_int(),
>> parent_cid,
>> BlockdevVmdkSubformat_str(subformat),
>> parent_desc_line,
>
> Why do you also change this in block/ and not only in tests/ ?
Because today was not my day. :/
Paolo
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-12-12 1:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-11 14:23 [PATCH] tests: use g_test_rand_int Paolo Bonzini
2019-12-11 19:25 ` Thomas Huth
2019-12-12 1:17 ` Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).