1 #define TRACE_NAME "CommandableFragmentGenerator_t"
3 #define BOOST_TEST_MODULE CommandableFragmentGenerator_t
4 #include <boost/test/unit_test.hpp>
6 #include "artdaq-core/Data/ContainerFragment.hh"
7 #include "artdaq-core/Data/Fragment.hh"
8 #include "artdaq/DAQrate/RequestSender.hh"
9 #include "artdaq/Generators/CommandableFragmentGenerator.hh"
11 #define TRACE_REQUIRE_EQUAL(l, r) \
16 TLOG(TLVL_DEBUG) << __LINE__ << ": Checking if " << #l << " (" << (l) << ") equals " << #r << " (" << (r) << ")...YES!"; \
20 TLOG(TLVL_ERROR) << __LINE__ << ": Checking if " << #l << " (" << (l) << ") equals " << #r << " (" << (r) << ")...NO!"; \
22 BOOST_REQUIRE_EQUAL((l), (r)); \
25 #define TRACE_REQUIRE(b) \
30 TLOG(TLVL_DEBUG) << __LINE__ << ": Checking if " << #b << " (" << (b) << ") is true...YES!"; \
34 TLOG(TLVL_ERROR) << __LINE__ << ": Checking if " << #b << " (" << (b) << ") is true...NO!"; \
39 namespace artdaqtest {
40 class CommandableFragmentGeneratorTest;
70 bool getNext_(artdaq::FragmentPtrs& frags)
override;
81 void start()
override;
96 void pause()
override;
138 std::atomic<size_t> fireCount_;
139 std::atomic<bool> hwFail_;
140 artdaq::Fragment::timestamp_t ts_;
141 std::atomic<bool> hw_stop_;
142 std::atomic<uint64_t> enabled_ids_;
146 : CommandableFragmentGenerator(ps)
153 metricMan->initialize(ps.get<fhicl::ParameterSet>(
"metrics", fhicl::ParameterSet()));
154 metricMan->do_start();
159 while (fireCount_ > 0)
162 for (
auto&
id : fragmentIDs())
164 if (
id < 64 && ((enabled_ids_ & (0x1 <<
id)) != 0))
166 TLOG(TLVL_DEBUG) <<
"Adding Fragment with ID " <<
id <<
", SeqID " << ev_counter() <<
", and timestamp " << ts_;
167 frags.emplace_back(
new artdaq::Fragment(ev_counter(),
id, artdaq::Fragment::FirstUserFragmentType, ts_));
187 BOOST_AUTO_TEST_SUITE(CommandableFragmentGenerator_t)
191 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
192 TLOG(TLVL_INFO) <<
"Simple test case BEGIN";
193 fhicl::ParameterSet ps;
194 ps.put<
int>(
"board_id", 1);
195 ps.put<
int>(
"fragment_id", 1);
197 artdaq::FragmentPtrs fps;
198 auto sts = testGen.getNext(fps);
199 TRACE_REQUIRE_EQUAL(sts,
true);
200 TRACE_REQUIRE_EQUAL(fps.size(), 1u);
201 TRACE_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
202 TRACE_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
203 TRACE_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
204 TLOG(TLVL_INFO) <<
"Simple test case END";
209 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
210 TLOG(TLVL_INFO) <<
"MultipleIDs test case BEGIN";
211 fhicl::ParameterSet ps;
212 ps.put<
int>(
"board_id", 1);
213 ps.put<std::vector<int>>(
"fragment_ids", {1, 2, 3});
216 artdaq::FragmentPtrs fps;
217 auto sts = testGen.getNext(fps);
219 std::map<artdaq::Fragment::fragment_id_t, size_t> ids;
220 TRACE_REQUIRE_EQUAL(sts,
true);
221 TRACE_REQUIRE_EQUAL(fps.size(), 3u);
222 while (fps.size() > 0)
224 ids[fps.front()->fragmentID()]++;
225 TRACE_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
226 TRACE_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
230 TRACE_REQUIRE_EQUAL(ids[1], 1);
231 TRACE_REQUIRE_EQUAL(ids[2], 1);
232 TRACE_REQUIRE_EQUAL(ids[3], 1);
237 testGen.setEnabledIds(0x6);
238 testGen.setFireCount(1);
240 sts = testGen.getNext(fps);
242 TRACE_REQUIRE_EQUAL(sts,
true);
243 TRACE_REQUIRE_EQUAL(fps.size(), 2u);
246 ids[fps.front()->fragmentID()]++;
247 TRACE_REQUIRE_EQUAL(fps.front()->timestamp(), 2);
248 TRACE_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
251 TRACE_REQUIRE_EQUAL(ids[1], 1);
252 TRACE_REQUIRE_EQUAL(ids[2], 1);
253 TRACE_REQUIRE_EQUAL(ids[3], 0);
255 TLOG(TLVL_INFO) <<
"MultipleIDs test case END";
260 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
261 TLOG(TLVL_INFO) <<
"HardwareFailure_NonThreaded test case BEGIN";
262 fhicl::ParameterSet ps;
263 ps.put<
int>(
"board_id", 1);
264 ps.put<
int>(
"fragment_id", 1);
265 ps.put<
bool>(
"separate_data_thread",
false);
266 ps.put<
bool>(
"separate_monitoring_thread",
false);
267 ps.put<int64_t>(
"hardware_poll_interval_us", 10);
269 auto buffer = std::make_shared<artdaq::RequestBuffer>();
270 buffer->setRunning(
true);
272 gen.SetRequestBuffer(buffer);
275 artdaq::FragmentPtrs fps;
277 TRACE_REQUIRE_EQUAL(sts,
true);
278 TRACE_REQUIRE_EQUAL(fps.size(), 1u);
279 TRACE_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
280 TRACE_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
281 TRACE_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
288 TRACE_REQUIRE_EQUAL(sts,
false);
289 TRACE_REQUIRE(fps.empty());
293 TLOG(TLVL_INFO) <<
"HardwareFailure_NonThreaded test case END";
298 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
299 TLOG(TLVL_INFO) <<
"HardwareFailure_Threaded test case BEGIN";
300 fhicl::ParameterSet ps;
301 ps.put<
int>(
"board_id", 1);
302 ps.put<
int>(
"fragment_id", 1);
303 ps.put<
bool>(
"separate_monitoring_thread",
true);
304 ps.put<int64_t>(
"hardware_poll_interval_us", 750000);
306 auto buffer = std::make_shared<artdaq::RequestBuffer>();
307 buffer->setRunning(
true);
309 gen.SetRequestBuffer(buffer);
312 artdaq::FragmentPtrs fps;
314 TRACE_REQUIRE_EQUAL(sts,
true);
315 TRACE_REQUIRE_EQUAL(fps.size(), 1u);
316 TRACE_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
317 TRACE_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
318 TRACE_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
321 TLOG(TLVL_INFO) <<
"Setting failure bit";
326 TLOG(TLVL_INFO) <<
"Checking that failure is reported by getNext";
329 TRACE_REQUIRE_EQUAL(sts,
false);
330 TRACE_REQUIRE(fps.empty());
334 TLOG(TLVL_INFO) <<
"HardwareFailure_Threaded test case END";
337 BOOST_AUTO_TEST_SUITE_END()
bool getNext_(artdaq::FragmentPtrs &frags) override
Generate data and return it to CommandableFragmentGenerator.
void setEnabledIds(uint64_t bitmask)
Set the enabled IDs mask for the Fragment Generator.
CommandableFragmentGenerator derived class for testing.
void StopCmd(uint64_t timeout, uint64_t timestamp)
Stop the CommandableFragmentGenerator.
CommandableFragmentGeneratorTest(const fhicl::ParameterSet &ps)
CommandableFragmentGeneratorTest Constructor.
void StartCmd(int run, uint64_t timeout, uint64_t timestamp)
Start the CommandableFragmentGenerator.
bool getNext(FragmentPtrs &output) overridefinal
getNext calls either applyRequests or getNext_ to get any data that is ready to be sent to the EventB...
bool checkHWStatus_() override
Returns whether the hwFail flag has not been set.
void stopNoMutex() override
Perform immediate stop actions. No-Op.
void start() override
Perform start actions. No-Op.
CommandableFragmentGenerator is a FragmentGenerator-derived abstract class that defines the interface...
void resume() override
Perform resume actions. No-Op.
void pause() override
Perform pause actions. No-Op.
void setHwFail()
Set the hwFail flag.
void setTimestamp(artdaq::Fragment::timestamp_t ts)
Set the timestamp to be used for the next Fragment.
artdaq::Fragment::timestamp_t getTimestamp()
Get the timestamp that will be used for the next Fragment.
void stop() override
Perform stop actions. No-Op.
void joinThreads()
Join any data-taking threads. Should be called when destructing CommandableFragmentGenerator.
void setFireCount(size_t count)
Have getNext_ generate count fragments.