add_cpputest(file_connector_test file_connector))
+add_cpputest(file_connector_module_test file_connector_module))
AM_DEFAULT_SOURCE_EXT = .cc
check_PROGRAMS = \
-file_connector_test
+file_connector_test \
+file_connector_module_test
TESTS = $(check_PROGRAMS)
file_connector_test_CPPFLAGS = @AM_CPPFLAGS@ @CPPUTEST_CPPFLAGS@
-file_connector_test_LDADD = ../libfile_connector.a ../../../framework/libframework.a @CPPUTEST_LDFLAGS@
+file_connector_test_LDADD = \
+../file_connector.o \
+../../../framework/libframework.a \
+@CPPUTEST_LDFLAGS@
+
+file_connector_module_test_LDADD = \
+../file_connector_module.o \
+../../../framework/libframework.a \
+../../../sfip/libsfip.a \
+../../../catch/libcatch_tests.a \
+@CPPUTEST_LDFLAGS@
--- /dev/null
+//--------------------------------------------------------------------------
+// Copyright (C) 2015-2016 Cisco and/or its affiliates. All rights reserved.
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License Version 2 as published
+// by the Free Software Foundation. You may not use, modify or distribute
+// this program under any other version of the GNU General Public License.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//--------------------------------------------------------------------------
+
+// file_connector_module_test.cc author Ed Borgoyn <eborgoyn@cisco.com>
+// unit test main
+
+#include <CppUTest/CommandLineTestRunner.h>
+#include <CppUTest/TestHarness.h>
+
+#include "connectors/file_connector/file_connector_module.h"
+#include "profiler/profiler.h"
+
+#include "main/snort_debug.h"
+
+THREAD_LOCAL SimpleStats file_connector_stats;
+THREAD_LOCAL ProfileStats file_connector_perfstats;
+
+void show_stats(PegCount*, const PegInfo*, unsigned, const char*) { }
+
+void show_stats(PegCount*, const PegInfo*, IndexVec&, const char*) { }
+
+void show_stats(PegCount*, const PegInfo*, IndexVec&, const char*, FILE*) { }
+
+void Debug::print(const char*, int, uint64_t, const char*, ...) { }
+
+TEST_GROUP(file_connector_module)
+{
+ void setup()
+ {
+ MemoryLeakWarningPlugin::turnOffNewDeleteOverloads();
+ }
+
+ void teardown()
+ {
+ MemoryLeakWarningPlugin::turnOnNewDeleteOverloads();
+ }
+};
+
+TEST(file_connector_module, test)
+{
+ Value connector_val("rx");
+ Value name_val("rx");
+ Value format_val("binary");
+ Value direction_val("receive");
+ Parameter direction_param =
+ {"direction", Parameter::PT_ENUM, "receive | transmit | duplex", nullptr, "direction"};
+ Parameter format_param =
+ {"format", Parameter::PT_ENUM, "binary | text", nullptr, "format"};
+ Parameter connector_param =
+ {"connector", Parameter::PT_STRING, nullptr, nullptr, "connector"};
+ Parameter name_param =
+ {"name", Parameter::PT_STRING, nullptr, nullptr, "name"};
+
+ FileConnectorModule module;
+
+ name_val.set(&name_param);
+ direction_val.set(&direction_param);
+ format_val.set(&format_param);
+ connector_val.set(&connector_param);
+
+ module.begin("file_connector", 0, nullptr);
+ module.begin("file_connector", 1, nullptr);
+ module.set("file_connector.name", name_val, nullptr);
+ module.set("file_connector.direction", direction_val, nullptr);
+ module.set("file_connector.connector", connector_val, nullptr);
+ module.set("file_connector.format", format_val, nullptr);
+ module.end("file_connector", 1, nullptr);
+ module.end("file_connector", 0, nullptr);
+
+ FileConnectorConfig::FileConnectorConfigSet* config_set = module.get_and_clear_config();
+
+ CHECK(config_set != nullptr);
+
+ CHECK(config_set->size() == 1);
+
+ FileConnectorConfig config = *(config_set->front());
+ CHECK(config.name == "rx");
+ CHECK(config.connector_name == "rx");
+ CHECK(config.direction == Connector::CONN_RECEIVE);
+ CHECK(config.text_format == false);
+}
+
+int main(int argc, char** argv)
+{
+ return CommandLineTestRunner::RunAllTests(argc, argv);
+}
+
#include "main/snort_debug.h"
+extern const BaseApi* file_connector;
+ConnectorApi* fc_api = nullptr;
+
+FileConnectorConfig connector_tx_text_config;
+FileConnectorConfig connector_rx_text_config;
+FileConnectorConfig connector_tx_binary_config;
+FileConnectorConfig connector_rx_binary_config;
+
+Module* mod;
+
+ConnectorCommon* connector_common;
+
+Connector* connector_tt;
+Connector* connector_rt;
+Connector* connector_tb;
+Connector* connector_rb;
+
void show_stats(PegCount*, const PegInfo*, unsigned, const char*) { }
void show_stats(PegCount*, const PegInfo*, IndexVec&, const char*) { }
void show_stats(PegCount*, const PegInfo*, IndexVec&, const char*, FILE*) { }
const char* get_instance_file(std::string& file, const char* name)
-{ UNUSED(file); UNUSED(name); return "filename"; }
+{ file += name; return nullptr; }
void Debug::print(const char*, int, uint64_t, const char*, ...) { }
+FileConnectorModule::FileConnectorModule() :
+ Module("FC", "FC Help", nullptr)
+{ }
+
+FileConnectorConfig::FileConnectorConfigSet* FileConnectorModule::get_and_clear_config()
+{
+ FileConnectorConfig::FileConnectorConfigSet* config_set = new FileConnectorConfig::FileConnectorConfigSet;
+
+ return config_set;
+}
+
+FileConnectorModule::~FileConnectorModule() { }
+
+ProfileStats* FileConnectorModule::get_profile() const { return nullptr; }
+
+bool FileConnectorModule::set(const char*, Value&, SnortConfig*) { return true; }
+
+bool FileConnectorModule::begin(const char*, int, SnortConfig*) { return true; }
+
+bool FileConnectorModule::end(const char*, int, SnortConfig*) { return true; }
+
+const PegInfo* FileConnectorModule::get_pegs() const { return nullptr; }
+
+PegCount* FileConnectorModule::get_counts() const { return nullptr; }
+
+
+TEST_GROUP(file_connector)
+{
+ void setup()
+ {
+ // FIXIT-H - Workaround for CppUTest mem leak detector issue
+ MemoryLeakWarningPlugin::turnOffNewDeleteOverloads();
+ fc_api = (ConnectorApi*)file_connector;
+ connector_tx_text_config.direction = Connector::CONN_TRANSMIT;
+ connector_tx_text_config.connector_name = "tx_t";
+ connector_tx_text_config.name = "tx_t";
+ connector_tx_text_config.text_format = true;
+ connector_rx_text_config.direction = Connector::CONN_RECEIVE;
+ connector_rx_text_config.connector_name = "rx_t";
+ connector_rx_text_config.name = "rx_t";
+ connector_rx_text_config.text_format = true;
+ connector_tx_binary_config.direction = Connector::CONN_TRANSMIT;
+ connector_tx_binary_config.connector_name = "tx_t";
+ connector_tx_binary_config.name = "tx_t";
+ connector_tx_binary_config.text_format = false;
+ connector_rx_binary_config.direction = Connector::CONN_RECEIVE;
+ connector_rx_binary_config.connector_name = "rx_t";
+ connector_rx_binary_config.name = "rx_t";
+ connector_rx_binary_config.text_format = false;
+ }
+
+ void teardown()
+ {
+ MemoryLeakWarningPlugin::turnOnNewDeleteOverloads();
+ }
+};
+
+TEST(file_connector, mod_ctor_dtor)
+{
+ CHECK(file_connector != nullptr);
+ mod = file_connector->mod_ctor();
+ CHECK(mod != nullptr);
+ file_connector->mod_dtor(mod);
+}
+
+TEST(file_connector, mod_instance_ctor_dtor)
+{
+ CHECK(file_connector != nullptr);
+ mod = file_connector->mod_ctor();
+ CHECK(mod != nullptr);
+ connector_common = fc_api->ctor(mod);
+ CHECK(connector_common != nullptr);
+ fc_api->dtor(connector_common);
+ file_connector->mod_dtor(mod);
+}
+
+TEST_GROUP(file_connector_tinit_tterm)
+{
+ void setup()
+ {
+ // FIXIT-H - Workaround for CppUTest mem leak detector issue
+ MemoryLeakWarningPlugin::turnOffNewDeleteOverloads();
+ fc_api = (ConnectorApi*)file_connector;
+ connector_tx_text_config.direction = Connector::CONN_TRANSMIT;
+ connector_tx_text_config.connector_name = "tx_t";
+ connector_tx_text_config.name = "tx_t";
+ connector_tx_text_config.text_format = true;
+ connector_rx_text_config.direction = Connector::CONN_RECEIVE;
+ connector_rx_text_config.connector_name = "rx_t";
+ connector_rx_text_config.name = "rx_t";
+ connector_rx_text_config.text_format = true;
+ connector_tx_binary_config.direction = Connector::CONN_TRANSMIT;
+ connector_tx_binary_config.connector_name = "tx_b";
+ connector_tx_binary_config.name = "tx_b";
+ connector_tx_binary_config.text_format = false;
+ connector_rx_binary_config.direction = Connector::CONN_RECEIVE;
+ connector_rx_binary_config.connector_name = "rx_b";
+ connector_rx_binary_config.name = "rx_b";
+ connector_rx_binary_config.text_format = false;
+ CHECK(file_connector != nullptr);
+ mod = file_connector->mod_ctor();
+ CHECK(mod != nullptr);
+ connector_common = fc_api->ctor(mod);
+ CHECK(connector_common != nullptr);
+ connector_tt = fc_api->tinit(&connector_tx_text_config);
+ connector_rt = fc_api->tinit(&connector_rx_text_config);
+ connector_tb = fc_api->tinit(&connector_tx_binary_config);
+ connector_rb = fc_api->tinit(&connector_rx_binary_config);
+ CHECK(connector_tt != nullptr);
+ CHECK(connector_rt != nullptr);
+ CHECK(connector_tb != nullptr);
+ CHECK(connector_rb != nullptr);
+ }
+
+ void teardown()
+ {
+ fc_api->tterm(connector_tt);
+ fc_api->tterm(connector_rt);
+ fc_api->tterm(connector_tb);
+ fc_api->tterm(connector_rb);
+ fc_api->dtor(connector_common);
+ file_connector->mod_dtor(mod);
+ MemoryLeakWarningPlugin::turnOnNewDeleteOverloads();
+ }
+};
+
+TEST(file_connector_tinit_tterm, null)
+{
+ CHECK(1==1);
+}
+
+TEST(file_connector_tinit_tterm, alloc_discard)
+{
+ const uint8_t* data = nullptr;
+ FileConnector* fc_rt = (FileConnector*)connector_rt;
+
+ FileConnectorMsgHandle* handle = (FileConnectorMsgHandle*)(fc_rt->alloc_message(40,&data));
+ CHECK(data != nullptr);
+ CHECK(handle->connector_msg.length == 40);
+ CHECK(handle->connector_msg.data == data);
+ fc_rt->discard_message(handle);
+}
+
+TEST_GROUP(file_connector_text)
+{
+ void setup()
+ {
+ // FIXIT-H - Workaround for CppUTest mem leak detector issue
+ MemoryLeakWarningPlugin::turnOffNewDeleteOverloads();
+ fc_api = (ConnectorApi*)file_connector;
+ connector_tx_text_config.direction = Connector::CONN_TRANSMIT;
+ connector_tx_text_config.connector_name = "tx_t";
+ connector_tx_text_config.name = "tx_t";
+ connector_tx_text_config.text_format = true;
+ connector_rx_text_config.direction = Connector::CONN_RECEIVE;
+ connector_rx_text_config.connector_name = "rx_t";
+ connector_rx_text_config.name = "rx_t";
+ connector_rx_text_config.text_format = true;
+ CHECK(file_connector != nullptr);
+ }
+
+ void teardown()
+ {
+ MemoryLeakWarningPlugin::turnOnNewDeleteOverloads();
+ }
+};
+
+TEST(file_connector_text, alloc_transmit_rename_receive_discard)
+{
+ mod = file_connector->mod_ctor();
+ CHECK(mod != nullptr);
+ connector_common = fc_api->ctor(mod);
+ CHECK(connector_common != nullptr);
+ connector_tt = fc_api->tinit(&connector_tx_text_config);
+ CHECK(connector_tt != nullptr);
+ FileConnector* fc_tt = (FileConnector*)connector_tt;
+
+ const uint8_t* data = nullptr;
+ FileConnectorMsgHandle* t_handle = (FileConnectorMsgHandle*)(fc_tt->alloc_message(40,&data));
+ CHECK(data != nullptr);
+ CHECK(t_handle->connector_msg.length == 40);
+ CHECK(t_handle->connector_msg.data == data);
+ CHECK(fc_tt->transmit_message(t_handle) == true);
+
+ fc_api->tterm(connector_tt);
+ fc_api->dtor(connector_common);
+ file_connector->mod_dtor(mod);
+
+ std::rename("file_connector_tx_t_transmit", "file_connector_rx_t_receive");
+
+ mod = file_connector->mod_ctor();
+ CHECK(mod != nullptr);
+ connector_common = fc_api->ctor(mod);
+ CHECK(connector_common != nullptr);
+ connector_rt = fc_api->tinit(&connector_rx_text_config);
+ CHECK(connector_rt != nullptr);
+ FileConnector* fc_rt = (FileConnector*)connector_rt;
+
+ FileConnectorMsgHandle* r_handle = (FileConnectorMsgHandle*)(fc_rt->receive_message(true));
+ CHECK(r_handle != nullptr);
+ CHECK(r_handle->connector_msg.length == 40);
+
+ fc_rt->discard_message(r_handle);
+
+ fc_api->tterm(connector_rt);
+ fc_api->dtor(connector_common);
+ file_connector->mod_dtor(mod);
+}
+
+TEST_GROUP(file_connector_binary)
+{
+ void setup()
+ {
+ // FIXIT-H - Workaround for CppUTest mem leak detector issue
+ MemoryLeakWarningPlugin::turnOffNewDeleteOverloads();
+ fc_api = (ConnectorApi*)file_connector;
+ connector_tx_binary_config.direction = Connector::CONN_TRANSMIT;
+ connector_tx_binary_config.connector_name = "tx_b";
+ connector_tx_binary_config.name = "tx_b";
+ connector_tx_binary_config.text_format = false;
+ connector_rx_binary_config.direction = Connector::CONN_RECEIVE;
+ connector_rx_binary_config.connector_name = "rx_b";
+ connector_rx_binary_config.name = "rx_b";
+ connector_rx_binary_config.text_format = false;
+ CHECK(file_connector != nullptr);
+ }
+
+ void teardown()
+ {
+ MemoryLeakWarningPlugin::turnOnNewDeleteOverloads();
+ }
+};
+
+TEST(file_connector_binary, alloc_transmit_rename_receive_discard)
+{
+ mod = file_connector->mod_ctor();
+ CHECK(mod != nullptr);
+ connector_common = fc_api->ctor(mod);
+ CHECK(connector_common != nullptr);
+ connector_tb = fc_api->tinit(&connector_tx_binary_config);
+ CHECK(connector_tb != nullptr);
+ FileConnector* fc_tb = (FileConnector*)connector_tb;
+
+ const uint8_t* data = nullptr;
+ FileConnectorMsgHandle* t_handle = (FileConnectorMsgHandle*)(fc_tb->alloc_message(40,&data));
+ CHECK(data != nullptr);
+ CHECK(t_handle->connector_msg.length == 40);
+ CHECK(t_handle->connector_msg.data == data);
+ CHECK(fc_tb->transmit_message(t_handle) == true);
+
+ fc_api->tterm(connector_tb);
+ fc_api->dtor(connector_common);
+ file_connector->mod_dtor(mod);
+
+ std::rename("file_connector_tx_b_transmit", "file_connector_rx_b_receive");
+
+ mod = file_connector->mod_ctor();
+ CHECK(mod != nullptr);
+ connector_common = fc_api->ctor(mod);
+ CHECK(connector_common != nullptr);
+ connector_rb = fc_api->tinit(&connector_rx_binary_config);
+ CHECK(connector_rb != nullptr);
+ FileConnector* fc_rb = (FileConnector*)connector_rb;
+
+ FileConnectorMsgHandle* r_handle = (FileConnectorMsgHandle*)(fc_rb->receive_message(true));
+ CHECK(r_handle != nullptr);
+ CHECK(r_handle->connector_msg.length == 40);
+
+ fc_rb->discard_message(r_handle);
+
+ fc_api->tterm(connector_rb);
+ fc_api->dtor(connector_common);
+ file_connector->mod_dtor(mod);
+}
+
TEST_GROUP(file_connector_msg_handle)
{
+ void setup()
+ {
+ }
+
+ void teardown()
+ {
+ }
};
TEST(file_connector_msg_handle, test)
DebugMessage(DEBUG_SIDE_CHANNEL,"SideChannel::SideChannel()\n");
sequence = 0;
default_port = 0;
+ connector_receive = nullptr;
+ connector_transmit = nullptr;
+ receive_handler = nullptr;
}
SideChannel::~SideChannel()
void SideChannel::set_message_port(SCMessage* msg, SCPort port)
{
- if ( msg != nullptr )
- msg->hdr->port = port;
+ assert ( msg );
+ assert ( msg->hdr );
+ msg->hdr->port = port;
}
void SideChannel::set_default_port(SCPort port)
scm->connectors = *connectors;
scm->ports = *ports;
- // convert to rvalue for move to vector
- s_maps.push_back(std::move(scm));
+ s_maps.push_back(scm);
}
// Initialize state to be ready to accept configuration
}
/* Save the thread specific map */
- map_list->push_back(std::move(map));
+ map_list->push_back(map);
}
/* Finally, save the thread-specific list */
add_cpputest(side_channel_test side_channel)
+add_cpputest(side_channel_module_test side_channel_module)
AM_DEFAULT_SOURCE_EXT = .cc
check_PROGRAMS = \
-side_channel_test
+side_channel_test \
+side_channel_module_test
TESTS = $(check_PROGRAMS)
side_channel_test_CPPFLAGS = @AM_CPPFLAGS@ @CPPUTEST_CPPFLAGS@
+side_channel_module_test_CPPFLAGS = @AM_CPPFLAGS@ @CPPUTEST_CPPFLAGS@
-side_channel_test_LDADD = ../libside_channel.a ../../framework/libframework.a ../../sfip/libsfip.a ../../catch/libcatch_tests.a @CPPUTEST_LDFLAGS@
+side_channel_test_LDADD = \
+../side_channel.o \
+../../framework/libframework.a \
+../../sfip/libsfip.a \
+../../catch/libcatch_tests.a \
+@CPPUTEST_LDFLAGS@
+
+side_channel_module_test_LDADD = \
+../side_channel_module.o \
+../../framework/libframework.a \
+../../sfip/libsfip.a \
+../../catch/libcatch_tests.a \
+@CPPUTEST_LDFLAGS@
--- /dev/null
+//--------------------------------------------------------------------------
+// Copyright (C) 2015-2016 Cisco and/or its affiliates. All rights reserved.
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License Version 2 as published
+// by the Free Software Foundation. You may not use, modify or distribute
+// this program under any other version of the GNU General Public License.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//--------------------------------------------------------------------------
+
+// side_channel_module_test.cc author Ed Borgoyn <eborgoyn@cisco.com>
+// unit test main
+
+#include <CppUTest/CommandLineTestRunner.h>
+#include <CppUTest/TestHarness.h>
+
+#include "side_channel/side_channel.h"
+#include "side_channel/side_channel_module.h"
+
+#include "log/messages.h"
+#include "main/snort_debug.h"
+#include "profiler/profiler.h"
+
+THREAD_LOCAL SimpleStats sc_stats;
+THREAD_LOCAL ProfileStats sc_perf_stats;
+
+static bool port_1_set = false;
+
+static char* make_bit_string(int bit)
+{
+ static char bit_string[65537];
+ for ( int i=0; i<65536; i++)
+ bit_string[i] = (bit == i) ? '1' : '0';
+
+ bit_string[65536] = '\0';
+
+ return bit_string;
+}
+
+void SideChannelManager::instantiate(const SCConnectors*, const PortBitSet* ports)
+{
+ port_1_set = ports->test(1);
+}
+
+void show_stats(PegCount*, const PegInfo*, unsigned, const char*) { }
+void show_stats(PegCount*, const PegInfo*, IndexVec&, const char*) { }
+void show_stats(PegCount*, const PegInfo*, IndexVec&, const char*, FILE*) { }
+
+void ParseWarning(WarningGroup, const char*, ...) { }
+
+void Debug::print(const char*, int, uint64_t, const char*, ...) { }
+
+TEST_GROUP(side_channel_module)
+{
+ void setup()
+ {
+ }
+
+ void teardown()
+ {
+ }
+};
+
+TEST(side_channel_module, test_connector_module_valid)
+{
+ Value ports_val(make_bit_string(1));
+ Value connector_t_val("transmit");
+ Value connector_r_val("receive");
+ Parameter ports_param = {"ports", Parameter::PT_BIT_LIST, "65535", nullptr, "ports"};
+ Parameter connector_param = {"connector", Parameter::PT_STRING, nullptr, nullptr, "connector"};
+
+ SideChannelModule module;
+
+ ports_val.set(&ports_param);
+ connector_t_val.set(&connector_param);
+ connector_r_val.set(&connector_param);
+
+ module.begin("side_channel", 0, nullptr);
+ module.begin("side_channel", 1, nullptr);
+ module.begin("side_channel.connectors", 0, nullptr);
+ module.begin("side_channel.connectors", 1, nullptr);
+ module.set("side_channel.connectors.connector", connector_t_val, nullptr);
+ module.end("side_channel.connectors", 1, nullptr);
+ module.begin("side_channel.connectors", 2, nullptr);
+ module.set("side_channel.connectors.connector", connector_r_val, nullptr);
+ module.end("side_channel.connectors", 2, nullptr);
+ module.end("side_channel.connectors", 0, nullptr);
+ module.set("side_channel.ports", ports_val, nullptr);
+ module.end("side_channel", 1, nullptr);
+ module.end("side_channel", 0, nullptr);
+
+ CHECK(port_1_set == true);
+}
+
+int main(int argc, char** argv)
+{
+ return CommandLineTestRunner::RunAllTests(argc, argv);
+}
+
#include <CppUTest/TestHarness.h>
#include "side_channel/side_channel.h"
-#include "side_channel/side_channel_module.h"
#include "log/messages.h"
#include "main/snort_debug.h"
#include "managers/connector_manager.h"
-class TestConnector : public Connector
+class TestConnectorMsgHandle : public ConnectorMsgHandle
{
- ConnectorMsgHandle* alloc_message(const uint32_t, const uint8_t**) { return nullptr; }
- void discard_message(ConnectorMsgHandle*) { }
- bool transmit_message(ConnectorMsgHandle*) { return true; }
- ConnectorMsgHandle* receive_message(bool) { return nullptr; }
- ConnectorMsg* get_connector_msg(ConnectorMsgHandle*) { return nullptr; }
- Direction get_connector_direction() { return CONN_UNDEFINED; }
+public:
+ TestConnectorMsgHandle(const uint32_t length)
+ {
+ connector_msg.length = length;
+ connector_msg.data = new uint8_t[length];
+ }
+
+ ~TestConnectorMsgHandle()
+ {
+ delete[] connector_msg.data;
+ }
+
+ ConnectorMsg connector_msg;
};
class ReceiveConnector : public Connector
{
- ConnectorMsgHandle* alloc_message(const uint32_t, const uint8_t**) { return nullptr; }
- void discard_message(ConnectorMsgHandle*) { }
- bool transmit_message(ConnectorMsgHandle*) { return true; }
- ConnectorMsgHandle* receive_message(bool) { return nullptr; }
- ConnectorMsg* get_connector_msg(ConnectorMsgHandle*) { return nullptr; }
- Direction get_connector_direction() { return CONN_RECEIVE; }
+ ConnectorMsgHandle* alloc_message(const uint32_t length, const uint8_t** data)
+ {
+ TestConnectorMsgHandle* msg = new TestConnectorMsgHandle(length);
+ *data = (uint8_t*)msg->connector_msg.data;
+ return msg;
+ }
+ void discard_message(ConnectorMsgHandle* msg)
+ { delete (TestConnectorMsgHandle*)msg; }
+ bool transmit_message(ConnectorMsgHandle* msg)
+ { delete (TestConnectorMsgHandle*)msg; return true; }
+ ConnectorMsgHandle* receive_message(bool)
+ { return new TestConnectorMsgHandle(30); }
+ ConnectorMsg* get_connector_msg(ConnectorMsgHandle* handle)
+ { return &((TestConnectorMsgHandle*)handle)->connector_msg; }
+ Direction get_connector_direction()
+ { return CONN_RECEIVE; }
};
class TransmitConnector : public Connector
{
- ConnectorMsgHandle* alloc_message(const uint32_t, const uint8_t**) { return nullptr; }
- void discard_message(ConnectorMsgHandle*) { }
- bool transmit_message(ConnectorMsgHandle*) { return true; }
- ConnectorMsgHandle* receive_message(bool) { return nullptr; }
- ConnectorMsg* get_connector_msg(ConnectorMsgHandle*) { return nullptr; }
- Direction get_connector_direction() { return CONN_TRANSMIT; }
+ ConnectorMsgHandle* alloc_message(const uint32_t length, const uint8_t** data)
+ {
+ TestConnectorMsgHandle* msg = new TestConnectorMsgHandle(length);
+ *data = (uint8_t*)msg->connector_msg.data;
+ return msg;
+ }
+ void discard_message(ConnectorMsgHandle* msg)
+ { delete (TestConnectorMsgHandle*)msg; }
+ bool transmit_message(ConnectorMsgHandle* msg)
+ { delete (TestConnectorMsgHandle*)msg; return true; }
+ ConnectorMsgHandle* receive_message(bool)
+ { return nullptr; }
+ ConnectorMsg* get_connector_msg(ConnectorMsgHandle*)
+ { return nullptr; }
+ Direction get_connector_direction()
+ { return CONN_TRANSMIT; }
};
-void ConnectorManager::thread_init() { }
+Connector* receive_connector = nullptr;
+Connector* transmit_connector = nullptr;
+
+void ConnectorManager::thread_init()
+{
+ receive_connector = new ReceiveConnector;
+ transmit_connector = new TransmitConnector;
+}
-void ConnectorManager::thread_term() { }
+void ConnectorManager::thread_term()
+{
+ delete receive_connector;
+ delete transmit_connector;
+}
Connector* ConnectorManager::get_connector(const std::string connector_name)
{
- if ( connector_name == "U" )
- return new TestConnector();
- else if ( connector_name == "R" )
- return new ReceiveConnector();
+ if ( connector_name == "R" )
+ return receive_connector;
else if ( connector_name == "T" )
- return new TransmitConnector();
+ return transmit_connector;
else
return nullptr;
}
-void show_stats(PegCount*, const PegInfo*, unsigned, const char*) { }
-
-void show_stats(PegCount*, const PegInfo*, IndexVec&, const char*) { }
-
void ParseWarning(WarningGroup, const char*, ...) { }
void Debug::print(const char*, int, uint64_t, const char*, ...) { }
{
void setup()
{
+ // FIXIT-H - Workaround for issue with CppUTest memory leak detection
+ MemoryLeakWarningPlugin::turnOffNewDeleteOverloads();
+ SideChannelManager::pre_config_init();
+
+ SCConnectors test_connectors;
+ PortBitSet test_ports;
+
+ test_connectors.push_back("R");
+ test_connectors.push_back("T");
+ test_ports.set(1);
+
+ SideChannelManager::instantiate(&test_connectors, &test_ports);
+
+ test_connectors.clear();
+ test_ports.reset(1);
+
+ test_connectors.push_back("R");
+ test_ports.set(2);
+
+ SideChannelManager::instantiate(&test_connectors, &test_ports);
+
+ test_connectors.clear();
+ test_ports.reset(2);
+
+ test_connectors.push_back("T");
+ test_ports.set(3);
+
+ SideChannelManager::instantiate(&test_connectors, &test_ports);
+
+ test_connectors.clear();
+ test_ports.reset(3);
+
+ test_ports.set(4);
+
+ SideChannelManager::instantiate(&test_connectors, &test_ports);
+
+ test_connectors.clear();
+ test_ports.reset(4);
+
+ SideChannelManager::thread_init();
}
void teardown()
{
+ SideChannelManager::thread_term();
+ SideChannelManager::term();
+ MemoryLeakWarningPlugin::turnOnNewDeleteOverloads();
}
};
-TEST(side_channel, test)
+TEST(side_channel, test_connector_null)
{
- CHECK(1==1);
+}
+
+TEST(side_channel, test_connector_get_none)
+{
+ SideChannel* sc = SideChannelManager::get_side_channel(5);
+ CHECK(sc == nullptr);
+}
+
+TEST(side_channel, test_connector_directions)
+{
+ SideChannel* sc = SideChannelManager::get_side_channel(1);
+ CHECK(sc != nullptr);
+ CHECK(sc->get_direction() == Connector::CONN_DUPLEX);
+
+ sc = SideChannelManager::get_side_channel(2);
+ CHECK(sc != nullptr);
+ CHECK(sc->get_direction() == Connector::CONN_RECEIVE);
+
+ sc = SideChannelManager::get_side_channel(3);
+ CHECK(sc != nullptr);
+ CHECK(sc->get_direction() == Connector::CONN_TRANSMIT);
+
+ sc = SideChannelManager::get_side_channel(4);
+ CHECK(sc != nullptr);
+ CHECK(sc->get_direction() == Connector::CONN_UNDEFINED);
+}
+
+TEST(side_channel, test_connector_alloc_discard)
+{
+ SideChannel* sc = SideChannelManager::get_side_channel(1);
+ CHECK(sc != nullptr);
+ CHECK(sc->get_direction() == Connector::CONN_DUPLEX);
+
+ sc->set_default_port(1);
+
+ SCMessage* msg = sc->alloc_transmit_message(30);
+ CHECK(msg != nullptr);
+
+ bool success = sc->discard_message(msg);
+ CHECK(success == true);
+}
+
+TEST(side_channel, test_connector_alloc_transmit)
+{
+ SideChannel* sc = SideChannelManager::get_side_channel(1);
+ CHECK(sc != nullptr);
+ CHECK(sc->get_direction() == Connector::CONN_DUPLEX);
+
+ sc->set_default_port(2);
+ SCMessage* msg = sc->alloc_transmit_message(30);
+ CHECK(msg != nullptr);
+ CHECK(msg->content_length == 30);
+ CHECK(msg->content != nullptr);
+ CHECK(msg->hdr->port == 2);
+
+ sc->set_message_port(msg,1);
+ CHECK(msg->hdr->port == 1);
+
+ bool success = sc->transmit_message(msg);
+ CHECK(success == true);
+}
+
+static void receive_handler(SCMessage* sc_msg)
+{
+ CHECK(sc_msg != nullptr);
+ CHECK(sc_msg->sc != nullptr);
+ sc_msg->sc->discard_message(sc_msg);
+}
+
+TEST(side_channel, test_connector_receive_process_dispatch_discard)
+{
+ SideChannel* sc = SideChannelManager::get_side_channel(1);
+ CHECK(sc != nullptr);
+
+ sc->register_receive_handler(receive_handler);
+
+ bool success = sc->process(1);
+ CHECK(success == true);
+
+ sc->unregister_receive_handler();
}
int main(int argc, char** argv)