1 #define TRACE_NAME "CommandableFragmentGenerator_t"
3 #define BOOST_TEST_MODULE CommandableFragmentGenerator_t
4 #include <boost/test/auto_unit_test.hpp>
6 #include "artdaq-core/Data/Fragment.hh"
7 #include "artdaq-core/Data/ContainerFragment.hh"
8 #include "artdaq/Application/CommandableFragmentGenerator.hh"
9 #include "artdaq/DAQrate/RequestSender.hh"
11 #define MULTICAST_MODE 0
15 class CommandableFragmentGeneratorTest;
40 bool getNext_(artdaq::FragmentPtrs& frags)
override;
51 void start()
override;
66 void pause()
override;
89 auto start_time = std::chrono::steady_clock::now();
90 while (fireCount_ > 0) { usleep(1000); }
91 TLOG(TLVL_INFO) <<
"Waited " << std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - start_time).count() <<
" us for events to be picked up by CFG" ;
94 std::atomic<size_t> fireCount_;
95 std::atomic<bool> hwFail_;
96 artdaq::Fragment::timestamp_t ts_;
101 : CommandableFragmentGenerator(ps)
111 while (fireCount_ > 0)
113 frags.emplace_back(
new artdaq::Fragment(ev_counter(), fragment_id(), artdaq::Fragment::FirstUserFragmentType, ++ts_));
135 BOOST_AUTO_TEST_SUITE(CommandableFragmentGenerator_t)
139 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
140 TLOG(TLVL_INFO) <<
"Simple test case BEGIN" ;
141 fhicl::ParameterSet ps;
142 ps.put<
int>(
"board_id", 1);
143 ps.put<
int>(
"fragment_id", 1);
145 artdaq::FragmentPtrs fps;
146 auto sts = testGen.getNext(fps);
147 BOOST_REQUIRE_EQUAL(sts,
true);
148 BOOST_REQUIRE_EQUAL(fps.size(), 1u);
149 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
150 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
151 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
152 TLOG(TLVL_INFO) <<
"Simple test case END" ;
157 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
158 TLOG(TLVL_INFO) <<
"IgnoreRequests test case BEGIN" ;
159 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
160 const int DELAY_TIME = 1;
161 fhicl::ParameterSet ps;
162 ps.put<
int>(
"board_id", 1);
163 ps.put<
int>(
"fragment_id", 1);
164 ps.put<
int>(
"request_port", REQUEST_PORT);
166 ps.put<std::string>(
"request_address",
"227.18.12.29");
168 ps.put<std::string>(
"request_address",
"localhost");
170 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_offset", 0);
171 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_width", 0);
172 ps.put<
bool>(
"separate_data_thread",
true);
173 ps.put<
bool>(
"separate_monitoring_thread",
false);
174 ps.put<int64_t>(
"hardware_poll_interval_us", 0);
175 ps.put<std::string>(
"request_mode",
"ignored");
176 ps.put(
"request_delay_ms", DELAY_TIME);
177 ps.put(
"send_requests",
true);
184 artdaq::FragmentPtrs fps;
186 BOOST_REQUIRE_EQUAL(sts,
true);
187 BOOST_REQUIRE_EQUAL(fps.size(), 1u);
188 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
189 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
190 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
193 TLOG(TLVL_INFO) <<
"IgnoreRequests test case END" ;
198 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
199 TLOG(TLVL_INFO) <<
"SingleMode test case BEGIN" ;
200 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
201 const int DELAY_TIME = 100;
202 fhicl::ParameterSet ps;
203 ps.put<
int>(
"board_id", 1);
204 ps.put<
int>(
"fragment_id", 1);
205 ps.put<
int>(
"request_port", REQUEST_PORT);
207 ps.put<std::string>(
"request_address",
"227.18.12.30");
209 ps.put<std::string>(
"request_address",
"localhost");
211 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_offset", 0);
212 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_width", 0);
213 ps.put<
bool>(
"separate_data_thread",
true);
214 ps.put<
bool>(
"separate_monitoring_thread",
false);
215 ps.put<int64_t>(
"hardware_poll_interval_us", 0);
216 ps.put<std::string>(
"request_mode",
"single");
217 ps.put(
"request_delay_ms", DELAY_TIME);
218 ps.put(
"send_requests",
true);
227 artdaq::FragmentPtrs fps;
229 auto type = artdaq::Fragment::FirstUserFragmentType;
230 BOOST_REQUIRE_EQUAL(sts,
true);
231 BOOST_REQUIRE_EQUAL(fps.size(), 1u);
232 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
233 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
234 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
235 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
240 BOOST_REQUIRE_EQUAL(sts,
true);
241 BOOST_REQUIRE_EQUAL(fps.size(), 1u);
242 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
243 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 5);
244 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
245 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
252 BOOST_REQUIRE_EQUAL(sts,
true);
253 BOOST_REQUIRE_EQUAL(fps.size(), 2);
254 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
255 auto ts = artdaq::Fragment::InvalidTimestamp;
256 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), ts);
257 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 3);
258 auto emptyType = artdaq::Fragment::EmptyFragmentType;
259 BOOST_REQUIRE_EQUAL(fps.front()->type(), emptyType);
261 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
262 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 7);
263 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 4);
264 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
269 TLOG(TLVL_INFO) <<
"SingleMode test case END" ;
274 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
275 TLOG(TLVL_INFO) <<
"BufferMode test case BEGIN" ;
276 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
277 const int DELAY_TIME = 100;
278 fhicl::ParameterSet ps;
279 ps.put<
int>(
"board_id", 1);
280 ps.put<
int>(
"fragment_id", 1);
281 ps.put<
int>(
"request_port", REQUEST_PORT);
283 ps.put<std::string>(
"request_address",
"227.18.12.31");
285 ps.put<std::string>(
"request_address",
"localhost");
287 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_offset", 0);
288 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_width", 0);
289 ps.put<
bool>(
"separate_data_thread",
true);
290 ps.put<
bool>(
"separate_monitoring_thread",
false);
291 ps.put<int64_t>(
"hardware_poll_interval_us", 0);
292 ps.put<std::string>(
"request_mode",
"buffer");
293 ps.put(
"request_delay_ms", DELAY_TIME);
294 ps.put(
"send_requests",
true);
303 artdaq::FragmentPtrs fps;
305 BOOST_REQUIRE_EQUAL(sts,
true);
306 BOOST_REQUIRE_EQUAL(fps.size(), 1u);
307 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
308 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
309 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
310 auto type = artdaq::Fragment::ContainerFragmentType;
311 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
312 BOOST_REQUIRE_GE(fps.front()->sizeBytes(), 2 *
sizeof(artdaq::detail::RawEventHeader) +
sizeof(artdaq::ContainerFragment::Metadata));
313 auto cf = artdaq::ContainerFragment(*fps.front());
314 BOOST_REQUIRE_EQUAL(cf.block_count(), 1);
315 BOOST_REQUIRE_EQUAL(cf.missing_data(),
false);
316 type = artdaq::Fragment::FirstUserFragmentType;
317 BOOST_REQUIRE_EQUAL(cf.fragment_type(), type);
322 BOOST_REQUIRE_EQUAL(sts,
true);
323 BOOST_REQUIRE_EQUAL(fps.size(), 1u);
324 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
325 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 5);
326 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
327 type = artdaq::Fragment::ContainerFragmentType;
328 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
329 auto cf2 = artdaq::ContainerFragment(*fps.front());
330 BOOST_REQUIRE_EQUAL(cf2.block_count(), 0);
331 BOOST_REQUIRE_EQUAL(cf2.missing_data(),
false);
332 type = artdaq::Fragment::EmptyFragmentType;
333 BOOST_REQUIRE_EQUAL(cf2.fragment_type(), type);
340 BOOST_REQUIRE_EQUAL(sts,
true);
341 BOOST_REQUIRE_EQUAL(fps.size(), 2);
343 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
344 auto ts = artdaq::Fragment::InvalidTimestamp;
345 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), ts);
346 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 3);
347 auto emptyType = artdaq::Fragment::EmptyFragmentType;
348 BOOST_REQUIRE_EQUAL(fps.front()->type(), emptyType);
349 BOOST_REQUIRE_EQUAL(fps.front()->size(), artdaq::detail::RawFragmentHeader::num_words());
351 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
352 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 7);
353 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 4);
354 type = artdaq::Fragment::ContainerFragmentType;
355 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
356 auto cf3 = artdaq::ContainerFragment(*fps.front());
357 BOOST_REQUIRE_EQUAL(cf3.block_count(), 2);
358 BOOST_REQUIRE_EQUAL(cf3.missing_data(),
false);
359 type = artdaq::Fragment::FirstUserFragmentType;
360 BOOST_REQUIRE_EQUAL(cf3.fragment_type(), type);
368 TLOG(TLVL_INFO) <<
"BufferMode test case END" ;
373 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
374 TLOG(TLVL_INFO) <<
"WindowMode_Function test case BEGIN" ;
375 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
376 const int DELAY_TIME = 100;
377 fhicl::ParameterSet ps;
378 ps.put<
int>(
"board_id", 1);
379 ps.put<
int>(
"fragment_id", 1);
380 ps.put<
int>(
"request_port", REQUEST_PORT);
382 ps.put<std::string>(
"request_address",
"227.18.12.32");
384 ps.put<std::string>(
"request_address",
"localhost");
386 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_offset", 0);
387 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_width", 0);
388 ps.put<
bool>(
"separate_data_thread",
true);
389 ps.put<
bool>(
"separate_monitoring_thread",
false);
390 ps.put<int64_t>(
"hardware_poll_interval_us", 0);
391 ps.put<
size_t>(
"data_buffer_depth_fragments", 5);
392 ps.put<std::string>(
"request_mode",
"window");
393 ps.put(
"request_delay_ms", DELAY_TIME);
394 ps.put(
"send_requests",
true);
402 artdaq::FragmentPtrs fps;
404 BOOST_REQUIRE_EQUAL(sts,
true);
405 BOOST_REQUIRE_EQUAL(fps.size(), 1u);
406 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
407 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
408 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
409 auto type = artdaq::Fragment::ContainerFragmentType;
410 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
411 BOOST_REQUIRE_GE(fps.front()->sizeBytes(), 2 *
sizeof(artdaq::detail::RawEventHeader) +
sizeof(artdaq::ContainerFragment::Metadata));
412 auto cf = artdaq::ContainerFragment(*fps.front());
413 BOOST_REQUIRE_EQUAL(cf.block_count(), 1);
414 BOOST_REQUIRE_EQUAL(cf.missing_data(),
false);
415 type = artdaq::Fragment::FirstUserFragmentType;
416 BOOST_REQUIRE_EQUAL(cf.fragment_type(), type);
422 BOOST_REQUIRE_EQUAL(sts,
true);
423 BOOST_REQUIRE_EQUAL(fps.size(), 0);
428 BOOST_REQUIRE_EQUAL(sts,
true);
429 BOOST_REQUIRE_EQUAL(fps.size(), 1);
430 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
431 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 2);
432 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
433 type = artdaq::Fragment::ContainerFragmentType;
434 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
435 auto cf2 = artdaq::ContainerFragment(*fps.front());
436 BOOST_REQUIRE_EQUAL(cf2.block_count(), 1);
437 BOOST_REQUIRE_EQUAL(cf2.missing_data(),
false);
438 type = artdaq::Fragment::FirstUserFragmentType;
439 BOOST_REQUIRE_EQUAL(cf2.fragment_type(), type);
447 BOOST_REQUIRE_EQUAL(sts,
true);
448 BOOST_REQUIRE_EQUAL(fps.size(), 1);
452 BOOST_REQUIRE_EQUAL(sts,
true);
453 BOOST_REQUIRE_EQUAL(fps.size(), 2);
456 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
457 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 3);
458 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 4);
459 type = artdaq::Fragment::ContainerFragmentType;
460 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
461 auto cf3 = artdaq::ContainerFragment(*fps.front());
462 BOOST_REQUIRE_EQUAL(cf3.block_count(), 1);
463 BOOST_REQUIRE_EQUAL(cf3.missing_data(),
false);
464 type = artdaq::Fragment::FirstUserFragmentType;
465 BOOST_REQUIRE_EQUAL(cf3.fragment_type(), type);
468 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
469 auto ts = artdaq::Fragment::InvalidTimestamp;
470 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), ts);
471 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 3);
472 auto emptyType = artdaq::Fragment::EmptyFragmentType;
473 BOOST_REQUIRE_EQUAL(fps.front()->type(), emptyType);
474 BOOST_REQUIRE_EQUAL(fps.front()->size(), artdaq::detail::RawFragmentHeader::num_words());
482 BOOST_REQUIRE_EQUAL(sts,
true);
483 BOOST_REQUIRE_EQUAL(fps.size(), 1);
484 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
485 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 4);
486 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 5);
487 type = artdaq::Fragment::ContainerFragmentType;
488 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
489 auto cf4 = artdaq::ContainerFragment(*fps.front());
490 BOOST_REQUIRE_EQUAL(cf4.block_count(), 0);
491 BOOST_REQUIRE_EQUAL(cf4.missing_data(),
true);
492 type = artdaq::Fragment::EmptyFragmentType;
493 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
497 TLOG(TLVL_INFO) <<
"WindowMode_Function test case END" ;
510 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
511 TLOG(TLVL_INFO) <<
"WindowMode_RequestBeforeBuffer test case BEGIN" ;
512 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
513 const int DELAY_TIME = 100;
514 fhicl::ParameterSet ps;
515 ps.put<
int>(
"board_id", 1);
516 ps.put<
int>(
"fragment_id", 1);
517 ps.put<
int>(
"request_port", REQUEST_PORT);
519 ps.put<std::string>(
"request_address",
"227.18.12.32");
521 ps.put<std::string>(
"request_address",
"localhost");
523 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_offset", 0);
524 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_width", 3);
525 ps.put<
bool>(
"separate_data_thread",
true);
526 ps.put<
bool>(
"separate_monitoring_thread",
false);
527 ps.put<int64_t>(
"hardware_poll_interval_us", 0);
528 ps.put<
size_t>(
"data_buffer_depth_fragments", 5);
529 ps.put<std::string>(
"request_mode",
"window");
530 ps.put(
"request_delay_ms", DELAY_TIME);
531 ps.put(
"send_requests",
true);
538 artdaq::FragmentPtrs fps;
540 artdaq::Fragment::type_t type;
549 BOOST_REQUIRE_EQUAL(sts,
true);
550 BOOST_REQUIRE_EQUAL(fps.size(), 1);
551 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
552 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
553 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
554 type = artdaq::Fragment::ContainerFragmentType;
555 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
556 auto cf4 = artdaq::ContainerFragment(*fps.front());
557 BOOST_REQUIRE_EQUAL(cf4.block_count(), 0);
558 BOOST_REQUIRE_EQUAL(cf4.missing_data(),
true);
559 type = artdaq::Fragment::EmptyFragmentType;
560 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
563 TLOG(TLVL_INFO) <<
"WindowMode_RequestBeforeBuffer test case END" ;
568 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
569 TLOG(TLVL_INFO) <<
"WindowMode_RequestStartsBeforeBuffer test case BEGIN" ;
570 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
571 const int DELAY_TIME = 100;
572 fhicl::ParameterSet ps;
573 ps.put<
int>(
"board_id", 1);
574 ps.put<
int>(
"fragment_id", 1);
575 ps.put<
int>(
"request_port", REQUEST_PORT);
577 ps.put<std::string>(
"request_address",
"227.18.12.32");
579 ps.put<std::string>(
"request_address",
"localhost");
581 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_offset", 0);
582 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_width", 3);
583 ps.put<
bool>(
"separate_data_thread",
true);
584 ps.put<
bool>(
"separate_monitoring_thread",
false);
585 ps.put<int64_t>(
"hardware_poll_interval_us", 0);
586 ps.put<
size_t>(
"data_buffer_depth_fragments", 5);
587 ps.put<std::string>(
"request_mode",
"window");
588 ps.put(
"request_delay_ms", DELAY_TIME);
589 ps.put(
"send_requests",
true);
596 artdaq::FragmentPtrs fps;
598 artdaq::Fragment::type_t type;
609 BOOST_REQUIRE_EQUAL(sts,
true);
610 BOOST_REQUIRE_EQUAL(fps.size(), 1);
611 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
612 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 4);
613 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
614 type = artdaq::Fragment::ContainerFragmentType;
615 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
616 auto cf4 = artdaq::ContainerFragment(*fps.front());
617 BOOST_REQUIRE_EQUAL(cf4.block_count(), 1);
618 BOOST_REQUIRE_EQUAL(cf4.missing_data(),
true);
619 type = artdaq::Fragment::FirstUserFragmentType;
620 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
624 TLOG(TLVL_INFO) <<
"WindowMode_RequestStartsBeforeBuffer test case END" ;
629 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
630 TLOG(TLVL_INFO) <<
"WindowMode_RequestOutsideBuffer test case BEGIN" ;
631 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
632 const int DELAY_TIME = 100;
633 fhicl::ParameterSet ps;
634 ps.put<
int>(
"board_id", 1);
635 ps.put<
int>(
"fragment_id", 1);
636 ps.put<
int>(
"request_port", REQUEST_PORT);
638 ps.put<std::string>(
"request_address",
"227.18.12.32");
640 ps.put<std::string>(
"request_address",
"localhost");
642 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_offset", 0);
643 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_width", 4);
644 ps.put<
size_t>(
"window_close_timeout_us", 500000);
645 ps.put<
bool>(
"separate_data_thread",
true);
646 ps.put<
bool>(
"separate_monitoring_thread",
false);
647 ps.put<int64_t>(
"hardware_poll_interval_us", 0);
648 ps.put<
size_t>(
"data_buffer_depth_fragments", 5);
649 ps.put<std::string>(
"request_mode",
"window");
650 ps.put(
"request_delay_ms", DELAY_TIME);
651 ps.put(
"send_requests",
true);
658 artdaq::FragmentPtrs fps;
660 artdaq::Fragment::type_t type;
671 BOOST_REQUIRE_EQUAL(sts,
true);
672 BOOST_REQUIRE_EQUAL(fps.size(), 1);
673 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
674 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 6);
675 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
676 type = artdaq::Fragment::ContainerFragmentType;
677 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
678 auto cf = artdaq::ContainerFragment(*fps.front());
679 BOOST_REQUIRE_EQUAL(cf.block_count(), 4);
680 BOOST_REQUIRE_EQUAL(cf.missing_data(),
false);
681 type = artdaq::Fragment::FirstUserFragmentType;
682 BOOST_REQUIRE_EQUAL(cf.fragment_type(), type);
687 BOOST_REQUIRE_EQUAL(sts,
true);
688 BOOST_REQUIRE_EQUAL(fps.size(), 0);
694 BOOST_REQUIRE_EQUAL(sts,
true);
695 BOOST_REQUIRE_EQUAL(fps.size(), 1);
696 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
697 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 9);
698 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
699 type = artdaq::Fragment::ContainerFragmentType;
700 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
701 auto cf2 = artdaq::ContainerFragment(*fps.front());
702 BOOST_REQUIRE_EQUAL(cf2.block_count(), 3);
703 BOOST_REQUIRE_EQUAL(cf2.missing_data(),
true);
704 type = artdaq::Fragment::FirstUserFragmentType;
705 BOOST_REQUIRE_EQUAL(cf2.fragment_type(), type);
713 BOOST_REQUIRE_EQUAL(sts,
true);
714 BOOST_REQUIRE_EQUAL(fps.size(), 0);
719 BOOST_REQUIRE_EQUAL(sts,
true);
720 BOOST_REQUIRE_EQUAL(fps.size(), 1);
721 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
722 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 12);
723 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 3);
724 type = artdaq::Fragment::ContainerFragmentType;
725 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
726 auto cf4 = artdaq::ContainerFragment(*fps.front());
727 BOOST_REQUIRE_EQUAL(cf4.block_count(), 1);
728 BOOST_REQUIRE_EQUAL(cf4.missing_data(),
true);
729 type = artdaq::Fragment::FirstUserFragmentType;
730 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
734 TLOG(TLVL_INFO) <<
"WindowMode_RequestOutsideBuffer test case END" ;
739 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
740 TLOG(TLVL_INFO) <<
"WindowMode_RequestInBuffer test case BEGIN" ;
741 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
742 const int DELAY_TIME = 100;
743 fhicl::ParameterSet ps;
744 ps.put<
int>(
"board_id", 1);
745 ps.put<
int>(
"fragment_id", 1);
746 ps.put<
int>(
"request_port", REQUEST_PORT);
748 ps.put<std::string>(
"request_address",
"227.18.12.32");
750 ps.put<std::string>(
"request_address",
"localhost");
752 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_offset", 0);
753 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_width", 3);
754 ps.put<
bool>(
"separate_data_thread",
true);
755 ps.put<
bool>(
"separate_monitoring_thread",
false);
756 ps.put<int64_t>(
"hardware_poll_interval_us", 0);
757 ps.put<
size_t>(
"data_buffer_depth_fragments", 5);
758 ps.put<std::string>(
"request_mode",
"window");
759 ps.put(
"request_delay_ms", DELAY_TIME);
760 ps.put(
"send_requests",
true);
767 artdaq::FragmentPtrs fps;
769 artdaq::Fragment::type_t type;
779 BOOST_REQUIRE_EQUAL(sts,
true);
780 BOOST_REQUIRE_EQUAL(fps.size(), 1);
781 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
782 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 3);
783 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
784 type = artdaq::Fragment::ContainerFragmentType;
785 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
786 auto cf4 = artdaq::ContainerFragment(*fps.front());
787 BOOST_REQUIRE_EQUAL(cf4.block_count(), 3);
788 BOOST_REQUIRE_EQUAL(cf4.missing_data(),
false);
789 type = artdaq::Fragment::FirstUserFragmentType;
790 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
793 TLOG(TLVL_INFO) <<
"WindowMode_RequestInBuffer test case END" ;
798 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
799 TLOG(TLVL_INFO) <<
"WindowMode_RequestEndsAfterBuffer test case BEGIN" ;
800 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
801 const int DELAY_TIME = 100;
802 fhicl::ParameterSet ps;
803 ps.put<
int>(
"board_id", 1);
804 ps.put<
int>(
"fragment_id", 1);
805 ps.put<
int>(
"request_port", REQUEST_PORT);
807 ps.put<std::string>(
"request_address",
"227.18.12.32");
809 ps.put<std::string>(
"request_address",
"localhost");
811 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_offset", 0);
812 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_width", 3);
813 ps.put<
size_t>(
"window_close_timeout_us", 500000);
814 ps.put<
bool>(
"separate_data_thread",
true);
815 ps.put<
bool>(
"separate_monitoring_thread",
false);
816 ps.put<int64_t>(
"hardware_poll_interval_us", 0);
817 ps.put<
size_t>(
"data_buffer_depth_fragments", 5);
818 ps.put<std::string>(
"request_mode",
"window");
819 ps.put(
"request_delay_ms", DELAY_TIME);
820 ps.put(
"send_requests",
true);
827 artdaq::FragmentPtrs fps;
829 artdaq::Fragment::type_t type;
838 BOOST_REQUIRE_EQUAL(sts,
true);
839 BOOST_REQUIRE_EQUAL(fps.size(), 0);
844 BOOST_REQUIRE_EQUAL(sts,
true);
845 BOOST_REQUIRE_EQUAL(fps.size(), 1);
846 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
847 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 5);
848 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
849 type = artdaq::Fragment::ContainerFragmentType;
850 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
851 auto cf = artdaq::ContainerFragment(*fps.front());
852 BOOST_REQUIRE_EQUAL(cf.block_count(), 3);
853 BOOST_REQUIRE_EQUAL(cf.missing_data(),
false);
854 type = artdaq::Fragment::FirstUserFragmentType;
855 BOOST_REQUIRE_EQUAL(cf.fragment_type(), type);
861 BOOST_REQUIRE_EQUAL(sts,
true);
862 BOOST_REQUIRE_EQUAL(fps.size(), 0);
867 BOOST_REQUIRE_EQUAL(sts,
true);
868 BOOST_REQUIRE_EQUAL(fps.size(), 1);
869 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
870 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 8);
871 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
872 type = artdaq::Fragment::ContainerFragmentType;
873 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
874 auto cf4 = artdaq::ContainerFragment(*fps.front());
875 BOOST_REQUIRE_EQUAL(cf4.block_count(), 1);
876 BOOST_REQUIRE_EQUAL(cf4.missing_data(),
true);
877 type = artdaq::Fragment::FirstUserFragmentType;
878 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
882 TLOG(TLVL_INFO) <<
"WindowMode_RequestEndsAfterBuffer test case END" ;
887 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
888 TLOG(TLVL_INFO) <<
"WindowMode_RequestAfterBuffer test case BEGIN" ;
889 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
890 const int DELAY_TIME = 100;
891 fhicl::ParameterSet ps;
892 ps.put<
int>(
"board_id", 1);
893 ps.put<
int>(
"fragment_id", 1);
894 ps.put<
int>(
"request_port", REQUEST_PORT);
896 ps.put<std::string>(
"request_address",
"227.18.12.32");
898 ps.put<std::string>(
"request_address",
"localhost");
900 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_offset", 0);
901 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_width", 3);
902 ps.put<
size_t>(
"window_close_timeout_us", 500000);
903 ps.put<
bool>(
"separate_data_thread",
true);
904 ps.put<
bool>(
"separate_monitoring_thread",
false);
905 ps.put<int64_t>(
"hardware_poll_interval_us", 0);
906 ps.put<
size_t>(
"data_buffer_depth_fragments", 5);
907 ps.put<std::string>(
"request_mode",
"window");
908 ps.put(
"request_delay_ms", DELAY_TIME);
909 ps.put(
"send_requests",
true);
916 artdaq::FragmentPtrs fps;
918 artdaq::Fragment::type_t type;
928 BOOST_REQUIRE_EQUAL(sts,
true);
929 BOOST_REQUIRE_EQUAL(fps.size(), 0);
933 BOOST_REQUIRE_EQUAL(sts,
true);
934 BOOST_REQUIRE_EQUAL(fps.size(), 0);
939 BOOST_REQUIRE_EQUAL(sts,
true);
940 BOOST_REQUIRE_EQUAL(fps.size(), 1);
941 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
942 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 11);
943 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
944 type = artdaq::Fragment::ContainerFragmentType;
945 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
946 auto cf = artdaq::ContainerFragment(*fps.front());
947 BOOST_REQUIRE_EQUAL(cf.block_count(), 3);
948 BOOST_REQUIRE_EQUAL(cf.missing_data(),
false);
949 type = artdaq::Fragment::FirstUserFragmentType;
950 BOOST_REQUIRE_EQUAL(cf.fragment_type(), type);
955 BOOST_REQUIRE_EQUAL(sts,
true);
956 BOOST_REQUIRE_EQUAL(fps.size(), 0);
961 BOOST_REQUIRE_EQUAL(sts,
true);
962 BOOST_REQUIRE_EQUAL(fps.size(), 1);
963 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
964 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 16);
965 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
966 type = artdaq::Fragment::ContainerFragmentType;
967 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
968 auto cf4 = artdaq::ContainerFragment(*fps.front());
969 BOOST_REQUIRE_EQUAL(cf4.block_count(), 0);
970 BOOST_REQUIRE_EQUAL(cf4.missing_data(),
true);
971 type = artdaq::Fragment::EmptyFragmentType;
972 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
976 TLOG(TLVL_INFO) <<
"WindowMode_RequestAfterBuffer test case END" ;
982 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
983 TLOG(TLVL_INFO) <<
"HardwareFailure_NonThreaded test case BEGIN" ;
984 fhicl::ParameterSet ps;
985 ps.put<
int>(
"board_id", 1);
986 ps.put<
int>(
"fragment_id", 1);
987 ps.put<
bool>(
"separate_data_thread",
false);
988 ps.put<
bool>(
"separate_monitoring_thread",
false);
989 ps.put<int64_t>(
"hardware_poll_interval_us", 10);
992 gen.StartCmd(1, 0xFFFFFFFF, 1);
994 artdaq::FragmentPtrs fps;
995 auto sts = gen.getNext(fps);
996 BOOST_REQUIRE_EQUAL(sts,
true);
997 BOOST_REQUIRE_EQUAL(fps.size(), 1u);
998 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
999 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
1000 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
1003 gen.setFireCount(1);
1006 sts = gen.getNext(fps);
1007 BOOST_REQUIRE_EQUAL(sts,
false);
1008 BOOST_REQUIRE_EQUAL(fps.size(), 0);
1010 gen.StopCmd(0xFFFFFFFF, 1);
1012 TLOG(TLVL_INFO) <<
"HardwareFailure_NonThreaded test case END" ;
1017 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
1018 TLOG(TLVL_INFO) <<
"HardwareFailure_Threaded test case BEGIN" ;
1019 fhicl::ParameterSet ps;
1020 ps.put<
int>(
"board_id", 1);
1021 ps.put<
int>(
"fragment_id", 1);
1022 ps.put<
bool>(
"separate_data_thread",
true);
1023 ps.put<
bool>(
"separate_monitoring_thread",
true);
1024 ps.put<int64_t>(
"hardware_poll_interval_us", 750000);
1027 gen.StartCmd(1, 0xFFFFFFFF, 1);
1031 artdaq::FragmentPtrs fps;
1032 auto sts = gen.getNext(fps);
1033 BOOST_REQUIRE_EQUAL(sts,
true);
1034 BOOST_REQUIRE_EQUAL(fps.size(), 1u);
1035 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
1036 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
1037 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
1052 gen.setFireCount(1);
1053 sts = gen.getNext(fps);
1054 BOOST_REQUIRE_EQUAL(sts,
false);
1055 BOOST_REQUIRE_EQUAL(fps.size(), 0);
1057 gen.StopCmd(0xFFFFFFFF, 1);
1059 TLOG(TLVL_INFO) <<
"HardwareFailure_Threaded test case END" ;
1062 BOOST_AUTO_TEST_SUITE_END()
bool getNext_(artdaq::FragmentPtrs &frags) override
Generate data and return it to CommandableFragmentGenerator.
CommandableFragmentGenerator derived class for testing.
The RequestSender contains methods used to send data requests and Routing tokens. ...
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 stop() override
Perform stop actions. No-Op.
void AddRequest(Fragment::sequence_id_t seqID, Fragment::timestamp_t timestamp)
Add a request to the request list.
void waitForFrags()
Wait for all fragments generated to be read by the CommandableFragmentGenerator
void joinThreads()
Join any data-taking threads. Should be called when destructing CommandableFragmentGenerator.
void setFireCount(size_t count)
Have getNext_ generate count fragments.