mirror of
https://github.com/zeek/zeek.git
synced 2025-10-10 10:38:20 +00:00
Fixing btests.
- When Bro is given a PRNG seed, it now uses its own internal random number generator that produces consistent results across sytems. Note that this internal generator isn't very good, so it should only be used for testing purposes. - The BTest configuration now sets the environemnt variables TZ=UTC and LANG=C to ensure consistent results. - Fixing doc markup in logging.bro. - Updating baselines.
This commit is contained in:
parent
5fba6d144e
commit
da0ea67453
13 changed files with 163 additions and 124 deletions
38
src/util.cc
38
src/util.cc
|
@ -573,6 +573,17 @@ static bool write_random_seeds(const char* write_file, uint32 seed,
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool bro_rand_determistic = false;
|
||||
static unsigned int bro_rand_state = 0;
|
||||
|
||||
static void bro_srand(unsigned int seed, bool deterministic)
|
||||
{
|
||||
bro_rand_state = seed;
|
||||
bro_rand_determistic = deterministic;
|
||||
|
||||
srand(seed);
|
||||
}
|
||||
|
||||
void init_random_seed(uint32 seed, const char* read_file, const char* write_file)
|
||||
{
|
||||
static const int bufsiz = 16;
|
||||
|
@ -633,9 +644,11 @@ void init_random_seed(uint32 seed, const char* read_file, const char* write_file
|
|||
seed = (seed << 1) | (seed >> 31);
|
||||
}
|
||||
}
|
||||
else
|
||||
seeds_done = true;
|
||||
}
|
||||
|
||||
srandom(seed);
|
||||
bro_srand(seed, seeds_done);
|
||||
|
||||
if ( ! hmac_key_set )
|
||||
{
|
||||
|
@ -648,6 +661,25 @@ void init_random_seed(uint32 seed, const char* read_file, const char* write_file
|
|||
write_file);
|
||||
}
|
||||
|
||||
long int bro_random()
|
||||
{
|
||||
if ( ! bro_rand_determistic )
|
||||
return random(); // Use system PRNG.
|
||||
|
||||
// Use our own simple linear congruence PRNG to make sure we are
|
||||
// predictable across platforms.
|
||||
const long int m = 2147483647;
|
||||
const long int a = 16807;
|
||||
const long int q = m / a;
|
||||
const long int r = m % a;
|
||||
|
||||
bro_rand_state = a * ( bro_rand_state % q ) - r * ( bro_rand_state / q );
|
||||
|
||||
if ( bro_rand_state <= 0 )
|
||||
bro_rand_state += m;
|
||||
|
||||
return bro_rand_state;
|
||||
}
|
||||
|
||||
// Returns a 64-bit random string.
|
||||
uint64 rand64bit()
|
||||
|
@ -656,7 +688,7 @@ uint64 rand64bit()
|
|||
int i;
|
||||
|
||||
for ( i = 1; i <= 4; ++i )
|
||||
base = (base<<16) | random();
|
||||
base = (base<<16) | bro_random();
|
||||
return base;
|
||||
}
|
||||
|
||||
|
@ -778,7 +810,7 @@ const char* bro_path()
|
|||
if ( ! path )
|
||||
path = ".:"
|
||||
POLICYDEST ":"
|
||||
POLICYDEST "/sigs:"
|
||||
POLICYDEST "/sigs:"
|
||||
POLICYDEST "/time-machine:"
|
||||
POLICYDEST "/site";
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue