wifi unit tests ported to new framework
authorPavel Boyko <boyko@iitp.ru>
Wed, 30 Sep 2009 20:02:17 +0400
changeset 5320 0fb5a9f1a9c0
parent 5317 afe8c8f1d3dd
child 5321 4e0214eefe4e
wifi unit tests ported to new framework
src/devices/wifi/dcf-manager-test.cc
src/devices/wifi/interference-helper-tx-duration-test.cc
src/devices/wifi/mac-rx-middle.cc
src/devices/wifi/wifi-test.cc
--- a/src/devices/wifi/dcf-manager-test.cc	Wed Sep 30 19:17:16 2009 +0400
+++ b/src/devices/wifi/dcf-manager-test.cc	Wed Sep 30 20:02:17 2009 +0400
@@ -17,13 +17,11 @@
  *
  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
  */
-#ifdef RUN_SELF_TESTS
 
 #include "ns3/test.h"
 #include "ns3/simulator.h"
 #include "dcf-manager.h"
 
-
 namespace ns3 {
 
 class DcfManagerTest;
@@ -56,11 +54,11 @@
 };
 
 
-class DcfManagerTest : public Test
+class DcfManagerTest : public TestCase
 {
 public:
   DcfManagerTest ();
-  virtual bool RunTests (void);
+  virtual bool DoRun (void);
 
 
   void NotifyAccessGranted (uint32_t i);
@@ -99,7 +97,6 @@
   DcfManager *m_dcfManager;
   DcfStates m_dcfStates;
   uint32_t m_ackTimeoutValue;
-  bool m_result;
 };
 
 
@@ -135,24 +132,19 @@
 
 
 DcfManagerTest::DcfManagerTest ()
-  : Test ("DcfManager")
+  : TestCase ("DcfManager")
 {}
 
 void 
 DcfManagerTest::NotifyAccessGranted (uint32_t i)
 {
   DcfStateTest *state = m_dcfStates[i];
-  bool result = true;
-  NS_TEST_ASSERT (!state->m_expectedGrants.empty ());
+  NS_TEST_EXPECT_MSG_EQ (state->m_expectedGrants.empty (), false, "Have expected grants");
   std::pair<uint64_t, uint64_t> expected = state->m_expectedGrants.front ();
   state->m_expectedGrants.pop_front ();
-  NS_TEST_ASSERT_EQUAL (Simulator::Now (), MicroSeconds (expected.second));
+  NS_TEST_EXPECT_MSG_EQ (Simulator::Now (), MicroSeconds (expected.second), "Expected access grant is now");
   m_dcfManager->NotifyTxStartNow (MicroSeconds (expected.first));
   m_dcfManager->NotifyAckTimeoutStartNow (MicroSeconds (m_ackTimeoutValue + expected.first));
-  if (!result)
-    {
-      m_result = result;
-    }
 }
 void
 DcfManagerTest::AddTxEvt (uint64_t at, uint64_t duration)
@@ -165,46 +157,31 @@
 DcfManagerTest::NotifyInternalCollision (uint32_t i)
 {
   DcfStateTest *state = m_dcfStates[i];
-  bool result = true;
-  NS_TEST_ASSERT (!state->m_expectedInternalCollision.empty ());
+  NS_TEST_EXPECT_MSG_EQ (state->m_expectedInternalCollision.empty (), false, "Have expected internal collisions");
   struct DcfStateTest::ExpectedCollision expected = state->m_expectedInternalCollision.front ();
   state->m_expectedInternalCollision.pop_front ();
-  NS_TEST_ASSERT_EQUAL (Simulator::Now (), MicroSeconds (expected.at));
+  NS_TEST_EXPECT_MSG_EQ (Simulator::Now (), MicroSeconds (expected.at), "Expected internal collision time is now");
   state->StartBackoffNow (expected.nSlots);
-  if (!result)
-    {
-      m_result = result;
-    }
 }
 void 
 DcfManagerTest::NotifyCollision (uint32_t i)
 {
   DcfStateTest *state = m_dcfStates[i];
-  bool result = true;
-  NS_TEST_ASSERT (!state->m_expectedCollision.empty ());
+  NS_TEST_EXPECT_MSG_EQ (state->m_expectedCollision.empty (), false, "Have expected collisions");
   struct DcfStateTest::ExpectedCollision expected = state->m_expectedCollision.front ();
   state->m_expectedCollision.pop_front ();
-  NS_TEST_ASSERT_EQUAL (Simulator::Now (), MicroSeconds (expected.at));
+  NS_TEST_EXPECT_MSG_EQ (Simulator::Now (), MicroSeconds (expected.at), "Expected collision is now");
   state->StartBackoffNow (expected.nSlots);
-  if (!result)
-    {
-      m_result = result;
-    }
 }
 void 
 DcfManagerTest::NotifyChannelSwitching (uint32_t i)
 {
   DcfStateTest *state = m_dcfStates[i];
-  bool result = true;
   if (!state->m_expectedGrants.empty ())
     {
       std::pair<uint64_t, uint64_t> expected = state->m_expectedGrants.front ();
       state->m_expectedGrants.pop_front ();
-      NS_TEST_ASSERT_EQUAL (Simulator::Now (), MicroSeconds (expected.second));
-    }
-  if (!result)
-    {
-      m_result = result;
+      NS_TEST_EXPECT_MSG_EQ (Simulator::Now (), MicroSeconds (expected.second), "Expected grant is now");
     }
 }
 
@@ -249,23 +226,18 @@
 void
 DcfManagerTest::EndTest (void)
 {
-  bool result = true;
   Simulator::Run ();
   Simulator::Destroy ();
   for (DcfStates::const_iterator i = m_dcfStates.begin (); i != m_dcfStates.end (); i++)
     {
       DcfStateTest *state = *i;
-      NS_TEST_ASSERT (state->m_expectedGrants.empty ());
-      NS_TEST_ASSERT (state->m_expectedInternalCollision.empty ());
-      NS_TEST_ASSERT (state->m_expectedCollision.empty ());
+      NS_TEST_EXPECT_MSG_EQ (state->m_expectedGrants.empty (), true, "Have no expected grants");
+      NS_TEST_EXPECT_MSG_EQ (state->m_expectedInternalCollision.empty (), true, "Have no internal collisions");
+      NS_TEST_EXPECT_MSG_EQ (state->m_expectedCollision.empty (), true, "Have no expected collisions");
       delete state;
     }
   m_dcfStates.clear ();
   delete m_dcfManager;
-  if (!result)
-    {
-      m_result = result;
-    }
 }
 
 void 
@@ -369,10 +341,8 @@
 
 
 bool 
-DcfManagerTest::RunTests (void)
+DcfManagerTest::DoRun (void)
 {
-  m_result = true;
-
   //  0      3       4    5      8       9  10   12
   //  | sifs | aifsn | tx | sifs | aifsn |   | tx | 
   //
@@ -691,15 +661,24 @@
   AddSwitchingEvt(80,20);
   AddAccessRequest (101, 2, 110, 0);
   EndTest ();
-
-
-  return m_result;
+  
+  return GetErrorStatus ();
 }
 
+//-----------------------------------------------------------------------------
 
+class DcfTestSuite : public TestSuite
+{
+public:
+  DcfTestSuite ();
+};
 
-static DcfManagerTest g_dcf_manager_test;
+DcfTestSuite::DcfTestSuite ()
+  : TestSuite ("devices-wifi-dcf", UNIT)
+{
+  AddTestCase (new DcfManagerTest);
+}
+
+DcfTestSuite g_dcfTestSuite;
 
 } // namespace ns3
-
-#endif /* RUN_SELF_TESTS */
--- a/src/devices/wifi/interference-helper-tx-duration-test.cc	Wed Sep 30 19:17:16 2009 +0400
+++ b/src/devices/wifi/interference-helper-tx-duration-test.cc	Wed Sep 30 20:02:17 2009 +0400
@@ -18,26 +18,23 @@
  * Author: Nicola Baldo <nbaldo@cttc.es>
  */
 
-#include<ns3/object.h>
-#include<ns3/log.h>
+#include <ns3/object.h>
+#include <ns3/log.h>
 #include <ns3/test.h>
-#include<iostream>
-#include"interference-helper.h"
-#include"wifi-phy.h"
+#include <iostream>
+#include "interference-helper.h"
+#include "wifi-phy.h"
 
 NS_LOG_COMPONENT_DEFINE ("InterferenceHelperTxDurationTest");
 
-
-#ifdef RUN_SELF_TESTS
-
-
 namespace ns3 {
 
-class InterferenceHelperTxDurationTest : public Test {
+class InterferenceHelperTxDurationTest : public TestCase 
+{
 public:
   InterferenceHelperTxDurationTest ();
   virtual ~InterferenceHelperTxDurationTest ();
-  virtual bool RunTests (void);
+  virtual bool DoRun (void);
 
 private:
 
@@ -69,12 +66,8 @@
 };
 
 
-// we need to create one instance of InterferenceHelperTxDurationTest
-static InterferenceHelperTxDurationTest interferenceHelperTxDurationTestInstance;
-
-
 InterferenceHelperTxDurationTest::InterferenceHelperTxDurationTest ()
-  : Test ("InterferenceHelperTxDuration")
+  : TestCase ("InterferenceHelper TX Duration")
 {
 }
 
@@ -83,8 +76,6 @@
 {
 }
 
-
-
 bool
 InterferenceHelperTxDurationTest::CheckPayloadDuration(uint32_t size, WifiMode payloadMode, uint32_t knownDurationMicroSeconds)
 {
@@ -119,7 +110,7 @@
 }
 
 bool 
-InterferenceHelperTxDurationTest::RunTests (void)
+InterferenceHelperTxDurationTest::DoRun (void)
 {
   bool retval = true;
 
@@ -182,12 +173,21 @@
     && CheckTxDuration (76, WifiPhy::Get54mba (), WIFI_PREAMBLE_LONG, 32)
     && CheckTxDuration (14, WifiPhy::Get54mba (), WIFI_PREAMBLE_LONG, 24);
 
-
-  return retval;
+  return (!retval);
 }
 
+class TxDurationTestSuite : public TestSuite
+{
+public:
+  TxDurationTestSuite ();
+};
 
+TxDurationTestSuite::TxDurationTestSuite ()
+  : TestSuite ("devices-wifi-tx-duration", UNIT)
+{
+  AddTestCase (new InterferenceHelperTxDurationTest);
+}
+
+TxDurationTestSuite g_txDurationTestSuite;
 } //namespace ns3 
 
-
-#endif /* RUN_SELF_TESTS */
--- a/src/devices/wifi/mac-rx-middle.cc	Wed Sep 30 19:17:16 2009 +0400
+++ b/src/devices/wifi/mac-rx-middle.cc	Wed Sep 30 20:02:17 2009 +0400
@@ -299,54 +299,3 @@
 }
 
 } // namespace ns3
-
-#ifdef RUN_SELF_TESTS
-
-#include "ns3/test.h"
-
-namespace ns3 {
-
-class MacRxMiddleTest : public Test
-{
-public:
-  MacRxMiddleTest () : Test ("MacRxMiddle") {}
-  virtual bool RunTests (void) 
-  {
-    bool result = true;
-    MacRxMiddle middle;
-    // 0 < 1
-    NS_TEST_ASSERT (middle.SequenceControlSmaller (0 << 4, 1 << 4));
-    // 0 < 2047
-    NS_TEST_ASSERT (middle.SequenceControlSmaller (0 << 4, 2047 << 4));
-    // 0 > 2048
-    NS_TEST_ASSERT (!middle.SequenceControlSmaller (0 << 4, 2048 << 4));
-    // 0 > 2049
-    NS_TEST_ASSERT (!middle.SequenceControlSmaller (0 << 4, 2049 << 4));
-    // 0 > 4095
-    NS_TEST_ASSERT (!middle.SequenceControlSmaller (0 << 4, 4095 << 4));
-
-    // 1 > 0
-    NS_TEST_ASSERT (!middle.SequenceControlSmaller (1 << 4, 0 << 4));
-    // 2047 > 0
-    NS_TEST_ASSERT (!middle.SequenceControlSmaller (2047 << 4, 0 << 4));
-    // 2048 < 0
-    NS_TEST_ASSERT (middle.SequenceControlSmaller (2048 << 4, 0 << 4));
-    // 2049 < 0
-    NS_TEST_ASSERT (middle.SequenceControlSmaller (2049 << 4, 0 << 4));
-    // 4095 < 0 
-    NS_TEST_ASSERT (middle.SequenceControlSmaller (4095 << 4, 0 << 4));
-
-    // 2048 < 2049
-    NS_TEST_ASSERT (middle.SequenceControlSmaller (2048 << 4, 2049 << 4));
-    // 2048 < 4095
-    NS_TEST_ASSERT (middle.SequenceControlSmaller (2048 << 4, 4095 << 4));
-    // 2047 > 4095
-    NS_TEST_ASSERT (!middle.SequenceControlSmaller (2047 << 4, 4095 << 4));
-
-    return result;
-  }
-} g_macRxMiddleTest;
-
-} // namespace ns3
-
-#endif /* RUN_SELF_TESTS */
--- a/src/devices/wifi/wifi-test.cc	Wed Sep 30 19:17:16 2009 +0400
+++ b/src/devices/wifi/wifi-test.cc	Wed Sep 30 20:02:17 2009 +0400
@@ -17,7 +17,6 @@
  *
  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
  */
-#ifdef RUN_SELF_TESTS
 
 #include "wifi-net-device.h"
 #include "yans-wifi-channel.h"
@@ -34,16 +33,17 @@
 #include "ns3/test.h"
 #include "ns3/object-factory.h"
 #include "dca-txop.h"
+#include "mac-rx-middle.h"
 #include "ns3/pointer.h"
 
 namespace ns3 {
 
-class WifiTest : public Test
+class WifiTest : public TestCase
 {
 public:
   WifiTest ();
 
-  virtual bool RunTests (void);
+  virtual bool DoRun (void);
 private:
   void RunOne (void);
   void CreateOne (Vector pos, Ptr<YansWifiChannel> channel);
@@ -55,7 +55,7 @@
 };
 
 WifiTest::WifiTest ()
-  : Test ("Wifi")
+  : TestCase ("Wifi")
 {}
 
 void 
@@ -114,14 +114,11 @@
 }
 
 bool
-WifiTest::RunTests (void)
+WifiTest::DoRun (void)
 {
-  bool result = true;
-
   m_mac.SetTypeId ("ns3::AdhocWifiMac");
   m_propDelay.SetTypeId ("ns3::ConstantSpeedPropagationDelayModel");
   
-
   m_manager.SetTypeId ("ns3::ArfWifiManager");
   RunOne ();
   m_manager.SetTypeId ("ns3::AarfWifiManager");
@@ -147,12 +144,65 @@
   m_mac.SetTypeId ("ns3::AdhocWifiMac");
   RunOne ();
 
-  return result;
+  return false;
 }
 
-static WifiTest g_wifiTest;
+//-----------------------------------------------------------------------------
+class MacRxMiddleTest : public TestCase
+{
+public:
+  MacRxMiddleTest () : TestCase ("MacRxMiddle") {}
+  virtual bool DoRun (void) 
+  {
+    MacRxMiddle middle;
+    // 0 < 1
+    NS_TEST_EXPECT_MSG_EQ (middle.SequenceControlSmaller (0 << 4, 1 << 4), true, "0 < 1");
+    // 0 < 2047
+    NS_TEST_EXPECT_MSG_EQ (middle.SequenceControlSmaller (0 << 4, 2047 << 4), true, "0 < 2047");
+    // 0 > 2048
+    NS_TEST_EXPECT_MSG_EQ (!middle.SequenceControlSmaller (0 << 4, 2048 << 4), true, "0 > 2048");
+    // 0 > 2049
+    NS_TEST_EXPECT_MSG_EQ (!middle.SequenceControlSmaller (0 << 4, 2049 << 4), true, "0 > 2049");
+    // 0 > 4095
+    NS_TEST_EXPECT_MSG_EQ (!middle.SequenceControlSmaller (0 << 4, 4095 << 4), true, "0 > 4095");
 
+    // 1 > 0
+    NS_TEST_EXPECT_MSG_EQ (!middle.SequenceControlSmaller (1 << 4, 0 << 4), true, "1 > 0");
+    // 2047 > 0
+    NS_TEST_EXPECT_MSG_EQ (!middle.SequenceControlSmaller (2047 << 4, 0 << 4), true, "2047 > 0");
+    // 2048 < 0
+    NS_TEST_EXPECT_MSG_EQ (middle.SequenceControlSmaller (2048 << 4, 0 << 4), true, "2048 < 0");
+    // 2049 < 0
+    NS_TEST_EXPECT_MSG_EQ (middle.SequenceControlSmaller (2049 << 4, 0 << 4), true, "2049 < 0");
+    // 4095 < 0 
+    NS_TEST_EXPECT_MSG_EQ (middle.SequenceControlSmaller (4095 << 4, 0 << 4), true, "4095 < 0");
+
+    // 2048 < 2049
+    NS_TEST_EXPECT_MSG_EQ (middle.SequenceControlSmaller (2048 << 4, 2049 << 4), true, "2048 < 2049");
+    // 2048 < 4095
+    NS_TEST_EXPECT_MSG_EQ (middle.SequenceControlSmaller (2048 << 4, 4095 << 4), true, "2048 < 4095");
+    // 2047 > 4095
+    NS_TEST_EXPECT_MSG_EQ (!middle.SequenceControlSmaller (2047 << 4, 4095 << 4), true, "2047 > 4095");
+
+    return GetErrorStatus ();
+  }
+};
+
+//-----------------------------------------------------------------------------
+
+class WifiTestSuite : public TestSuite
+{
+public:
+  WifiTestSuite ();
+};
+
+WifiTestSuite::WifiTestSuite ()
+  : TestSuite ("devices-wifi", UNIT)
+{
+  AddTestCase (new WifiTest);
+  AddTestCase (new MacRxMiddleTest);
+}
+
+WifiTestSuite g_wifiTestSuite;
 
 } // namespace ns3
-
-#endif /* RUN_SELF_TESTS */