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"
33 #include <senf/Utils/auto_unit_test.hh>
34 #include <boost/test/test_tools.hpp>
35 #include <boost/test/floating_point_comparison.hpp>
38 ///////////////////////////////cc.p////////////////////////////////////////
43 float ppss[] = { 13.333333f, 20.f, 13.333333f, 20.f, 13.333333f, 20.f };
48 void collectPPS(float packetsPerSecond)
50 // 2 + 3 + 2 + 3 + 2 + 3 packets / interval
51 // -> 13.333333 + 20. + 13.333333 + 20. + 13.333333 + 20. / 6 pps
54 // This test sometime fails when system load is to high ...
55 // BOOST_CHECK_CLOSE( packetsPerSecond, ppss[calls], 0.1f );
56 pps += packetsPerSecond;
58 if (calls >= sizeof(ppss) / sizeof(ppss[0]))
59 senf::scheduler::terminate();
62 void collectBPS(float bytesPerSecond)
64 bps += bytesPerSecond;
67 void collectSize(float min, float avg, float max)
69 BOOST_CHECK_CLOSE(min, 13.f, 0.01f);
70 BOOST_CHECK_CLOSE(avg, 13.f, 0.01f);
71 BOOST_CHECK_CLOSE(max, 13.f, 0.01f);
75 SENF_AUTO_UNIT_TEST(rateAnalyzer)
77 char const * enabled (getenv("SENF_TIMING_CRITICAL_TESTS"));
79 BOOST_WARN_MESSAGE(false, "Set SENF_TIMING_CRITICAL_TESTS to not skip timing critical tests");
81 senf::DataPacket p (senf::DataPacket::create(13u));
82 senf::ppi::module::CloneSource source (p);
83 senf::ppi::module::RateFilter filter (senf::ClockService::milliseconds(58u));
84 senf::ppi::module::RateAnalyzer analyzer;
85 analyzer.startStatistics(senf::ClockService::milliseconds(150u));
86 analyzer.signals.packetsPerSecond.connect(&collectPPS);
87 analyzer.signals.bytesPerSecond.connect(&collectBPS);
88 analyzer.signals.bytesPerPacket.connect(&collectSize);
90 senf::ppi::connect(source, filter);
91 senf::ppi::connect(filter, analyzer);
95 BOOST_CHECK_EQUAL( calls, 6u );
101 BOOST_CHECK_CLOSE( pps, 16.67f, .1f );
102 BOOST_CHECK_CLOSE( bps, 216.67f, .1f );
106 ///////////////////////////////cc.e////////////////////////////////////////
113 // comment-column: 40
114 // c-file-style: "senf"
115 // indent-tabs-mode: nil
116 // ispell-local-dictionary: "american"
117 // compile-command: "scons -u test"