bug 1927: allow deterministic seeding of random-variable-stream-generators TestSuite

After this commit, the following will cause the test suite to always fail:
NS_GLOBAL_VALUE="RngRun=231" ./test.py -s random-variable-stream-generators
This commit is contained in:
Tom Henderson
2015-09-01 21:03:55 -07:00
parent 9b7f0c36e7
commit 13de20bb3a

View File

@@ -34,11 +34,14 @@
#include "ns3/string.h"
#include "ns3/integer.h"
#include "ns3/test.h"
#include "ns3/log.h"
#include "ns3/rng-seed-manager.h"
#include "ns3/random-variable-stream.h"
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("RandomVariableStreamGenerators");
namespace {
void
@@ -54,6 +57,57 @@ FillHistoRangeUniformly (double *array, uint32_t n, double start, double end)
}
}
bool seedSet = false;
// Over time, this test suite is designed to be run with varying seed
// values so that the distributions can be evaluated with chi-squared
// tests. To enable this, normal invocation of this test suite will
// result in a seed value corresponding to the seconds since epoch
// (time (0) from ctime). Note: this is not a recommended practice for
// seeding normal simulations, as described in the ns-3 manual, but
// suits our purposes here.
//
// However, we also want to provide the ability to run this test suite
// with a repeatable value, such as when the seed or run number is configured
// to a specific value. Therefore, we adopt the following policy. When
// the test program is being run with the default global values for seed
// and run number, this function will instead pick a random, time-based
// seed for use within this test suite. If the global values for seed or
// run number have been configured differently from the default values,
// the global seed value will be used instead of the time-based one.
//
// For example, this command will cause this test suite to use the
// deterministic value of seed=3 every time:
// NS_GLOBAL_VALUE="RngSeed=3" ./test.py -s random-variable-stream-generators
// or equivalently (to see log output):
// NS_LOG="RandomVariableStreamGenerators" NS_GLOBAL_VALUE="RngSeed=3" ./waf --run "test-runner --suite=random-variable-stream-generators"
// Similarly, if the value of RngRun is not set to 1, the globals will be
// used.
//
void
SetTestSuiteSeed (void)
{
if (seedSet == false)
{
uint32_t seed;
if (RngSeedManager::GetSeed () == 1 && RngSeedManager::GetRun () == 1)
{
seed = static_cast<uint32_t> (time (0));
seedSet = true;
NS_LOG_DEBUG ("Global seed and run number are default; seeding with time of day: " << seed);
}
else
{
seed = RngSeedManager::GetSeed ();
seedSet = true;
NS_LOG_DEBUG ("Global seed and run number are not default; using the non-default values seed: " <<
seed << " and run: " << RngSeedManager::GetRun ());
}
SeedManager::SetSeed (seed);
}
}
} // anonymous namespace
// ===========================================================================
@@ -125,7 +179,7 @@ RandomVariableStreamUniformTestCase::ChiSquaredTest (Ptr<UniformRandomVariable>
void
RandomVariableStreamUniformTestCase::DoRun (void)
{
SeedManager::SetSeed (time (0));
SetTestSuiteSeed ();
double sum = 0.;
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS);
@@ -268,7 +322,7 @@ RandomVariableStreamUniformAntitheticTestCase::ChiSquaredTest (Ptr<UniformRandom
void
RandomVariableStreamUniformAntitheticTestCase::DoRun (void)
{
SeedManager::SetSeed (time (0));
SetTestSuiteSeed ();
double sum = 0.;
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS);
@@ -345,7 +399,7 @@ RandomVariableStreamConstantTestCase::~RandomVariableStreamConstantTestCase ()
void
RandomVariableStreamConstantTestCase::DoRun (void)
{
SeedManager::SetSeed (time (0));
SetTestSuiteSeed ();
Ptr<ConstantRandomVariable> c = CreateObject<ConstantRandomVariable> ();
@@ -395,7 +449,7 @@ RandomVariableStreamSequentialTestCase::~RandomVariableStreamSequentialTestCase
void
RandomVariableStreamSequentialTestCase::DoRun (void)
{
SeedManager::SetSeed (time (0));
SetTestSuiteSeed ();
Ptr<SequentialRandomVariable> s = CreateObject<SequentialRandomVariable> ();
@@ -509,7 +563,7 @@ RandomVariableStreamNormalTestCase::ChiSquaredTest (Ptr<NormalRandomVariable> n)
void
RandomVariableStreamNormalTestCase::DoRun (void)
{
SeedManager::SetSeed (time (0));
SetTestSuiteSeed ();
double sum = 0.;
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS);
@@ -635,7 +689,7 @@ RandomVariableStreamNormalAntitheticTestCase::ChiSquaredTest (Ptr<NormalRandomVa
void
RandomVariableStreamNormalAntitheticTestCase::DoRun (void)
{
SeedManager::SetSeed (time (0));
SetTestSuiteSeed ();
double sum = 0.;
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS);
@@ -766,7 +820,7 @@ RandomVariableStreamExponentialTestCase::ChiSquaredTest (Ptr<ExponentialRandomVa
void
RandomVariableStreamExponentialTestCase::DoRun (void)
{
SeedManager::SetSeed (time (0));
SetTestSuiteSeed ();
double sum = 0.;
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS);
@@ -886,7 +940,7 @@ RandomVariableStreamExponentialAntitheticTestCase::ChiSquaredTest (Ptr<Exponenti
void
RandomVariableStreamExponentialAntitheticTestCase::DoRun (void)
{
SeedManager::SetSeed (time (0));
SetTestSuiteSeed ();
double sum = 0.;
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS);
@@ -1015,7 +1069,7 @@ RandomVariableStreamParetoTestCase::ChiSquaredTest (Ptr<ParetoRandomVariable> p)
void
RandomVariableStreamParetoTestCase::DoRun (void)
{
SeedManager::SetSeed (time (0));
SetTestSuiteSeed ();
double sum = 0.;
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS);
@@ -1149,7 +1203,7 @@ RandomVariableStreamParetoAntitheticTestCase::ChiSquaredTest (Ptr<ParetoRandomVa
void
RandomVariableStreamParetoAntitheticTestCase::DoRun (void)
{
SeedManager::SetSeed (time (0));
SetTestSuiteSeed ();
double sum = 0.;
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS);
@@ -1291,7 +1345,7 @@ RandomVariableStreamWeibullTestCase::ChiSquaredTest (Ptr<WeibullRandomVariable>
void
RandomVariableStreamWeibullTestCase::DoRun (void)
{
SeedManager::SetSeed (time (0));
SetTestSuiteSeed ();
double sum = 0.;
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS);
@@ -1437,7 +1491,7 @@ RandomVariableStreamWeibullAntitheticTestCase::ChiSquaredTest (Ptr<WeibullRandom
void
RandomVariableStreamWeibullAntitheticTestCase::DoRun (void)
{
SeedManager::SetSeed (time (0));
SetTestSuiteSeed ();
double sum = 0.;
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS);
@@ -1590,7 +1644,7 @@ RandomVariableStreamLogNormalTestCase::ChiSquaredTest (Ptr<LogNormalRandomVariab
void
RandomVariableStreamLogNormalTestCase::DoRun (void)
{
SeedManager::SetSeed (time (0));
SetTestSuiteSeed ();
double sum = 0.;
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS);
@@ -1726,7 +1780,7 @@ RandomVariableStreamLogNormalAntitheticTestCase::ChiSquaredTest (Ptr<LogNormalRa
void
RandomVariableStreamLogNormalAntitheticTestCase::DoRun (void)
{
SeedManager::SetSeed (time (0));
SetTestSuiteSeed ();
double sum = 0.;
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS);
@@ -1869,7 +1923,7 @@ RandomVariableStreamGammaTestCase::ChiSquaredTest (Ptr<GammaRandomVariable> n)
void
RandomVariableStreamGammaTestCase::DoRun (void)
{
SeedManager::SetSeed (time (0));
SetTestSuiteSeed ();
double sum = 0.;
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS);
@@ -1998,7 +2052,7 @@ RandomVariableStreamGammaAntitheticTestCase::ChiSquaredTest (Ptr<GammaRandomVari
void
RandomVariableStreamGammaAntitheticTestCase::DoRun (void)
{
SeedManager::SetSeed (time (0));
SetTestSuiteSeed ();
double sum = 0.;
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS);
@@ -2138,7 +2192,7 @@ RandomVariableStreamErlangTestCase::ChiSquaredTest (Ptr<ErlangRandomVariable> n)
void
RandomVariableStreamErlangTestCase::DoRun (void)
{
SeedManager::SetSeed (time (0));
SetTestSuiteSeed ();
double sum = 0.;
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS);
@@ -2270,7 +2324,7 @@ RandomVariableStreamErlangAntitheticTestCase::ChiSquaredTest (Ptr<ErlangRandomVa
void
RandomVariableStreamErlangAntitheticTestCase::DoRun (void)
{
SeedManager::SetSeed (time (0));
SetTestSuiteSeed ();
double sum = 0.;
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS);
@@ -2351,7 +2405,7 @@ RandomVariableStreamZipfTestCase::~RandomVariableStreamZipfTestCase ()
void
RandomVariableStreamZipfTestCase::DoRun (void)
{
SeedManager::SetSeed (time (0));
SetTestSuiteSeed ();
uint32_t n = 1;
double alpha = 2.0;
@@ -2433,7 +2487,7 @@ RandomVariableStreamZipfAntitheticTestCase::~RandomVariableStreamZipfAntitheticT
void
RandomVariableStreamZipfAntitheticTestCase::DoRun (void)
{
SeedManager::SetSeed (time (0));
SetTestSuiteSeed ();
uint32_t n = 1;
double alpha = 2.0;
@@ -2518,7 +2572,7 @@ RandomVariableStreamZetaTestCase::~RandomVariableStreamZetaTestCase ()
void
RandomVariableStreamZetaTestCase::DoRun (void)
{
SeedManager::SetSeed (time (0));
SetTestSuiteSeed ();
double alpha = 5.0;
double value;
@@ -2582,7 +2636,7 @@ RandomVariableStreamZetaAntitheticTestCase::~RandomVariableStreamZetaAntitheticT
void
RandomVariableStreamZetaAntitheticTestCase::DoRun (void)
{
SeedManager::SetSeed (time (0));
SetTestSuiteSeed ();
double alpha = 5.0;
double value;
@@ -2651,7 +2705,7 @@ RandomVariableStreamDeterministicTestCase::~RandomVariableStreamDeterministicTes
void
RandomVariableStreamDeterministicTestCase::DoRun (void)
{
SeedManager::SetSeed (time (0));
SetTestSuiteSeed ();
Ptr<DeterministicRandomVariable> s = CreateObject<DeterministicRandomVariable> ();
@@ -2726,7 +2780,7 @@ RandomVariableStreamEmpiricalTestCase::~RandomVariableStreamEmpiricalTestCase ()
void
RandomVariableStreamEmpiricalTestCase::DoRun (void)
{
SeedManager::SetSeed (time (0));
SetTestSuiteSeed ();
// Create the RNG with a uniform distribution between 0 and 10.
Ptr<EmpiricalRandomVariable> x = CreateObject<EmpiricalRandomVariable> ();
@@ -2790,7 +2844,7 @@ RandomVariableStreamEmpiricalAntitheticTestCase::~RandomVariableStreamEmpiricalA
void
RandomVariableStreamEmpiricalAntitheticTestCase::DoRun (void)
{
SeedManager::SetSeed (time (0));
SetTestSuiteSeed ();
// Create the RNG with a uniform distribution between 0 and 10.
Ptr<EmpiricalRandomVariable> x = CreateObject<EmpiricalRandomVariable> ();