4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief RateAnalyzer unit tests */
31 //#include "RateAnalyzer.test.hh"
32 //#include "RateAnalyzer.test.ih"
35 #include "RateAnalyzer.hh"
36 #include "CloneSource.hh"
37 #include "RateFilter.hh"
40 #include <senf/Utils/auto_unit_test.hh>
41 #include <boost/test/test_tools.hpp>
42 #include <boost/test/floating_point_comparison.hpp>
45 //-/////////////////////////////////////////////////////////////////////////////////////////////////
50 float ppss[] = { 13.333333f, 20.f, 13.333333f, 20.f, 13.333333f, 20.f };
55 void collectPPS(float packetsPerSecond)
57 // 2 + 3 + 2 + 3 + 2 + 3 packets / interval
58 // -> 13.333333 + 20. + 13.333333 + 20. + 13.333333 + 20. / 6 pps
61 // This test sometime fails when system load is to high ...
62 // BOOST_CHECK_CLOSE( packetsPerSecond, ppss[calls], 0.1f );
63 pps += packetsPerSecond;
65 if (calls >= sizeof(ppss) / sizeof(ppss[0]))
66 senf::scheduler::terminate();
69 void collectBPS(float bytesPerSecond)
71 bps += bytesPerSecond;
74 void collectSize(float min, float avg, float max)
76 BOOST_CHECK_CLOSE(min, 13.f, 0.01f);
77 BOOST_CHECK_CLOSE(avg, 13.f, 0.01f);
78 BOOST_CHECK_CLOSE(max, 13.f, 0.01f);
82 SENF_AUTO_UNIT_TEST(rateAnalyzer)
84 char const * enabled (getenv("SENF_TIMING_CRITICAL_TESTS"));
86 BOOST_WARN_MESSAGE(false, "Set SENF_TIMING_CRITICAL_TESTS to not skip timing critical tests");
88 senf::DataPacket p (senf::DataPacket::create(13u));
89 senf::ppi::module::CloneSource source (p);
90 senf::ppi::module::RateFilter filter (senf::ClockService::milliseconds(58u));
91 senf::ppi::module::RateAnalyzer analyzer;
92 analyzer.startStatistics(senf::ClockService::milliseconds(150u));
93 analyzer.signals.packetsPerSecond.connect(&collectPPS);
94 analyzer.signals.bytesPerSecond.connect(&collectBPS);
95 analyzer.signals.bytesPerPacket.connect(&collectSize);
97 senf::ppi::connect(source, filter);
98 senf::ppi::connect(filter, analyzer);
102 BOOST_CHECK_EQUAL( calls, 6u );
108 BOOST_CHECK_CLOSE( pps, 16.67f, .1f );
109 BOOST_CHECK_CLOSE( bps, 216.67f, .1f );
113 //-/////////////////////////////////////////////////////////////////////////////////////////////////
120 // comment-column: 40
121 // c-file-style: "senf"
122 // indent-tabs-mode: nil
123 // ispell-local-dictionary: "american"
124 // compile-command: "scons -u test"