From e7ba33b0831b13c8b1c159d6fc6ed5310e2c1e66 Mon Sep 17 00:00:00 2001 From: g0dil <g0dil@wiback.org> Date: Fri, 17 Aug 2007 11:57:27 +0000 Subject: [PATCH] PPI: Make connect auto-expand module arguments PPI: Add additional unit testing --- PPI/Connectors.test.cc | 8 +-- PPI/DebugModules.test.cc | 4 +- PPI/IOEvent.hh | 2 + PPI/IOEvent.test.cc | 55 +++++++++++++++++++ PPI/Module.test.cc | 2 +- PPI/ModuleManager.test.cc | 55 +++++++++++++++++++ PPI/Queueing.test.cc | 109 ++++++++++++++++++++++++++++++++++++++ PPI/Route.test.cc | 8 +-- PPI/Setup.cci | 2 + PPI/Setup.cti | 72 +++++++++++++++++++++++++ PPI/Setup.hh | 19 ++++++- PPI/SocketReader.test.cc | 4 +- PPI/SocketWriter.test.cc | 4 +- 13 files changed, 327 insertions(+), 17 deletions(-) create mode 100644 PPI/IOEvent.test.cc create mode 100644 PPI/ModuleManager.test.cc create mode 100644 PPI/Queueing.test.cc create mode 100644 PPI/Setup.cti diff --git a/PPI/Connectors.test.cc b/PPI/Connectors.test.cc index feb7266ff..3a4b621bd 100644 --- a/PPI/Connectors.test.cc +++ b/PPI/Connectors.test.cc @@ -184,7 +184,7 @@ BOOST_AUTO_UNIT_TEST(passiveInput) debug::ActivePacketSource source; PassiveInputTest target; - ppi::connect(source.output,target.input); + ppi::connect(source,target); ppi::init(); BOOST_CHECK_EQUAL( & target.input.peer(), & source.output ); @@ -227,7 +227,7 @@ BOOST_AUTO_UNIT_TEST(passiveOutput) debug::PassivePacketSource source; debug::ActivePacketSink target; - ppi::connect(source.output,target.input); + ppi::connect(source,target); ppi::init(); senf::Packet p (senf::DataPacket::create()); @@ -248,7 +248,7 @@ BOOST_AUTO_UNIT_TEST(activeInput) debug::PassivePacketSource source; debug::ActivePacketSink target; - ppi::connect(source.output,target.input); + ppi::connect(source,target); ppi::init(); BOOST_CHECK_EQUAL( & target.input.peer(), & source.output ); @@ -273,7 +273,7 @@ BOOST_AUTO_UNIT_TEST(activeOutput) debug::ActivePacketSource source; debug::PassivePacketSink target; - ppi::connect(source.output,target.input); + ppi::connect(source,target); ppi::init(); BOOST_CHECK_EQUAL( & source.output.peer(), & target.input ); diff --git a/PPI/DebugModules.test.cc b/PPI/DebugModules.test.cc index 0fc70ccd8..fdde4c092 100644 --- a/PPI/DebugModules.test.cc +++ b/PPI/DebugModules.test.cc @@ -47,7 +47,7 @@ BOOST_AUTO_UNIT_TEST(debugModules) debug::ActivePacketSource source; debug::PassivePacketSink sink; - ppi::connect(source.output, sink.input); + ppi::connect(source, sink); ppi::init(); senf::PacketData::byte data[] = { 0x13u, 0x24u, 0x35u }; @@ -76,7 +76,7 @@ BOOST_AUTO_UNIT_TEST(debugModules) debug::PassivePacketSource source; debug::ActivePacketSink sink; - ppi::connect(source.output, sink.input); + ppi::connect(source, sink); ppi::init(); senf::PacketData::byte data[] = { 0x13u, 0x24u, 0x35u }; diff --git a/PPI/IOEvent.hh b/PPI/IOEvent.hh index 4e143b238..a61dec521 100644 --- a/PPI/IOEvent.hh +++ b/PPI/IOEvent.hh @@ -42,6 +42,8 @@ namespace ppi { }; /** \brief + + \fixme Implement error/EOF handling */ class IOEvent : public EventImplementation<IOEventInfo> diff --git a/PPI/IOEvent.test.cc b/PPI/IOEvent.test.cc new file mode 100644 index 000000000..cdd97b7f1 --- /dev/null +++ b/PPI/IOEvent.test.cc @@ -0,0 +1,55 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Stefan Bund <g0dil@berlios.de> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// 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., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +/** \file + \brief IOEvent.test unit tests */ + +//#include "IOEvent.test.hh" +//#include "IOEvent.test.ih" + +// Custom includes +#include "IOEvent.hh" + +#include <boost/test/auto_unit_test.hpp> +#include <boost/test/test_tools.hpp> + +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +BOOST_AUTO_UNIT_TEST(ioEvent) +{ + // Tested in SocketReader.test.cc and SocketWriter.test.cc +} + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// comment-column: 40 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// End: diff --git a/PPI/Module.test.cc b/PPI/Module.test.cc index c54ef51f0..bfb2201a8 100644 --- a/PPI/Module.test.cc +++ b/PPI/Module.test.cc @@ -70,7 +70,7 @@ BOOST_AUTO_UNIT_TEST(module) TestModule tester; debug::PassivePacketSink sink; - ppi::connect(tester.output, sink.input); + ppi::connect(tester, sink); ppi::init(); tester.event.trigger(); diff --git a/PPI/ModuleManager.test.cc b/PPI/ModuleManager.test.cc new file mode 100644 index 000000000..0693b0cab --- /dev/null +++ b/PPI/ModuleManager.test.cc @@ -0,0 +1,55 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Stefan Bund <g0dil@berlios.de> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// 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., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +/** \file + \brief ModuleManager.test unit tests */ + +//#include "ModuleManager.test.hh" +//#include "ModuleManager.test.ih" + +// Custom includes +#include "ModuleManager.hh" + +#include <boost/test/auto_unit_test.hpp> +#include <boost/test/test_tools.hpp> + +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +BOOST_AUTO_UNIT_TEST(moduleManager) +{ + // Tested in Module.test.cc +} + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// comment-column: 40 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// End: diff --git a/PPI/Queueing.test.cc b/PPI/Queueing.test.cc new file mode 100644 index 000000000..cd256b6ef --- /dev/null +++ b/PPI/Queueing.test.cc @@ -0,0 +1,109 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Stefan Bund <g0dil@berlios.de> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// 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., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +/** \file + \brief Queueing.test unit tests */ + +//#include "Queueing.test.hh" +//#include "Queueing.test.ih" + +// Custom includes +#include "Queueing.hh" +#include "Module.hh" +#include "Connectors.hh" +#include "DebugModules.hh" +#include "Packets/Packets.hh" +#include "Setup.hh" + +#include <boost/test/auto_unit_test.hpp> +#include <boost/test/test_tools.hpp> + +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +namespace ppi = senf::ppi; +namespace connector = ppi::connector; +namespace module = ppi::module; +namespace debug = module::debug; + +namespace { + class QueueTester : public module::Module + { + SENF_PPI_MODULE(QueueTester); + public: + connector::PassiveInput input; + connector::ActiveOutput output; + + QueueTester() { + route(input, output); + input.qdisc(ppi::ThresholdQueueing(2,1)); + input.onRequest(&QueueTester::nop); + } + + void nop() {} + + void forward() { + if (input && output) + output(input()); + } + + }; +} + +BOOST_AUTO_UNIT_TEST(thresholdQueueing) +{ + debug::ActivePacketSource source; + QueueTester tester; + debug::PassivePacketSink sink; + + ppi::connect(source, tester); + ppi::connect(tester, sink); + ppi::init(); + + senf::Packet p (senf::DataPacket::create()); + BOOST_CHECK( source ); + source.submit(p); + BOOST_CHECK( source ); + source.submit(p); + BOOST_CHECK( ! source ); + BOOST_CHECK_EQUAL( tester.input.queueSize(), 2u ); + tester.forward(); + BOOST_CHECK_EQUAL( tester.input.queueSize(), 1u ); + BOOST_CHECK( source ); + tester.forward(); + BOOST_CHECK_EQUAL( tester.input.queueSize(), 0u ); + BOOST_CHECK( source ); +} + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// comment-column: 40 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// End: diff --git a/PPI/Route.test.cc b/PPI/Route.test.cc index f31b8a9d7..be33ee6e6 100644 --- a/PPI/Route.test.cc +++ b/PPI/Route.test.cc @@ -111,10 +111,10 @@ BOOST_AUTO_UNIT_TEST(route) debug::ActivePacketSink activeSink; RouteTester tester; - ppi::connect(passiveSource.output, tester.activeIn); - ppi::connect(activeSource.output, tester.passiveIn); - ppi::connect(tester.activeOut, passiveSink.input); - ppi::connect(tester.passiveOut, activeSink.input); + ppi::connect(passiveSource, tester.activeIn); + ppi::connect(activeSource, tester.passiveIn); + ppi::connect(tester.activeOut, passiveSink); + ppi::connect(tester.passiveOut, activeSink); ppi::init(); diff --git a/PPI/Setup.cci b/PPI/Setup.cci index 01c31681a..f8f556b1e 100644 --- a/PPI/Setup.cci +++ b/PPI/Setup.cci @@ -23,6 +23,8 @@ /** \file \brief Setup inline non-template implementation */ +//#include "Setup.ih" + // Custom includes #include "Connectors.hh" #include "ModuleManager.hh" diff --git a/PPI/Setup.cti b/PPI/Setup.cti new file mode 100644 index 000000000..fa119e68a --- /dev/null +++ b/PPI/Setup.cti @@ -0,0 +1,72 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Stefan Bund <g0dil@berlios.de> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// 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., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +/** \file + \brief Setup inline template implementation */ + +//#include "Setup.ih" + +// Custom includes + +#define prefix_ inline +///////////////////////////////cti.p/////////////////////////////////////// + +template <class M, class C> +prefix_ void +senf::ppi::connect(M & source, C & target, + typename boost::enable_if< boost::is_base_of<module::Module, M> >::type *, + typename boost::enable_if< boost::is_base_of<connector::Connector, C> >::type *) +{ + connect(source.output, target); +} + +template <class C, class M> +prefix_ void +senf::ppi::connect(C & source, M & target, + typename boost::enable_if< boost::is_base_of<connector::Connector, C> >::type *, + typename boost::enable_if< boost::is_base_of<module::Module, M> >::type *) +{ + connect(source, target.input); +} + +template <class M1, class M2> +prefix_ void +senf::ppi::connect(M1 & source, M2 & target, + typename boost::enable_if< boost::is_base_of<module::Module, M1> >::type *, + typename boost::enable_if< boost::is_base_of<module::Module, M2> >::type *) +{ + connect(source.output, target.input); +} + +///////////////////////////////cti.e/////////////////////////////////////// +#undef prefix_ + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// comment-column: 40 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// End: diff --git a/PPI/Setup.hh b/PPI/Setup.hh index 2920e1eb7..12e7d905f 100644 --- a/PPI/Setup.hh +++ b/PPI/Setup.hh @@ -34,10 +34,25 @@ namespace senf { namespace ppi { - + void connect(connector::ActiveOutput & source, connector::PassiveInput & target); void connect(connector::PassiveOutput & source, connector::ActiveInput & target); + + template <class M, class C> + void connect(M & source, C & target, + typename boost::enable_if< boost::is_base_of<module::Module, M> >::type * = 0, + typename boost::enable_if< boost::is_base_of<connector::Connector, C> >::type * = 0); + + template <class C, class M> + void connect(C & source, M & target, + typename boost::enable_if< boost::is_base_of<connector::Connector, C> >::type * = 0, + typename boost::enable_if< boost::is_base_of<module::Module, M> >::type * = 0); + template <class M1, class M2> + void connect(M1 & source, M2 & target, + typename boost::enable_if< boost::is_base_of<module::Module, M1> >::type * = 0, + typename boost::enable_if< boost::is_base_of<module::Module, M2> >::type * = 0); + void run(); void init(); @@ -46,7 +61,7 @@ namespace ppi { ///////////////////////////////hh.e//////////////////////////////////////// #include "Setup.cci" //#include "Setup.ct" -//#include "Setup.cti" +#include "Setup.cti" #endif diff --git a/PPI/SocketReader.test.cc b/PPI/SocketReader.test.cc index 1d58e1c77..8a28946b2 100644 --- a/PPI/SocketReader.test.cc +++ b/PPI/SocketReader.test.cc @@ -58,13 +58,13 @@ BOOST_AUTO_UNIT_TEST(socketReader) inputSocket.blocking(false); module::ActiveSocketReader<> udpReader(inputSocket); debug::PassivePacketSink sink; - ppi::connect(udpReader.output, sink.input); + ppi::connect(udpReader, sink); std::string data ("TEST"); senf::UDPv4ClientSocketHandle outputSocket; outputSocket.writeto(senf::INet4SocketAddress("localhost:44344"),data); - senf::Scheduler::instance().timeout(1000, &timeout); + senf::Scheduler::instance().timeout(100, &timeout); senf::ppi::run(); BOOST_REQUIRE( ! sink.empty() ); diff --git a/PPI/SocketWriter.test.cc b/PPI/SocketWriter.test.cc index 78814ca81..25c1a5dd0 100644 --- a/PPI/SocketWriter.test.cc +++ b/PPI/SocketWriter.test.cc @@ -57,7 +57,7 @@ BOOST_AUTO_UNIT_TEST(passiveSocketWriter) senf::INet4SocketAddress("localhost:44344")); module::PassiveSocketWriter<> udpWriter(outputSocket); debug::ActivePacketSource source; - ppi::connect(source.output, udpWriter.input); + ppi::connect(source, udpWriter); std::string data ("TEST"); senf::Packet p (senf::DataPacket::create(data)); @@ -77,7 +77,7 @@ BOOST_AUTO_UNIT_TEST(activeSocketWriter) senf::INet4SocketAddress("localhost:44344")); module::ActiveSocketWriter<> udpWriter(outputSocket); debug::PassivePacketSource source; - ppi::connect(source.output, udpWriter.input); + ppi::connect(source, udpWriter); std::string data ("TEST"); senf::Packet p (senf::DataPacket::create(data)); -- GitLab