Refactor tests for brevity

This commit is contained in:
Tim Schubert 2020-08-29 18:21:09 +02:00
parent 37631d0758
commit 4c008e32f0
5 changed files with 112 additions and 139 deletions

View file

@ -133,6 +133,7 @@ int main (int argc, char *argv[])
if (routingProto == "epidemic") if (routingProto == "epidemic")
{ {
EpidemicHelper epidemic; EpidemicHelper epidemic;
//epidemic.Set ("BeaconInterval", TimeValue (MilliSeconds (100)));
stack.SetRoutingHelper (epidemic); stack.SetRoutingHelper (epidemic);
} }
else else

View file

@ -42,7 +42,7 @@ LeoCircularOrbitMobilityModel::GetTypeId ()
return tid; return tid;
} }
LeoCircularOrbitMobilityModel::LeoCircularOrbitMobilityModel() : MobilityModel (), m_latitude (0.0), m_offset (0.0), m_position () LeoCircularOrbitMobilityModel::LeoCircularOrbitMobilityModel() : MobilityModel (), m_longitude (0.0), m_offset (0.0), m_position ()
{ {
NS_LOG_FUNCTION_NOARGS (); NS_LOG_FUNCTION_NOARGS ();
} }
@ -123,7 +123,7 @@ LeoCircularOrbitMobilityModel::RotatePlane (double a, const Vector3D &x) const
double double
LeoCircularOrbitMobilityModel::CalcLatitude () const LeoCircularOrbitMobilityModel::CalcLatitude () const
{ {
return m_latitude + ((Simulator::Now ().GetDouble () / Hours (24).GetDouble ()) * 2 * M_PI); return m_longitude + ((Simulator::Now ().GetDouble () / Hours (24).GetDouble ()) * 2 * M_PI);
} }
Vector Vector
@ -169,7 +169,7 @@ LeoCircularOrbitMobilityModel::DoSetPosition (const Vector &position)
// this works nicely with MobilityHelper and GetPostion will still get the // this works nicely with MobilityHelper and GetPostion will still get the
// correct position, but be aware that it will not be the same as supplied to // correct position, but be aware that it will not be the same as supplied to
// SetPostion // SetPostion
m_latitude = position.x; m_longitude = position.x;
m_offset = position.y; m_offset = position.y;
Update (); Update ();
} }

View file

@ -56,9 +56,9 @@ private:
double m_inclination; double m_inclination;
/** /**
* Latitude in rad * Longitudinal offset in rad
*/ */
double m_latitude; double m_longitude;
/** /**
* Offset on the orbital plane in rad * Offset on the orbital plane in rad

View file

@ -14,25 +14,12 @@ using namespace ns3;
class LeoMockChannelTransmitUnknownTestCase : public TestCase class LeoMockChannelTransmitUnknownTestCase : public TestCase
{ {
public: public:
LeoMockChannelTransmitUnknownTestCase (); LeoMockChannelTransmitUnknownTestCase () : TestCase ("transmission from unknown source fails") {}
virtual ~LeoMockChannelTransmitUnknownTestCase (); virtual ~LeoMockChannelTransmitUnknownTestCase () {}
private: private:
virtual void DoRun (void); virtual void DoRun (void)
}; {
LeoMockChannelTransmitUnknownTestCase::LeoMockChannelTransmitUnknownTestCase ()
: TestCase ("Test transmission to unkown destination")
{
}
LeoMockChannelTransmitUnknownTestCase::~LeoMockChannelTransmitUnknownTestCase ()
{
}
void
LeoMockChannelTransmitUnknownTestCase::DoRun (void)
{
Ptr<LeoMockChannel> channel = CreateObject<LeoMockChannel> (); Ptr<LeoMockChannel> channel = CreateObject<LeoMockChannel> ();
Packet *packet = new Packet (); Packet *packet = new Packet ();
Ptr<Packet> p = Ptr<Packet>(packet); Ptr<Packet> p = Ptr<Packet>(packet);
@ -42,31 +29,18 @@ LeoMockChannelTransmitUnknownTestCase::DoRun (void)
channel->SetAttribute ("PropagationLoss", StringValue ("ns3::LeoPropagationLossModel")); channel->SetAttribute ("PropagationLoss", StringValue ("ns3::LeoPropagationLossModel"));
bool result = channel->TransmitStart (p, 10000, destAddr, txTime); bool result = channel->TransmitStart (p, 10000, destAddr, txTime);
NS_TEST_ASSERT_MSG_EQ (result, false, "Unknown source fails to deliver"); NS_TEST_ASSERT_MSG_EQ (result, false, "unknown source fails to deliver");
} }
};
class LeoMockChannelTransmitKnownTestCase : public TestCase class LeoMockChannelTransmitKnownTestCase : public TestCase
{ {
public: public:
LeoMockChannelTransmitKnownTestCase (); LeoMockChannelTransmitKnownTestCase () : TestCase ("transmission from known source succeeds") {}
virtual ~LeoMockChannelTransmitKnownTestCase (); virtual ~LeoMockChannelTransmitKnownTestCase () {}
private: private:
virtual void DoRun (void); virtual void DoRun (void)
}; {
LeoMockChannelTransmitKnownTestCase::LeoMockChannelTransmitKnownTestCase ()
: TestCase ("Test transmission to known destination")
{
}
LeoMockChannelTransmitKnownTestCase::~LeoMockChannelTransmitKnownTestCase ()
{
}
void
LeoMockChannelTransmitKnownTestCase::DoRun (void)
{
Ptr<LeoMockChannel> channel = CreateObject<LeoMockChannel> (); Ptr<LeoMockChannel> channel = CreateObject<LeoMockChannel> ();
channel->SetAttribute ("PropagationDelay", StringValue ("ns3::ConstantSpeedPropagationDelayModel")); channel->SetAttribute ("PropagationDelay", StringValue ("ns3::ConstantSpeedPropagationDelayModel"));
channel->SetAttribute ("PropagationLoss", StringValue ("ns3::LeoPropagationLossModel")); channel->SetAttribute ("PropagationLoss", StringValue ("ns3::LeoPropagationLossModel"));
@ -92,31 +66,18 @@ LeoMockChannelTransmitKnownTestCase::DoRun (void)
Time txTime; Time txTime;
bool result = channel->TransmitStart (p, srcId, destAddr, txTime); bool result = channel->TransmitStart (p, srcId, destAddr, txTime);
NS_TEST_ASSERT_MSG_EQ (result, true, "Known source delivers"); NS_TEST_ASSERT_MSG_EQ (result, true, "known source does not deliver");
} }
};
class LeoMockChannelTransmitSpaceGroundTestCase : public TestCase class LeoMockChannelTransmitSpaceGroundTestCase : public TestCase
{ {
public: public:
LeoMockChannelTransmitSpaceGroundTestCase (); LeoMockChannelTransmitSpaceGroundTestCase () : TestCase ("space to ground transmission succeeds") {}
virtual ~LeoMockChannelTransmitSpaceGroundTestCase (); virtual ~LeoMockChannelTransmitSpaceGroundTestCase () {}
private: private:
virtual void DoRun (void); virtual void DoRun (void)
}; {
LeoMockChannelTransmitSpaceGroundTestCase::LeoMockChannelTransmitSpaceGroundTestCase ()
: TestCase ("Test transmission to known destination")
{
}
LeoMockChannelTransmitSpaceGroundTestCase::~LeoMockChannelTransmitSpaceGroundTestCase ()
{
}
void
LeoMockChannelTransmitSpaceGroundTestCase::DoRun (void)
{
Ptr<LeoMockChannel> channel = CreateObject<LeoMockChannel> (); Ptr<LeoMockChannel> channel = CreateObject<LeoMockChannel> ();
channel->SetAttribute ("PropagationDelay", StringValue ("ns3::ConstantSpeedPropagationDelayModel")); channel->SetAttribute ("PropagationDelay", StringValue ("ns3::ConstantSpeedPropagationDelayModel"));
channel->SetAttribute ("PropagationLoss", StringValue ("ns3::LeoPropagationLossModel")); channel->SetAttribute ("PropagationLoss", StringValue ("ns3::LeoPropagationLossModel"));
@ -142,8 +103,9 @@ LeoMockChannelTransmitSpaceGroundTestCase::DoRun (void)
Time txTime; Time txTime;
bool result = channel->TransmitStart (p, srcId, destAddr, txTime); bool result = channel->TransmitStart (p, srcId, destAddr, txTime);
NS_TEST_ASSERT_MSG_EQ (result, true, "Space to ground destination delivers"); NS_TEST_ASSERT_MSG_EQ (result, true, "space to ground transmission failed");
} }
};
class LeoMockChannelTestSuite : public TestSuite class LeoMockChannelTestSuite : public TestSuite
{ {
@ -154,11 +116,9 @@ public:
LeoMockChannelTestSuite::LeoMockChannelTestSuite () LeoMockChannelTestSuite::LeoMockChannelTestSuite ()
: TestSuite ("leo-mock-channel", UNIT) : TestSuite ("leo-mock-channel", UNIT)
{ {
// TestDuration for TestCase can be QUICK, EXTENSIVE or TAKES_FOREVER
AddTestCase (new LeoMockChannelTransmitUnknownTestCase, TestCase::QUICK); AddTestCase (new LeoMockChannelTransmitUnknownTestCase, TestCase::QUICK);
AddTestCase (new LeoMockChannelTransmitKnownTestCase, TestCase::QUICK); AddTestCase (new LeoMockChannelTransmitKnownTestCase, TestCase::QUICK);
AddTestCase (new LeoMockChannelTransmitSpaceGroundTestCase, TestCase::QUICK); AddTestCase (new LeoMockChannelTransmitSpaceGroundTestCase, TestCase::QUICK);
} }
// Do not forget to allocate an instance of this TestSuite
static LeoMockChannelTestSuite islMockChannelTestSuite; static LeoMockChannelTestSuite islMockChannelTestSuite;

View file

@ -14,7 +14,7 @@ using namespace ns3;
class LeoOrbitSpeedTestCase : public TestCase class LeoOrbitSpeedTestCase : public TestCase
{ {
public: public:
LeoOrbitSpeedTestCase () : TestCase ("Test speed for 0 altitude") {} LeoOrbitSpeedTestCase () : TestCase ("speed at 0 altitude is earth rotation speed") {}
virtual ~LeoOrbitSpeedTestCase () {} virtual ~LeoOrbitSpeedTestCase () {}
private: private:
virtual void DoRun (void) virtual void DoRun (void)
@ -22,14 +22,14 @@ private:
Ptr<LeoCircularOrbitMobilityModel> mob = CreateObject<LeoCircularOrbitMobilityModel> (); Ptr<LeoCircularOrbitMobilityModel> mob = CreateObject<LeoCircularOrbitMobilityModel> ();
mob->SetAttribute ("Altitude", DoubleValue (0.0)); mob->SetAttribute ("Altitude", DoubleValue (0.0));
NS_TEST_ASSERT_MSG_EQ ((uint64_t) mob->GetSpeed (), (uint64_t) 7909.79, "Unexpected velocity at earths surface"); NS_TEST_ASSERT_MSG_EQ ((uint64_t) mob->GetSpeed (), (uint64_t) 7909.79, "postion at 0 altitude is on surface");
} }
}; };
class LeoOrbitPositionTestCase : public TestCase class LeoOrbitPositionTestCase : public TestCase
{ {
public: public:
LeoOrbitPositionTestCase () : TestCase ("Test position for 0 altitude and 1.0 inclination") {} LeoOrbitPositionTestCase () : TestCase ("position is on surface") {}
virtual ~LeoOrbitPositionTestCase () {} virtual ~LeoOrbitPositionTestCase () {}
private: private:
virtual void DoRun (void) virtual void DoRun (void)
@ -38,21 +38,21 @@ private:
mob->SetAttribute ("Altitude", DoubleValue (0.0)); mob->SetAttribute ("Altitude", DoubleValue (0.0));
mob->SetAttribute ("Inclination", DoubleValue (1.0)); mob->SetAttribute ("Inclination", DoubleValue (1.0));
NS_TEST_ASSERT_MSG_EQ_TOL (mob->GetPosition ().GetLength() / 1000, LEO_EARTH_RAD_KM, 0.1, "Unexpected position on earths surface for 1 deg inclination"); NS_TEST_ASSERT_MSG_EQ_TOL (mob->GetPosition ().GetLength() / 1000, LEO_EARTH_RAD_KM, 0.1, "unexpected position on earths surface for 1 deg inclination");
} }
}; };
class LeoOrbitProgressTestCase : public TestCase class LeoOrbitProgressTestCase : public TestCase
{ {
public: public:
LeoOrbitProgressTestCase () : TestCase ("Test position shoudl not be the same after some time") {} LeoOrbitProgressTestCase () : TestCase ("position changes over time") {}
virtual ~LeoOrbitProgressTestCase () {} virtual ~LeoOrbitProgressTestCase () {}
private: private:
void TestLengthPosition (double expl, double expx, Ptr<LeoCircularOrbitMobilityModel> mob) void TestLengthPosition (double expl, double expx, Ptr<LeoCircularOrbitMobilityModel> mob)
{ {
Vector pos = mob->GetPosition (); Vector pos = mob->GetPosition ();
NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL (pos.GetLength () / 1000, expl, 0.001, "Distance to earth should be the same", __FILE__, __LINE__); NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL (pos.GetLength () / 1000, expl, 0.001, "Distance to earth should be the same", __FILE__, __LINE__);
NS_TEST_EXPECT_MSG_NE_INTERNAL (pos.x, expx, "Position should not be equal", __FILE__, __LINE__); NS_TEST_EXPECT_MSG_NE_INTERNAL (pos.x, expx, "position should not be equal", __FILE__, __LINE__);
} }
virtual void DoRun (void) virtual void DoRun (void)
@ -72,7 +72,7 @@ private:
class LeoOrbitLatitudeTestCase : public TestCase class LeoOrbitLatitudeTestCase : public TestCase
{ {
public: public:
LeoOrbitLatitudeTestCase () : TestCase ("Test offset between neighboring satellites planes") {} LeoOrbitLatitudeTestCase () : TestCase ("neighboring satellite planes have offset") {}
virtual ~LeoOrbitLatitudeTestCase () {} virtual ~LeoOrbitLatitudeTestCase () {}
private: private:
virtual void DoRun (void) virtual void DoRun (void)
@ -86,14 +86,14 @@ private:
mob->SetPosition (Vector3D (20.0, 0, 0)); mob->SetPosition (Vector3D (20.0, 0, 0));
Vector pos2 = mob->GetPosition (); Vector pos2 = mob->GetPosition ();
NS_TEST_ASSERT_MSG_NE (pos1.x, pos2.x, "Neighboring satellite should have different position"); NS_TEST_ASSERT_MSG_NE (pos1.x, pos2.x, "neighboring satellite planes should have different position");
} }
}; };
class LeoOrbitOffsetTestCase : public TestCase class LeoOrbitOffsetTestCase : public TestCase
{ {
public: public:
LeoOrbitOffsetTestCase () : TestCase ("Test offset between neighboring satellites") {} LeoOrbitOffsetTestCase () : TestCase ("neighboring satellites have offset") {}
virtual ~LeoOrbitOffsetTestCase () {} virtual ~LeoOrbitOffsetTestCase () {}
private: private:
virtual void DoRun (void) virtual void DoRun (void)
@ -107,21 +107,19 @@ private:
mob->SetPosition (Vector3D (0, 20.0, 0)); mob->SetPosition (Vector3D (0, 20.0, 0));
Vector pos2 = mob->GetPosition (); Vector pos2 = mob->GetPosition ();
NS_TEST_ASSERT_MSG_NE (pos1.x, pos2.x, "Neighboring satellite should have different position"); NS_TEST_ASSERT_MSG_NE (pos1.x, pos2.x, "neighboring satellite should have different position");
} }
}; };
class LeoOrbitTracingTestCase : public TestCase class LeoOrbitTracingTestCase : public TestCase
{ {
public: public:
LeoOrbitTracingTestCase () : TestCase ("Test tracing of position changes") {} LeoOrbitTracingTestCase () : TestCase ("position changes are traced") {}
virtual ~LeoOrbitTracingTestCase () {} virtual ~LeoOrbitTracingTestCase () {}
static void CourseChange (std::string context, Ptr<const MobilityModel> position)
{ static uint64_t traced;
Vector pos = position->GetPosition ();
std::cout << Simulator::Now () << ", pos=" << position << ", x=" << pos.x << ", y=" << pos.y static void CourseChange (std::string context, Ptr<const MobilityModel> position);
<< ", z=" << pos.z << std::endl;
}
private: private:
virtual void DoRun (void) virtual void DoRun (void)
{ {
@ -142,13 +140,27 @@ private:
Config::Connect ("/NodeList/*/$ns3::MobilityModel/CourseChange", Config::Connect ("/NodeList/*/$ns3::MobilityModel/CourseChange",
MakeCallback (&CourseChange)); MakeCallback (&CourseChange));
traced = 0;
Simulator::Stop (Seconds (100.0)); Simulator::Stop (Seconds (100.0));
Simulator::Run (); Simulator::Run ();
NS_TEST_ASSERT_MSG_GT (traced, 8, "position not every time");
Simulator::Destroy (); Simulator::Destroy ();
} }
}; };
uint64_t LeoOrbitTracingTestCase::traced = 0;
void LeoOrbitTracingTestCase::CourseChange (std::string context, Ptr<const MobilityModel> position)
{
traced ++;
Vector pos = position->GetPosition ();
std::cout << Simulator::Now () << ", pos=" << position << ", x=" << pos.x << ", y=" << pos.y
<< ", z=" << pos.z << std::endl;
}
class LeoOrbitTestSuite : TestSuite class LeoOrbitTestSuite : TestSuite
{ {