mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-12 11:18:59 +00:00
tests: update prng to return better pseudo random numbers
Signed-off-by: Christian Franke <chris@opensourcerouting.org>
This commit is contained in:
parent
991ae35b17
commit
6c968614b5
@ -4,6 +4,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (C) 2012 by Open Source Routing.
|
* Copyright (C) 2012 by Open Source Routing.
|
||||||
* Copyright (C) 2012 by Internet Systems Consortium, Inc. ("ISC")
|
* Copyright (C) 2012 by Internet Systems Consortium, Inc. ("ISC")
|
||||||
|
* Copyright (C) 2017 Christian Franke
|
||||||
*
|
*
|
||||||
* This file is part of Quagga
|
* This file is part of Quagga
|
||||||
*
|
*
|
||||||
@ -32,49 +33,32 @@
|
|||||||
|
|
||||||
struct prng
|
struct prng
|
||||||
{
|
{
|
||||||
unsigned long long state1;
|
uint64_t state;
|
||||||
unsigned long long state2;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static char
|
|
||||||
prng_bit(struct prng *prng)
|
|
||||||
{
|
|
||||||
prng->state1 *= 2416;
|
|
||||||
prng->state1 += 374441;
|
|
||||||
prng->state1 %= 1771875;
|
|
||||||
|
|
||||||
if (prng->state1 % 2)
|
|
||||||
{
|
|
||||||
prng->state2 *= 84589;
|
|
||||||
prng->state2 += 45989;
|
|
||||||
prng->state2 %= 217728;
|
|
||||||
}
|
|
||||||
|
|
||||||
return prng->state2 % 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct prng*
|
struct prng*
|
||||||
prng_new(unsigned long long seed)
|
prng_new(unsigned long long seed)
|
||||||
{
|
{
|
||||||
struct prng *rv = calloc(sizeof(*rv), 1);
|
struct prng *rv = calloc(sizeof(*rv), 1);
|
||||||
assert(rv);
|
assert(rv);
|
||||||
|
|
||||||
rv->state1 = rv->state2 = seed;
|
rv->state = seed;
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int
|
/*
|
||||||
|
* This implementation has originally been provided to musl libc by
|
||||||
|
* Szabolcs Nagy <nsz at port70 dot net> in 2013 under the terms of
|
||||||
|
* the MIT license.
|
||||||
|
* It is a simple LCG which D.E. Knuth attributes to C.E. Haynes in
|
||||||
|
* TAOCP Vol2 3.3.4
|
||||||
|
*/
|
||||||
|
int
|
||||||
prng_rand(struct prng *prng)
|
prng_rand(struct prng *prng)
|
||||||
{
|
{
|
||||||
unsigned int i, rv = 0;
|
prng->state = 6364136223846793005ULL*prng->state + 1;
|
||||||
|
return prng->state>>33;
|
||||||
for (i = 0; i < 32; i++)
|
|
||||||
{
|
|
||||||
rv |= prng_bit(prng);
|
|
||||||
rv <<= 1;
|
|
||||||
}
|
|
||||||
return rv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
struct prng;
|
struct prng;
|
||||||
|
|
||||||
struct prng* prng_new(unsigned long long seed);
|
struct prng* prng_new(unsigned long long seed);
|
||||||
unsigned int prng_rand(struct prng*);
|
int prng_rand(struct prng*);
|
||||||
const char * prng_fuzz(struct prng*,
|
const char * prng_fuzz(struct prng*,
|
||||||
const char *string,
|
const char *string,
|
||||||
const char *charset,
|
const char *charset,
|
||||||
|
@ -386,7 +386,13 @@ static void
|
|||||||
test_state_del_one_route(struct test_state *test,
|
test_state_del_one_route(struct test_state *test,
|
||||||
struct prng *prng)
|
struct prng *prng)
|
||||||
{
|
{
|
||||||
unsigned int which_route = prng_rand(prng) % test->log->count;
|
unsigned int which_route;
|
||||||
|
|
||||||
|
if (test->log->count == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
which_route = prng_rand(prng) % test->log->count;
|
||||||
|
|
||||||
struct route_node *rn;
|
struct route_node *rn;
|
||||||
struct prefix *dst_p, *src_p;
|
struct prefix *dst_p, *src_p;
|
||||||
struct prefix_ipv6 dst6_p, src6_p;
|
struct prefix_ipv6 dst6_p, src6_p;
|
||||||
|
Loading…
Reference in New Issue
Block a user