4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief RateAnalyzer unit tests */
26 //#include "RateAnalyzer.test.hh"
27 //#include "RateAnalyzer.test.ih"
30 #include "RateAnalyzer.hh"
31 #include "CloneSource.hh"
32 #include "RateFilter.hh"
35 #include <senf/Utils/auto_unit_test.hh>
36 #include <boost/test/test_tools.hpp>
37 #include <boost/test/floating_point_comparison.hpp>
40 ///////////////////////////////cc.p////////////////////////////////////////
45 float ppss[] = { 13.333333f, 20.f, 13.333333f, 20.f, 13.333333f, 20.f };
50 void collectPPS(float packetsPerSecond)
52 // 2 + 3 + 2 + 3 + 2 + 3 packets / interval
53 // -> 13.333333 + 20. + 13.333333 + 20. + 13.333333 + 20. / 6 pps
56 // This test sometime fails when system load is to high ...
57 // BOOST_CHECK_CLOSE( packetsPerSecond, ppss[calls], 0.1f );
58 pps += packetsPerSecond;
60 if (calls >= sizeof(ppss) / sizeof(ppss[0]))
61 senf::scheduler::terminate();
64 void collectBPS(float bytesPerSecond)
66 bps += bytesPerSecond;
69 void collectSize(float min, float avg, float max)
71 BOOST_CHECK_CLOSE(min, 13.f, 0.01f);
72 BOOST_CHECK_CLOSE(avg, 13.f, 0.01f);
73 BOOST_CHECK_CLOSE(max, 13.f, 0.01f);
77 SENF_AUTO_UNIT_TEST(rateAnalyzer)
79 char const * enabled (getenv("SENF_TIMING_CRITICAL_TESTS"));
81 BOOST_WARN_MESSAGE(false, "Set SENF_TIMING_CRITICAL_TESTS to not skip timing critical tests");
83 senf::DataPacket p (senf::DataPacket::create(13u));
84 senf::ppi::module::CloneSource source (p);
85 senf::ppi::module::RateFilter filter (senf::ClockService::milliseconds(58u));
86 senf::ppi::module::RateAnalyzer analyzer;
87 analyzer.startStatistics(senf::ClockService::milliseconds(150u));
88 analyzer.signals.packetsPerSecond.connect(&collectPPS);
89 analyzer.signals.bytesPerSecond.connect(&collectBPS);
90 analyzer.signals.bytesPerPacket.connect(&collectSize);
92 senf::ppi::connect(source, filter);
93 senf::ppi::connect(filter, analyzer);
97 BOOST_CHECK_EQUAL( calls, 6u );
103 BOOST_CHECK_CLOSE( pps, 16.67f, .1f );
104 BOOST_CHECK_CLOSE( bps, 216.67f, .1f );
108 ///////////////////////////////cc.e////////////////////////////////////////
115 // comment-column: 40
116 // c-file-style: "senf"
117 // indent-tabs-mode: nil
118 // ispell-local-dictionary: "american"
119 // compile-command: "scons -u test"