# HG changeset patch # User cdfreire # Date 1308582107 -7200 # Node ID be4fcee9c19523e32467e600f668eac9015da793 # Parent 34605964f100d5190d89eb90ea4eefb187d5457e Ensure clean simulation environments within tests by issuing Simulator::Destroy both at setup and teardown. diff -r 34605964f100 -r be4fcee9c195 src/core/model/test.cc --- a/src/core/model/test.cc Fri Jun 17 15:03:42 2011 +0200 +++ b/src/core/model/test.cc Mon Jun 20 17:01:47 2011 +0200 @@ -21,6 +21,8 @@ #include "abort.h" #include +#include "ns3/simulator.h" + // Set to true to enable a segmentation fault upon a test case macro test // failing (for debugging purposes) bool gBreakOnFailure = false; @@ -395,11 +397,22 @@ void TestCase::DoSetup (void) { + /* + * Ensure a clean execution environment + */ + Simulator::Destroy(); } void TestCase::DoTeardown (void) { + /* + * Most tests will destroy their simulators when successful, + * but on failure, they tend to leave the simulator alive. + * This can be a problem for subsequent test runs, so we + * must destroy the simulator on TestCase teardown just in case. + */ + Simulator::Destroy(); } TestSuite::TestSuite (std::string name, TestType type) # HG changeset patch # User cdfreire # Date 1308582267 -7200 # Node ID a8dbc37fbaedbc332b760bd6c8ae6dc6cf824002 # Parent 79d44c3ce810a9f803bd3838e2f5aa1f22292c7f Fix RvBatteryModel test case to ensure reproducible conditions when ran multiple times. diff -r 79d44c3ce810 -r a8dbc37fbaed src/energy/test/rv-battery-model-test.cc --- a/src/energy/test/rv-battery-model-test.cc Mon Jun 20 17:03:38 2011 +0200 +++ b/src/energy/test/rv-battery-model-test.cc Mon Jun 20 17:04:27 2011 +0200 @@ -107,6 +107,9 @@ // Itsy battery m_alpha = 35220; m_beta = 0.637; + + // create load profiles for variable load test + CreateLoadProfiles (); } BatteryLifetimeTest::~BatteryLifetimeTest () @@ -642,6 +645,10 @@ { NS_LOG_DEBUG ("Constant load run."); + // set constant load test parameters + m_alpha = 35220; + m_beta = 0.637; + // 640mA NS_TEST_ASSERT_MSG_EQ (ConstantLoadTest (0.640, Seconds (2844.0)), false, "Problems with constant load test (640mA)."); // 320mA @@ -653,9 +660,6 @@ // 32mA NS_TEST_ASSERT_MSG_EQ (ConstantLoadTest (0.032, Seconds (65580.0)), false, "Problems with constant load test (32)."); - // create load profiles for variable load test - CreateLoadProfiles (); - // variable load with Itsy battery NS_LOG_DEBUG ("\n\nItsy"); m_alpha = 35220; @@ -759,7 +763,7 @@ NS_LOG_DEBUG ("Expected lifetime = " << expLifetime.GetSeconds () << "s"); NS_LOG_DEBUG ("Actual lifetime = " << actualLifetime.GetSeconds () << "s"); - + NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL (actualLifetime, expLifetime, "Incorrect lifetime!"); /* NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL (actualLifetime.GetSeconds () / 60, # HG changeset patch # User cdfreire # Date 1308669285 -7200 # Node ID 3aa7dfca1d27f9dcb0e0f5e8b442e5ae52a5405b # Parent 3881cbe7fcc7c66cd4c5a84a5a204a80627b41da Tests should roll back configuration changes on teardown diff -r 3881cbe7fcc7 -r 3aa7dfca1d27 src/energy/test/basic-energy-model-test.cc --- a/src/energy/test/basic-energy-model-test.cc Mon Jun 20 17:04:42 2011 +0200 +++ b/src/energy/test/basic-energy-model-test.cc Tue Jun 21 17:14:45 2011 +0200 @@ -217,6 +217,8 @@ private: void DoRun (void); + void DoSetup (void); + void DoTeardown (void); /** * Callback invoked when energy is drained from source. @@ -238,11 +240,13 @@ double m_simTimeS; // maximum simulation time, in seconds double m_timeStepS; // simulation time step size, in seconds double m_updateIntervalS; // update interval of each device model + std::string m_phyMode; }; BasicEnergyDepletionTest::BasicEnergyDepletionTest () : TestCase ("Basic energy model energy depletion test case") + , m_phyMode ("DsssRate1Mbps") { m_numOfNodes = 10; m_callbackCount = 0; @@ -256,6 +260,34 @@ } void +BasicEnergyDepletionTest::DoSetup (void) +{ + TestCase::DoSetup (); + + // disable fragmentation for frames below 2200 bytes + Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", + StringValue ("2200")); + // turn off RTS/CTS for frames below 2200 bytes + Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", + StringValue ("2200")); + // Fix non-unicast data rate to be the same as that of unicast + Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", + StringValue (m_phyMode)); +} + +void +BasicEnergyDepletionTest::DoTeardown (void) +{ + // Restore defaults + std::string invalidWifiMode ("Invalid-WifiMode"); + Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2346")); + Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2346")); + Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue (invalidWifiMode)); + + TestCase::DoTeardown (); +} + +void BasicEnergyDepletionTest::DoRun (void) { /* @@ -287,18 +319,6 @@ NodeContainer c; c.Create (m_numOfNodes); - std::string phyMode ("DsssRate1Mbps"); - - // disable fragmentation for frames below 2200 bytes - Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", - StringValue ("2200")); - // turn off RTS/CTS for frames below 2200 bytes - Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", - StringValue ("2200")); - // Fix non-unicast data rate to be the same as that of unicast - Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", - StringValue (phyMode)); - // install YansWifiPhy WifiHelper wifi; wifi.SetStandard (WIFI_PHY_STANDARD_80211b); @@ -319,8 +339,8 @@ // Add a non-QoS upper MAC, and disable rate control NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", - "DataMode", StringValue (phyMode), - "ControlMode", StringValue (phyMode)); + "DataMode", StringValue (m_phyMode), + "ControlMode", StringValue (m_phyMode)); // Set it to ad-hoc mode wifiMac.SetType ("ns3::AdhocWifiMac"); NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c); diff -r 3881cbe7fcc7 -r 3aa7dfca1d27 src/energy/test/rv-battery-model-test.cc --- a/src/energy/test/rv-battery-model-test.cc Mon Jun 20 17:04:42 2011 +0200 +++ b/src/energy/test/rv-battery-model-test.cc Tue Jun 21 17:14:45 2011 +0200 @@ -57,13 +57,21 @@ void CreateLoadProfiles (void); /** - * \returns False if no error occurs. - * * Runs test. */ void DoRun (void); /** + * Sets up test configuration + */ + void DoSetup (void); + + /** + * Restores environment after test runs + */ + void DoTeardown (void); + + /** * \param load Load value, in Amperes (A). * \param expLifetime Expected lifetime. * \return False if no error occurs. @@ -99,10 +107,12 @@ std::vector m_loadProfiles; double m_alpha; double m_beta; + std::string m_phyMode; }; BatteryLifetimeTest::BatteryLifetimeTest () : TestCase ("RV battery model battery lifetime test case.") + , m_phyMode ("DsssRate1Mbps") { // Itsy battery m_alpha = 35220; @@ -641,6 +651,34 @@ } void +BatteryLifetimeTest::DoSetup (void) +{ + TestCase::DoSetup (); + + // disable fragmentation for frames below 2200 bytes + Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", + StringValue ("2200")); + // turn off RTS/CTS for frames below 2200 bytes + Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", + StringValue ("2200")); + // Fix non-unicast data rate to be the same as that of unicast + Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", + StringValue (m_phyMode)); +} + +void +BatteryLifetimeTest::DoTeardown (void) +{ + // Restore defaults + std::string invalidWifiMode ("Invalid-WifiMode"); + Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2346")); + Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2346")); + Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue (invalidWifiMode)); + + TestCase::DoTeardown (); +} + +void BatteryLifetimeTest::DoRun (void) { NS_LOG_DEBUG ("Constant load run."); @@ -700,18 +738,6 @@ NodeContainer c; c.Create (1); - std::string phyMode ("DsssRate1Mbps"); - - // disable fragmentation for frames below 2200 bytes - Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", - StringValue ("2200")); - // turn off RTS/CTS for frames below 2200 bytes - Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", - StringValue ("2200")); - // Fix non-unicast data rate to be the same as that of unicast - Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", - StringValue (phyMode)); - // install YansWifiPhy WifiHelper wifi; wifi.SetStandard (WIFI_PHY_STANDARD_80211b); @@ -732,8 +758,8 @@ // Add a non-QoS upper MAC, and disable rate control NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", - "DataMode", StringValue (phyMode), - "ControlMode", StringValue (phyMode)); + "DataMode", StringValue (m_phyMode), + "ControlMode", StringValue (m_phyMode)); // Set it to ad-hoc mode wifiMac.SetType ("ns3::AdhocWifiMac"); NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c); @@ -787,18 +813,6 @@ NodeContainer c; c.Create (1); - std::string phyMode ("DsssRate1Mbps"); - - // disable fragmentation for frames below 2200 bytes - Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", - StringValue ("2200")); - // turn off RTS/CTS for frames below 2200 bytes - Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", - StringValue ("2200")); - // Fix non-unicast data rate to be the same as that of unicast - Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", - StringValue (phyMode)); - // install YansWifiPhy WifiHelper wifi; wifi.SetStandard (WIFI_PHY_STANDARD_80211b); @@ -819,8 +833,8 @@ // Add a non-QoS upper MAC, and disable rate control NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", - "DataMode", StringValue (phyMode), - "ControlMode", StringValue (phyMode)); + "DataMode", StringValue (m_phyMode), + "ControlMode", StringValue (m_phyMode)); // Set it to ad-hoc mode wifiMac.SetType ("ns3::AdhocWifiMac"); NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c); diff -r 3881cbe7fcc7 -r 3aa7dfca1d27 src/mobility/test/ns2-mobility-helper-test-suite.cc --- a/src/mobility/test/ns2-mobility-helper-test-suite.cc Mon Jun 20 17:04:42 2011 +0200 +++ b/src/mobility/test/ns2-mobility-helper-test-suite.cc Tue Jun 21 17:14:45 2011 +0200 @@ -204,6 +204,7 @@ void DoSetup () { + Simulator::Destroy(); CreateNodes (); } diff -r 3881cbe7fcc7 -r 3aa7dfca1d27 src/olsr/test/bug780-test.cc --- a/src/olsr/test/bug780-test.cc Mon Jun 20 17:04:42 2011 +0200 +++ b/src/olsr/test/bug780-test.cc Tue Jun 21 17:14:45 2011 +0200 @@ -75,6 +75,28 @@ } void +Bug780Test::DoSetup () +{ + TestCase::DoSetup (); + + //sending one packets per sec + // Fix non-unicast data rate to be the same as that of unicast + Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", + StringValue ("400")); +} + +void +Bug780Test::DoTeardown () +{ + //sending one packets per sec + // Fix non-unicast data rate to be the same as that of unicast + Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", + StringValue ("2346")); + + TestCase::DoTeardown (); +} + +void Bug780Test::DoRun () { SeedManager::SetSeed (123); @@ -97,11 +119,6 @@ double SimTime = 200.0; std::string phyMode ("DsssRate1Mbps"); - //sending one packets per sec - // Fix non-unicast data rate to be the same as that of unicast - Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", - StringValue ("400")); - NodeContainer adhocNodes; adhocNodes.Create (nWifis); diff -r 3881cbe7fcc7 -r 3aa7dfca1d27 src/olsr/test/bug780-test.h --- a/src/olsr/test/bug780-test.h Mon Jun 20 17:04:42 2011 +0200 +++ b/src/olsr/test/bug780-test.h Tue Jun 21 17:14:45 2011 +0200 @@ -42,6 +42,8 @@ void CheckResults (); /// Go void DoRun (); + void DoSetup (); + void DoTeardown (); }; } diff -r 3881cbe7fcc7 -r 3aa7dfca1d27 src/propagation/test/propagation-loss-model-test-suite.cc --- a/src/propagation/test/propagation-loss-model-test-suite.cc Mon Jun 20 17:04:42 2011 +0200 +++ b/src/propagation/test/propagation-loss-model-test-suite.cc Tue Jun 21 17:14:45 2011 +0200 @@ -42,6 +42,8 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); + virtual void DoTeardown (void); typedef struct { Vector m_position; @@ -63,14 +65,33 @@ } void -FriisPropagationLossModelTestCase::DoRun (void) +FriisPropagationLossModelTestCase::DoSetup (void) { + TestCase::DoSetup (); + // The ns-3 testing manual gives more background on the values selected // for this test. First, set a few defaults. // wavelength at 2.4 GHz is 0.125m Config::SetDefault ("ns3::FriisPropagationLossModel::Lambda", DoubleValue (0.125)); Config::SetDefault ("ns3::FriisPropagationLossModel::SystemLoss", DoubleValue (1.0)); +} + +void +FriisPropagationLossModelTestCase::DoTeardown (void) +{ + // Restore defaults + Config::SetDefault ("ns3::FriisPropagationLossModel::Lambda", DoubleValue (0.0582524)); + Config::SetDefault ("ns3::FriisPropagationLossModel::SystemLoss", DoubleValue (1.0)); + + TestCase::DoTeardown (); +} + +void +FriisPropagationLossModelTestCase::DoRun (void) +{ + // The ns-3 testing manual gives more background on the values selected + // for this test. // Select a reference transmit power // Pt = 10^(17.0206/10)/10^3 = .05035702 W @@ -139,6 +160,8 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); + virtual void DoTeardown (void); typedef struct { @@ -162,15 +185,32 @@ } void -TwoRayGroundPropagationLossModelTestCase::DoRun (void) +TwoRayGroundPropagationLossModelTestCase::DoSetup (void) { + TestCase::DoSetup (); + // wavelength at 2.4 GHz is 0.125m Config::SetDefault ("ns3::TwoRayGroundPropagationLossModel::Lambda", DoubleValue (0.125)); Config::SetDefault ("ns3::TwoRayGroundPropagationLossModel::SystemLoss", DoubleValue (1.0)); // set antenna height to 1.5m above z coordinate Config::SetDefault ("ns3::TwoRayGroundPropagationLossModel::HeightAboveZ", DoubleValue (1.5)); +} +void +TwoRayGroundPropagationLossModelTestCase::DoTeardown (void) +{ + TestCase::DoTeardown (); + + // Restore defaults + Config::SetDefault ("ns3::TwoRayGroundPropagationLossModel::Lambda", DoubleValue (0.0582524)); + Config::SetDefault ("ns3::TwoRayGroundPropagationLossModel::SystemLoss", DoubleValue (1.0)); + Config::SetDefault ("ns3::TwoRayGroundPropagationLossModel::HeightAboveZ", DoubleValue (0.0)); +} + +void +TwoRayGroundPropagationLossModelTestCase::DoRun (void) +{ // Select a reference transmit power of 17.0206 dBm // Pt = 10^(17.0206/10)/10^3 = .05035702 W double txPowerW = 0.05035702; @@ -267,6 +307,8 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); + virtual void DoTeardown (void); typedef struct { Vector m_position; @@ -288,12 +330,28 @@ } void -LogDistancePropagationLossModelTestCase::DoRun (void) +LogDistancePropagationLossModelTestCase::DoSetup (void) { + TestCase::DoSetup (); + // reference loss at 2.4 GHz is 40.045997 Config::SetDefault ("ns3::LogDistancePropagationLossModel::ReferenceLoss", DoubleValue (40.045997)); Config::SetDefault ("ns3::LogDistancePropagationLossModel::Exponent", DoubleValue (3)); +} +void +LogDistancePropagationLossModelTestCase::DoTeardown (void) +{ + // Restore defaults + Config::SetDefault ("ns3::LogDistancePropagationLossModel::ReferenceLoss", DoubleValue (46.6777)); + Config::SetDefault ("ns3::LogDistancePropagationLossModel::Exponent", DoubleValue (3)); + + TestCase::DoTeardown (); +} + +void +LogDistancePropagationLossModelTestCase::DoRun (void) +{ // Select a reference transmit power // Pt = 10^(17.0206/10)/10^3 = .05035702 W double txPowerW = 0.05035702; @@ -402,6 +460,8 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); + virtual void DoTeardown (void); }; RangePropagationLossModelTestCase::RangePropagationLossModelTestCase () @@ -414,9 +474,26 @@ } void +RangePropagationLossModelTestCase::DoSetup (void) +{ + TestCase::DoSetup (); + + // Set testcase parameters + Config::SetDefault ("ns3::RangePropagationLossModel::MaxRange", DoubleValue (127.2)); +} + +void +RangePropagationLossModelTestCase::DoTeardown (void) +{ + // Restore defaults + Config::SetDefault ("ns3::RangePropagationLossModel::MaxRange", DoubleValue (250.0)); + + TestCase::DoTeardown (); +} + +void RangePropagationLossModelTestCase::DoRun (void) { - Config::SetDefault ("ns3::RangePropagationLossModel::MaxRange", DoubleValue (127.2)); Ptr a = CreateObject (); a->SetPosition (Vector (0,0,0)); Ptr b = CreateObject (); diff -r 3881cbe7fcc7 -r 3aa7dfca1d27 src/test/csma-system-test-suite.cc --- a/src/test/csma-system-test-suite.cc Mon Jun 20 17:04:42 2011 +0200 +++ b/src/test/csma-system-test-suite.cc Tue Jun 21 17:14:45 2011 +0200 @@ -165,6 +165,9 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); + virtual void DoTeardown (void); + void SinkRxNode1 (Ptr p, const Address &ad); void SinkRxNode2 (Ptr p, const Address &ad); void DropEvent (Ptr p); @@ -201,6 +204,28 @@ m_drops++; } + +void +CsmaBroadcastTestCase::DoSetup () +{ + TestCase::DoSetup(); + + // + // Set up default values for the simulation. + // + // Select DIX/Ethernet II-style encapsulation (no LLC/Snap header) + Config::SetDefault ("ns3::CsmaNetDevice::EncapsulationMode", StringValue ("Dix")); +} + +void +CsmaBroadcastTestCase::DoTeardown () +{ + // Restore defaults + // NOTE: don't, Dix is the default + + TestCase::DoTeardown (); +} + // // Example of the sending of a datagram to a broadcast address // @@ -333,12 +358,6 @@ void CsmaMulticastTestCase::DoRun (void) { - // - // Set up default values for the simulation. - // - // Select DIX/Ethernet II-style encapsulation (no LLC/Snap header) - Config::SetDefault ("ns3::CsmaNetDevice::EncapsulationMode", StringValue ("Dix")); - NodeContainer c; c.Create (5); // We will later want two subcontainers of these nodes, for the two LANs diff -r 3881cbe7fcc7 -r 3aa7dfca1d27 src/test/global-routing-test-suite.cc --- a/src/test/global-routing-test-suite.cc Mon Jun 20 17:04:42 2011 +0200 +++ b/src/test/global-routing-test-suite.cc Tue Jun 21 17:14:45 2011 +0200 @@ -55,7 +55,11 @@ private: void SinkRx (std::string path, Ptr p, const Address &address); void HandleRead (Ptr); + virtual void DoRun (void); + virtual void DoSetup (void); + virtual void DoTeardown (void); + int m_count; std::vector m_firstInterface; std::vector m_secondInterface; @@ -118,6 +122,25 @@ } } +void +DynamicGlobalRoutingTestCase::DoSetup () +{ + TestCase::DoSetup(); + + // The below value configures the default behavior of global routing. + // By default, it is disabled. To respond to interface events, set to true + Config::SetDefault ("ns3::Ipv4GlobalRouting::RespondToInterfaceEvents", BooleanValue (true)); +} + +void +DynamicGlobalRoutingTestCase::DoTeardown () +{ + // By default, it is disabled. Restore it. + Config::SetDefault ("ns3::Ipv4GlobalRouting::RespondToInterfaceEvents", BooleanValue (false)); + + TestCase::DoTeardown(); +} + // Test derived from examples/routing/dynamic-global-routing.cc // // Network topology @@ -140,10 +163,6 @@ void DynamicGlobalRoutingTestCase::DoRun (void) { - // The below value configures the default behavior of global routing. - // By default, it is disabled. To respond to interface events, set to true - Config::SetDefault ("ns3::Ipv4GlobalRouting::RespondToInterfaceEvents", BooleanValue (true)); - NodeContainer c; c.Create (7); NodeContainer n0n2 = NodeContainer (c.Get (0), c.Get (2)); diff -r 3881cbe7fcc7 -r 3aa7dfca1d27 src/test/ns3tcp/ns3tcp-cwnd-test-suite.cc --- a/src/test/ns3tcp/ns3tcp-cwnd-test-suite.cc Mon Jun 20 17:04:42 2011 +0200 +++ b/src/test/ns3tcp/ns3tcp-cwnd-test-suite.cc Tue Jun 21 17:14:45 2011 +0200 @@ -384,6 +384,9 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); + virtual void DoTeardown (void); + bool m_writeResults; class CwndEvent { @@ -419,11 +422,26 @@ } void +Ns3TcpCwndTestCase2::DoSetup (void) +{ + TestCase::DoSetup (); + + // Set up some default values for the simulation. + Config::SetDefault ("ns3::DropTailQueue::MaxPackets", UintegerValue (4)); +} + +void +Ns3TcpCwndTestCase2::DoTeardown (void) +{ + // Restore defaults + Config::SetDefault ("ns3::DropTailQueue::MaxPackets", UintegerValue (100)); + + TestCase::DoTeardown (); +} + +void Ns3TcpCwndTestCase2::DoRun (void) { - // Set up some default values for the simulation. - Config::SetDefault ("ns3::DropTailQueue::MaxPackets", UintegerValue (4)); - NodeContainer n0n1; n0n1.Create (2); diff -r 3881cbe7fcc7 -r 3aa7dfca1d27 src/test/ns3tcp/ns3tcp-loss-test-suite.cc --- a/src/test/ns3tcp/ns3tcp-loss-test-suite.cc Mon Jun 20 17:04:42 2011 +0200 +++ b/src/test/ns3tcp/ns3tcp-loss-test-suite.cc Tue Jun 21 17:14:45 2011 +0200 @@ -115,6 +115,11 @@ void Ns3TcpLossTestCase::DoSetup (void) { + Simulator::Destroy(); + + // Enable packet metadata + Packet::EnablePrinting (); + // // We expect there to be a file called ns3tcp-state-response-vectors.pcap in // response-vectors/ of this directory @@ -133,12 +138,56 @@ m_pcapFile.Open (m_pcapFilename, std::ios::in|std::ios::binary); NS_ABORT_MSG_UNLESS (m_pcapFile.GetDataLinkType () == PCAP_LINK_TYPE, "Wrong response vectors in directory"); } + + // Config + std::ostringstream tcpModel; + tcpModel << "ns3::Tcp" << m_tcpModel; + Config::SetDefault ("ns3::TcpL4Protocol::SocketType", StringValue (tcpModel.str ())); + Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1000)); + Config::SetDefault ("ns3::TcpSocket::DelAckCount", UintegerValue (1)); + + // Logging + if (m_writeLogging) + { + LogComponentEnableAll (LOG_PREFIX_FUNC); + LogComponentEnable ("TcpLossResponse", LOG_LEVEL_ALL); + LogComponentEnable ("ErrorModel", LOG_LEVEL_DEBUG); + LogComponentEnable ("TcpLossResponse", LOG_LEVEL_ALL); + LogComponentEnable ("TcpNewReno", LOG_LEVEL_INFO); + LogComponentEnable ("TcpReno", LOG_LEVEL_INFO); + LogComponentEnable ("TcpTahoe", LOG_LEVEL_INFO); + LogComponentEnable ("TcpSocketBase", LOG_LEVEL_INFO); + } + } void Ns3TcpLossTestCase::DoTeardown (void) { + // Restore Config + std::string tcpModel ("ns3::TcpNewReno"); + Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (536)); + Config::SetDefault ("ns3::TcpSocket::DelAckCount", UintegerValue (2)); + + // Restore Logging + if (m_writeLogging) + { + LogComponentDisableAll (LOG_PREFIX_FUNC); + LogComponentDisable ("TcpLossResponse", LOG_LEVEL_ALL); + LogComponentDisable ("ErrorModel", LOG_LEVEL_DEBUG); + LogComponentDisable ("TcpLossResponse", LOG_LEVEL_ALL); + LogComponentDisable ("TcpNewReno", LOG_LEVEL_INFO); + LogComponentDisable ("TcpReno", LOG_LEVEL_INFO); + LogComponentDisable ("TcpTahoe", LOG_LEVEL_INFO); + LogComponentDisable ("TcpSocketBase", LOG_LEVEL_INFO); + } + m_pcapFile.Close (); + + // Enable packet metadata + Packet::DisablePrinting (); + + Simulator::Destroy(); } void @@ -182,22 +231,29 @@ // file and see if it still does the right thing. // uint8_t expected[PCAP_SNAPLEN]; - uint32_t tsSec, tsUsec, inclLen, origLen, readLen; + uint32_t tsSec=0, tsUsec=0, inclLen=0, origLen=0, readLen=0; m_pcapFile.Read (expected, sizeof(expected), tsSec, tsUsec, inclLen, origLen, readLen); - uint8_t *actual = new uint8_t[readLen]; - p->CopyData (actual, readLen); + if (readLen != 0 && origLen != 0) + { + uint8_t *actual = new uint8_t[readLen]; + p->CopyData (actual, readLen); - uint32_t result = memcmp (actual, expected, readLen); + uint32_t result = memcmp (actual, expected, readLen); - delete [] actual; + delete [] actual; - // - // Avoid streams of errors -- only report the first. - // - if (GetErrorStatus () == false) + // + // Avoid streams of errors -- only report the first. + // + if (GetErrorStatus () == false) + { + NS_TEST_EXPECT_MSG_EQ (result, 0, "Expected data comparison error"); + } + } + else if (GetErrorStatus () == false) { - NS_TEST_EXPECT_MSG_EQ (result, 0, "Expected data comparison error"); + NS_TEST_EXPECT_MSG_GT (readLen, 0, "Unexpected packet error"); } } } @@ -282,25 +338,6 @@ // Example corresponding to simulations in the paper "Simulation-based // Comparisons of Tahoe, Reno, and SACK TCP - std::ostringstream tcpModel; - tcpModel << "ns3::Tcp" << m_tcpModel; - Config::SetDefault ("ns3::TcpL4Protocol::SocketType", - StringValue (tcpModel.str ())); - Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1000)); - Config::SetDefault ("ns3::TcpSocket::DelAckCount", UintegerValue (1)); - - if (m_writeLogging) - { - LogComponentEnableAll (LOG_PREFIX_FUNC); - LogComponentEnable ("TcpLossResponse", LOG_LEVEL_ALL); - LogComponentEnable ("ErrorModel", LOG_LEVEL_DEBUG); - LogComponentEnable ("TcpLossResponse", LOG_LEVEL_ALL); - LogComponentEnable ("TcpNewReno", LOG_LEVEL_INFO); - LogComponentEnable ("TcpReno", LOG_LEVEL_INFO); - LogComponentEnable ("TcpTahoe", LOG_LEVEL_INFO); - LogComponentEnable ("TcpSocketBase", LOG_LEVEL_INFO); - } - //////////////////////////////////////////////////////// // Topology construction // @@ -359,13 +396,6 @@ ipInterfs.GetAddress (1), servPort); - Config::Connect ("/NodeList/0/$ns3::Ipv4L3Protocol/Tx", - MakeCallback (&Ns3TcpLossTestCase::Ipv4L3Tx, this)); - - Config::ConnectWithoutContext - ("/NodeList/0/$ns3::TcpL4Protocol/SocketList/0/CongestionWindow", - MakeCallback (&Ns3TcpLossTestCase::CwndTracer, this)); - //////////////////////////////////////////////////////// // Set up loss model at node k1 // @@ -403,6 +433,13 @@ pem->SetList (sampleList); dev1.Get (1)->SetAttribute ("ReceiveErrorModel", PointerValue (pem)); + Config::Connect ("/NodeList/0/$ns3::Ipv4L3Protocol/Tx", + MakeCallback (&Ns3TcpLossTestCase::Ipv4L3Tx, this)); + + Config::ConnectWithoutContext + ("/NodeList/0/$ns3::TcpL4Protocol/SocketList/0/CongestionWindow", + MakeCallback (&Ns3TcpLossTestCase::CwndTracer, this)); + // One can toggle the comment for the following line on or off to see the // effects of finite send buffer modelling. One can also change the size of // that buffer. @@ -442,7 +479,6 @@ Ns3TcpLossTestSuite::Ns3TcpLossTestSuite () : TestSuite ("ns3-tcp-loss", SYSTEM) { - Packet::EnablePrinting (); // Enable packet metadata for all test cases AddTestCase (new Ns3TcpLossTestCase ("Tahoe", 0)); AddTestCase (new Ns3TcpLossTestCase ("Tahoe", 1)); AddTestCase (new Ns3TcpLossTestCase ("Tahoe", 2)); diff -r 3881cbe7fcc7 -r 3aa7dfca1d27 src/test/ns3tcp/ns3tcp-socket-test-suite.cc --- a/src/test/ns3tcp/ns3tcp-socket-test-suite.cc Mon Jun 20 17:04:42 2011 +0200 +++ b/src/test/ns3tcp/ns3tcp-socket-test-suite.cc Tue Jun 21 17:14:45 2011 +0200 @@ -158,6 +158,9 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); + virtual void DoTeardown (void); + bool m_writeResults; void SinkRx (std::string path, Ptr p, const Address &address); @@ -179,6 +182,22 @@ } void +Ns3TcpSocketTestCase2::DoSetup (void) +{ + TestCase::DoSetup (); + Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1000)); +} + +void +Ns3TcpSocketTestCase2::DoTeardown (void) +{ + // Restore defaults + Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (536)); + + TestCase::DoTeardown (); +} + +void Ns3TcpSocketTestCase2::DoRun (void) { uint16_t sinkPort = 50000; @@ -189,8 +208,6 @@ Time writerStopTimeObj = Seconds (writerStopTime); Time simStopTimeObj= Seconds (simStopTime); - Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1000)); - NodeContainer nodes; nodes.Create (2); Ptr n0 = nodes.Get (0); diff -r 3881cbe7fcc7 -r 3aa7dfca1d27 src/test/ns3tcp/ns3tcp-state-test-suite.cc --- a/src/test/ns3tcp/ns3tcp-state-test-suite.cc Mon Jun 20 17:04:42 2011 +0200 +++ b/src/test/ns3tcp/ns3tcp-state-test-suite.cc Tue Jun 21 17:14:45 2011 +0200 @@ -110,6 +110,11 @@ void Ns3TcpStateTestCase::DoSetup (void) { + Simulator::Destroy(); + + // Enable packet metadata + Packet::EnablePrinting (); + // // We expect there to be a file called ns3tcp-state-response-vectors.pcap in // response-vectors/ of this directory @@ -128,12 +133,56 @@ m_pcapFile.Open (m_pcapFilename, std::ios::in|std::ios::binary); NS_ABORT_MSG_UNLESS (m_pcapFile.GetDataLinkType () == PCAP_LINK_TYPE, "Wrong response vectors in directory"); } + + // Config + std::string tcpModel ("ns3::TcpNewReno"); + Config::SetDefault ("ns3::TcpL4Protocol::SocketType", StringValue (tcpModel)); + Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1000)); + Config::SetDefault ("ns3::TcpSocket::DelAckCount", UintegerValue (1)); + Config::SetDefault ("ns3::DropTailQueue::MaxPackets", UintegerValue (20)); + + // Logging + if (m_writeLogging) + { + LogComponentEnableAll (LOG_PREFIX_FUNC); + LogComponentEnable ("TcpTestCases", LOG_LEVEL_ALL); + LogComponentEnable ("ErrorModel", LOG_LEVEL_DEBUG); + LogComponentEnable ("TcpTestCases", LOG_LEVEL_ALL); + LogComponentEnable ("TcpNewReno", LOG_LEVEL_INFO); + LogComponentEnable ("TcpReno", LOG_LEVEL_INFO); + LogComponentEnable ("TcpTahoe", LOG_LEVEL_INFO); + LogComponentEnable ("TcpSocketBase", LOG_LEVEL_INFO); + } } void Ns3TcpStateTestCase::DoTeardown (void) { + // Restore Logging + if (m_writeLogging) + { + LogComponentDisableAll (LOG_PREFIX_FUNC); + LogComponentDisable ("TcpTestCases", LOG_LEVEL_ALL); + LogComponentDisable ("ErrorModel", LOG_LEVEL_DEBUG); + LogComponentDisable ("TcpTestCases", LOG_LEVEL_ALL); + LogComponentDisable ("TcpNewReno", LOG_LEVEL_INFO); + LogComponentDisable ("TcpReno", LOG_LEVEL_INFO); + LogComponentDisable ("TcpTahoe", LOG_LEVEL_INFO); + LogComponentDisable ("TcpSocketBase", LOG_LEVEL_INFO); + } + + // Restore config to usual defaults + Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (536)); + Config::SetDefault ("ns3::TcpSocket::DelAckCount", UintegerValue (2)); + Config::SetDefault ("ns3::DropTailQueue::MaxPackets", UintegerValue (100)); + // No need to restore ns3::TcpL4Protocol::SocketType, ns3::TcpNewReno is already the default + m_pcapFile.Close (); + + // Enable packet metadata + Packet::DisablePrinting (); + + Simulator::Destroy(); } void @@ -177,22 +226,29 @@ // file and see if it still does the right thing. // uint8_t expected[PCAP_SNAPLEN]; - uint32_t tsSec, tsUsec, inclLen, origLen, readLen; + uint32_t tsSec=0, tsUsec=0, inclLen=0, origLen=0, readLen=0; m_pcapFile.Read (expected, sizeof(expected), tsSec, tsUsec, inclLen, origLen, readLen); + + if (readLen != 0 && origLen != 0) + { + uint8_t *actual = new uint8_t[readLen]; + p->CopyData (actual, readLen); - uint8_t *actual = new uint8_t[readLen]; - p->CopyData (actual, readLen); + uint32_t result = memcmp (actual, expected, readLen); - uint32_t result = memcmp (actual, expected, readLen); + delete [] actual; - delete [] actual; - - // - // Avoid streams of errors -- only report the first. - // - if (GetErrorStatus () == false) + // + // Avoid streams of errors -- only report the first. + // + if (GetErrorStatus () == false) + { + NS_TEST_EXPECT_MSG_EQ (result, 0, "Expected data comparison error"); + } + } + else if (GetErrorStatus () == false) { - NS_TEST_EXPECT_MSG_EQ (result, 0, "Expected data comparison error"); + NS_TEST_EXPECT_MSG_GT (readLen, 0, "Unexpected packet error"); } } } @@ -266,29 +322,10 @@ // 10Mb/s, 0.1ms 10Mb/s, 0.1ms // n0-----------------n1-----------------n2 - std::string tcpModel ("ns3::TcpNewReno"); - - Config::SetDefault ("ns3::TcpL4Protocol::SocketType", StringValue (tcpModel)); - Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1000)); - Config::SetDefault ("ns3::TcpSocket::DelAckCount", UintegerValue (1)); - Config::SetDefault ("ns3::DropTailQueue::MaxPackets", UintegerValue (20)); - - if (m_writeLogging) - { - LogComponentEnableAll (LOG_PREFIX_FUNC); - LogComponentEnable ("TcpTestCases", LOG_LEVEL_ALL); - LogComponentEnable ("ErrorModel", LOG_LEVEL_DEBUG); - LogComponentEnable ("TcpTestCases", LOG_LEVEL_ALL); - LogComponentEnable ("TcpNewReno", LOG_LEVEL_INFO); - LogComponentEnable ("TcpReno", LOG_LEVEL_INFO); - LogComponentEnable ("TcpTahoe", LOG_LEVEL_INFO); - LogComponentEnable ("TcpSocketBase", LOG_LEVEL_INFO); - } - //////////////////////////////////////////////////////// // Topology construction // - + // Create three nodes NodeContainer n0n1; n0n1.Create (2); @@ -338,9 +375,6 @@ Simulator::ScheduleNow (&Ns3TcpStateTestCase::StartFlow, this, localSocket, ipInterfs.GetAddress (1), servPort); - Config::Connect ("/NodeList/0/$ns3::Ipv4L3Protocol/Tx", - MakeCallback (&Ns3TcpStateTestCase::Ipv4L3Tx, this)); - //////////////////////////////////////////////////////// // Set up different test cases: Lost model at node n1, different file size // @@ -411,6 +445,9 @@ errN1->SetList (dropListN1); dev1.Get (0)->SetAttribute ("ReceiveErrorModel", PointerValue (errN1)); + Config::Connect ("/NodeList/0/$ns3::Ipv4L3Protocol/Tx", + MakeCallback (&Ns3TcpStateTestCase::Ipv4L3Tx, this)); + std::ostringstream oss; oss << "tcp-state" << m_testCase << "-test-case"; if (m_writeResults) @@ -434,8 +471,6 @@ Simulator::Stop (Seconds (1000)); Simulator::Run (); Simulator::Destroy (); - - } class Ns3TcpStateTestSuite : public TestSuite @@ -447,7 +482,6 @@ Ns3TcpStateTestSuite::Ns3TcpStateTestSuite () : TestSuite ("ns3-tcp-state", SYSTEM) { - Packet::EnablePrinting (); // Enable packet metadata for all test cases AddTestCase (new Ns3TcpStateTestCase (0)); AddTestCase (new Ns3TcpStateTestCase (1)); AddTestCase (new Ns3TcpStateTestCase (2)); diff -r 3881cbe7fcc7 -r 3aa7dfca1d27 src/test/ns3wifi/wifi-interference-test-suite.cc --- a/src/test/ns3wifi/wifi-interference-test-suite.cc Mon Jun 20 17:04:42 2011 +0200 +++ b/src/test/ns3wifi/wifi-interference-test-suite.cc Tue Jun 21 17:14:45 2011 +0200 @@ -57,6 +57,9 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); + virtual void DoTeardown (void); + void ReceivePacket (Ptr socket); static void GenerateTraffic (Ptr socket, uint32_t pktSize, uint32_t pktCount, Time pktInterval); void PrintEndSync (std::string context, uint32_t dataRate, double snr, double per); @@ -65,11 +68,14 @@ double m_PER; double m_SNR; uint32_t m_DataRate; + + std::string m_phyMode; }; // Add some help text to this case to describe what it is intended to test WifiInterferenceTestCase::WifiInterferenceTestCase () : TestCase ("Test interference calculation when interfering frame exactly overlaps intended frame") + , m_phyMode ("DsssRate1Mbps") { } @@ -77,6 +83,31 @@ { } +void +WifiInterferenceTestCase::DoSetup () +{ + TestCase::DoSetup (); + + // disable fragmentation for frames below 2200 bytes + Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200")); + // turn off RTS/CTS for frames below 2200 bytes + Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200")); + // Fix non-unicast data rate to be the same as that of unicast + Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue (m_phyMode)); +} + +void +WifiInterferenceTestCase::DoTeardown () +{ + // Restore default configuration + std::string invalidWifiMode ("Invalid-WifiMode"); + Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2346")); + Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2346")); + Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue (invalidWifiMode)); + + TestCase::DoTeardown (); +} + void WifiInterferenceTestCase::ReceivePacket (Ptr socket) { @@ -131,14 +162,6 @@ // Convert to time object Time interPacketInterval = Seconds (interval); - // disable fragmentation for frames below 2200 bytes - Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200")); - // turn off RTS/CTS for frames below 2200 bytes - Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200")); - // Fix non-unicast data rate to be the same as that of unicast - Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", - StringValue (phyMode)); - NodeContainer c; c.Create (3); @@ -232,8 +255,6 @@ void WifiInterferenceTestCase::DoRun (void) { - - std::string phyMode ("DsssRate1Mbps"); double Prss = -90; // -dBm double Irss = -90; // -dBm double delta = 0; // microseconds @@ -246,17 +267,17 @@ // Compute the packet error rate (PER) when delta=0 microseconds. This // means that the interferer arrives at exactly the same time as the // intended packet - PER = WifiSimpleInterference (phyMode,Prss,Irss,delta,PpacketSize,IpacketSize,verbose,internet); + PER = WifiSimpleInterference (m_phyMode,Prss,Irss,delta,PpacketSize,IpacketSize,verbose,internet); // Now rerun this test case and compute the PER when the delta time between // arrival of the intended frame and interferer is 1 microsecond. delta = 1; - PER1 = WifiSimpleInterference (phyMode,Prss,Irss,delta,PpacketSize,IpacketSize,verbose,internet); + PER1 = WifiSimpleInterference (m_phyMode,Prss,Irss,delta,PpacketSize,IpacketSize,verbose,internet); // Now rerun this test case and compute the PER when the delta time between // arrival of the intended frame and interferer is 2 microseconds. delta = 2; - PER2 = WifiSimpleInterference (phyMode,Prss,Irss,delta,PpacketSize,IpacketSize,verbose,internet); + PER2 = WifiSimpleInterference (m_phyMode,Prss,Irss,delta,PpacketSize,IpacketSize,verbose,internet); double PERDiff1 = PER - PER1; # HG changeset patch # User cdfreire # Date 1310034624 -7200 # Node ID 891c9d1aa185973a6f839a6d7bd771b36cfa6c20 # Parent b9cfa43318dd3fe7292c91f8f234f7905098ca91 Config reset for test teardown diff -r b9cfa43318dd -r 891c9d1aa185 src/aodv/test/bug-772.cc --- a/src/aodv/test/bug-772.cc Thu Jul 07 11:47:03 2011 +0200 +++ b/src/aodv/test/bug-772.cc Thu Jul 07 12:30:24 2011 +0200 @@ -74,6 +74,7 @@ Bug772ChainTest::DoRun () { SeedManager::SetSeed (12345); + Config::SetDefault ("ns3::ArpCache::AliveTimeout", TimeValue (Seconds (1))); CreateNodes (); CreateDevices (); diff -r b9cfa43318dd -r 891c9d1aa185 src/core/model/test.cc --- a/src/core/model/test.cc Thu Jul 07 11:47:03 2011 +0200 +++ b/src/core/model/test.cc Thu Jul 07 12:30:24 2011 +0200 @@ -22,6 +22,7 @@ #include #include "ns3/simulator.h" +#include "ns3/config.h" // Set to true to enable a segmentation fault upon a test case macro test // failing (for debugging purposes) @@ -414,6 +415,13 @@ * must destroy the simulator on TestCase teardown just in case. */ Simulator::Destroy(); + + /** + * Some tests will change default configuration settings. In + * those cases, a full configuration reset is the only way to get + * back to a reproducible state. + */ + Config::Reset (); } TestSuite::TestSuite (std::string name, TestType type) # HG changeset patch # User cdfreire # Date 1310041315 -7200 # Node ID ef7992b8ef92356cf0d451ca911f0a5196ba4548 # Parent 891c9d1aa185973a6f839a6d7bd771b36cfa6c20 Teardown fix: make all teardown calls call TestCase::DoTeardown() diff -r 891c9d1aa185 -r ef7992b8ef92 src/core/test/names-test-suite.cc --- a/src/core/test/names-test-suite.cc Thu Jul 07 12:30:24 2011 +0200 +++ b/src/core/test/names-test-suite.cc Thu Jul 07 14:21:55 2011 +0200 @@ -87,6 +87,7 @@ BasicAddTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -153,6 +154,7 @@ StringContextAddTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -216,6 +218,7 @@ FullyQualifiedAddTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -282,6 +285,7 @@ RelativeAddTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -347,6 +351,7 @@ BasicRenameTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -407,6 +412,7 @@ StringContextRenameTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -467,6 +473,7 @@ FullyQualifiedRenameTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -527,6 +534,7 @@ RelativeRenameTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -587,6 +595,7 @@ FindPathTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -641,6 +650,7 @@ BasicFindTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -703,6 +713,7 @@ StringContextFindTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -765,6 +776,7 @@ FullyQualifiedFindTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -827,6 +839,7 @@ RelativeFindTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -887,6 +900,7 @@ AlternateFindTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void diff -r 891c9d1aa185 -r ef7992b8ef92 src/core/test/time-test-suite.cc --- a/src/core/test/time-test-suite.cc Thu Jul 07 12:30:24 2011 +0200 +++ b/src/core/test/time-test-suite.cc Thu Jul 07 14:21:55 2011 +0200 @@ -76,6 +76,7 @@ TimeSimpleTestCase::DoTeardown (void) { Time::SetResolution (m_originalResolution); + TestCase::DoTeardown (); } static class TimeTestSuite : public TestSuite diff -r 891c9d1aa185 -r ef7992b8ef92 src/core/test/timer-test-suite.cc --- a/src/core/test/timer-test-suite.cc Thu Jul 07 12:30:24 2011 +0200 +++ b/src/core/test/timer-test-suite.cc Thu Jul 07 14:21:55 2011 +0200 @@ -215,6 +215,7 @@ { Simulator::Run (); Simulator::Destroy (); + TestCase::DoTeardown (); } static class TimerTestSuite : public TestSuite diff -r 891c9d1aa185 -r ef7992b8ef92 src/energy/test/basic-energy-model-test.cc --- a/src/energy/test/basic-energy-model-test.cc Thu Jul 07 12:30:24 2011 +0200 +++ b/src/energy/test/basic-energy-model-test.cc Thu Jul 07 14:21:55 2011 +0200 @@ -218,7 +218,6 @@ private: void DoRun (void); void DoSetup (void); - void DoTeardown (void); /** * Callback invoked when energy is drained from source. @@ -276,18 +275,6 @@ } void -BasicEnergyDepletionTest::DoTeardown (void) -{ - // Restore defaults - std::string invalidWifiMode ("Invalid-WifiMode"); - Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2346")); - Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2346")); - Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue (invalidWifiMode)); - - TestCase::DoTeardown (); -} - -void BasicEnergyDepletionTest::DoRun (void) { /* diff -r 891c9d1aa185 -r ef7992b8ef92 src/energy/test/rv-battery-model-test.cc --- a/src/energy/test/rv-battery-model-test.cc Thu Jul 07 12:30:24 2011 +0200 +++ b/src/energy/test/rv-battery-model-test.cc Thu Jul 07 14:21:55 2011 +0200 @@ -67,11 +67,6 @@ void DoSetup (void); /** - * Restores environment after test runs - */ - void DoTeardown (void); - - /** * \param load Load value, in Amperes (A). * \param expLifetime Expected lifetime. * \return False if no error occurs. @@ -667,18 +662,6 @@ } void -BatteryLifetimeTest::DoTeardown (void) -{ - // Restore defaults - std::string invalidWifiMode ("Invalid-WifiMode"); - Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2346")); - Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2346")); - Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue (invalidWifiMode)); - - TestCase::DoTeardown (); -} - -void BatteryLifetimeTest::DoRun (void) { NS_LOG_DEBUG ("Constant load run."); diff -r 891c9d1aa185 -r ef7992b8ef92 src/internet/test/ipv4-address-generator-test-suite.cc --- a/src/internet/test/ipv4-address-generator-test-suite.cc Thu Jul 07 12:30:24 2011 +0200 +++ b/src/internet/test/ipv4-address-generator-test-suite.cc Thu Jul 07 14:21:55 2011 +0200 @@ -38,6 +38,7 @@ NetworkNumberAllocatorTestCase::DoTeardown (void) { Ipv4AddressGenerator::Reset (); + TestCase::DoTeardown (); } void NetworkNumberAllocatorTestCase::DoRun (void) @@ -117,7 +118,7 @@ AddressAllocatorTestCase::DoTeardown (void) { Ipv4AddressGenerator::Reset (); - Simulator::Destroy (); + TestCase::DoTeardown (); } @@ -138,7 +139,7 @@ NetworkAndAddressTestCase::DoTeardown (void) { Ipv4AddressGenerator::Reset (); - Simulator::Destroy (); + TestCase::DoTeardown (); } void @@ -202,6 +203,7 @@ ExampleAddressGeneratorTestCase::DoTeardown (void) { Ipv4AddressGenerator::Reset (); + TestCase::DoTeardown (); } void @@ -254,7 +256,7 @@ AddressCollisionTestCase::DoTeardown (void) { Ipv4AddressGenerator::Reset (); - Simulator::Destroy (); + TestCase::DoTeardown (); } void AddressCollisionTestCase::DoRun (void) diff -r 891c9d1aa185 -r ef7992b8ef92 src/internet/test/ipv4-address-helper-test-suite.cc --- a/src/internet/test/ipv4-address-helper-test-suite.cc Thu Jul 07 12:30:24 2011 +0200 +++ b/src/internet/test/ipv4-address-helper-test-suite.cc Thu Jul 07 14:21:55 2011 +0200 @@ -41,7 +41,7 @@ NetworkAllocatorHelperTestCase::DoTeardown (void) { Ipv4AddressGenerator::Reset (); - Simulator::Destroy (); + TestCase::DoTeardown (); } void NetworkAllocatorHelperTestCase::DoRun (void) @@ -87,7 +87,7 @@ AddressAllocatorHelperTestCase::DoTeardown (void) { Ipv4AddressGenerator::Reset (); - Simulator::Destroy (); + TestCase::DoTeardown (); } void @@ -176,7 +176,7 @@ ResetAllocatorHelperTestCase::DoTeardown (void) { Ipv4AddressGenerator::Reset (); - Simulator::Destroy (); + TestCase::DoTeardown (); } static class Ipv4AddressHelperTestSuite : public TestSuite diff -r 891c9d1aa185 -r ef7992b8ef92 src/internet/test/tcp-test.cc --- a/src/internet/test/tcp-test.cc Thu Jul 07 12:30:24 2011 +0200 +++ b/src/internet/test/tcp-test.cc Thu Jul 07 14:21:55 2011 +0200 @@ -160,7 +160,7 @@ delete [] m_sourceTxPayload; delete [] m_sourceRxPayload; delete [] m_serverRxPayload; - Simulator::Destroy (); + TestCase::DoTeardown (); } void diff -r 891c9d1aa185 -r ef7992b8ef92 src/mobility/test/ns2-mobility-helper-test-suite.cc --- a/src/mobility/test/ns2-mobility-helper-test-suite.cc Thu Jul 07 12:30:24 2011 +0200 +++ b/src/mobility/test/ns2-mobility-helper-test-suite.cc Thu Jul 07 14:21:55 2011 +0200 @@ -212,7 +212,7 @@ { Names::Clear (); std::remove (m_traceFile.c_str ()); - Simulator::Destroy (); + TestCase::DoTeardown (); } /// Go diff -r 891c9d1aa185 -r ef7992b8ef92 src/mobility/test/steady-state-random-waypoint-mobility-model-test.cc --- a/src/mobility/test/steady-state-random-waypoint-mobility-model-test.cc Thu Jul 07 12:30:24 2011 +0200 +++ b/src/mobility/test/steady-state-random-waypoint-mobility-model-test.cc Thu Jul 07 14:21:55 2011 +0200 @@ -47,6 +47,7 @@ SteadyStateRandomWaypointTest::DoTeardown (void) { mobilityStack.clear(); + TestCase::DoTeardown(); } void diff -r 891c9d1aa185 -r ef7992b8ef92 src/mobility/test/waypoint-mobility-model-test.cc --- a/src/mobility/test/waypoint-mobility-model-test.cc Thu Jul 07 12:30:24 2011 +0200 +++ b/src/mobility/test/waypoint-mobility-model-test.cc Thu Jul 07 14:21:55 2011 +0200 @@ -57,6 +57,7 @@ { mobilityStack.clear(); waypoints.clear(); + TestCase::DoTeardown(); } void diff -r 891c9d1aa185 -r ef7992b8ef92 src/network/test/pcap-file-test-suite.cc --- a/src/network/test/pcap-file-test-suite.cc Thu Jul 07 12:30:24 2011 +0200 +++ b/src/network/test/pcap-file-test-suite.cc Thu Jul 07 14:21:55 2011 +0200 @@ -114,6 +114,7 @@ WriteModeCreateTestCase::DoTeardown (void) { remove (m_testFilename.c_str ()); + TestCase::DoTeardown (); } void @@ -226,6 +227,7 @@ ReadModeCreateTestCase::DoTeardown (void) { remove (m_testFilename.c_str ()); + TestCase::DoTeardown (); } void @@ -332,6 +334,7 @@ AppendModeCreateTestCase::DoTeardown (void) { remove (m_testFilename.c_str ()); + TestCase::DoTeardown (); } void @@ -438,6 +441,7 @@ FileHeaderTestCase::DoTeardown (void) { remove (m_testFilename.c_str ()); + TestCase::DoTeardown (); } void @@ -675,6 +679,7 @@ RecordHeaderTestCase::DoTeardown (void) { remove (m_testFilename.c_str ()); + TestCase::DoTeardown (); } void @@ -972,6 +977,7 @@ void ReadFileTestCase::DoTeardown (void) { + TestCase::DoTeardown (); } const uint32_t N_KNOWN_PACKETS = 6; diff -r 891c9d1aa185 -r ef7992b8ef92 src/olsr/test/bug780-test.cc --- a/src/olsr/test/bug780-test.cc Thu Jul 07 12:30:24 2011 +0200 +++ b/src/olsr/test/bug780-test.cc Thu Jul 07 14:21:55 2011 +0200 @@ -86,17 +86,6 @@ } void -Bug780Test::DoTeardown () -{ - //sending one packets per sec - // Fix non-unicast data rate to be the same as that of unicast - Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", - StringValue ("2346")); - - TestCase::DoTeardown (); -} - -void Bug780Test::DoRun () { SeedManager::SetSeed (123); diff -r 891c9d1aa185 -r ef7992b8ef92 src/olsr/test/bug780-test.h --- a/src/olsr/test/bug780-test.h Thu Jul 07 12:30:24 2011 +0200 +++ b/src/olsr/test/bug780-test.h Thu Jul 07 14:21:55 2011 +0200 @@ -43,7 +43,6 @@ /// Go void DoRun (); void DoSetup (); - void DoTeardown (); }; } diff -r 891c9d1aa185 -r ef7992b8ef92 src/propagation/test/propagation-loss-model-test-suite.cc --- a/src/propagation/test/propagation-loss-model-test-suite.cc Thu Jul 07 12:30:24 2011 +0200 +++ b/src/propagation/test/propagation-loss-model-test-suite.cc Thu Jul 07 14:21:55 2011 +0200 @@ -43,7 +43,6 @@ private: virtual void DoRun (void); virtual void DoSetup (void); - virtual void DoTeardown (void); typedef struct { Vector m_position; @@ -78,16 +77,6 @@ } void -FriisPropagationLossModelTestCase::DoTeardown (void) -{ - // Restore defaults - Config::SetDefault ("ns3::FriisPropagationLossModel::Lambda", DoubleValue (0.0582524)); - Config::SetDefault ("ns3::FriisPropagationLossModel::SystemLoss", DoubleValue (1.0)); - - TestCase::DoTeardown (); -} - -void FriisPropagationLossModelTestCase::DoRun (void) { // The ns-3 testing manual gives more background on the values selected @@ -161,7 +150,6 @@ private: virtual void DoRun (void); virtual void DoSetup (void); - virtual void DoTeardown (void); typedef struct { @@ -198,17 +186,6 @@ } void -TwoRayGroundPropagationLossModelTestCase::DoTeardown (void) -{ - TestCase::DoTeardown (); - - // Restore defaults - Config::SetDefault ("ns3::TwoRayGroundPropagationLossModel::Lambda", DoubleValue (0.0582524)); - Config::SetDefault ("ns3::TwoRayGroundPropagationLossModel::SystemLoss", DoubleValue (1.0)); - Config::SetDefault ("ns3::TwoRayGroundPropagationLossModel::HeightAboveZ", DoubleValue (0.0)); -} - -void TwoRayGroundPropagationLossModelTestCase::DoRun (void) { // Select a reference transmit power of 17.0206 dBm @@ -308,7 +285,6 @@ private: virtual void DoRun (void); virtual void DoSetup (void); - virtual void DoTeardown (void); typedef struct { Vector m_position; @@ -340,16 +316,6 @@ } void -LogDistancePropagationLossModelTestCase::DoTeardown (void) -{ - // Restore defaults - Config::SetDefault ("ns3::LogDistancePropagationLossModel::ReferenceLoss", DoubleValue (46.6777)); - Config::SetDefault ("ns3::LogDistancePropagationLossModel::Exponent", DoubleValue (3)); - - TestCase::DoTeardown (); -} - -void LogDistancePropagationLossModelTestCase::DoRun (void) { // Select a reference transmit power @@ -461,7 +427,6 @@ private: virtual void DoRun (void); virtual void DoSetup (void); - virtual void DoTeardown (void); }; RangePropagationLossModelTestCase::RangePropagationLossModelTestCase () @@ -483,15 +448,6 @@ } void -RangePropagationLossModelTestCase::DoTeardown (void) -{ - // Restore defaults - Config::SetDefault ("ns3::RangePropagationLossModel::MaxRange", DoubleValue (250.0)); - - TestCase::DoTeardown (); -} - -void RangePropagationLossModelTestCase::DoRun (void) { Ptr a = CreateObject (); diff -r 891c9d1aa185 -r ef7992b8ef92 src/test/csma-system-test-suite.cc --- a/src/test/csma-system-test-suite.cc Thu Jul 07 12:30:24 2011 +0200 +++ b/src/test/csma-system-test-suite.cc Thu Jul 07 14:21:55 2011 +0200 @@ -166,7 +166,6 @@ private: virtual void DoRun (void); virtual void DoSetup (void); - virtual void DoTeardown (void); void SinkRxNode1 (Ptr p, const Address &ad); void SinkRxNode2 (Ptr p, const Address &ad); @@ -217,15 +216,6 @@ Config::SetDefault ("ns3::CsmaNetDevice::EncapsulationMode", StringValue ("Dix")); } -void -CsmaBroadcastTestCase::DoTeardown () -{ - // Restore defaults - // NOTE: don't, Dix is the default - - TestCase::DoTeardown (); -} - // // Example of the sending of a datagram to a broadcast address // diff -r 891c9d1aa185 -r ef7992b8ef92 src/test/error-model-test-suite.cc --- a/src/test/error-model-test-suite.cc Thu Jul 07 12:30:24 2011 +0200 +++ b/src/test/error-model-test-suite.cc Thu Jul 07 14:21:55 2011 +0200 @@ -81,6 +81,9 @@ // Set some arbitrary deterministic values SeedManager::SetSeed (7); SeedManager::SetRun (5); + + m_count = 0; + m_drops = 0; Ptr a = CreateObject (); Ptr b = CreateObject (); diff -r 891c9d1aa185 -r ef7992b8ef92 src/test/global-routing-test-suite.cc --- a/src/test/global-routing-test-suite.cc Thu Jul 07 12:30:24 2011 +0200 +++ b/src/test/global-routing-test-suite.cc Thu Jul 07 14:21:55 2011 +0200 @@ -58,7 +58,6 @@ virtual void DoRun (void); virtual void DoSetup (void); - virtual void DoTeardown (void); int m_count; std::vector m_firstInterface; @@ -132,15 +131,6 @@ Config::SetDefault ("ns3::Ipv4GlobalRouting::RespondToInterfaceEvents", BooleanValue (true)); } -void -DynamicGlobalRoutingTestCase::DoTeardown () -{ - // By default, it is disabled. Restore it. - Config::SetDefault ("ns3::Ipv4GlobalRouting::RespondToInterfaceEvents", BooleanValue (false)); - - TestCase::DoTeardown(); -} - // Test derived from examples/routing/dynamic-global-routing.cc // // Network topology diff -r 891c9d1aa185 -r ef7992b8ef92 src/test/ns3tcp/ns3tcp-cwnd-test-suite.cc --- a/src/test/ns3tcp/ns3tcp-cwnd-test-suite.cc Thu Jul 07 12:30:24 2011 +0200 +++ b/src/test/ns3tcp/ns3tcp-cwnd-test-suite.cc Thu Jul 07 14:21:55 2011 +0200 @@ -385,7 +385,6 @@ private: virtual void DoRun (void); virtual void DoSetup (void); - virtual void DoTeardown (void); bool m_writeResults; @@ -431,15 +430,6 @@ } void -Ns3TcpCwndTestCase2::DoTeardown (void) -{ - // Restore defaults - Config::SetDefault ("ns3::DropTailQueue::MaxPackets", UintegerValue (100)); - - TestCase::DoTeardown (); -} - -void Ns3TcpCwndTestCase2::DoRun (void) { NodeContainer n0n1; diff -r 891c9d1aa185 -r ef7992b8ef92 src/test/ns3tcp/ns3tcp-interop-test-suite.cc --- a/src/test/ns3tcp/ns3tcp-interop-test-suite.cc Thu Jul 07 12:30:24 2011 +0200 +++ b/src/test/ns3tcp/ns3tcp-interop-test-suite.cc Thu Jul 07 14:21:55 2011 +0200 @@ -128,6 +128,7 @@ Ns3TcpInteroperabilityTestCase::DoTeardown (void) { m_pcapFile.Close (); + TestCase::DoTeardown (); } void diff -r 891c9d1aa185 -r ef7992b8ef92 src/test/ns3tcp/ns3tcp-loss-test-suite.cc --- a/src/test/ns3tcp/ns3tcp-loss-test-suite.cc Thu Jul 07 12:30:24 2011 +0200 +++ b/src/test/ns3tcp/ns3tcp-loss-test-suite.cc Thu Jul 07 14:21:55 2011 +0200 @@ -164,11 +164,6 @@ void Ns3TcpLossTestCase::DoTeardown (void) { - // Restore Config - std::string tcpModel ("ns3::TcpNewReno"); - Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (536)); - Config::SetDefault ("ns3::TcpSocket::DelAckCount", UintegerValue (2)); - // Restore Logging if (m_writeLogging) { @@ -187,7 +182,7 @@ // Enable packet metadata Packet::DisablePrinting (); - Simulator::Destroy(); + TestCase::DoTeardown (); } void diff -r 891c9d1aa185 -r ef7992b8ef92 src/test/ns3tcp/ns3tcp-socket-test-suite.cc --- a/src/test/ns3tcp/ns3tcp-socket-test-suite.cc Thu Jul 07 12:30:24 2011 +0200 +++ b/src/test/ns3tcp/ns3tcp-socket-test-suite.cc Thu Jul 07 14:21:55 2011 +0200 @@ -159,7 +159,6 @@ private: virtual void DoRun (void); virtual void DoSetup (void); - virtual void DoTeardown (void); bool m_writeResults; @@ -189,15 +188,6 @@ } void -Ns3TcpSocketTestCase2::DoTeardown (void) -{ - // Restore defaults - Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (536)); - - TestCase::DoTeardown (); -} - -void Ns3TcpSocketTestCase2::DoRun (void) { uint16_t sinkPort = 50000; diff -r 891c9d1aa185 -r ef7992b8ef92 src/test/ns3tcp/ns3tcp-state-test-suite.cc --- a/src/test/ns3tcp/ns3tcp-state-test-suite.cc Thu Jul 07 12:30:24 2011 +0200 +++ b/src/test/ns3tcp/ns3tcp-state-test-suite.cc Thu Jul 07 14:21:55 2011 +0200 @@ -171,18 +171,12 @@ LogComponentDisable ("TcpSocketBase", LOG_LEVEL_INFO); } - // Restore config to usual defaults - Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (536)); - Config::SetDefault ("ns3::TcpSocket::DelAckCount", UintegerValue (2)); - Config::SetDefault ("ns3::DropTailQueue::MaxPackets", UintegerValue (100)); - // No need to restore ns3::TcpL4Protocol::SocketType, ns3::TcpNewReno is already the default - m_pcapFile.Close (); // Enable packet metadata Packet::DisablePrinting (); - Simulator::Destroy(); + TestCase::DoTeardown (); } void diff -r 891c9d1aa185 -r ef7992b8ef92 src/test/ns3wifi/wifi-interference-test-suite.cc --- a/src/test/ns3wifi/wifi-interference-test-suite.cc Thu Jul 07 12:30:24 2011 +0200 +++ b/src/test/ns3wifi/wifi-interference-test-suite.cc Thu Jul 07 14:21:55 2011 +0200 @@ -58,7 +58,6 @@ private: virtual void DoRun (void); virtual void DoSetup (void); - virtual void DoTeardown (void); void ReceivePacket (Ptr socket); static void GenerateTraffic (Ptr socket, uint32_t pktSize, uint32_t pktCount, Time pktInterval); @@ -96,18 +95,6 @@ Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue (m_phyMode)); } -void -WifiInterferenceTestCase::DoTeardown () -{ - // Restore default configuration - std::string invalidWifiMode ("Invalid-WifiMode"); - Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2346")); - Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2346")); - Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue (invalidWifiMode)); - - TestCase::DoTeardown (); -} - void WifiInterferenceTestCase::ReceivePacket (Ptr socket) { # HG changeset patch # User cdfreire@antar.inria.fr # Date 1310395426 -7200 # Node ID 5838cba3783a9ef28447b879f845d0fae2a959f4 # Parent 52b9c759b9dd9b934563e41519daaeea1e37548b RNG fix: * TestSuite: DoSetup and DoTeardown save/restore RNG state, to isolate test suites - NOTE: it should be done per-case, not per-suite, but some test cases in some suites depend on RNG state set by previous cases. diff -r 52b9c759b9dd -r 5838cba3783a src/aodv/test/aodv-regression.cc --- a/src/aodv/test/aodv-regression.cc Wed Jul 13 10:02:50 2011 +0200 +++ b/src/aodv/test/aodv-regression.cc Mon Jul 11 16:43:46 2011 +0200 @@ -67,6 +67,14 @@ // Ping loopback test case AddTestCase (new LoopbackTestCase ()); } + + virtual void DoSetup (void) + { + TestSuite::DoSetup(); + + // Set a reproducible random seed + SeedManager::SetSeed(12345); + } } g_aodvRegressionTestSuite; @@ -92,7 +100,6 @@ void ChainRegressionTest::DoRun () { - SeedManager::SetSeed (12345); Config::SetDefault ("ns3::ArpCache::AliveTimeout", TimeValue (m_arpAliveTimeout)); CreateNodes (); diff -r 52b9c759b9dd -r 5838cba3783a src/core/model/test.cc --- a/src/core/model/test.cc Wed Jul 13 10:02:50 2011 +0200 +++ b/src/core/model/test.cc Mon Jul 11 16:43:46 2011 +0200 @@ -681,6 +681,17 @@ void TestSuite::DoSetup (void) { + /* + * Preserve global RNG state (RngStream contains process-wide side effects) + */ + m_rngRunBackup = SeedManager::GetRun(); + m_rngSeedBackup = SeedManager::GetSeed(); + + /* + * Reset RNG state (in case the testing framework changed it somehow between runs) + */ + SeedManager::SetRun(m_rngRunBackup); + SeedManager::SetSeed(m_rngSeedBackup); } void @@ -719,6 +730,11 @@ void TestSuite::DoTeardown (void) { + /* + * Restore global RNG state + */ + SeedManager::SetRun(m_rngRunBackup); + SeedManager::SetSeed(m_rngSeedBackup); } class TestRunnerImpl diff -r 52b9c759b9dd -r 5838cba3783a src/core/model/test.h --- a/src/core/model/test.h Wed Jul 13 10:02:50 2011 +0200 +++ b/src/core/model/test.h Mon Jul 11 16:43:46 2011 +0200 @@ -29,6 +29,7 @@ #include #include "ns3/system-wall-clock-ms.h" +#include "ns3/random-variable.h" extern bool gBreakOnFailure; @@ -1276,6 +1277,15 @@ bool m_error; TestType m_type; + // Backup of process-wide RNG state + // FIXME: This *should* be done per-testcase, but current test cases + // depend have cases where they depend on RNG state resulting from + // previous runs within a TestSuite (like routing-aodv-regression), + // so in order not to break them, we do not reset RNG state between + // test cases, only between tests suites. + uint32_t m_rngSeedBackup; + uint32_t m_rngRunBackup; + typedef std::vector TestCaseVector_t; TestCaseVector_t m_tests; }; # HG changeset patch # User cdfreire # Date 1310561119 -7200 # Node ID d210b6af8fd0e86145c9e30a9c064173cc66d65e # Parent 50cfaed380dcb466ef4e4ed4cd856488a223c41a Final fix in test isolation: - fix TestSuite::DoSetup() to explicitly clear configuration before running - just in case diff -r 50cfaed380dc -r d210b6af8fd0 src/core/model/test.cc --- a/src/core/model/test.cc Wed Jul 13 13:44:16 2011 +0200 +++ b/src/core/model/test.cc Wed Jul 13 14:45:19 2011 +0200 @@ -681,6 +681,11 @@ void TestSuite::DoSetup (void) { + /* + * Ensure repeatable state, reset all configuration settings to their defaults + */ + Config::Reset (); + /* * Preserve global RNG state (RngStream contains process-wide side effects) */ # HG changeset patch # User cdfreire # Date 1310572735 -7200 # Node ID 6bc7f45725ed001cff33fa663fa902a67488571e # Parent 4f5fb52fde54d18585d9806e27450d8bf1908be4 * The test framework now assures repeatable conditions within test cases, by: - Destroying the simulator at base TestCase::DoTeardown/Setup - Resetting configuration (attribute defaults and global values) at various points (TestCase::DoTeardown, TestSuite::DoSetup) - Saving/Restoring the RNG state at TestSuite::DoSetup/Teardown (I tried per TestCase, but some test cases depend on RNG state set by previous test cases, sorting that out would have been a LOT more work) PCAP traces need to be re-generated diff -r 4f5fb52fde54 -r 6bc7f45725ed src/aodv/test/aodv-regression.cc --- a/src/aodv/test/aodv-regression.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/aodv/test/aodv-regression.cc Wed Jul 13 17:58:55 2011 +0200 @@ -67,6 +67,14 @@ // Ping loopback test case AddTestCase (new LoopbackTestCase ()); } + + virtual void DoSetup (void) + { + TestSuite::DoSetup(); + + // Set a reproducible random seed + SeedManager::SetSeed(12345); + } } g_aodvRegressionTestSuite; @@ -92,7 +100,6 @@ void ChainRegressionTest::DoRun () { - SeedManager::SetSeed (12345); Config::SetDefault ("ns3::ArpCache::AliveTimeout", TimeValue (m_arpAliveTimeout)); CreateNodes (); diff -r 4f5fb52fde54 -r 6bc7f45725ed src/aodv/test/bug-772.cc --- a/src/aodv/test/bug-772.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/aodv/test/bug-772.cc Wed Jul 13 17:58:55 2011 +0200 @@ -74,6 +74,7 @@ Bug772ChainTest::DoRun () { SeedManager::SetSeed (12345); + Config::SetDefault ("ns3::ArpCache::AliveTimeout", TimeValue (Seconds (1))); CreateNodes (); CreateDevices (); diff -r 4f5fb52fde54 -r 6bc7f45725ed src/core/model/test.cc --- a/src/core/model/test.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/core/model/test.cc Wed Jul 13 17:58:55 2011 +0200 @@ -21,6 +21,9 @@ #include "abort.h" #include +#include "ns3/simulator.h" +#include "ns3/config.h" + // Set to true to enable a segmentation fault upon a test case macro test // failing (for debugging purposes) bool gBreakOnFailure = false; @@ -395,11 +398,29 @@ void TestCase::DoSetup (void) { + /* + * Ensure a clean execution environment + */ + Simulator::Destroy(); } void TestCase::DoTeardown (void) { + /* + * Most tests will destroy their simulators when successful, + * but on failure, they tend to leave the simulator alive. + * This can be a problem for subsequent test runs, so we + * must destroy the simulator on TestCase teardown just in case. + */ + Simulator::Destroy(); + + /** + * Some tests will change default configuration settings. In + * those cases, a full configuration reset is the only way to get + * back to a reproducible state. + */ + Config::Reset (); } TestSuite::TestSuite (std::string name, TestType type) @@ -659,6 +680,22 @@ void TestSuite::DoSetup (void) { + /* + * Ensure repeatable state, reset all configuration settings to their defaults + */ + Config::Reset (); + + /* + * Preserve global RNG state (RngStream contains process-wide side effects) + */ + m_rngRunBackup = SeedManager::GetRun(); + m_rngSeedBackup = SeedManager::GetSeed(); + + /* + * Reset RNG state (in case the testing framework changed it somehow between runs) + */ + SeedManager::SetRun(m_rngRunBackup); + SeedManager::SetSeed(m_rngSeedBackup); } void @@ -697,6 +734,11 @@ void TestSuite::DoTeardown (void) { + /* + * Restore global RNG state + */ + SeedManager::SetRun(m_rngRunBackup); + SeedManager::SetSeed(m_rngSeedBackup); } class TestRunnerImpl diff -r 4f5fb52fde54 -r 6bc7f45725ed src/core/model/test.h --- a/src/core/model/test.h Mon Jul 11 18:15:52 2011 +0200 +++ b/src/core/model/test.h Wed Jul 13 17:58:55 2011 +0200 @@ -29,6 +29,7 @@ #include #include "ns3/system-wall-clock-ms.h" +#include "ns3/random-variable.h" extern bool gBreakOnFailure; @@ -1276,6 +1277,15 @@ bool m_error; TestType m_type; + // Backup of process-wide RNG state + // FIXME: This *should* be done per-testcase, but current test cases + // depend have cases where they depend on RNG state resulting from + // previous runs within a TestSuite (like routing-aodv-regression), + // so in order not to break them, we do not reset RNG state between + // test cases, only between tests suites. + uint32_t m_rngSeedBackup; + uint32_t m_rngRunBackup; + typedef std::vector TestCaseVector_t; TestCaseVector_t m_tests; }; diff -r 4f5fb52fde54 -r 6bc7f45725ed src/core/test/names-test-suite.cc --- a/src/core/test/names-test-suite.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/core/test/names-test-suite.cc Wed Jul 13 17:58:55 2011 +0200 @@ -87,6 +87,7 @@ BasicAddTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -153,6 +154,7 @@ StringContextAddTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -216,6 +218,7 @@ FullyQualifiedAddTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -282,6 +285,7 @@ RelativeAddTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -347,6 +351,7 @@ BasicRenameTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -407,6 +412,7 @@ StringContextRenameTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -467,6 +473,7 @@ FullyQualifiedRenameTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -527,6 +534,7 @@ RelativeRenameTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -587,6 +595,7 @@ FindPathTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -641,6 +650,7 @@ BasicFindTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -703,6 +713,7 @@ StringContextFindTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -765,6 +776,7 @@ FullyQualifiedFindTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -827,6 +839,7 @@ RelativeFindTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -887,6 +900,7 @@ AlternateFindTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void diff -r 4f5fb52fde54 -r 6bc7f45725ed src/core/test/time-test-suite.cc --- a/src/core/test/time-test-suite.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/core/test/time-test-suite.cc Wed Jul 13 17:58:55 2011 +0200 @@ -76,6 +76,7 @@ TimeSimpleTestCase::DoTeardown (void) { Time::SetResolution (m_originalResolution); + TestCase::DoTeardown (); } static class TimeTestSuite : public TestSuite diff -r 4f5fb52fde54 -r 6bc7f45725ed src/core/test/timer-test-suite.cc --- a/src/core/test/timer-test-suite.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/core/test/timer-test-suite.cc Wed Jul 13 17:58:55 2011 +0200 @@ -215,6 +215,7 @@ { Simulator::Run (); Simulator::Destroy (); + TestCase::DoTeardown (); } static class TimerTestSuite : public TestSuite diff -r 4f5fb52fde54 -r 6bc7f45725ed src/energy/test/basic-energy-model-test.cc --- a/src/energy/test/basic-energy-model-test.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/energy/test/basic-energy-model-test.cc Wed Jul 13 17:58:55 2011 +0200 @@ -217,6 +217,7 @@ private: void DoRun (void); + void DoSetup (void); /** * Callback invoked when energy is drained from source. @@ -238,11 +239,13 @@ double m_simTimeS; // maximum simulation time, in seconds double m_timeStepS; // simulation time step size, in seconds double m_updateIntervalS; // update interval of each device model + std::string m_phyMode; }; BasicEnergyDepletionTest::BasicEnergyDepletionTest () : TestCase ("Basic energy model energy depletion test case") + , m_phyMode ("DsssRate1Mbps") { m_numOfNodes = 10; m_callbackCount = 0; @@ -256,6 +259,22 @@ } void +BasicEnergyDepletionTest::DoSetup (void) +{ + TestCase::DoSetup (); + + // disable fragmentation for frames below 2200 bytes + Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", + StringValue ("2200")); + // turn off RTS/CTS for frames below 2200 bytes + Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", + StringValue ("2200")); + // Fix non-unicast data rate to be the same as that of unicast + Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", + StringValue (m_phyMode)); +} + +void BasicEnergyDepletionTest::DoRun (void) { /* @@ -287,18 +306,6 @@ NodeContainer c; c.Create (m_numOfNodes); - std::string phyMode ("DsssRate1Mbps"); - - // disable fragmentation for frames below 2200 bytes - Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", - StringValue ("2200")); - // turn off RTS/CTS for frames below 2200 bytes - Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", - StringValue ("2200")); - // Fix non-unicast data rate to be the same as that of unicast - Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", - StringValue (phyMode)); - // install YansWifiPhy WifiHelper wifi; wifi.SetStandard (WIFI_PHY_STANDARD_80211b); @@ -319,8 +326,8 @@ // Add a non-QoS upper MAC, and disable rate control NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", - "DataMode", StringValue (phyMode), - "ControlMode", StringValue (phyMode)); + "DataMode", StringValue (m_phyMode), + "ControlMode", StringValue (m_phyMode)); // Set it to ad-hoc mode wifiMac.SetType ("ns3::AdhocWifiMac"); NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c); diff -r 4f5fb52fde54 -r 6bc7f45725ed src/energy/test/rv-battery-model-test.cc --- a/src/energy/test/rv-battery-model-test.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/energy/test/rv-battery-model-test.cc Wed Jul 13 17:58:55 2011 +0200 @@ -57,13 +57,16 @@ void CreateLoadProfiles (void); /** - * \returns False if no error occurs. - * * Runs test. */ void DoRun (void); /** + * Sets up test configuration + */ + void DoSetup (void); + + /** * \param load Load value, in Amperes (A). * \param expLifetime Expected lifetime. * \return False if no error occurs. @@ -99,14 +102,19 @@ std::vector m_loadProfiles; double m_alpha; double m_beta; + std::string m_phyMode; }; BatteryLifetimeTest::BatteryLifetimeTest () : TestCase ("RV battery model battery lifetime test case.") + , m_phyMode ("DsssRate1Mbps") { // Itsy battery m_alpha = 35220; m_beta = 0.637; + + // create load profiles for variable load test + CreateLoadProfiles (); } BatteryLifetimeTest::~BatteryLifetimeTest () @@ -638,10 +646,30 @@ } void +BatteryLifetimeTest::DoSetup (void) +{ + TestCase::DoSetup (); + + // disable fragmentation for frames below 2200 bytes + Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", + StringValue ("2200")); + // turn off RTS/CTS for frames below 2200 bytes + Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", + StringValue ("2200")); + // Fix non-unicast data rate to be the same as that of unicast + Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", + StringValue (m_phyMode)); +} + +void BatteryLifetimeTest::DoRun (void) { NS_LOG_DEBUG ("Constant load run."); + // set constant load test parameters + m_alpha = 35220; + m_beta = 0.637; + // 640mA NS_TEST_ASSERT_MSG_EQ (ConstantLoadTest (0.640, Seconds (2844.0)), false, "Problems with constant load test (640mA)."); // 320mA @@ -653,9 +681,6 @@ // 32mA NS_TEST_ASSERT_MSG_EQ (ConstantLoadTest (0.032, Seconds (65580.0)), false, "Problems with constant load test (32)."); - // create load profiles for variable load test - CreateLoadProfiles (); - // variable load with Itsy battery NS_LOG_DEBUG ("\n\nItsy"); m_alpha = 35220; @@ -696,18 +721,6 @@ NodeContainer c; c.Create (1); - std::string phyMode ("DsssRate1Mbps"); - - // disable fragmentation for frames below 2200 bytes - Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", - StringValue ("2200")); - // turn off RTS/CTS for frames below 2200 bytes - Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", - StringValue ("2200")); - // Fix non-unicast data rate to be the same as that of unicast - Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", - StringValue (phyMode)); - // install YansWifiPhy WifiHelper wifi; wifi.SetStandard (WIFI_PHY_STANDARD_80211b); @@ -728,8 +741,8 @@ // Add a non-QoS upper MAC, and disable rate control NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", - "DataMode", StringValue (phyMode), - "ControlMode", StringValue (phyMode)); + "DataMode", StringValue (m_phyMode), + "ControlMode", StringValue (m_phyMode)); // Set it to ad-hoc mode wifiMac.SetType ("ns3::AdhocWifiMac"); NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c); @@ -759,7 +772,7 @@ NS_LOG_DEBUG ("Expected lifetime = " << expLifetime.GetSeconds () << "s"); NS_LOG_DEBUG ("Actual lifetime = " << actualLifetime.GetSeconds () << "s"); - + NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL (actualLifetime, expLifetime, "Incorrect lifetime!"); /* NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL (actualLifetime.GetSeconds () / 60, @@ -783,18 +796,6 @@ NodeContainer c; c.Create (1); - std::string phyMode ("DsssRate1Mbps"); - - // disable fragmentation for frames below 2200 bytes - Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", - StringValue ("2200")); - // turn off RTS/CTS for frames below 2200 bytes - Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", - StringValue ("2200")); - // Fix non-unicast data rate to be the same as that of unicast - Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", - StringValue (phyMode)); - // install YansWifiPhy WifiHelper wifi; wifi.SetStandard (WIFI_PHY_STANDARD_80211b); @@ -815,8 +816,8 @@ // Add a non-QoS upper MAC, and disable rate control NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", - "DataMode", StringValue (phyMode), - "ControlMode", StringValue (phyMode)); + "DataMode", StringValue (m_phyMode), + "ControlMode", StringValue (m_phyMode)); // Set it to ad-hoc mode wifiMac.SetType ("ns3::AdhocWifiMac"); NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c); diff -r 4f5fb52fde54 -r 6bc7f45725ed src/internet/test/ipv4-address-generator-test-suite.cc --- a/src/internet/test/ipv4-address-generator-test-suite.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/internet/test/ipv4-address-generator-test-suite.cc Wed Jul 13 17:58:55 2011 +0200 @@ -38,6 +38,7 @@ NetworkNumberAllocatorTestCase::DoTeardown (void) { Ipv4AddressGenerator::Reset (); + TestCase::DoTeardown (); } void NetworkNumberAllocatorTestCase::DoRun (void) @@ -117,7 +118,7 @@ AddressAllocatorTestCase::DoTeardown (void) { Ipv4AddressGenerator::Reset (); - Simulator::Destroy (); + TestCase::DoTeardown (); } @@ -138,7 +139,7 @@ NetworkAndAddressTestCase::DoTeardown (void) { Ipv4AddressGenerator::Reset (); - Simulator::Destroy (); + TestCase::DoTeardown (); } void @@ -202,6 +203,7 @@ ExampleAddressGeneratorTestCase::DoTeardown (void) { Ipv4AddressGenerator::Reset (); + TestCase::DoTeardown (); } void @@ -254,7 +256,7 @@ AddressCollisionTestCase::DoTeardown (void) { Ipv4AddressGenerator::Reset (); - Simulator::Destroy (); + TestCase::DoTeardown (); } void AddressCollisionTestCase::DoRun (void) diff -r 4f5fb52fde54 -r 6bc7f45725ed src/internet/test/ipv4-address-helper-test-suite.cc --- a/src/internet/test/ipv4-address-helper-test-suite.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/internet/test/ipv4-address-helper-test-suite.cc Wed Jul 13 17:58:55 2011 +0200 @@ -41,7 +41,7 @@ NetworkAllocatorHelperTestCase::DoTeardown (void) { Ipv4AddressGenerator::Reset (); - Simulator::Destroy (); + TestCase::DoTeardown (); } void NetworkAllocatorHelperTestCase::DoRun (void) @@ -87,7 +87,7 @@ AddressAllocatorHelperTestCase::DoTeardown (void) { Ipv4AddressGenerator::Reset (); - Simulator::Destroy (); + TestCase::DoTeardown (); } void @@ -176,7 +176,7 @@ ResetAllocatorHelperTestCase::DoTeardown (void) { Ipv4AddressGenerator::Reset (); - Simulator::Destroy (); + TestCase::DoTeardown (); } static class Ipv4AddressHelperTestSuite : public TestSuite diff -r 4f5fb52fde54 -r 6bc7f45725ed src/internet/test/tcp-test.cc --- a/src/internet/test/tcp-test.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/internet/test/tcp-test.cc Wed Jul 13 17:58:55 2011 +0200 @@ -160,7 +160,7 @@ delete [] m_sourceTxPayload; delete [] m_sourceRxPayload; delete [] m_serverRxPayload; - Simulator::Destroy (); + TestCase::DoTeardown (); } void diff -r 4f5fb52fde54 -r 6bc7f45725ed src/mobility/test/ns2-mobility-helper-test-suite.cc --- a/src/mobility/test/ns2-mobility-helper-test-suite.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/mobility/test/ns2-mobility-helper-test-suite.cc Wed Jul 13 17:58:55 2011 +0200 @@ -204,6 +204,7 @@ void DoSetup () { + Simulator::Destroy(); CreateNodes (); } @@ -211,7 +212,7 @@ { Names::Clear (); std::remove (m_traceFile.c_str ()); - Simulator::Destroy (); + TestCase::DoTeardown (); } /// Go diff -r 4f5fb52fde54 -r 6bc7f45725ed src/mobility/test/steady-state-random-waypoint-mobility-model-test.cc --- a/src/mobility/test/steady-state-random-waypoint-mobility-model-test.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/mobility/test/steady-state-random-waypoint-mobility-model-test.cc Wed Jul 13 17:58:55 2011 +0200 @@ -47,6 +47,7 @@ SteadyStateRandomWaypointTest::DoTeardown (void) { mobilityStack.clear(); + TestCase::DoTeardown(); } void diff -r 4f5fb52fde54 -r 6bc7f45725ed src/mobility/test/waypoint-mobility-model-test.cc --- a/src/mobility/test/waypoint-mobility-model-test.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/mobility/test/waypoint-mobility-model-test.cc Wed Jul 13 17:58:55 2011 +0200 @@ -57,6 +57,7 @@ { mobilityStack.clear(); waypoints.clear(); + TestCase::DoTeardown(); } void diff -r 4f5fb52fde54 -r 6bc7f45725ed src/network/test/pcap-file-test-suite.cc --- a/src/network/test/pcap-file-test-suite.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/network/test/pcap-file-test-suite.cc Wed Jul 13 17:58:55 2011 +0200 @@ -114,6 +114,7 @@ WriteModeCreateTestCase::DoTeardown (void) { remove (m_testFilename.c_str ()); + TestCase::DoTeardown (); } void @@ -226,6 +227,7 @@ ReadModeCreateTestCase::DoTeardown (void) { remove (m_testFilename.c_str ()); + TestCase::DoTeardown (); } void @@ -332,6 +334,7 @@ AppendModeCreateTestCase::DoTeardown (void) { remove (m_testFilename.c_str ()); + TestCase::DoTeardown (); } void @@ -438,6 +441,7 @@ FileHeaderTestCase::DoTeardown (void) { remove (m_testFilename.c_str ()); + TestCase::DoTeardown (); } void @@ -675,6 +679,7 @@ RecordHeaderTestCase::DoTeardown (void) { remove (m_testFilename.c_str ()); + TestCase::DoTeardown (); } void @@ -972,6 +977,7 @@ void ReadFileTestCase::DoTeardown (void) { + TestCase::DoTeardown (); } const uint32_t N_KNOWN_PACKETS = 6; diff -r 4f5fb52fde54 -r 6bc7f45725ed src/olsr/test/bug780-test.cc --- a/src/olsr/test/bug780-test.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/olsr/test/bug780-test.cc Wed Jul 13 17:58:55 2011 +0200 @@ -75,6 +75,17 @@ } void +Bug780Test::DoSetup () +{ + TestCase::DoSetup (); + + //sending one packets per sec + // Fix non-unicast data rate to be the same as that of unicast + Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", + StringValue ("400")); +} + +void Bug780Test::DoRun () { SeedManager::SetSeed (123); @@ -97,11 +108,6 @@ double SimTime = 200.0; std::string phyMode ("DsssRate1Mbps"); - //sending one packets per sec - // Fix non-unicast data rate to be the same as that of unicast - Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", - StringValue ("400")); - NodeContainer adhocNodes; adhocNodes.Create (nWifis); diff -r 4f5fb52fde54 -r 6bc7f45725ed src/olsr/test/bug780-test.h --- a/src/olsr/test/bug780-test.h Mon Jul 11 18:15:52 2011 +0200 +++ b/src/olsr/test/bug780-test.h Wed Jul 13 17:58:55 2011 +0200 @@ -43,6 +43,7 @@ void CheckResults (); /// Go void DoRun (); + void DoSetup (); }; } diff -r 4f5fb52fde54 -r 6bc7f45725ed src/propagation/test/propagation-loss-model-test-suite.cc --- a/src/propagation/test/propagation-loss-model-test-suite.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/propagation/test/propagation-loss-model-test-suite.cc Wed Jul 13 17:58:55 2011 +0200 @@ -42,6 +42,7 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); typedef struct { Vector m_position; @@ -63,14 +64,23 @@ } void -FriisPropagationLossModelTestCase::DoRun (void) +FriisPropagationLossModelTestCase::DoSetup (void) { + TestCase::DoSetup (); + // The ns-3 testing manual gives more background on the values selected // for this test. First, set a few defaults. // wavelength at 2.4 GHz is 0.125m Config::SetDefault ("ns3::FriisPropagationLossModel::Lambda", DoubleValue (0.125)); Config::SetDefault ("ns3::FriisPropagationLossModel::SystemLoss", DoubleValue (1.0)); +} + +void +FriisPropagationLossModelTestCase::DoRun (void) +{ + // The ns-3 testing manual gives more background on the values selected + // for this test. // Select a reference transmit power // Pt = 10^(17.0206/10)/10^3 = .05035702 W @@ -139,6 +149,7 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); typedef struct { @@ -162,15 +173,21 @@ } void -TwoRayGroundPropagationLossModelTestCase::DoRun (void) +TwoRayGroundPropagationLossModelTestCase::DoSetup (void) { + TestCase::DoSetup (); + // wavelength at 2.4 GHz is 0.125m Config::SetDefault ("ns3::TwoRayGroundPropagationLossModel::Lambda", DoubleValue (0.125)); Config::SetDefault ("ns3::TwoRayGroundPropagationLossModel::SystemLoss", DoubleValue (1.0)); // set antenna height to 1.5m above z coordinate Config::SetDefault ("ns3::TwoRayGroundPropagationLossModel::HeightAboveZ", DoubleValue (1.5)); +} +void +TwoRayGroundPropagationLossModelTestCase::DoRun (void) +{ // Select a reference transmit power of 17.0206 dBm // Pt = 10^(17.0206/10)/10^3 = .05035702 W double txPowerW = 0.05035702; @@ -267,6 +284,7 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); typedef struct { Vector m_position; @@ -288,12 +306,18 @@ } void -LogDistancePropagationLossModelTestCase::DoRun (void) +LogDistancePropagationLossModelTestCase::DoSetup (void) { + TestCase::DoSetup (); + // reference loss at 2.4 GHz is 40.045997 Config::SetDefault ("ns3::LogDistancePropagationLossModel::ReferenceLoss", DoubleValue (40.045997)); Config::SetDefault ("ns3::LogDistancePropagationLossModel::Exponent", DoubleValue (3)); +} +void +LogDistancePropagationLossModelTestCase::DoRun (void) +{ // Select a reference transmit power // Pt = 10^(17.0206/10)/10^3 = .05035702 W double txPowerW = 0.05035702; @@ -402,6 +426,7 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); }; RangePropagationLossModelTestCase::RangePropagationLossModelTestCase () @@ -414,9 +439,17 @@ } void +RangePropagationLossModelTestCase::DoSetup (void) +{ + TestCase::DoSetup (); + + // Set testcase parameters + Config::SetDefault ("ns3::RangePropagationLossModel::MaxRange", DoubleValue (127.2)); +} + +void RangePropagationLossModelTestCase::DoRun (void) { - Config::SetDefault ("ns3::RangePropagationLossModel::MaxRange", DoubleValue (127.2)); Ptr a = CreateObject (); a->SetPosition (Vector (0,0,0)); Ptr b = CreateObject (); diff -r 4f5fb52fde54 -r 6bc7f45725ed src/test/csma-system-test-suite.cc --- a/src/test/csma-system-test-suite.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/test/csma-system-test-suite.cc Wed Jul 13 17:58:55 2011 +0200 @@ -165,6 +165,8 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); + void SinkRxNode1 (Ptr p, const Address &ad); void SinkRxNode2 (Ptr p, const Address &ad); void DropEvent (Ptr p); @@ -201,6 +203,19 @@ m_drops++; } + +void +CsmaBroadcastTestCase::DoSetup () +{ + TestCase::DoSetup(); + + // + // Set up default values for the simulation. + // + // Select DIX/Ethernet II-style encapsulation (no LLC/Snap header) + Config::SetDefault ("ns3::CsmaNetDevice::EncapsulationMode", StringValue ("Dix")); +} + // // Example of the sending of a datagram to a broadcast address // @@ -333,12 +348,6 @@ void CsmaMulticastTestCase::DoRun (void) { - // - // Set up default values for the simulation. - // - // Select DIX/Ethernet II-style encapsulation (no LLC/Snap header) - Config::SetDefault ("ns3::CsmaNetDevice::EncapsulationMode", StringValue ("Dix")); - NodeContainer c; c.Create (5); // We will later want two subcontainers of these nodes, for the two LANs diff -r 4f5fb52fde54 -r 6bc7f45725ed src/test/error-model-test-suite.cc --- a/src/test/error-model-test-suite.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/test/error-model-test-suite.cc Wed Jul 13 17:58:55 2011 +0200 @@ -81,6 +81,9 @@ // Set some arbitrary deterministic values SeedManager::SetSeed (7); SeedManager::SetRun (5); + + m_count = 0; + m_drops = 0; Ptr a = CreateObject (); Ptr b = CreateObject (); diff -r 4f5fb52fde54 -r 6bc7f45725ed src/test/global-routing-test-suite.cc --- a/src/test/global-routing-test-suite.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/test/global-routing-test-suite.cc Wed Jul 13 17:58:55 2011 +0200 @@ -55,7 +55,10 @@ private: void SinkRx (std::string path, Ptr p, const Address &address); void HandleRead (Ptr); + virtual void DoRun (void); + virtual void DoSetup (void); + int m_count; std::vector m_firstInterface; std::vector m_secondInterface; @@ -118,6 +121,16 @@ } } +void +DynamicGlobalRoutingTestCase::DoSetup () +{ + TestCase::DoSetup(); + + // The below value configures the default behavior of global routing. + // By default, it is disabled. To respond to interface events, set to true + Config::SetDefault ("ns3::Ipv4GlobalRouting::RespondToInterfaceEvents", BooleanValue (true)); +} + // Test derived from examples/routing/dynamic-global-routing.cc // // Network topology @@ -140,10 +153,6 @@ void DynamicGlobalRoutingTestCase::DoRun (void) { - // The below value configures the default behavior of global routing. - // By default, it is disabled. To respond to interface events, set to true - Config::SetDefault ("ns3::Ipv4GlobalRouting::RespondToInterfaceEvents", BooleanValue (true)); - NodeContainer c; c.Create (7); NodeContainer n0n2 = NodeContainer (c.Get (0), c.Get (2)); diff -r 4f5fb52fde54 -r 6bc7f45725ed src/test/ns3tcp/ns3tcp-cwnd-test-suite.cc --- a/src/test/ns3tcp/ns3tcp-cwnd-test-suite.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/test/ns3tcp/ns3tcp-cwnd-test-suite.cc Wed Jul 13 17:58:55 2011 +0200 @@ -384,6 +384,8 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); + bool m_writeResults; class CwndEvent { @@ -419,11 +421,17 @@ } void +Ns3TcpCwndTestCase2::DoSetup (void) +{ + TestCase::DoSetup (); + + // Set up some default values for the simulation. + Config::SetDefault ("ns3::DropTailQueue::MaxPackets", UintegerValue (4)); +} + +void Ns3TcpCwndTestCase2::DoRun (void) { - // Set up some default values for the simulation. - Config::SetDefault ("ns3::DropTailQueue::MaxPackets", UintegerValue (4)); - NodeContainer n0n1; n0n1.Create (2); diff -r 4f5fb52fde54 -r 6bc7f45725ed src/test/ns3tcp/ns3tcp-interop-test-suite.cc --- a/src/test/ns3tcp/ns3tcp-interop-test-suite.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/test/ns3tcp/ns3tcp-interop-test-suite.cc Wed Jul 13 17:58:55 2011 +0200 @@ -128,6 +128,7 @@ Ns3TcpInteroperabilityTestCase::DoTeardown (void) { m_pcapFile.Close (); + TestCase::DoTeardown (); } void diff -r 4f5fb52fde54 -r 6bc7f45725ed src/test/ns3tcp/ns3tcp-loss-test-suite.cc --- a/src/test/ns3tcp/ns3tcp-loss-test-suite.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/test/ns3tcp/ns3tcp-loss-test-suite.cc Wed Jul 13 17:58:55 2011 +0200 @@ -115,6 +115,11 @@ void Ns3TcpLossTestCase::DoSetup (void) { + Simulator::Destroy(); + + // Enable packet metadata + Packet::EnablePrinting (); + // // We expect there to be a file called ns3tcp-state-response-vectors.pcap in // response-vectors/ of this directory @@ -133,12 +138,51 @@ m_pcapFile.Open (m_pcapFilename, std::ios::in|std::ios::binary); NS_ABORT_MSG_UNLESS (m_pcapFile.GetDataLinkType () == PCAP_LINK_TYPE, "Wrong response vectors in directory"); } + + // Config + std::ostringstream tcpModel; + tcpModel << "ns3::Tcp" << m_tcpModel; + Config::SetDefault ("ns3::TcpL4Protocol::SocketType", StringValue (tcpModel.str ())); + Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1000)); + Config::SetDefault ("ns3::TcpSocket::DelAckCount", UintegerValue (1)); + + // Logging + if (m_writeLogging) + { + LogComponentEnableAll (LOG_PREFIX_FUNC); + LogComponentEnable ("TcpLossResponse", LOG_LEVEL_ALL); + LogComponentEnable ("ErrorModel", LOG_LEVEL_DEBUG); + LogComponentEnable ("TcpLossResponse", LOG_LEVEL_ALL); + LogComponentEnable ("TcpNewReno", LOG_LEVEL_INFO); + LogComponentEnable ("TcpReno", LOG_LEVEL_INFO); + LogComponentEnable ("TcpTahoe", LOG_LEVEL_INFO); + LogComponentEnable ("TcpSocketBase", LOG_LEVEL_INFO); + } + } void Ns3TcpLossTestCase::DoTeardown (void) { + // Restore Logging + if (m_writeLogging) + { + LogComponentDisableAll (LOG_PREFIX_FUNC); + LogComponentDisable ("TcpLossResponse", LOG_LEVEL_ALL); + LogComponentDisable ("ErrorModel", LOG_LEVEL_DEBUG); + LogComponentDisable ("TcpLossResponse", LOG_LEVEL_ALL); + LogComponentDisable ("TcpNewReno", LOG_LEVEL_INFO); + LogComponentDisable ("TcpReno", LOG_LEVEL_INFO); + LogComponentDisable ("TcpTahoe", LOG_LEVEL_INFO); + LogComponentDisable ("TcpSocketBase", LOG_LEVEL_INFO); + } + m_pcapFile.Close (); + + // Enable packet metadata + Packet::DisablePrinting (); + + TestCase::DoTeardown (); } void @@ -182,22 +226,29 @@ // file and see if it still does the right thing. // uint8_t expected[PCAP_SNAPLEN]; - uint32_t tsSec, tsUsec, inclLen, origLen, readLen; + uint32_t tsSec=0, tsUsec=0, inclLen=0, origLen=0, readLen=0; m_pcapFile.Read (expected, sizeof(expected), tsSec, tsUsec, inclLen, origLen, readLen); - uint8_t *actual = new uint8_t[readLen]; - p->CopyData (actual, readLen); + if (readLen != 0 && origLen != 0) + { + uint8_t *actual = new uint8_t[readLen]; + p->CopyData (actual, readLen); - uint32_t result = memcmp (actual, expected, readLen); + uint32_t result = memcmp (actual, expected, readLen); - delete [] actual; + delete [] actual; - // - // Avoid streams of errors -- only report the first. - // - if (GetErrorStatus () == false) + // + // Avoid streams of errors -- only report the first. + // + if (GetErrorStatus () == false) + { + NS_TEST_EXPECT_MSG_EQ (result, 0, "Expected data comparison error"); + } + } + else if (GetErrorStatus () == false) { - NS_TEST_EXPECT_MSG_EQ (result, 0, "Expected data comparison error"); + NS_TEST_EXPECT_MSG_GT (readLen, 0, "Unexpected packet error"); } } } @@ -282,25 +333,6 @@ // Example corresponding to simulations in the paper "Simulation-based // Comparisons of Tahoe, Reno, and SACK TCP - std::ostringstream tcpModel; - tcpModel << "ns3::Tcp" << m_tcpModel; - Config::SetDefault ("ns3::TcpL4Protocol::SocketType", - StringValue (tcpModel.str ())); - Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1000)); - Config::SetDefault ("ns3::TcpSocket::DelAckCount", UintegerValue (1)); - - if (m_writeLogging) - { - LogComponentEnableAll (LOG_PREFIX_FUNC); - LogComponentEnable ("TcpLossResponse", LOG_LEVEL_ALL); - LogComponentEnable ("ErrorModel", LOG_LEVEL_DEBUG); - LogComponentEnable ("TcpLossResponse", LOG_LEVEL_ALL); - LogComponentEnable ("TcpNewReno", LOG_LEVEL_INFO); - LogComponentEnable ("TcpReno", LOG_LEVEL_INFO); - LogComponentEnable ("TcpTahoe", LOG_LEVEL_INFO); - LogComponentEnable ("TcpSocketBase", LOG_LEVEL_INFO); - } - //////////////////////////////////////////////////////// // Topology construction // @@ -359,13 +391,6 @@ ipInterfs.GetAddress (1), servPort); - Config::Connect ("/NodeList/0/$ns3::Ipv4L3Protocol/Tx", - MakeCallback (&Ns3TcpLossTestCase::Ipv4L3Tx, this)); - - Config::ConnectWithoutContext - ("/NodeList/0/$ns3::TcpL4Protocol/SocketList/0/CongestionWindow", - MakeCallback (&Ns3TcpLossTestCase::CwndTracer, this)); - //////////////////////////////////////////////////////// // Set up loss model at node k1 // @@ -403,6 +428,13 @@ pem->SetList (sampleList); dev1.Get (1)->SetAttribute ("ReceiveErrorModel", PointerValue (pem)); + Config::Connect ("/NodeList/0/$ns3::Ipv4L3Protocol/Tx", + MakeCallback (&Ns3TcpLossTestCase::Ipv4L3Tx, this)); + + Config::ConnectWithoutContext + ("/NodeList/0/$ns3::TcpL4Protocol/SocketList/0/CongestionWindow", + MakeCallback (&Ns3TcpLossTestCase::CwndTracer, this)); + // One can toggle the comment for the following line on or off to see the // effects of finite send buffer modelling. One can also change the size of // that buffer. @@ -442,7 +474,6 @@ Ns3TcpLossTestSuite::Ns3TcpLossTestSuite () : TestSuite ("ns3-tcp-loss", SYSTEM) { - Packet::EnablePrinting (); // Enable packet metadata for all test cases AddTestCase (new Ns3TcpLossTestCase ("Tahoe", 0)); AddTestCase (new Ns3TcpLossTestCase ("Tahoe", 1)); AddTestCase (new Ns3TcpLossTestCase ("Tahoe", 2)); diff -r 4f5fb52fde54 -r 6bc7f45725ed src/test/ns3tcp/ns3tcp-socket-test-suite.cc --- a/src/test/ns3tcp/ns3tcp-socket-test-suite.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/test/ns3tcp/ns3tcp-socket-test-suite.cc Wed Jul 13 17:58:55 2011 +0200 @@ -158,6 +158,8 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); + bool m_writeResults; void SinkRx (std::string path, Ptr p, const Address &address); @@ -179,6 +181,13 @@ } void +Ns3TcpSocketTestCase2::DoSetup (void) +{ + TestCase::DoSetup (); + Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1000)); +} + +void Ns3TcpSocketTestCase2::DoRun (void) { uint16_t sinkPort = 50000; @@ -189,8 +198,6 @@ Time writerStopTimeObj = Seconds (writerStopTime); Time simStopTimeObj= Seconds (simStopTime); - Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1000)); - NodeContainer nodes; nodes.Create (2); Ptr n0 = nodes.Get (0); diff -r 4f5fb52fde54 -r 6bc7f45725ed src/test/ns3tcp/ns3tcp-state-test-suite.cc --- a/src/test/ns3tcp/ns3tcp-state-test-suite.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/test/ns3tcp/ns3tcp-state-test-suite.cc Wed Jul 13 17:58:55 2011 +0200 @@ -110,6 +110,11 @@ void Ns3TcpStateTestCase::DoSetup (void) { + Simulator::Destroy(); + + // Enable packet metadata + Packet::EnablePrinting (); + // // We expect there to be a file called ns3tcp-state-response-vectors.pcap in // response-vectors/ of this directory @@ -128,12 +133,50 @@ m_pcapFile.Open (m_pcapFilename, std::ios::in|std::ios::binary); NS_ABORT_MSG_UNLESS (m_pcapFile.GetDataLinkType () == PCAP_LINK_TYPE, "Wrong response vectors in directory"); } + + // Config + std::string tcpModel ("ns3::TcpNewReno"); + Config::SetDefault ("ns3::TcpL4Protocol::SocketType", StringValue (tcpModel)); + Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1000)); + Config::SetDefault ("ns3::TcpSocket::DelAckCount", UintegerValue (1)); + Config::SetDefault ("ns3::DropTailQueue::MaxPackets", UintegerValue (20)); + + // Logging + if (m_writeLogging) + { + LogComponentEnableAll (LOG_PREFIX_FUNC); + LogComponentEnable ("TcpTestCases", LOG_LEVEL_ALL); + LogComponentEnable ("ErrorModel", LOG_LEVEL_DEBUG); + LogComponentEnable ("TcpTestCases", LOG_LEVEL_ALL); + LogComponentEnable ("TcpNewReno", LOG_LEVEL_INFO); + LogComponentEnable ("TcpReno", LOG_LEVEL_INFO); + LogComponentEnable ("TcpTahoe", LOG_LEVEL_INFO); + LogComponentEnable ("TcpSocketBase", LOG_LEVEL_INFO); + } } void Ns3TcpStateTestCase::DoTeardown (void) { + // Restore Logging + if (m_writeLogging) + { + LogComponentDisableAll (LOG_PREFIX_FUNC); + LogComponentDisable ("TcpTestCases", LOG_LEVEL_ALL); + LogComponentDisable ("ErrorModel", LOG_LEVEL_DEBUG); + LogComponentDisable ("TcpTestCases", LOG_LEVEL_ALL); + LogComponentDisable ("TcpNewReno", LOG_LEVEL_INFO); + LogComponentDisable ("TcpReno", LOG_LEVEL_INFO); + LogComponentDisable ("TcpTahoe", LOG_LEVEL_INFO); + LogComponentDisable ("TcpSocketBase", LOG_LEVEL_INFO); + } + m_pcapFile.Close (); + + // Enable packet metadata + Packet::DisablePrinting (); + + TestCase::DoTeardown (); } void @@ -177,22 +220,29 @@ // file and see if it still does the right thing. // uint8_t expected[PCAP_SNAPLEN]; - uint32_t tsSec, tsUsec, inclLen, origLen, readLen; + uint32_t tsSec=0, tsUsec=0, inclLen=0, origLen=0, readLen=0; m_pcapFile.Read (expected, sizeof(expected), tsSec, tsUsec, inclLen, origLen, readLen); + + if (readLen != 0 && origLen != 0) + { + uint8_t *actual = new uint8_t[readLen]; + p->CopyData (actual, readLen); - uint8_t *actual = new uint8_t[readLen]; - p->CopyData (actual, readLen); + uint32_t result = memcmp (actual, expected, readLen); - uint32_t result = memcmp (actual, expected, readLen); + delete [] actual; - delete [] actual; - - // - // Avoid streams of errors -- only report the first. - // - if (GetErrorStatus () == false) + // + // Avoid streams of errors -- only report the first. + // + if (GetErrorStatus () == false) + { + NS_TEST_EXPECT_MSG_EQ (result, 0, "Expected data comparison error"); + } + } + else if (GetErrorStatus () == false) { - NS_TEST_EXPECT_MSG_EQ (result, 0, "Expected data comparison error"); + NS_TEST_EXPECT_MSG_GT (readLen, 0, "Unexpected packet error"); } } } @@ -266,29 +316,10 @@ // 10Mb/s, 0.1ms 10Mb/s, 0.1ms // n0-----------------n1-----------------n2 - std::string tcpModel ("ns3::TcpNewReno"); - - Config::SetDefault ("ns3::TcpL4Protocol::SocketType", StringValue (tcpModel)); - Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1000)); - Config::SetDefault ("ns3::TcpSocket::DelAckCount", UintegerValue (1)); - Config::SetDefault ("ns3::DropTailQueue::MaxPackets", UintegerValue (20)); - - if (m_writeLogging) - { - LogComponentEnableAll (LOG_PREFIX_FUNC); - LogComponentEnable ("TcpTestCases", LOG_LEVEL_ALL); - LogComponentEnable ("ErrorModel", LOG_LEVEL_DEBUG); - LogComponentEnable ("TcpTestCases", LOG_LEVEL_ALL); - LogComponentEnable ("TcpNewReno", LOG_LEVEL_INFO); - LogComponentEnable ("TcpReno", LOG_LEVEL_INFO); - LogComponentEnable ("TcpTahoe", LOG_LEVEL_INFO); - LogComponentEnable ("TcpSocketBase", LOG_LEVEL_INFO); - } - //////////////////////////////////////////////////////// // Topology construction // - + // Create three nodes NodeContainer n0n1; n0n1.Create (2); @@ -338,9 +369,6 @@ Simulator::ScheduleNow (&Ns3TcpStateTestCase::StartFlow, this, localSocket, ipInterfs.GetAddress (1), servPort); - Config::Connect ("/NodeList/0/$ns3::Ipv4L3Protocol/Tx", - MakeCallback (&Ns3TcpStateTestCase::Ipv4L3Tx, this)); - //////////////////////////////////////////////////////// // Set up different test cases: Lost model at node n1, different file size // @@ -411,6 +439,9 @@ errN1->SetList (dropListN1); dev1.Get (0)->SetAttribute ("ReceiveErrorModel", PointerValue (errN1)); + Config::Connect ("/NodeList/0/$ns3::Ipv4L3Protocol/Tx", + MakeCallback (&Ns3TcpStateTestCase::Ipv4L3Tx, this)); + std::ostringstream oss; oss << "tcp-state" << m_testCase << "-test-case"; if (m_writeResults) @@ -434,8 +465,6 @@ Simulator::Stop (Seconds (1000)); Simulator::Run (); Simulator::Destroy (); - - } class Ns3TcpStateTestSuite : public TestSuite @@ -447,7 +476,6 @@ Ns3TcpStateTestSuite::Ns3TcpStateTestSuite () : TestSuite ("ns3-tcp-state", SYSTEM) { - Packet::EnablePrinting (); // Enable packet metadata for all test cases AddTestCase (new Ns3TcpStateTestCase (0)); AddTestCase (new Ns3TcpStateTestCase (1)); AddTestCase (new Ns3TcpStateTestCase (2)); diff -r 4f5fb52fde54 -r 6bc7f45725ed src/test/ns3wifi/wifi-interference-test-suite.cc --- a/src/test/ns3wifi/wifi-interference-test-suite.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/test/ns3wifi/wifi-interference-test-suite.cc Wed Jul 13 17:58:55 2011 +0200 @@ -57,6 +57,8 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); + void ReceivePacket (Ptr socket); static void GenerateTraffic (Ptr socket, uint32_t pktSize, uint32_t pktCount, Time pktInterval); void PrintEndSync (std::string context, uint32_t dataRate, double snr, double per); @@ -65,11 +67,14 @@ double m_PER; double m_SNR; uint32_t m_DataRate; + + std::string m_phyMode; }; // Add some help text to this case to describe what it is intended to test WifiInterferenceTestCase::WifiInterferenceTestCase () : TestCase ("Test interference calculation when interfering frame exactly overlaps intended frame") + , m_phyMode ("DsssRate1Mbps") { } @@ -77,6 +82,19 @@ { } +void +WifiInterferenceTestCase::DoSetup () +{ + TestCase::DoSetup (); + + // disable fragmentation for frames below 2200 bytes + Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200")); + // turn off RTS/CTS for frames below 2200 bytes + Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200")); + // Fix non-unicast data rate to be the same as that of unicast + Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue (m_phyMode)); +} + void WifiInterferenceTestCase::ReceivePacket (Ptr socket) { @@ -131,14 +149,6 @@ // Convert to time object Time interPacketInterval = Seconds (interval); - // disable fragmentation for frames below 2200 bytes - Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200")); - // turn off RTS/CTS for frames below 2200 bytes - Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200")); - // Fix non-unicast data rate to be the same as that of unicast - Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", - StringValue (phyMode)); - NodeContainer c; c.Create (3); @@ -232,8 +242,6 @@ void WifiInterferenceTestCase::DoRun (void) { - - std::string phyMode ("DsssRate1Mbps"); double Prss = -90; // -dBm double Irss = -90; // -dBm double delta = 0; // microseconds @@ -246,17 +254,17 @@ // Compute the packet error rate (PER) when delta=0 microseconds. This // means that the interferer arrives at exactly the same time as the // intended packet - PER = WifiSimpleInterference (phyMode,Prss,Irss,delta,PpacketSize,IpacketSize,verbose,internet); + PER = WifiSimpleInterference (m_phyMode,Prss,Irss,delta,PpacketSize,IpacketSize,verbose,internet); // Now rerun this test case and compute the PER when the delta time between // arrival of the intended frame and interferer is 1 microsecond. delta = 1; - PER1 = WifiSimpleInterference (phyMode,Prss,Irss,delta,PpacketSize,IpacketSize,verbose,internet); + PER1 = WifiSimpleInterference (m_phyMode,Prss,Irss,delta,PpacketSize,IpacketSize,verbose,internet); // Now rerun this test case and compute the PER when the delta time between // arrival of the intended frame and interferer is 2 microseconds. delta = 2; - PER2 = WifiSimpleInterference (phyMode,Prss,Irss,delta,PpacketSize,IpacketSize,verbose,internet); + PER2 = WifiSimpleInterference (m_phyMode,Prss,Irss,delta,PpacketSize,IpacketSize,verbose,internet); double PERDiff1 = PER - PER1; # HG changeset patch # User cdfreire # Date 1310572735 -7200 # Node ID 6bc7f45725ed001cff33fa663fa902a67488571e # Parent 4f5fb52fde54d18585d9806e27450d8bf1908be4 * The test framework now assures repeatable conditions within test cases, by: - Destroying the simulator at base TestCase::DoTeardown/Setup - Resetting configuration (attribute defaults and global values) at various points (TestCase::DoTeardown, TestSuite::DoSetup) - Saving/Restoring the RNG state at TestSuite::DoSetup/Teardown (I tried per TestCase, but some test cases depend on RNG state set by previous test cases, sorting that out would have been a LOT more work) PCAP traces need to be re-generated diff -r 4f5fb52fde54 -r 6bc7f45725ed src/aodv/test/aodv-regression.cc --- a/src/aodv/test/aodv-regression.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/aodv/test/aodv-regression.cc Wed Jul 13 17:58:55 2011 +0200 @@ -67,6 +67,14 @@ // Ping loopback test case AddTestCase (new LoopbackTestCase ()); } + + virtual void DoSetup (void) + { + TestSuite::DoSetup(); + + // Set a reproducible random seed + SeedManager::SetSeed(12345); + } } g_aodvRegressionTestSuite; @@ -92,7 +100,6 @@ void ChainRegressionTest::DoRun () { - SeedManager::SetSeed (12345); Config::SetDefault ("ns3::ArpCache::AliveTimeout", TimeValue (m_arpAliveTimeout)); CreateNodes (); diff -r 4f5fb52fde54 -r 6bc7f45725ed src/aodv/test/bug-772.cc --- a/src/aodv/test/bug-772.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/aodv/test/bug-772.cc Wed Jul 13 17:58:55 2011 +0200 @@ -74,6 +74,7 @@ Bug772ChainTest::DoRun () { SeedManager::SetSeed (12345); + Config::SetDefault ("ns3::ArpCache::AliveTimeout", TimeValue (Seconds (1))); CreateNodes (); CreateDevices (); diff -r 4f5fb52fde54 -r 6bc7f45725ed src/core/model/test.cc --- a/src/core/model/test.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/core/model/test.cc Wed Jul 13 17:58:55 2011 +0200 @@ -21,6 +21,9 @@ #include "abort.h" #include +#include "ns3/simulator.h" +#include "ns3/config.h" + // Set to true to enable a segmentation fault upon a test case macro test // failing (for debugging purposes) bool gBreakOnFailure = false; @@ -395,11 +398,29 @@ void TestCase::DoSetup (void) { + /* + * Ensure a clean execution environment + */ + Simulator::Destroy(); } void TestCase::DoTeardown (void) { + /* + * Most tests will destroy their simulators when successful, + * but on failure, they tend to leave the simulator alive. + * This can be a problem for subsequent test runs, so we + * must destroy the simulator on TestCase teardown just in case. + */ + Simulator::Destroy(); + + /** + * Some tests will change default configuration settings. In + * those cases, a full configuration reset is the only way to get + * back to a reproducible state. + */ + Config::Reset (); } TestSuite::TestSuite (std::string name, TestType type) @@ -659,6 +680,22 @@ void TestSuite::DoSetup (void) { + /* + * Ensure repeatable state, reset all configuration settings to their defaults + */ + Config::Reset (); + + /* + * Preserve global RNG state (RngStream contains process-wide side effects) + */ + m_rngRunBackup = SeedManager::GetRun(); + m_rngSeedBackup = SeedManager::GetSeed(); + + /* + * Reset RNG state (in case the testing framework changed it somehow between runs) + */ + SeedManager::SetRun(m_rngRunBackup); + SeedManager::SetSeed(m_rngSeedBackup); } void @@ -697,6 +734,11 @@ void TestSuite::DoTeardown (void) { + /* + * Restore global RNG state + */ + SeedManager::SetRun(m_rngRunBackup); + SeedManager::SetSeed(m_rngSeedBackup); } class TestRunnerImpl diff -r 4f5fb52fde54 -r 6bc7f45725ed src/core/model/test.h --- a/src/core/model/test.h Mon Jul 11 18:15:52 2011 +0200 +++ b/src/core/model/test.h Wed Jul 13 17:58:55 2011 +0200 @@ -29,6 +29,7 @@ #include #include "ns3/system-wall-clock-ms.h" +#include "ns3/random-variable.h" extern bool gBreakOnFailure; @@ -1276,6 +1277,15 @@ bool m_error; TestType m_type; + // Backup of process-wide RNG state + // FIXME: This *should* be done per-testcase, but current test cases + // depend have cases where they depend on RNG state resulting from + // previous runs within a TestSuite (like routing-aodv-regression), + // so in order not to break them, we do not reset RNG state between + // test cases, only between tests suites. + uint32_t m_rngSeedBackup; + uint32_t m_rngRunBackup; + typedef std::vector TestCaseVector_t; TestCaseVector_t m_tests; }; diff -r 4f5fb52fde54 -r 6bc7f45725ed src/core/test/names-test-suite.cc --- a/src/core/test/names-test-suite.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/core/test/names-test-suite.cc Wed Jul 13 17:58:55 2011 +0200 @@ -87,6 +87,7 @@ BasicAddTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -153,6 +154,7 @@ StringContextAddTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -216,6 +218,7 @@ FullyQualifiedAddTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -282,6 +285,7 @@ RelativeAddTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -347,6 +351,7 @@ BasicRenameTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -407,6 +412,7 @@ StringContextRenameTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -467,6 +473,7 @@ FullyQualifiedRenameTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -527,6 +534,7 @@ RelativeRenameTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -587,6 +595,7 @@ FindPathTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -641,6 +650,7 @@ BasicFindTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -703,6 +713,7 @@ StringContextFindTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -765,6 +776,7 @@ FullyQualifiedFindTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -827,6 +839,7 @@ RelativeFindTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -887,6 +900,7 @@ AlternateFindTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void diff -r 4f5fb52fde54 -r 6bc7f45725ed src/core/test/time-test-suite.cc --- a/src/core/test/time-test-suite.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/core/test/time-test-suite.cc Wed Jul 13 17:58:55 2011 +0200 @@ -76,6 +76,7 @@ TimeSimpleTestCase::DoTeardown (void) { Time::SetResolution (m_originalResolution); + TestCase::DoTeardown (); } static class TimeTestSuite : public TestSuite diff -r 4f5fb52fde54 -r 6bc7f45725ed src/core/test/timer-test-suite.cc --- a/src/core/test/timer-test-suite.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/core/test/timer-test-suite.cc Wed Jul 13 17:58:55 2011 +0200 @@ -215,6 +215,7 @@ { Simulator::Run (); Simulator::Destroy (); + TestCase::DoTeardown (); } static class TimerTestSuite : public TestSuite diff -r 4f5fb52fde54 -r 6bc7f45725ed src/energy/test/basic-energy-model-test.cc --- a/src/energy/test/basic-energy-model-test.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/energy/test/basic-energy-model-test.cc Wed Jul 13 17:58:55 2011 +0200 @@ -217,6 +217,7 @@ private: void DoRun (void); + void DoSetup (void); /** * Callback invoked when energy is drained from source. @@ -238,11 +239,13 @@ double m_simTimeS; // maximum simulation time, in seconds double m_timeStepS; // simulation time step size, in seconds double m_updateIntervalS; // update interval of each device model + std::string m_phyMode; }; BasicEnergyDepletionTest::BasicEnergyDepletionTest () : TestCase ("Basic energy model energy depletion test case") + , m_phyMode ("DsssRate1Mbps") { m_numOfNodes = 10; m_callbackCount = 0; @@ -256,6 +259,22 @@ } void +BasicEnergyDepletionTest::DoSetup (void) +{ + TestCase::DoSetup (); + + // disable fragmentation for frames below 2200 bytes + Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", + StringValue ("2200")); + // turn off RTS/CTS for frames below 2200 bytes + Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", + StringValue ("2200")); + // Fix non-unicast data rate to be the same as that of unicast + Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", + StringValue (m_phyMode)); +} + +void BasicEnergyDepletionTest::DoRun (void) { /* @@ -287,18 +306,6 @@ NodeContainer c; c.Create (m_numOfNodes); - std::string phyMode ("DsssRate1Mbps"); - - // disable fragmentation for frames below 2200 bytes - Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", - StringValue ("2200")); - // turn off RTS/CTS for frames below 2200 bytes - Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", - StringValue ("2200")); - // Fix non-unicast data rate to be the same as that of unicast - Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", - StringValue (phyMode)); - // install YansWifiPhy WifiHelper wifi; wifi.SetStandard (WIFI_PHY_STANDARD_80211b); @@ -319,8 +326,8 @@ // Add a non-QoS upper MAC, and disable rate control NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", - "DataMode", StringValue (phyMode), - "ControlMode", StringValue (phyMode)); + "DataMode", StringValue (m_phyMode), + "ControlMode", StringValue (m_phyMode)); // Set it to ad-hoc mode wifiMac.SetType ("ns3::AdhocWifiMac"); NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c); diff -r 4f5fb52fde54 -r 6bc7f45725ed src/energy/test/rv-battery-model-test.cc --- a/src/energy/test/rv-battery-model-test.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/energy/test/rv-battery-model-test.cc Wed Jul 13 17:58:55 2011 +0200 @@ -57,13 +57,16 @@ void CreateLoadProfiles (void); /** - * \returns False if no error occurs. - * * Runs test. */ void DoRun (void); /** + * Sets up test configuration + */ + void DoSetup (void); + + /** * \param load Load value, in Amperes (A). * \param expLifetime Expected lifetime. * \return False if no error occurs. @@ -99,14 +102,19 @@ std::vector m_loadProfiles; double m_alpha; double m_beta; + std::string m_phyMode; }; BatteryLifetimeTest::BatteryLifetimeTest () : TestCase ("RV battery model battery lifetime test case.") + , m_phyMode ("DsssRate1Mbps") { // Itsy battery m_alpha = 35220; m_beta = 0.637; + + // create load profiles for variable load test + CreateLoadProfiles (); } BatteryLifetimeTest::~BatteryLifetimeTest () @@ -638,10 +646,30 @@ } void +BatteryLifetimeTest::DoSetup (void) +{ + TestCase::DoSetup (); + + // disable fragmentation for frames below 2200 bytes + Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", + StringValue ("2200")); + // turn off RTS/CTS for frames below 2200 bytes + Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", + StringValue ("2200")); + // Fix non-unicast data rate to be the same as that of unicast + Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", + StringValue (m_phyMode)); +} + +void BatteryLifetimeTest::DoRun (void) { NS_LOG_DEBUG ("Constant load run."); + // set constant load test parameters + m_alpha = 35220; + m_beta = 0.637; + // 640mA NS_TEST_ASSERT_MSG_EQ (ConstantLoadTest (0.640, Seconds (2844.0)), false, "Problems with constant load test (640mA)."); // 320mA @@ -653,9 +681,6 @@ // 32mA NS_TEST_ASSERT_MSG_EQ (ConstantLoadTest (0.032, Seconds (65580.0)), false, "Problems with constant load test (32)."); - // create load profiles for variable load test - CreateLoadProfiles (); - // variable load with Itsy battery NS_LOG_DEBUG ("\n\nItsy"); m_alpha = 35220; @@ -696,18 +721,6 @@ NodeContainer c; c.Create (1); - std::string phyMode ("DsssRate1Mbps"); - - // disable fragmentation for frames below 2200 bytes - Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", - StringValue ("2200")); - // turn off RTS/CTS for frames below 2200 bytes - Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", - StringValue ("2200")); - // Fix non-unicast data rate to be the same as that of unicast - Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", - StringValue (phyMode)); - // install YansWifiPhy WifiHelper wifi; wifi.SetStandard (WIFI_PHY_STANDARD_80211b); @@ -728,8 +741,8 @@ // Add a non-QoS upper MAC, and disable rate control NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", - "DataMode", StringValue (phyMode), - "ControlMode", StringValue (phyMode)); + "DataMode", StringValue (m_phyMode), + "ControlMode", StringValue (m_phyMode)); // Set it to ad-hoc mode wifiMac.SetType ("ns3::AdhocWifiMac"); NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c); @@ -759,7 +772,7 @@ NS_LOG_DEBUG ("Expected lifetime = " << expLifetime.GetSeconds () << "s"); NS_LOG_DEBUG ("Actual lifetime = " << actualLifetime.GetSeconds () << "s"); - + NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL (actualLifetime, expLifetime, "Incorrect lifetime!"); /* NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL (actualLifetime.GetSeconds () / 60, @@ -783,18 +796,6 @@ NodeContainer c; c.Create (1); - std::string phyMode ("DsssRate1Mbps"); - - // disable fragmentation for frames below 2200 bytes - Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", - StringValue ("2200")); - // turn off RTS/CTS for frames below 2200 bytes - Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", - StringValue ("2200")); - // Fix non-unicast data rate to be the same as that of unicast - Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", - StringValue (phyMode)); - // install YansWifiPhy WifiHelper wifi; wifi.SetStandard (WIFI_PHY_STANDARD_80211b); @@ -815,8 +816,8 @@ // Add a non-QoS upper MAC, and disable rate control NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", - "DataMode", StringValue (phyMode), - "ControlMode", StringValue (phyMode)); + "DataMode", StringValue (m_phyMode), + "ControlMode", StringValue (m_phyMode)); // Set it to ad-hoc mode wifiMac.SetType ("ns3::AdhocWifiMac"); NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c); diff -r 4f5fb52fde54 -r 6bc7f45725ed src/internet/test/ipv4-address-generator-test-suite.cc --- a/src/internet/test/ipv4-address-generator-test-suite.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/internet/test/ipv4-address-generator-test-suite.cc Wed Jul 13 17:58:55 2011 +0200 @@ -38,6 +38,7 @@ NetworkNumberAllocatorTestCase::DoTeardown (void) { Ipv4AddressGenerator::Reset (); + TestCase::DoTeardown (); } void NetworkNumberAllocatorTestCase::DoRun (void) @@ -117,7 +118,7 @@ AddressAllocatorTestCase::DoTeardown (void) { Ipv4AddressGenerator::Reset (); - Simulator::Destroy (); + TestCase::DoTeardown (); } @@ -138,7 +139,7 @@ NetworkAndAddressTestCase::DoTeardown (void) { Ipv4AddressGenerator::Reset (); - Simulator::Destroy (); + TestCase::DoTeardown (); } void @@ -202,6 +203,7 @@ ExampleAddressGeneratorTestCase::DoTeardown (void) { Ipv4AddressGenerator::Reset (); + TestCase::DoTeardown (); } void @@ -254,7 +256,7 @@ AddressCollisionTestCase::DoTeardown (void) { Ipv4AddressGenerator::Reset (); - Simulator::Destroy (); + TestCase::DoTeardown (); } void AddressCollisionTestCase::DoRun (void) diff -r 4f5fb52fde54 -r 6bc7f45725ed src/internet/test/ipv4-address-helper-test-suite.cc --- a/src/internet/test/ipv4-address-helper-test-suite.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/internet/test/ipv4-address-helper-test-suite.cc Wed Jul 13 17:58:55 2011 +0200 @@ -41,7 +41,7 @@ NetworkAllocatorHelperTestCase::DoTeardown (void) { Ipv4AddressGenerator::Reset (); - Simulator::Destroy (); + TestCase::DoTeardown (); } void NetworkAllocatorHelperTestCase::DoRun (void) @@ -87,7 +87,7 @@ AddressAllocatorHelperTestCase::DoTeardown (void) { Ipv4AddressGenerator::Reset (); - Simulator::Destroy (); + TestCase::DoTeardown (); } void @@ -176,7 +176,7 @@ ResetAllocatorHelperTestCase::DoTeardown (void) { Ipv4AddressGenerator::Reset (); - Simulator::Destroy (); + TestCase::DoTeardown (); } static class Ipv4AddressHelperTestSuite : public TestSuite diff -r 4f5fb52fde54 -r 6bc7f45725ed src/internet/test/tcp-test.cc --- a/src/internet/test/tcp-test.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/internet/test/tcp-test.cc Wed Jul 13 17:58:55 2011 +0200 @@ -160,7 +160,7 @@ delete [] m_sourceTxPayload; delete [] m_sourceRxPayload; delete [] m_serverRxPayload; - Simulator::Destroy (); + TestCase::DoTeardown (); } void diff -r 4f5fb52fde54 -r 6bc7f45725ed src/mobility/test/ns2-mobility-helper-test-suite.cc --- a/src/mobility/test/ns2-mobility-helper-test-suite.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/mobility/test/ns2-mobility-helper-test-suite.cc Wed Jul 13 17:58:55 2011 +0200 @@ -204,6 +204,7 @@ void DoSetup () { + Simulator::Destroy(); CreateNodes (); } @@ -211,7 +212,7 @@ { Names::Clear (); std::remove (m_traceFile.c_str ()); - Simulator::Destroy (); + TestCase::DoTeardown (); } /// Go diff -r 4f5fb52fde54 -r 6bc7f45725ed src/mobility/test/steady-state-random-waypoint-mobility-model-test.cc --- a/src/mobility/test/steady-state-random-waypoint-mobility-model-test.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/mobility/test/steady-state-random-waypoint-mobility-model-test.cc Wed Jul 13 17:58:55 2011 +0200 @@ -47,6 +47,7 @@ SteadyStateRandomWaypointTest::DoTeardown (void) { mobilityStack.clear(); + TestCase::DoTeardown(); } void diff -r 4f5fb52fde54 -r 6bc7f45725ed src/mobility/test/waypoint-mobility-model-test.cc --- a/src/mobility/test/waypoint-mobility-model-test.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/mobility/test/waypoint-mobility-model-test.cc Wed Jul 13 17:58:55 2011 +0200 @@ -57,6 +57,7 @@ { mobilityStack.clear(); waypoints.clear(); + TestCase::DoTeardown(); } void diff -r 4f5fb52fde54 -r 6bc7f45725ed src/network/test/pcap-file-test-suite.cc --- a/src/network/test/pcap-file-test-suite.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/network/test/pcap-file-test-suite.cc Wed Jul 13 17:58:55 2011 +0200 @@ -114,6 +114,7 @@ WriteModeCreateTestCase::DoTeardown (void) { remove (m_testFilename.c_str ()); + TestCase::DoTeardown (); } void @@ -226,6 +227,7 @@ ReadModeCreateTestCase::DoTeardown (void) { remove (m_testFilename.c_str ()); + TestCase::DoTeardown (); } void @@ -332,6 +334,7 @@ AppendModeCreateTestCase::DoTeardown (void) { remove (m_testFilename.c_str ()); + TestCase::DoTeardown (); } void @@ -438,6 +441,7 @@ FileHeaderTestCase::DoTeardown (void) { remove (m_testFilename.c_str ()); + TestCase::DoTeardown (); } void @@ -675,6 +679,7 @@ RecordHeaderTestCase::DoTeardown (void) { remove (m_testFilename.c_str ()); + TestCase::DoTeardown (); } void @@ -972,6 +977,7 @@ void ReadFileTestCase::DoTeardown (void) { + TestCase::DoTeardown (); } const uint32_t N_KNOWN_PACKETS = 6; diff -r 4f5fb52fde54 -r 6bc7f45725ed src/olsr/test/bug780-test.cc --- a/src/olsr/test/bug780-test.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/olsr/test/bug780-test.cc Wed Jul 13 17:58:55 2011 +0200 @@ -75,6 +75,17 @@ } void +Bug780Test::DoSetup () +{ + TestCase::DoSetup (); + + //sending one packets per sec + // Fix non-unicast data rate to be the same as that of unicast + Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", + StringValue ("400")); +} + +void Bug780Test::DoRun () { SeedManager::SetSeed (123); @@ -97,11 +108,6 @@ double SimTime = 200.0; std::string phyMode ("DsssRate1Mbps"); - //sending one packets per sec - // Fix non-unicast data rate to be the same as that of unicast - Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", - StringValue ("400")); - NodeContainer adhocNodes; adhocNodes.Create (nWifis); diff -r 4f5fb52fde54 -r 6bc7f45725ed src/olsr/test/bug780-test.h --- a/src/olsr/test/bug780-test.h Mon Jul 11 18:15:52 2011 +0200 +++ b/src/olsr/test/bug780-test.h Wed Jul 13 17:58:55 2011 +0200 @@ -43,6 +43,7 @@ void CheckResults (); /// Go void DoRun (); + void DoSetup (); }; } diff -r 4f5fb52fde54 -r 6bc7f45725ed src/propagation/test/propagation-loss-model-test-suite.cc --- a/src/propagation/test/propagation-loss-model-test-suite.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/propagation/test/propagation-loss-model-test-suite.cc Wed Jul 13 17:58:55 2011 +0200 @@ -42,6 +42,7 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); typedef struct { Vector m_position; @@ -63,14 +64,23 @@ } void -FriisPropagationLossModelTestCase::DoRun (void) +FriisPropagationLossModelTestCase::DoSetup (void) { + TestCase::DoSetup (); + // The ns-3 testing manual gives more background on the values selected // for this test. First, set a few defaults. // wavelength at 2.4 GHz is 0.125m Config::SetDefault ("ns3::FriisPropagationLossModel::Lambda", DoubleValue (0.125)); Config::SetDefault ("ns3::FriisPropagationLossModel::SystemLoss", DoubleValue (1.0)); +} + +void +FriisPropagationLossModelTestCase::DoRun (void) +{ + // The ns-3 testing manual gives more background on the values selected + // for this test. // Select a reference transmit power // Pt = 10^(17.0206/10)/10^3 = .05035702 W @@ -139,6 +149,7 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); typedef struct { @@ -162,15 +173,21 @@ } void -TwoRayGroundPropagationLossModelTestCase::DoRun (void) +TwoRayGroundPropagationLossModelTestCase::DoSetup (void) { + TestCase::DoSetup (); + // wavelength at 2.4 GHz is 0.125m Config::SetDefault ("ns3::TwoRayGroundPropagationLossModel::Lambda", DoubleValue (0.125)); Config::SetDefault ("ns3::TwoRayGroundPropagationLossModel::SystemLoss", DoubleValue (1.0)); // set antenna height to 1.5m above z coordinate Config::SetDefault ("ns3::TwoRayGroundPropagationLossModel::HeightAboveZ", DoubleValue (1.5)); +} +void +TwoRayGroundPropagationLossModelTestCase::DoRun (void) +{ // Select a reference transmit power of 17.0206 dBm // Pt = 10^(17.0206/10)/10^3 = .05035702 W double txPowerW = 0.05035702; @@ -267,6 +284,7 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); typedef struct { Vector m_position; @@ -288,12 +306,18 @@ } void -LogDistancePropagationLossModelTestCase::DoRun (void) +LogDistancePropagationLossModelTestCase::DoSetup (void) { + TestCase::DoSetup (); + // reference loss at 2.4 GHz is 40.045997 Config::SetDefault ("ns3::LogDistancePropagationLossModel::ReferenceLoss", DoubleValue (40.045997)); Config::SetDefault ("ns3::LogDistancePropagationLossModel::Exponent", DoubleValue (3)); +} +void +LogDistancePropagationLossModelTestCase::DoRun (void) +{ // Select a reference transmit power // Pt = 10^(17.0206/10)/10^3 = .05035702 W double txPowerW = 0.05035702; @@ -402,6 +426,7 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); }; RangePropagationLossModelTestCase::RangePropagationLossModelTestCase () @@ -414,9 +439,17 @@ } void +RangePropagationLossModelTestCase::DoSetup (void) +{ + TestCase::DoSetup (); + + // Set testcase parameters + Config::SetDefault ("ns3::RangePropagationLossModel::MaxRange", DoubleValue (127.2)); +} + +void RangePropagationLossModelTestCase::DoRun (void) { - Config::SetDefault ("ns3::RangePropagationLossModel::MaxRange", DoubleValue (127.2)); Ptr a = CreateObject (); a->SetPosition (Vector (0,0,0)); Ptr b = CreateObject (); diff -r 4f5fb52fde54 -r 6bc7f45725ed src/test/csma-system-test-suite.cc --- a/src/test/csma-system-test-suite.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/test/csma-system-test-suite.cc Wed Jul 13 17:58:55 2011 +0200 @@ -165,6 +165,8 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); + void SinkRxNode1 (Ptr p, const Address &ad); void SinkRxNode2 (Ptr p, const Address &ad); void DropEvent (Ptr p); @@ -201,6 +203,19 @@ m_drops++; } + +void +CsmaBroadcastTestCase::DoSetup () +{ + TestCase::DoSetup(); + + // + // Set up default values for the simulation. + // + // Select DIX/Ethernet II-style encapsulation (no LLC/Snap header) + Config::SetDefault ("ns3::CsmaNetDevice::EncapsulationMode", StringValue ("Dix")); +} + // // Example of the sending of a datagram to a broadcast address // @@ -333,12 +348,6 @@ void CsmaMulticastTestCase::DoRun (void) { - // - // Set up default values for the simulation. - // - // Select DIX/Ethernet II-style encapsulation (no LLC/Snap header) - Config::SetDefault ("ns3::CsmaNetDevice::EncapsulationMode", StringValue ("Dix")); - NodeContainer c; c.Create (5); // We will later want two subcontainers of these nodes, for the two LANs diff -r 4f5fb52fde54 -r 6bc7f45725ed src/test/error-model-test-suite.cc --- a/src/test/error-model-test-suite.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/test/error-model-test-suite.cc Wed Jul 13 17:58:55 2011 +0200 @@ -81,6 +81,9 @@ // Set some arbitrary deterministic values SeedManager::SetSeed (7); SeedManager::SetRun (5); + + m_count = 0; + m_drops = 0; Ptr a = CreateObject (); Ptr b = CreateObject (); diff -r 4f5fb52fde54 -r 6bc7f45725ed src/test/global-routing-test-suite.cc --- a/src/test/global-routing-test-suite.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/test/global-routing-test-suite.cc Wed Jul 13 17:58:55 2011 +0200 @@ -55,7 +55,10 @@ private: void SinkRx (std::string path, Ptr p, const Address &address); void HandleRead (Ptr); + virtual void DoRun (void); + virtual void DoSetup (void); + int m_count; std::vector m_firstInterface; std::vector m_secondInterface; @@ -118,6 +121,16 @@ } } +void +DynamicGlobalRoutingTestCase::DoSetup () +{ + TestCase::DoSetup(); + + // The below value configures the default behavior of global routing. + // By default, it is disabled. To respond to interface events, set to true + Config::SetDefault ("ns3::Ipv4GlobalRouting::RespondToInterfaceEvents", BooleanValue (true)); +} + // Test derived from examples/routing/dynamic-global-routing.cc // // Network topology @@ -140,10 +153,6 @@ void DynamicGlobalRoutingTestCase::DoRun (void) { - // The below value configures the default behavior of global routing. - // By default, it is disabled. To respond to interface events, set to true - Config::SetDefault ("ns3::Ipv4GlobalRouting::RespondToInterfaceEvents", BooleanValue (true)); - NodeContainer c; c.Create (7); NodeContainer n0n2 = NodeContainer (c.Get (0), c.Get (2)); diff -r 4f5fb52fde54 -r 6bc7f45725ed src/test/ns3tcp/ns3tcp-cwnd-test-suite.cc --- a/src/test/ns3tcp/ns3tcp-cwnd-test-suite.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/test/ns3tcp/ns3tcp-cwnd-test-suite.cc Wed Jul 13 17:58:55 2011 +0200 @@ -384,6 +384,8 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); + bool m_writeResults; class CwndEvent { @@ -419,11 +421,17 @@ } void +Ns3TcpCwndTestCase2::DoSetup (void) +{ + TestCase::DoSetup (); + + // Set up some default values for the simulation. + Config::SetDefault ("ns3::DropTailQueue::MaxPackets", UintegerValue (4)); +} + +void Ns3TcpCwndTestCase2::DoRun (void) { - // Set up some default values for the simulation. - Config::SetDefault ("ns3::DropTailQueue::MaxPackets", UintegerValue (4)); - NodeContainer n0n1; n0n1.Create (2); diff -r 4f5fb52fde54 -r 6bc7f45725ed src/test/ns3tcp/ns3tcp-interop-test-suite.cc --- a/src/test/ns3tcp/ns3tcp-interop-test-suite.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/test/ns3tcp/ns3tcp-interop-test-suite.cc Wed Jul 13 17:58:55 2011 +0200 @@ -128,6 +128,7 @@ Ns3TcpInteroperabilityTestCase::DoTeardown (void) { m_pcapFile.Close (); + TestCase::DoTeardown (); } void diff -r 4f5fb52fde54 -r 6bc7f45725ed src/test/ns3tcp/ns3tcp-loss-test-suite.cc --- a/src/test/ns3tcp/ns3tcp-loss-test-suite.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/test/ns3tcp/ns3tcp-loss-test-suite.cc Wed Jul 13 17:58:55 2011 +0200 @@ -115,6 +115,11 @@ void Ns3TcpLossTestCase::DoSetup (void) { + Simulator::Destroy(); + + // Enable packet metadata + Packet::EnablePrinting (); + // // We expect there to be a file called ns3tcp-state-response-vectors.pcap in // response-vectors/ of this directory @@ -133,12 +138,51 @@ m_pcapFile.Open (m_pcapFilename, std::ios::in|std::ios::binary); NS_ABORT_MSG_UNLESS (m_pcapFile.GetDataLinkType () == PCAP_LINK_TYPE, "Wrong response vectors in directory"); } + + // Config + std::ostringstream tcpModel; + tcpModel << "ns3::Tcp" << m_tcpModel; + Config::SetDefault ("ns3::TcpL4Protocol::SocketType", StringValue (tcpModel.str ())); + Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1000)); + Config::SetDefault ("ns3::TcpSocket::DelAckCount", UintegerValue (1)); + + // Logging + if (m_writeLogging) + { + LogComponentEnableAll (LOG_PREFIX_FUNC); + LogComponentEnable ("TcpLossResponse", LOG_LEVEL_ALL); + LogComponentEnable ("ErrorModel", LOG_LEVEL_DEBUG); + LogComponentEnable ("TcpLossResponse", LOG_LEVEL_ALL); + LogComponentEnable ("TcpNewReno", LOG_LEVEL_INFO); + LogComponentEnable ("TcpReno", LOG_LEVEL_INFO); + LogComponentEnable ("TcpTahoe", LOG_LEVEL_INFO); + LogComponentEnable ("TcpSocketBase", LOG_LEVEL_INFO); + } + } void Ns3TcpLossTestCase::DoTeardown (void) { + // Restore Logging + if (m_writeLogging) + { + LogComponentDisableAll (LOG_PREFIX_FUNC); + LogComponentDisable ("TcpLossResponse", LOG_LEVEL_ALL); + LogComponentDisable ("ErrorModel", LOG_LEVEL_DEBUG); + LogComponentDisable ("TcpLossResponse", LOG_LEVEL_ALL); + LogComponentDisable ("TcpNewReno", LOG_LEVEL_INFO); + LogComponentDisable ("TcpReno", LOG_LEVEL_INFO); + LogComponentDisable ("TcpTahoe", LOG_LEVEL_INFO); + LogComponentDisable ("TcpSocketBase", LOG_LEVEL_INFO); + } + m_pcapFile.Close (); + + // Enable packet metadata + Packet::DisablePrinting (); + + TestCase::DoTeardown (); } void @@ -182,22 +226,29 @@ // file and see if it still does the right thing. // uint8_t expected[PCAP_SNAPLEN]; - uint32_t tsSec, tsUsec, inclLen, origLen, readLen; + uint32_t tsSec=0, tsUsec=0, inclLen=0, origLen=0, readLen=0; m_pcapFile.Read (expected, sizeof(expected), tsSec, tsUsec, inclLen, origLen, readLen); - uint8_t *actual = new uint8_t[readLen]; - p->CopyData (actual, readLen); + if (readLen != 0 && origLen != 0) + { + uint8_t *actual = new uint8_t[readLen]; + p->CopyData (actual, readLen); - uint32_t result = memcmp (actual, expected, readLen); + uint32_t result = memcmp (actual, expected, readLen); - delete [] actual; + delete [] actual; - // - // Avoid streams of errors -- only report the first. - // - if (GetErrorStatus () == false) + // + // Avoid streams of errors -- only report the first. + // + if (GetErrorStatus () == false) + { + NS_TEST_EXPECT_MSG_EQ (result, 0, "Expected data comparison error"); + } + } + else if (GetErrorStatus () == false) { - NS_TEST_EXPECT_MSG_EQ (result, 0, "Expected data comparison error"); + NS_TEST_EXPECT_MSG_GT (readLen, 0, "Unexpected packet error"); } } } @@ -282,25 +333,6 @@ // Example corresponding to simulations in the paper "Simulation-based // Comparisons of Tahoe, Reno, and SACK TCP - std::ostringstream tcpModel; - tcpModel << "ns3::Tcp" << m_tcpModel; - Config::SetDefault ("ns3::TcpL4Protocol::SocketType", - StringValue (tcpModel.str ())); - Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1000)); - Config::SetDefault ("ns3::TcpSocket::DelAckCount", UintegerValue (1)); - - if (m_writeLogging) - { - LogComponentEnableAll (LOG_PREFIX_FUNC); - LogComponentEnable ("TcpLossResponse", LOG_LEVEL_ALL); - LogComponentEnable ("ErrorModel", LOG_LEVEL_DEBUG); - LogComponentEnable ("TcpLossResponse", LOG_LEVEL_ALL); - LogComponentEnable ("TcpNewReno", LOG_LEVEL_INFO); - LogComponentEnable ("TcpReno", LOG_LEVEL_INFO); - LogComponentEnable ("TcpTahoe", LOG_LEVEL_INFO); - LogComponentEnable ("TcpSocketBase", LOG_LEVEL_INFO); - } - //////////////////////////////////////////////////////// // Topology construction // @@ -359,13 +391,6 @@ ipInterfs.GetAddress (1), servPort); - Config::Connect ("/NodeList/0/$ns3::Ipv4L3Protocol/Tx", - MakeCallback (&Ns3TcpLossTestCase::Ipv4L3Tx, this)); - - Config::ConnectWithoutContext - ("/NodeList/0/$ns3::TcpL4Protocol/SocketList/0/CongestionWindow", - MakeCallback (&Ns3TcpLossTestCase::CwndTracer, this)); - //////////////////////////////////////////////////////// // Set up loss model at node k1 // @@ -403,6 +428,13 @@ pem->SetList (sampleList); dev1.Get (1)->SetAttribute ("ReceiveErrorModel", PointerValue (pem)); + Config::Connect ("/NodeList/0/$ns3::Ipv4L3Protocol/Tx", + MakeCallback (&Ns3TcpLossTestCase::Ipv4L3Tx, this)); + + Config::ConnectWithoutContext + ("/NodeList/0/$ns3::TcpL4Protocol/SocketList/0/CongestionWindow", + MakeCallback (&Ns3TcpLossTestCase::CwndTracer, this)); + // One can toggle the comment for the following line on or off to see the // effects of finite send buffer modelling. One can also change the size of // that buffer. @@ -442,7 +474,6 @@ Ns3TcpLossTestSuite::Ns3TcpLossTestSuite () : TestSuite ("ns3-tcp-loss", SYSTEM) { - Packet::EnablePrinting (); // Enable packet metadata for all test cases AddTestCase (new Ns3TcpLossTestCase ("Tahoe", 0)); AddTestCase (new Ns3TcpLossTestCase ("Tahoe", 1)); AddTestCase (new Ns3TcpLossTestCase ("Tahoe", 2)); diff -r 4f5fb52fde54 -r 6bc7f45725ed src/test/ns3tcp/ns3tcp-socket-test-suite.cc --- a/src/test/ns3tcp/ns3tcp-socket-test-suite.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/test/ns3tcp/ns3tcp-socket-test-suite.cc Wed Jul 13 17:58:55 2011 +0200 @@ -158,6 +158,8 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); + bool m_writeResults; void SinkRx (std::string path, Ptr p, const Address &address); @@ -179,6 +181,13 @@ } void +Ns3TcpSocketTestCase2::DoSetup (void) +{ + TestCase::DoSetup (); + Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1000)); +} + +void Ns3TcpSocketTestCase2::DoRun (void) { uint16_t sinkPort = 50000; @@ -189,8 +198,6 @@ Time writerStopTimeObj = Seconds (writerStopTime); Time simStopTimeObj= Seconds (simStopTime); - Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1000)); - NodeContainer nodes; nodes.Create (2); Ptr n0 = nodes.Get (0); diff -r 4f5fb52fde54 -r 6bc7f45725ed src/test/ns3tcp/ns3tcp-state-test-suite.cc --- a/src/test/ns3tcp/ns3tcp-state-test-suite.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/test/ns3tcp/ns3tcp-state-test-suite.cc Wed Jul 13 17:58:55 2011 +0200 @@ -110,6 +110,11 @@ void Ns3TcpStateTestCase::DoSetup (void) { + Simulator::Destroy(); + + // Enable packet metadata + Packet::EnablePrinting (); + // // We expect there to be a file called ns3tcp-state-response-vectors.pcap in // response-vectors/ of this directory @@ -128,12 +133,50 @@ m_pcapFile.Open (m_pcapFilename, std::ios::in|std::ios::binary); NS_ABORT_MSG_UNLESS (m_pcapFile.GetDataLinkType () == PCAP_LINK_TYPE, "Wrong response vectors in directory"); } + + // Config + std::string tcpModel ("ns3::TcpNewReno"); + Config::SetDefault ("ns3::TcpL4Protocol::SocketType", StringValue (tcpModel)); + Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1000)); + Config::SetDefault ("ns3::TcpSocket::DelAckCount", UintegerValue (1)); + Config::SetDefault ("ns3::DropTailQueue::MaxPackets", UintegerValue (20)); + + // Logging + if (m_writeLogging) + { + LogComponentEnableAll (LOG_PREFIX_FUNC); + LogComponentEnable ("TcpTestCases", LOG_LEVEL_ALL); + LogComponentEnable ("ErrorModel", LOG_LEVEL_DEBUG); + LogComponentEnable ("TcpTestCases", LOG_LEVEL_ALL); + LogComponentEnable ("TcpNewReno", LOG_LEVEL_INFO); + LogComponentEnable ("TcpReno", LOG_LEVEL_INFO); + LogComponentEnable ("TcpTahoe", LOG_LEVEL_INFO); + LogComponentEnable ("TcpSocketBase", LOG_LEVEL_INFO); + } } void Ns3TcpStateTestCase::DoTeardown (void) { + // Restore Logging + if (m_writeLogging) + { + LogComponentDisableAll (LOG_PREFIX_FUNC); + LogComponentDisable ("TcpTestCases", LOG_LEVEL_ALL); + LogComponentDisable ("ErrorModel", LOG_LEVEL_DEBUG); + LogComponentDisable ("TcpTestCases", LOG_LEVEL_ALL); + LogComponentDisable ("TcpNewReno", LOG_LEVEL_INFO); + LogComponentDisable ("TcpReno", LOG_LEVEL_INFO); + LogComponentDisable ("TcpTahoe", LOG_LEVEL_INFO); + LogComponentDisable ("TcpSocketBase", LOG_LEVEL_INFO); + } + m_pcapFile.Close (); + + // Enable packet metadata + Packet::DisablePrinting (); + + TestCase::DoTeardown (); } void @@ -177,22 +220,29 @@ // file and see if it still does the right thing. // uint8_t expected[PCAP_SNAPLEN]; - uint32_t tsSec, tsUsec, inclLen, origLen, readLen; + uint32_t tsSec=0, tsUsec=0, inclLen=0, origLen=0, readLen=0; m_pcapFile.Read (expected, sizeof(expected), tsSec, tsUsec, inclLen, origLen, readLen); + + if (readLen != 0 && origLen != 0) + { + uint8_t *actual = new uint8_t[readLen]; + p->CopyData (actual, readLen); - uint8_t *actual = new uint8_t[readLen]; - p->CopyData (actual, readLen); + uint32_t result = memcmp (actual, expected, readLen); - uint32_t result = memcmp (actual, expected, readLen); + delete [] actual; - delete [] actual; - - // - // Avoid streams of errors -- only report the first. - // - if (GetErrorStatus () == false) + // + // Avoid streams of errors -- only report the first. + // + if (GetErrorStatus () == false) + { + NS_TEST_EXPECT_MSG_EQ (result, 0, "Expected data comparison error"); + } + } + else if (GetErrorStatus () == false) { - NS_TEST_EXPECT_MSG_EQ (result, 0, "Expected data comparison error"); + NS_TEST_EXPECT_MSG_GT (readLen, 0, "Unexpected packet error"); } } } @@ -266,29 +316,10 @@ // 10Mb/s, 0.1ms 10Mb/s, 0.1ms // n0-----------------n1-----------------n2 - std::string tcpModel ("ns3::TcpNewReno"); - - Config::SetDefault ("ns3::TcpL4Protocol::SocketType", StringValue (tcpModel)); - Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1000)); - Config::SetDefault ("ns3::TcpSocket::DelAckCount", UintegerValue (1)); - Config::SetDefault ("ns3::DropTailQueue::MaxPackets", UintegerValue (20)); - - if (m_writeLogging) - { - LogComponentEnableAll (LOG_PREFIX_FUNC); - LogComponentEnable ("TcpTestCases", LOG_LEVEL_ALL); - LogComponentEnable ("ErrorModel", LOG_LEVEL_DEBUG); - LogComponentEnable ("TcpTestCases", LOG_LEVEL_ALL); - LogComponentEnable ("TcpNewReno", LOG_LEVEL_INFO); - LogComponentEnable ("TcpReno", LOG_LEVEL_INFO); - LogComponentEnable ("TcpTahoe", LOG_LEVEL_INFO); - LogComponentEnable ("TcpSocketBase", LOG_LEVEL_INFO); - } - //////////////////////////////////////////////////////// // Topology construction // - + // Create three nodes NodeContainer n0n1; n0n1.Create (2); @@ -338,9 +369,6 @@ Simulator::ScheduleNow (&Ns3TcpStateTestCase::StartFlow, this, localSocket, ipInterfs.GetAddress (1), servPort); - Config::Connect ("/NodeList/0/$ns3::Ipv4L3Protocol/Tx", - MakeCallback (&Ns3TcpStateTestCase::Ipv4L3Tx, this)); - //////////////////////////////////////////////////////// // Set up different test cases: Lost model at node n1, different file size // @@ -411,6 +439,9 @@ errN1->SetList (dropListN1); dev1.Get (0)->SetAttribute ("ReceiveErrorModel", PointerValue (errN1)); + Config::Connect ("/NodeList/0/$ns3::Ipv4L3Protocol/Tx", + MakeCallback (&Ns3TcpStateTestCase::Ipv4L3Tx, this)); + std::ostringstream oss; oss << "tcp-state" << m_testCase << "-test-case"; if (m_writeResults) @@ -434,8 +465,6 @@ Simulator::Stop (Seconds (1000)); Simulator::Run (); Simulator::Destroy (); - - } class Ns3TcpStateTestSuite : public TestSuite @@ -447,7 +476,6 @@ Ns3TcpStateTestSuite::Ns3TcpStateTestSuite () : TestSuite ("ns3-tcp-state", SYSTEM) { - Packet::EnablePrinting (); // Enable packet metadata for all test cases AddTestCase (new Ns3TcpStateTestCase (0)); AddTestCase (new Ns3TcpStateTestCase (1)); AddTestCase (new Ns3TcpStateTestCase (2)); diff -r 4f5fb52fde54 -r 6bc7f45725ed src/test/ns3wifi/wifi-interference-test-suite.cc --- a/src/test/ns3wifi/wifi-interference-test-suite.cc Mon Jul 11 18:15:52 2011 +0200 +++ b/src/test/ns3wifi/wifi-interference-test-suite.cc Wed Jul 13 17:58:55 2011 +0200 @@ -57,6 +57,8 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); + void ReceivePacket (Ptr socket); static void GenerateTraffic (Ptr socket, uint32_t pktSize, uint32_t pktCount, Time pktInterval); void PrintEndSync (std::string context, uint32_t dataRate, double snr, double per); @@ -65,11 +67,14 @@ double m_PER; double m_SNR; uint32_t m_DataRate; + + std::string m_phyMode; }; // Add some help text to this case to describe what it is intended to test WifiInterferenceTestCase::WifiInterferenceTestCase () : TestCase ("Test interference calculation when interfering frame exactly overlaps intended frame") + , m_phyMode ("DsssRate1Mbps") { } @@ -77,6 +82,19 @@ { } +void +WifiInterferenceTestCase::DoSetup () +{ + TestCase::DoSetup (); + + // disable fragmentation for frames below 2200 bytes + Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200")); + // turn off RTS/CTS for frames below 2200 bytes + Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200")); + // Fix non-unicast data rate to be the same as that of unicast + Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue (m_phyMode)); +} + void WifiInterferenceTestCase::ReceivePacket (Ptr socket) { @@ -131,14 +149,6 @@ // Convert to time object Time interPacketInterval = Seconds (interval); - // disable fragmentation for frames below 2200 bytes - Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200")); - // turn off RTS/CTS for frames below 2200 bytes - Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200")); - // Fix non-unicast data rate to be the same as that of unicast - Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", - StringValue (phyMode)); - NodeContainer c; c.Create (3); @@ -232,8 +242,6 @@ void WifiInterferenceTestCase::DoRun (void) { - - std::string phyMode ("DsssRate1Mbps"); double Prss = -90; // -dBm double Irss = -90; // -dBm double delta = 0; // microseconds @@ -246,17 +254,17 @@ // Compute the packet error rate (PER) when delta=0 microseconds. This // means that the interferer arrives at exactly the same time as the // intended packet - PER = WifiSimpleInterference (phyMode,Prss,Irss,delta,PpacketSize,IpacketSize,verbose,internet); + PER = WifiSimpleInterference (m_phyMode,Prss,Irss,delta,PpacketSize,IpacketSize,verbose,internet); // Now rerun this test case and compute the PER when the delta time between // arrival of the intended frame and interferer is 1 microsecond. delta = 1; - PER1 = WifiSimpleInterference (phyMode,Prss,Irss,delta,PpacketSize,IpacketSize,verbose,internet); + PER1 = WifiSimpleInterference (m_phyMode,Prss,Irss,delta,PpacketSize,IpacketSize,verbose,internet); // Now rerun this test case and compute the PER when the delta time between // arrival of the intended frame and interferer is 2 microseconds. delta = 2; - PER2 = WifiSimpleInterference (phyMode,Prss,Irss,delta,PpacketSize,IpacketSize,verbose,internet); + PER2 = WifiSimpleInterference (m_phyMode,Prss,Irss,delta,PpacketSize,IpacketSize,verbose,internet); double PERDiff1 = PER - PER1; # HG changeset patch # User cdfreire # Date 1310572979 -7200 # Node ID 1212956c4b1558c48d6bd3468a2bbdbe8e42de52 # Parent 6bc7f45725ed001cff33fa663fa902a67488571e Fix typo in src/core/model/test.h diff -r 6bc7f45725ed -r 1212956c4b15 src/core/model/test.h --- a/src/core/model/test.h Wed Jul 13 17:58:55 2011 +0200 +++ b/src/core/model/test.h Wed Jul 13 18:02:59 2011 +0200 @@ -754,7 +754,7 @@ actualStream << actual; \ std::ostringstream limitStream; \ limitStream << limit; \ - ReporTesttFailure (std::string (# actual) + " (actual) > " + std::string (# limit) + " (limit)", \ + ReportTestFailure (std::string (# actual) + " (actual) > " + std::string (# limit) + " (limit)", \ actualStream.str (), limitStream.str (), msgStream.str (), file, line); \ } \ } while (false)