summaryrefslogtreecommitdiff
path: root/cesar/maximus/sci/utest/server/src
diff options
context:
space:
mode:
authorThierry Carré2012-10-16 12:45:48 +0200
committerThierry Carré2013-01-31 15:04:48 +0100
commit4452a8abe0d135b1f690b530a3bb4b1e495d7b65 (patch)
treeffa06423693d00cdaccd3d8a51d3c6c61ec2b2f3 /cesar/maximus/sci/utest/server/src
parent83441de4ab01355295cfe6a6e389ad5bc66fd361 (diff)
cesar/maximus: C++ maximus refactoring, closes #3336, closes #3098
Feedback on new performance on tests inside: test_general/station Ratio = Test duration before this commit divided by new duration. |--------------------------------------------|-------| | Unit test | Ratio | |--------------------------------------------|-------| | maximus/py/sc01_long_simu.py | 6.5 | | maximus/py/sc02_long_simu.py | 4.5 | | scenario/av/py/sc01_assoc_auth.py | 3.3 | | scenario/av/py/sc02_stas_communication.py | 4.5 | | scenario/av/py/sc03_two_avln_coexisting.py | 2.1 | | scenario/av/py/sc04_cc_whoru.py | 2.1 | | scenario/av/py/sc05_cc_leave.py | 2.3 | | scenario/av/py/sc06_discover_procedure.py | 2.3 | | scenario/av/py/sc07_bridge.py | 2.2 | | scenario/av/py/sc08_bentry_change.py | 2.1 | | scenario/av/py/sc09_simple_connect.py | 2.2 | | scenario/av/py/sc10_short_messages.py | 5.7 | | scenario/av/py/sc11_cm_nw_info.py | 4.7 | | scenario/av/py/sc12_change_nmk.py | 5.5 | | scenario/av/py/sc14_igmp.py | 4.0 | | scenario/av/py/sc15_hide.py | 6.0 | | compliance/py/sc01_dut_as_a_cco.py | 5.8 | | tonemap/py/sc01_bl_initial.py | 2.3 | | tonemap/py/sc02_vs_get_tonemap.py | 2.3 | |--------------------------------------------|-------| | Average speed improvement of Maximus is | 4.9 | |--------------------------------------------|-------| Many tickets have been opened to continue the refactoring. Titles begin by "[Maximus][Refactoring]" in pessac's trac. For this reason #3336 is close. #3098 is really fixed.
Diffstat (limited to 'cesar/maximus/sci/utest/server/src')
-rw-r--r--cesar/maximus/sci/utest/server/src/PipoProcessor.cpp69
-rw-r--r--cesar/maximus/sci/utest/server/src/PipoSciMsg.cpp44
-rw-r--r--cesar/maximus/sci/utest/server/src/TestSciServer.cpp103
-rw-r--r--cesar/maximus/sci/utest/server/src/fake_Station.cpp173
4 files changed, 389 insertions, 0 deletions
diff --git a/cesar/maximus/sci/utest/server/src/PipoProcessor.cpp b/cesar/maximus/sci/utest/server/src/PipoProcessor.cpp
new file mode 100644
index 0000000000..6b796cd94a
--- /dev/null
+++ b/cesar/maximus/sci/utest/server/src/PipoProcessor.cpp
@@ -0,0 +1,69 @@
+/* Maximus project {{{
+ *
+ * Copyright (C) 2012 MStar Semiconductor
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file maximus/sci/utest/server/src/PipoProcessor.cpp
+ * \ingroup maximus_sci_utest_server
+ *
+ */
+
+#include "inc/PipoProcessor.h"
+#include "inc/PipoSciMsg.h"
+#include "maximus/sci/inc/SciMsg.h"
+#include <ostream>
+#include <iostream>
+
+PipoProcessor::PipoProcessor (SciServer &ref1,
+ MaximusCallBack &ref2):
+ Processor (ref1, ref2, FAKE_SCI_TYPE)
+{
+ nb_msg_rx = 0;
+}
+
+PipoProcessor::~PipoProcessor ()
+{
+}
+
+SciMsg*
+PipoProcessor::create_sci_msg (
+ struct Sci_Msg_Header &header,
+ unsigned char *buffer)
+{
+ return new PipoSciMsg (header, buffer);
+}
+
+void
+PipoProcessor::dispatchMsgProc (
+ SciMsg *msg_rx)
+{
+ PipoSciMsg *msg =
+ static_cast <PipoSciMsg*> (msg_rx);
+
+ last_length = msg->get_sci_datalength ();
+ nb_msg_rx ++;
+ delete msg;
+}
+
+
+bool
+PipoProcessor::is_msg_received ()
+{
+ if (nb_msg_rx)
+ return true;
+ return false;
+}
+
+bool
+PipoProcessor::is_good_size (size_t size_expected)
+{
+ int check = nb_msg_rx;
+ nb_msg_rx = 0;
+
+ if (size_expected == last_length && check == 1)
+ return true;
+ return false;
+}
diff --git a/cesar/maximus/sci/utest/server/src/PipoSciMsg.cpp b/cesar/maximus/sci/utest/server/src/PipoSciMsg.cpp
new file mode 100644
index 0000000000..61fd0c8cac
--- /dev/null
+++ b/cesar/maximus/sci/utest/server/src/PipoSciMsg.cpp
@@ -0,0 +1,44 @@
+/* Maximus project {{{
+ *
+ * Copyright (C) 2012 MStar Semiconductor
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file maximus/sci/utest/server/src/PipoSciMsg.c
+ * \ingroup maximus_sci_utest_server
+ *
+ */
+
+#include "inc/PipoSciMsg.h"
+#include <cstring>
+
+PipoSciMsg::PipoSciMsg (struct Sci_Msg_Header &header,
+ unsigned char *buffer):
+ SciMsg (header, buffer)
+{
+}
+
+PipoSciMsg::PipoSciMsg (size_t size_of_data):
+ SciMsg (size_of_data, FAKE_SCI_TYPE)
+{
+ if (size_of_data)
+ memset (get_sci_data_addr (), 0, size_of_data);
+}
+
+PipoSciMsg::~PipoSciMsg ()
+{
+}
+
+void
+PipoSciMsg::display_specialized_header () const
+{
+}
+
+void
+PipoSciMsg::setup_and_send (SciServer &SciServer)
+{
+ SciMsg::setup_and_send (SciServer);
+}
+
diff --git a/cesar/maximus/sci/utest/server/src/TestSciServer.cpp b/cesar/maximus/sci/utest/server/src/TestSciServer.cpp
new file mode 100644
index 0000000000..7d76ccf1f6
--- /dev/null
+++ b/cesar/maximus/sci/utest/server/src/TestSciServer.cpp
@@ -0,0 +1,103 @@
+/* Maximus project {{{
+ *
+ * Copyright (C) 2012 MStar Semiconductor
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file maximus/sci/utest/server/src/TestSciServer.cpp
+ * \ingroup maximus_sci_utest_server
+ *
+ */
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include "maximus/interface/station/inc/Station.h"
+#include "maximus/sci/inc/SciServer.h"
+#include "maximus/utils/inc/Error.h"
+
+#include "inc/TestSciServer.h"
+#include "inc/fake_Maximus.h"
+#include "inc/PipoProcessor.h"
+#include "inc/PipoSciMsg.h"
+
+CPPUNIT_TEST_SUITE_REGISTRATION (TestSciServer);
+
+void
+TestSciServer::setUp ()
+{
+ server = new SciServer (sta_list);
+ max = new Maximus ();
+}
+
+void
+TestSciServer::tearDown ()
+{
+ delete server;
+ delete max;
+ max = NULL;
+ server = NULL;
+}
+
+void
+TestSciServer::test_pipe_bidir ()
+{
+ std::cout << __func__ << ": 0% .." << std::flush;
+ Network_Clock_Tick time = 0;
+
+ static const size_t progress[3] = {
+ /* 25% */
+ SCI_MSG_MAX_SIZE / 4,
+ /* 50% */
+ SCI_MSG_MAX_SIZE / 2,
+ /* 75% */
+ (3 * SCI_MSG_MAX_SIZE) / 4,
+ };
+
+ try
+ {
+ PipoProcessor *pipo_proc = new PipoProcessor (*server, *max);
+ server->register_current_tick_addr (&time);
+
+ Station *fake_sta = new Station (*max,
+ "noexec", 0, SCI_MSG_MAX_SIZE);
+ sta_list.push_back (fake_sta);
+
+ PipoSciMsg *msg = NULL;
+ for (size_t i = 0; i < SCI_MSG_MAX_SIZE; i++)
+ {
+ if (i == progress[0])
+ std::cout << "25% .." << std::flush;
+ if (i == progress[1])
+ std::cout << "50% .." << std::flush;
+ if (i == progress[2])
+ std::cout << "75% .." << std::flush;
+
+ msg = new PipoSciMsg (i);
+ msg->set_sci_stationid (fake_sta->getStationId ());
+
+ msg->setup_and_send (*server);
+ delete msg;
+ msg = NULL;
+
+ do
+ {
+ server->process ();
+ } while (!pipo_proc->is_msg_received ());
+
+
+ /* Is the message have been drive to pipo_proc. */
+ CPPUNIT_ASSERT (pipo_proc->is_good_size (i));
+ }
+ std::cout << "100%" << std::endl;
+
+ sta_list.clear ();
+ delete fake_sta;
+ delete pipo_proc;
+ }
+ catch (Error &e)
+ {
+ e.display ();
+ CPPUNIT_FAIL ("Error catched !");
+ }
+}
diff --git a/cesar/maximus/sci/utest/server/src/fake_Station.cpp b/cesar/maximus/sci/utest/server/src/fake_Station.cpp
new file mode 100644
index 0000000000..64d76b6578
--- /dev/null
+++ b/cesar/maximus/sci/utest/server/src/fake_Station.cpp
@@ -0,0 +1,173 @@
+/* Maximus project {{{
+ *
+ * Copyright (C) 2012 MStar Semiconductor
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file maximus/sci/utest/server/src/fake_station.cpp
+ * \ingroup maximus_sci_utest_server
+ *
+ */
+#include "maximus/interface/station/inc/Station.h"
+#include "maximus/utils/inc/Error.h"
+#include "maximus/sci/inc/SciServer.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <signal.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string>
+#include <string.h>
+#include <sstream>
+#include <stdio.h>
+#include <cstdlib>
+#include <netinet/in.h>
+#include <assert.h>
+
+Station::Station (
+ Maximus &ref1,
+ const std::string & station_executable,
+ const Network_Clock_Tick current_tick_value,
+ uint32_t seed):
+ interface (ref1),
+ fd_sta2max (-1),
+ fd_max2sta (-1),
+ fd_log (-1),
+ mStationStatus (MAXIMUS_STATION_STATUS_IDLE),
+ mStationIdleCounter (0)
+{
+ std::ostringstream pipe_max2sta, pipe_sta2max;
+
+ pipe_max2sta << STATION_PIPE_PATH;
+ pipe_max2sta << "/" ;
+ pipe_max2sta << STATION_PIPE_PREFIX;
+ pipe_sta2max << pipe_max2sta.str ();
+
+ pipe_sta2max << "_sta2max_";
+ pipe_max2sta << "_max2sta_";
+
+ mPid = fork ();
+
+ if (mPid == 0)
+ {
+ /* child process. */
+ mPid = getpid ();
+ pipe_sta2max << std::dec << mPid;
+ pipe_max2sta << std::dec << mPid;
+
+ mknod (pipe_max2sta.str ().c_str (), 0770 | S_IFIFO, 0);
+ mknod (pipe_sta2max.str ().c_str (), 0770 | S_IFIFO, 0);
+
+ /* output pipe for a sta. */
+ fd_sta2max = open (pipe_sta2max.str ().c_str (),
+ O_WRONLY);
+ if (fd_sta2max < 0)
+ exit (EXIT_FAILURE);
+
+ /* Input pipe for a sta. */
+ fd_max2sta = open (pipe_max2sta.str ().c_str (),
+ O_RDONLY | O_CLOEXEC);;
+ if (fd_max2sta < 0)
+ exit (EXIT_FAILURE);
+
+ try
+ {
+ const int header_size = sizeof (struct Sci_Msg_Header);
+ char alloc[SCI_MSG_MAX_SIZE];
+ struct Sci_Msg_Header *header = (Sci_Msg_Header *) alloc;
+ int msg_size;
+ int ret;
+ size_t nb_message;
+
+ for (nb_message = 0;
+ nb_message < seed;
+ nb_message++)
+ {
+ ret = read (fd_max2sta, alloc, header_size);
+ assert (ret == header_size);
+
+ msg_size = ntohl (header->length);
+
+ if (msg_size != 0)
+ {
+ ret = read (fd_max2sta, alloc + header_size, msg_size);
+ assert (ret == msg_size);
+ }
+
+ ret = write (fd_sta2max, alloc, msg_size + header_size);
+ assert (ret == msg_size + header_size);
+ }
+ }
+ catch (Error &e)
+ {
+ e.display ();
+ exit (EXIT_FAILURE);
+ }
+
+ /* Wait the SIGKILL. */
+ pause ();
+ }
+
+ assert (mPid >= 0);
+
+ pipe_sta2max << std::dec << mPid;
+ pipe_max2sta << std::dec << mPid;
+
+ mknod (pipe_max2sta.str ().c_str (), 0770 | S_IFIFO, 0);
+ mknod (pipe_sta2max.str ().c_str (), 0770 | S_IFIFO, 0);
+
+ fd_sta2max = open (pipe_sta2max.str ().c_str (),
+ O_RDONLY | O_CLOEXEC);;
+ assert (fd_sta2max >= 0);
+
+ fd_max2sta = open (pipe_max2sta.str ().c_str (),
+ O_WRONLY);
+ assert (fd_sta2max >= 0);
+}
+
+Station::~Station ()
+{
+ std::ostringstream pipe_max2sta, pipe_sta2max;
+
+ pipe_max2sta << STATION_PIPE_PATH;
+ pipe_max2sta << "/" ;
+ pipe_max2sta << STATION_PIPE_PREFIX;
+ pipe_sta2max << pipe_max2sta.str ();
+
+ pipe_sta2max << "_sta2max_";
+ pipe_max2sta << "_max2sta_";
+
+ pipe_sta2max << std::dec << mPid;
+ pipe_max2sta << std::dec << mPid;
+
+ if (fd_max2sta >= 0)
+ {
+ close (fd_max2sta);
+ fd_max2sta = 0;
+ }
+
+ if (fd_sta2max >= 0)
+ {
+ close (fd_sta2max);
+ fd_sta2max = 0;
+ }
+
+ remove (pipe_sta2max.str ().c_str ());
+ remove (pipe_max2sta.str ().c_str ());
+
+ kill (mPid, SIGKILL);
+}
+
+void
+Station::decrementStationIdleCounter ()
+{
+}
+
+bool
+Station::hideStation (
+ Sci_Msg_Station_Id station_id, bool hidden)
+{
+ return true;
+}