1 #include "artdaq-utilities/Plugins/MakeParameterSet.hh"
2 #include "artdaq-utilities/Plugins/MetricPlugin.hh"
5 #define BOOST_TEST_MODULE MetricPlugin_t
6 #include "cetlib/quiet_unit_test.hpp"
7 #include "cetlib_except/exception.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\"";
108 BOOST_REQUIRE_EQUAL(mpta.get_pset().to_string(), pset.to_string());
109 BOOST_REQUIRE_EQUAL(mpta.get_accumulationTime_(), 0.0);
110 BOOST_REQUIRE_EQUAL(mpta.get_level_mask_()[8],
true);
111 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(8),
true);
112 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case Constructor END";
115 BOOST_AUTO_TEST_CASE(IsLevelEnabled)
117 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case IsLevelEnabled BEGIN";
118 std::string testConfig =
"reporting_interval: 0 level: 4 metric_levels: [7,9,11] level_string: \"13-15,17,19-21,7-9\"";
122 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(0),
true);
123 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(1),
true);
124 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(2),
true);
125 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(3),
true);
126 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(4),
true);
127 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(5),
false);
128 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(6),
false);
129 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(7),
true);
130 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(8),
true);
131 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(9),
true);
132 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(10),
false);
133 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(11),
true);
134 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(12),
false);
135 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(13),
true);
136 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(14),
true);
137 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(15),
true);
138 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(16),
false);
139 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(17),
true);
140 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(18),
false);
141 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(19),
true);
142 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(20),
true);
143 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(21),
true);
144 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(22),
false);
146 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case IsLevelEnabled END";
149 BOOST_AUTO_TEST_CASE(LibraryName)
151 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case LibraryName BEGIN";
152 std::string testConfig =
"reporting_interval: 0 level: 4 metric_levels: [7,9,11] level_string: \"13-15,17,19-21,7-9\"";
156 BOOST_REQUIRE_EQUAL(mpta.getLibName(),
"ERROR");
157 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case LibraryName END";
160 BOOST_AUTO_TEST_CASE(AddMetricData)
162 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case AddMetricData BEGIN";
163 std::string testConfig =
"reporting_interval: 1.0 level: 4 metric_levels: [7,9,11] level_string: \"13-15,17,19-21,7-9\"";
173 mpta.addMetricData(smd);
174 mpta.addMetricData(imd);
175 mpta.addMetricData(fmd);
176 mpta.addMetricData(dmd);
177 mpta.addMetricData(umd);
179 BOOST_REQUIRE_EQUAL(mpta.sendMetric_string_calls, 1);
180 BOOST_REQUIRE_EQUAL(mpta.sendMetric_int_calls, 0);
181 BOOST_REQUIRE_EQUAL(mpta.sendMetric_float_calls, 0);
182 BOOST_REQUIRE_EQUAL(mpta.sendMetric_double_calls, 0);
183 BOOST_REQUIRE_EQUAL(mpta.sendMetric_unsigned_calls, 0);
185 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case AddMetricData END";
188 BOOST_AUTO_TEST_CASE(SendMetrics)
190 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case SendMetrics BEGIN";
191 std::string testConfig =
"reporting_interval: 0.01 level: 4 metric_levels: [7,9,11] level_string: \"13-15,17,19-21,7-9\"";
201 mpta.addMetricData(smd);
202 mpta.addMetricData(imd);
203 mpta.addMetricData(fmd);
204 mpta.addMetricData(dmd);
205 mpta.addMetricData(umd);
207 BOOST_REQUIRE_EQUAL(mpta.sendMetric_string_calls, 1);
208 BOOST_REQUIRE_EQUAL(mpta.sendMetric_int_calls, 0);
209 BOOST_REQUIRE_EQUAL(mpta.sendMetric_float_calls, 0);
210 BOOST_REQUIRE_EQUAL(mpta.sendMetric_double_calls, 0);
211 BOOST_REQUIRE_EQUAL(mpta.sendMetric_unsigned_calls, 0);
215 BOOST_REQUIRE_EQUAL(mpta.sendMetric_string_calls, 1);
216 BOOST_REQUIRE_EQUAL(mpta.sendMetric_int_calls, 1);
217 BOOST_REQUIRE_EQUAL(mpta.sendMetric_float_calls, 1);
218 BOOST_REQUIRE_EQUAL(mpta.sendMetric_double_calls, 1);
219 BOOST_REQUIRE_EQUAL(mpta.sendMetric_unsigned_calls, 1);
221 mpta.addMetricData(smd);
222 mpta.addMetricData(imd);
223 mpta.addMetricData(fmd);
224 mpta.addMetricData(dmd);
225 mpta.addMetricData(umd);
227 BOOST_REQUIRE_EQUAL(mpta.sendMetric_string_calls, 2);
228 BOOST_REQUIRE_EQUAL(mpta.sendMetric_int_calls, 1);
229 BOOST_REQUIRE_EQUAL(mpta.sendMetric_float_calls, 1);
230 BOOST_REQUIRE_EQUAL(mpta.sendMetric_double_calls, 1);
231 BOOST_REQUIRE_EQUAL(mpta.sendMetric_unsigned_calls, 1);
235 BOOST_REQUIRE_EQUAL(mpta.sendMetric_string_calls, 2);
236 BOOST_REQUIRE_EQUAL(mpta.sendMetric_int_calls, 1);
237 BOOST_REQUIRE_EQUAL(mpta.sendMetric_float_calls, 1);
238 BOOST_REQUIRE_EQUAL(mpta.sendMetric_double_calls, 1);
239 BOOST_REQUIRE_EQUAL(mpta.sendMetric_unsigned_calls, 1);
245 BOOST_REQUIRE_EQUAL(mpta.sendMetric_string_calls, 2);
246 BOOST_REQUIRE_EQUAL(mpta.sendMetric_int_calls, 2);
247 BOOST_REQUIRE_EQUAL(mpta.sendMetric_float_calls, 2);
248 BOOST_REQUIRE_EQUAL(mpta.sendMetric_double_calls, 2);
249 BOOST_REQUIRE_EQUAL(mpta.sendMetric_unsigned_calls, 2);
251 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case SendMetrics END";
254 BOOST_AUTO_TEST_CASE(StartMetrics)
256 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case StartMetrics BEGIN";
257 std::string testConfig =
"reporting_interval: 0 level: 4 metric_levels: [7,9,11] level_string: \"13-15,17,19-21,7-9\"";
262 BOOST_REQUIRE_EQUAL(mpta.startMetrics_calls, 1);
263 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case StartMetrics END";
266 BOOST_AUTO_TEST_CASE(StopMetrics)
268 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case StopMetrics BEGIN";
269 std::string testConfig =
"reporting_interval: 1.0 level: 4 metric_levels: [7,9,11] level_string: \"13-15,17,19-21,7-9\"";
279 mpta.addMetricData(smd);
280 mpta.addMetricData(imd);
281 mpta.addMetricData(fmd);
282 mpta.addMetricData(dmd);
283 mpta.addMetricData(umd);
285 BOOST_REQUIRE_EQUAL(mpta.sendMetric_string_calls, 1);
286 BOOST_REQUIRE_EQUAL(mpta.sendMetric_int_calls, 0);
287 BOOST_REQUIRE_EQUAL(mpta.sendMetric_float_calls, 0);
288 BOOST_REQUIRE_EQUAL(mpta.sendMetric_double_calls, 0);
289 BOOST_REQUIRE_EQUAL(mpta.sendMetric_unsigned_calls, 0);
293 BOOST_REQUIRE_EQUAL(mpta.stopMetrics_calls, 1);
294 BOOST_REQUIRE_EQUAL(mpta.sendMetric_string_calls, 1);
295 BOOST_REQUIRE_EQUAL(mpta.sendMetric_int_calls, 2);
296 BOOST_REQUIRE_EQUAL(mpta.sendMetric_float_calls, 2);
297 BOOST_REQUIRE_EQUAL(mpta.sendMetric_double_calls, 2);
298 BOOST_REQUIRE_EQUAL(mpta.sendMetric_unsigned_calls, 2);
300 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case StopMetrics END";
303 BOOST_AUTO_TEST_SUITE_END()
virtual void sendMetric_(const std::string &, const float &, const std::string &, const std::chrono::system_clock::time_point &) override
Send a float metric, record the call and discard the metric's data.
MetricPluginTestAdapter(fhicl::ParameterSet ps)
Constructor
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...
virtual void sendMetric_(const std::string &, const uint64_t &, const std::string &, const std::chrono::system_clock::time_point &) override
Send an unsigned metric, record the call and discard the metric's data.
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
MetricPlugin(fhicl::ParameterSet const &ps, std::string const &app_name, std::string const &metric_name)
MetricPlugin Constructor.
fhicl::ParameterSet get_pset()
Get the ParameterSet used to configure the plugin
fhicl::ParameterSet make_pset(std::string const &config_str)
Create a fhicl::ParameterSet from a string.
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.
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.
virtual void sendMetric_(const std::string &, const double &, const std::string &, const std::chrono::system_clock::time_point &) override
Send a double metric, record the call and discard the metric's data.
virtual void sendMetric_(const std::string &, const std::string &, const std::string &, const std::chrono::system_clock::time_point &) override
Send a String metric, record the call and discard the metric's data.
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.
size_t sendMetric_unsigned_calls
The numberof unsigned metric calls received.
size_t sendMetric_float_calls
The number of float metric calls received.
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
virtual void sendMetric_(const std::string &, const int &, const std::string &, const std::chrono::system_clock::time_point &) override
Send an int metric, record the call and discard the metric's data.