summaryrefslogtreecommitdiff
path: root/cesar/maximus/coreengine/src/MaximusTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/maximus/coreengine/src/MaximusTest.cpp')
-rw-r--r--cesar/maximus/coreengine/src/MaximusTest.cpp445
1 files changed, 445 insertions, 0 deletions
diff --git a/cesar/maximus/coreengine/src/MaximusTest.cpp b/cesar/maximus/coreengine/src/MaximusTest.cpp
new file mode 100644
index 0000000000..f308081266
--- /dev/null
+++ b/cesar/maximus/coreengine/src/MaximusTest.cpp
@@ -0,0 +1,445 @@
+
+#include "MaximusTest.h"
+
+#include "Maximus.h"
+#include "Msg.h"
+#include "Sta.h"
+#include "PhySciMsgPre.h"
+#include "PhySciMsgFc.h"
+#include "PhySciMsgMpdu.h"
+#include "EtherSciMsg.h"
+
+#include "Logger.h"
+
+#include "functioncall_types.h" // for 'PROBE_ID'
+
+#include <iostream>
+using namespace std;
+
+CPPUNIT_TEST_SUITE_REGISTRATION (MaximusTest);
+
+void phyCb (PhySciMsg & phy_sci_msg)
+{
+
+}
+
+void etherCb (EtherSciMsg & ether_sci_msg)
+{
+
+}
+
+
+void MaximusTest::setUp (void)
+{
+ logTest();
+
+ mpMaximus = new Maximus ();
+}
+
+
+void MaximusTest::tearDown (void)
+{
+ logTest();
+
+ if (NULL != mpMaximus)
+ {
+ delete (mpMaximus);
+ mpMaximus = NULL;
+ }
+}
+
+
+void MaximusTest::init_test (void)
+{
+ logTest();
+
+ if (NULL != mpMaximus)
+ {
+ //mpMaximus->init(argc, argv);
+ }
+ else
+ {
+ CPPUNIT_FAIL ("Maximus pointer is NULL");
+ }
+}
+
+
+void MaximusTest::init_phy_test (void)
+{
+ logTest();
+
+ if (NULL != mpMaximus)
+ {
+ mpMaximus->init_phy(&phyCb);
+ }
+ else
+ {
+ CPPUNIT_FAIL ("Maximus pointer is NULL");
+ }
+}
+
+
+void MaximusTest::init_ether_test (void)
+{
+ logTest();
+
+ if (NULL != mpMaximus)
+ {
+ CPPUNIT_ASSERT_MESSAGE ( "init_ether failed",
+ -1 == mpMaximus->init_ether(&etherCb) );
+ }
+ else
+ {
+ CPPUNIT_FAIL ("Maximus pointer is NULL");
+ }
+}
+
+
+void MaximusTest::process_test (void)
+{
+ logTest();
+
+ if (NULL != mpMaximus)
+ {
+ mpMaximus->process();
+ }
+ else
+ {
+ CPPUNIT_FAIL ("Maximus pointer is NULL");
+ }
+}
+
+
+void MaximusTest::create_sta_test (void)
+{
+ logTest();
+
+ if (NULL != mpMaximus)
+ {
+ Sta sta = mpMaximus->create_sta();
+
+ CPPUNIT_ASSERT_MESSAGE ( "create_sta failed",
+ 0 != sta.getStationId() );
+
+ sta.remove();
+ }
+ else
+ {
+ CPPUNIT_FAIL ("Maximus pointer is NULL");
+ }
+}
+
+
+void MaximusTest::create_fc_test (void)
+{
+ logTest();
+
+ if (NULL != mpMaximus)
+ {
+ Msg msg = mpMaximus->create_fc("function");
+
+ CPPUNIT_ASSERT_MESSAGE ( "create_fc failed",
+ 0 != msg.get_tx_msg_id() );
+ }
+ else
+ {
+ CPPUNIT_FAIL ("Maximus pointer is NULL");
+ }
+}
+
+
+void MaximusTest::create_probe_test (void)
+{
+ logTest();
+
+ if (NULL != mpMaximus)
+ {
+ Msg msg = mpMaximus->create_probe();
+
+ CPPUNIT_ASSERT_MESSAGE ( "create_probe failed",
+ 0 != msg.get_tx_msg_id() );
+ }
+ else
+ {
+ CPPUNIT_FAIL ("Maximus pointer is NULL");
+ }
+}
+
+
+void MaximusTest::create_mpdu_test (void)
+{
+ logTest();
+
+ if (NULL != mpMaximus)
+ {
+ PhySciMsgMpdu * pMpdu = mpMaximus->create_mpdu();
+
+ CPPUNIT_ASSERT_MESSAGE ( "create_mpdu failed",
+ NULL != pMpdu );
+
+ delete (pMpdu);
+ pMpdu = NULL;
+ }
+ else
+ {
+ CPPUNIT_FAIL ("Maximus pointer is NULL");
+ }
+}
+
+
+void MaximusTest::send_mpdu_test (void)
+{
+ logTest();
+
+ if (NULL != mpMaximus)
+ {
+ // create MPDU
+ PhySciMsgMpdu * pMpdu = mpMaximus->create_mpdu();
+ CPPUNIT_ASSERT_MESSAGE ( "PHY SCI message MPDU pointer is NULL", NULL != pMpdu );
+
+ /* Configure MPDU. */
+ unsigned long length = 5;
+ unsigned char payload[length];
+ memset(payload, 'P', length);
+
+ pMpdu->setMpdu(length, payload);
+
+ // create the transmitting station
+ Sta staTx = mpMaximus->create_sta();
+
+ // create the destination station
+ Sta staRx = mpMaximus->create_sta();
+
+ // set the destination station
+ pMpdu->setSciMsgStationId(staRx.getStationId());
+
+ // set FC
+ uint32_t fc_av[4];
+ memset(fc_av, 'A', 4*sizeof(uint32_t));
+ uint32_t fc_10 = 10;
+ pMpdu->setFc10(fc_10);
+ pMpdu->setFcAv(fc_av);
+
+ // set FC mode
+ pMpdu->setFcMode(PHY_FC_MODE_HYBRID_1);
+
+ // set short PPDU
+ pMpdu->setShortPpdu(1);
+
+ mpMaximus->send_mpdu(pMpdu);
+
+ while (!pMpdu->isSent() && !pMpdu->getFc()->isSent())
+ {
+ mpMaximus->process();
+ }
+
+ if (NULL != pMpdu)
+ {
+ delete (pMpdu);
+ pMpdu = NULL;
+ }
+ }
+ else
+ {
+ CPPUNIT_FAIL ("Maximus pointer is NULL");
+ }
+}
+
+
+void MaximusTest::create_ether_test (void)
+{
+ logTest();
+
+ if (NULL != mpMaximus)
+ {
+ EtherSciMsg * pEther = mpMaximus->create_ether();
+
+ CPPUNIT_ASSERT_MESSAGE ( "create_ether failed", NULL != pEther );
+
+ delete (pEther);
+ pEther = NULL;
+ }
+ else
+ {
+ CPPUNIT_FAIL ("Maximus pointer is NULL");
+ }
+}
+
+
+void MaximusTest::send_ether_test (void)
+{
+ logTest();
+
+ if (NULL != mpMaximus)
+ {
+ // create Ether SCI message
+ EtherSciMsg * pEtherSciMsg = mpMaximus->create_ether();
+
+ // create the destination station
+ Sta staRx = mpMaximus->create_sta();
+ mpMaximus->wait(5);
+
+ /* Configure Ether SCI message. */
+ pEtherSciMsg->setSpecializedSciMsgType(ETHERNET_TYPE_DATA);
+ unsigned long length = 5;
+ unsigned char payload[length];
+ memset(payload, 'E', length);
+ pEtherSciMsg->setSpecializedSciMsgDataLength(length);
+ pEtherSciMsg->setSpecializedSciMsgData(payload);
+ pEtherSciMsg->setSciMsgStationId(staRx.getStationId());
+
+ // send Ether SCI message
+ mpMaximus->send_ether(*pEtherSciMsg);
+
+ // remove the destination station
+ staRx.remove();
+
+ if (NULL != pEtherSciMsg)
+ {
+ delete (pEtherSciMsg);
+ pEtherSciMsg = NULL;
+ }
+ }
+ else
+ {
+ CPPUNIT_FAIL ("Maximus pointer is NULL");
+ }
+}
+
+
+void MaximusTest::wait_test (void)
+{
+ logTest();
+
+ if (NULL != mpMaximus)
+ {
+ Sta sta = mpMaximus->create_sta();
+ mpMaximus->wait(10);
+ mpMaximus->wait();
+ }
+ else
+ {
+ CPPUNIT_FAIL ("Maximus pointer is NULL");
+ }
+}
+
+
+void MaximusTest::disturb_channel_test (void)
+{
+ logTest();
+
+ if (NULL != mpMaximus)
+ {
+ //mpMaximus->disturb_channel();
+ //mpMaximus->disturb_channel(false);
+ }
+ else
+ {
+ CPPUNIT_FAIL ("Maximus pointer is NULL");
+ }
+}
+
+
+void MaximusTest::get_date_test (void)
+{
+ logTest();
+
+ if (NULL != mpMaximus)
+ {
+ tick_t date = mpMaximus->get_date();
+ tick_t offset = 100;
+ Sta sta = mpMaximus->create_sta();
+ mpMaximus->wait(offset);
+ CPPUNIT_ASSERT_MESSAGE ( "get_date failed", date + offset == mpMaximus->get_date() );
+ }
+ else
+ {
+ CPPUNIT_FAIL ("Maximus pointer is NULL");
+ }
+}
+
+
+void MaximusTest::set_freq_test (void)
+{
+ logTest();
+
+ if (NULL != mpMaximus)
+ {
+ Sta sta = mpMaximus->create_sta();
+
+ float freq = 0;
+ mpMaximus->set_freq(freq);
+ CPPUNIT_ASSERT_MESSAGE ( "set_freq failed", freq == mpMaximus->get_freq() );
+ mpMaximus->wait(100000);
+
+ sta.remove();
+ }
+ else
+ {
+ CPPUNIT_FAIL ("Maximus pointer is NULL");
+ }
+}
+
+
+void MaximusTest::activate_false_alarm_test (void)
+{
+ logTest();
+
+ if (NULL != mpMaximus)
+ {
+ Sta sta = mpMaximus->create_sta();
+
+ Network_Clock_Tick averageDuration = 10;
+ float stdDeviation = 0.1;
+ mpMaximus->activate_false_alarm(averageDuration, stdDeviation);
+ mpMaximus->wait(2*averageDuration);
+
+ sta.remove();
+ }
+ else
+ {
+ CPPUNIT_FAIL ("Maximus pointer is NULL");
+ }
+}
+
+
+void MaximusTest::deactivate_false_alarm_test (void)
+{
+ logTest();
+
+ if (NULL != mpMaximus)
+ {
+ Sta sta = mpMaximus->create_sta();
+
+ mpMaximus->deactivate_false_alarm();
+ mpMaximus->wait(1000);
+
+ sta.remove();
+ }
+ else
+ {
+ CPPUNIT_FAIL ("Maximus pointer is NULL");
+ }
+}
+
+
+void MaximusTest::is_station_idle_test (void)
+{
+ logTest();
+
+ if (NULL != mpMaximus)
+ {
+ Sta sta = mpMaximus->create_sta();
+
+ CPPUNIT_ASSERT_MESSAGE ( "is_station_idle failed", !mpMaximus->is_station_idle(sta.getStationId()) );
+ mpMaximus->wait(1);
+ CPPUNIT_ASSERT_MESSAGE ( "is_station_idle failed", mpMaximus->is_station_idle(sta.getStationId()) );
+
+ sta.remove();
+ }
+ else
+ {
+ CPPUNIT_FAIL ("Maximus pointer is NULL");
+ }
+}
+