1 #include "artdaq-utilities/Plugins/MetricPlugin.hh"
4 #define BOOST_TEST_MODULES MetricPlugin_t
5 #include "cetlib/quiet_unit_test.hpp"
6 #include "cetlib_except/exception.h"
7 #include "fhiclcpp/make_ParameterSet.h"
9 #include "TRACE/trace.h"
11 namespace artdaqtest {
100 BOOST_AUTO_TEST_SUITE(MetricPlugin_test)
102 BOOST_AUTO_TEST_CASE(Constructor)
104 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case Constructor BEGIN";
105 std::string testConfig =
"reporting_interval: 0 level: 4 metric_levels: [7,9,11] level_string: \"13-15,17,19-21,7-9\"";
106 fhicl::ParameterSet pset;
107 fhicl::make_ParameterSet(testConfig, pset);
109 BOOST_REQUIRE_EQUAL(mpta.get_pset().to_string(), pset.to_string());
110 BOOST_REQUIRE_EQUAL(mpta.get_accumulationTime_(), 0.0);
111 BOOST_REQUIRE_EQUAL(mpta.get_level_mask_()[8],
true);
112 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(8),
true);
113 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case Constructor END";
116 BOOST_AUTO_TEST_CASE(IsLevelEnabled)
118 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case IsLevelEnabled BEGIN";
119 std::string testConfig =
"reporting_interval: 0 level: 4 metric_levels: [7,9,11] level_string: \"13-15,17,19-21,7-9\"";
120 fhicl::ParameterSet pset;
121 fhicl::make_ParameterSet(testConfig, pset);
124 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(0),
true);
125 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(1),
true);
126 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(2),
true);
127 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(3),
true);
128 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(4),
true);
129 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(5),
false);
130 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(6),
false);
131 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(7),
true);
132 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(8),
true);
133 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(9),
true);
134 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(10),
false);
135 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(11),
true);
136 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(12),
false);
137 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(13),
true);
138 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(14),
true);
139 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(15),
true);
140 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(16),
false);
141 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(17),
true);
142 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(18),
false);
143 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(19),
true);
144 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(20),
true);
145 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(21),
true);
146 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(22),
false);
148 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case IsLevelEnabled END";
151 BOOST_AUTO_TEST_CASE(LibraryName)
153 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case LibraryName BEGIN";
154 std::string testConfig =
"reporting_interval: 0 level: 4 metric_levels: [7,9,11] level_string: \"13-15,17,19-21,7-9\"";
155 fhicl::ParameterSet pset;
156 fhicl::make_ParameterSet(testConfig, pset);
159 BOOST_REQUIRE_EQUAL(mpta.getLibName(),
"ERROR");
160 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case LibraryName END";
163 BOOST_AUTO_TEST_CASE(AddMetricData)
165 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case AddMetricData BEGIN";
166 std::string testConfig =
"reporting_interval: 1.0 level: 4 metric_levels: [7,9,11] level_string: \"13-15,17,19-21,7-9\"";
167 fhicl::ParameterSet pset;
168 fhicl::make_ParameterSet(testConfig, pset);
177 mpta.addMetricData(smd);
178 mpta.addMetricData(imd);
179 mpta.addMetricData(fmd);
180 mpta.addMetricData(dmd);
181 mpta.addMetricData(umd);
183 BOOST_REQUIRE_EQUAL(mpta.sendMetric_string_calls, 1);
184 BOOST_REQUIRE_EQUAL(mpta.sendMetric_int_calls, 0);
185 BOOST_REQUIRE_EQUAL(mpta.sendMetric_float_calls, 0);
186 BOOST_REQUIRE_EQUAL(mpta.sendMetric_double_calls, 0);
187 BOOST_REQUIRE_EQUAL(mpta.sendMetric_unsigned_calls, 0);
189 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case AddMetricData END";
192 BOOST_AUTO_TEST_CASE(SendMetrics)
194 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case SendMetrics BEGIN";
195 std::string testConfig =
"reporting_interval: 0.01 level: 4 metric_levels: [7,9,11] level_string: \"13-15,17,19-21,7-9\"";
196 fhicl::ParameterSet pset;
197 fhicl::make_ParameterSet(testConfig, pset);
206 mpta.addMetricData(smd);
207 mpta.addMetricData(imd);
208 mpta.addMetricData(fmd);
209 mpta.addMetricData(dmd);
210 mpta.addMetricData(umd);
212 BOOST_REQUIRE_EQUAL(mpta.sendMetric_string_calls, 1);
213 BOOST_REQUIRE_EQUAL(mpta.sendMetric_int_calls, 0);
214 BOOST_REQUIRE_EQUAL(mpta.sendMetric_float_calls, 0);
215 BOOST_REQUIRE_EQUAL(mpta.sendMetric_double_calls, 0);
216 BOOST_REQUIRE_EQUAL(mpta.sendMetric_unsigned_calls, 0);
220 BOOST_REQUIRE_EQUAL(mpta.sendMetric_string_calls, 1);
221 BOOST_REQUIRE_EQUAL(mpta.sendMetric_int_calls, 1);
222 BOOST_REQUIRE_EQUAL(mpta.sendMetric_float_calls, 1);
223 BOOST_REQUIRE_EQUAL(mpta.sendMetric_double_calls, 1);
224 BOOST_REQUIRE_EQUAL(mpta.sendMetric_unsigned_calls, 1);
226 mpta.addMetricData(smd);
227 mpta.addMetricData(imd);
228 mpta.addMetricData(fmd);
229 mpta.addMetricData(dmd);
230 mpta.addMetricData(umd);
232 BOOST_REQUIRE_EQUAL(mpta.sendMetric_string_calls, 2);
233 BOOST_REQUIRE_EQUAL(mpta.sendMetric_int_calls, 1);
234 BOOST_REQUIRE_EQUAL(mpta.sendMetric_float_calls, 1);
235 BOOST_REQUIRE_EQUAL(mpta.sendMetric_double_calls, 1);
236 BOOST_REQUIRE_EQUAL(mpta.sendMetric_unsigned_calls, 1);
240 BOOST_REQUIRE_EQUAL(mpta.sendMetric_string_calls, 2);
241 BOOST_REQUIRE_EQUAL(mpta.sendMetric_int_calls, 1);
242 BOOST_REQUIRE_EQUAL(mpta.sendMetric_float_calls, 1);
243 BOOST_REQUIRE_EQUAL(mpta.sendMetric_double_calls, 1);
244 BOOST_REQUIRE_EQUAL(mpta.sendMetric_unsigned_calls, 1);
250 BOOST_REQUIRE_EQUAL(mpta.sendMetric_string_calls, 2);
251 BOOST_REQUIRE_EQUAL(mpta.sendMetric_int_calls, 2);
252 BOOST_REQUIRE_EQUAL(mpta.sendMetric_float_calls, 2);
253 BOOST_REQUIRE_EQUAL(mpta.sendMetric_double_calls, 2);
254 BOOST_REQUIRE_EQUAL(mpta.sendMetric_unsigned_calls, 2);
256 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case SendMetrics END";
259 BOOST_AUTO_TEST_CASE(StartMetrics)
261 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case StartMetrics BEGIN";
262 std::string testConfig =
"reporting_interval: 0 level: 4 metric_levels: [7,9,11] level_string: \"13-15,17,19-21,7-9\"";
263 fhicl::ParameterSet pset;
264 fhicl::make_ParameterSet(testConfig, pset);
268 BOOST_REQUIRE_EQUAL(mpta.startMetrics_calls, 1);
269 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case StartMetrics END";
272 BOOST_AUTO_TEST_CASE(StopMetrics)
274 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case StopMetrics BEGIN";
275 std::string testConfig =
"reporting_interval: 1.0 level: 4 metric_levels: [7,9,11] level_string: \"13-15,17,19-21,7-9\"";
276 fhicl::ParameterSet pset;
277 fhicl::make_ParameterSet(testConfig, pset);
286 mpta.addMetricData(smd);
287 mpta.addMetricData(imd);
288 mpta.addMetricData(fmd);
289 mpta.addMetricData(dmd);
290 mpta.addMetricData(umd);
292 BOOST_REQUIRE_EQUAL(mpta.sendMetric_string_calls, 1);
293 BOOST_REQUIRE_EQUAL(mpta.sendMetric_int_calls, 0);
294 BOOST_REQUIRE_EQUAL(mpta.sendMetric_float_calls, 0);
295 BOOST_REQUIRE_EQUAL(mpta.sendMetric_double_calls, 0);
296 BOOST_REQUIRE_EQUAL(mpta.sendMetric_unsigned_calls, 0);
300 BOOST_REQUIRE_EQUAL(mpta.stopMetrics_calls, 1);
301 BOOST_REQUIRE_EQUAL(mpta.sendMetric_string_calls, 1);
302 BOOST_REQUIRE_EQUAL(mpta.sendMetric_int_calls, 2);
303 BOOST_REQUIRE_EQUAL(mpta.sendMetric_float_calls, 2);
304 BOOST_REQUIRE_EQUAL(mpta.sendMetric_double_calls, 2);
305 BOOST_REQUIRE_EQUAL(mpta.sendMetric_unsigned_calls, 2);
307 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case StopMetrics END";
310 BOOST_AUTO_TEST_SUITE_END()
void sendMetric_(const std::string &, const double &, const std::string &) override
Send a double metric, record the call and discard the metric's data.
size_t sendMetric_string_calls
The number of string metric calls received.
The MetricPlugin class defines the interface that MetricManager uses to send metric data to the vario...
void stopMetrics_() override
Record that a stopMetrics call was received.
bool get_inhibit_()
Get the MetricPlugin's inhibit_ variable
fhicl::ParameterSet pset
The ParameterSet used to configure the MetricPlugin.
double get_accumulationTime_()
Get the MetricPlugin's accumulationTime variable
fhicl::ParameterSet get_pset()
Get the ParameterSet used to configure the plugin
std::string app_name_
Name of the application which is sending metrics to this plugin.
size_t sendMetric_int_calls
The number of int metric calls received.
MetricPlugin(fhicl::ParameterSet const &ps, std::string const &app_name)
MetricPlugin Constructor.
size_t startMetrics_calls
The number of startMetrics_ calls received.
Report only the last value recorded. Useful for event counters, run numbers, etc. ...
size_t stopMetrics_calls
The number of stopMetrics_ calls received.
std::string get_app_name_()
Get the MetricPlugin's app_name_ variable
std::bitset< 64 > level_mask_
Bitset indicating for each possible metric level, whether this plugin will receive those metrics...
std::bitset< 64 > get_level_mask_()
Get the MetricPlugin's level_mask_ variable
void startMetrics_() override
Record that a startMetrics call was received.
void sendMetric_(const std::string &, const std::string &, const std::string &) override
Send a String metric, record the call and discard the metric's data.
MetricPluginTestAdapter(const fhicl::ParameterSet &ps)
Constructor
double accumulationTime_
The amount of time to average metric values; except for accumulate=false metrics, will be the interva...
size_t sendMetric_double_calls
The number of double metric calls received.
void sendMetric_(const std::string &, const int &, const std::string &) override
Send an int metric, record the call and discard the metric's data.
size_t sendMetric_unsigned_calls
The numberof unsigned metric calls received.
void sendMetric_(const std::string &, const float &, const std::string &) override
Send a float metric, record the call and discard the metric's data.
size_t sendMetric_float_calls
The number of float metric calls received.
void sendMetric_(const std::string &, const uint64_t &, const std::string &) override
Send an unsigned metric, record the call and discard the metric's data.
bool inhibit_
Flag to indicate that the MetricPlugin is being stopped, and any metric back-ends which do not have a...
Metric plugin which stores metric call counts for testing