Test that GetPerformanceCounter() increments
This commit is contained in:
parent
f544094d5e
commit
33f853d8d8
1 changed files with 11 additions and 1 deletions
|
@ -17,6 +17,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
@ -262,6 +263,8 @@ FastRandomContext::FastRandomContext(const uint256& seed) : requires_seed(false)
|
||||||
|
|
||||||
bool Random_SanityCheck()
|
bool Random_SanityCheck()
|
||||||
{
|
{
|
||||||
|
uint64_t start = GetPerformanceCounter();
|
||||||
|
|
||||||
/* This does not measure the quality of randomness, but it does test that
|
/* This does not measure the quality of randomness, but it does test that
|
||||||
* OSRandom() overwrites all 32 bytes of the output given a maximum
|
* OSRandom() overwrites all 32 bytes of the output given a maximum
|
||||||
* number of tries.
|
* number of tries.
|
||||||
|
@ -288,7 +291,14 @@ bool Random_SanityCheck()
|
||||||
|
|
||||||
tries += 1;
|
tries += 1;
|
||||||
} while (num_overwritten < NUM_OS_RANDOM_BYTES && tries < MAX_TRIES);
|
} while (num_overwritten < NUM_OS_RANDOM_BYTES && tries < MAX_TRIES);
|
||||||
return (num_overwritten == NUM_OS_RANDOM_BYTES); /* If this failed, bailed out after too many tries */
|
if (num_overwritten != NUM_OS_RANDOM_BYTES) return false; /* If this failed, bailed out after too many tries */
|
||||||
|
|
||||||
|
// Check that GetPerformanceCounter increases at least during a GetOSRand() call + 1ms sleep.
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||||
|
uint64_t stop = GetPerformanceCounter();
|
||||||
|
if (stop == start) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
FastRandomContext::FastRandomContext(bool fDeterministic) : requires_seed(!fDeterministic), bytebuf_size(0), bitbuf_size(0)
|
FastRandomContext::FastRandomContext(bool fDeterministic) : requires_seed(!fDeterministic), bytebuf_size(0), bitbuf_size(0)
|
||||||
|
|
Loading…
Reference in a new issue