artdaq  v3_00_01
CommandableFragmentGenerator_t.cc
1 #define BOOST_TEST_MODULE CommandableFragmentGenerator_t
2 #include <boost/test/auto_unit_test.hpp>
3 
4 #include "artdaq-core/Data/Fragment.hh"
5 #include "artdaq-core/Data/ContainerFragment.hh"
6 #include "artdaq/Application/CommandableFragmentGenerator.hh"
7 #include "artdaq/DAQrate/RequestSender.hh"
8 
9 #define MULTICAST_MODE 0
10 
11 namespace artdaqtest
12 {
13  class CommandableFragmentGeneratorTest;
14 }
15 
21 {
22 public:
26  explicit CommandableFragmentGeneratorTest(const fhicl::ParameterSet& ps);
27 
29 
30 protected:
38  bool getNext_(artdaq::FragmentPtrs& frags) override;
39 
44  bool checkHWStatus_() override { return !hwFail_.load(); }
45 
49  void start() override;
50 
54  void stopNoMutex() override;
55 
59  void stop() override;
60 
64  void pause() override;
65 
69  void resume() override;
70 
71 public:
76  void setFireCount(size_t count) { fireCount_ = count; }
77 
81  void setHwFail() { hwFail_ = true; }
82 
86  void waitForFrags() {
87  auto start_time = std::chrono::steady_clock::now();
88  while (fireCount_ > 0) { usleep(1000); }
89  TLOG_INFO("CommandableFragmentGenerator_t") << "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" << TLOG_ENDL;
90  }
91 private:
92  std::atomic<size_t> fireCount_;
93  std::atomic<bool> hwFail_;
94  artdaq::Fragment::timestamp_t ts_;
95  bool hw_stop_;
96 };
97 
99  : CommandableFragmentGenerator(ps)
100  , fireCount_(1)
101  , hwFail_(false)
102  , ts_(0)
103  , hw_stop_(false)
104 {}
105 
106 bool
108 {
109  while (fireCount_ > 0)
110  {
111  frags.emplace_back(new artdaq::Fragment(ev_counter(), fragment_id(), artdaq::Fragment::FirstUserFragmentType, ++ts_));
112  fireCount_--;
113  }
114 
115  return !hw_stop_;
116 }
117 
118 void
120 
121 void
123 
124 void
126 
127 void
129 
130 void
132 
133 BOOST_AUTO_TEST_SUITE(CommandableFragmentGenerator_t)
134 
135 BOOST_AUTO_TEST_CASE(Simple)
136 {
137  artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
138  TLOG_INFO("CommandableFragmentGenerator_t") << "Simple test case BEGIN" << TLOG_ENDL;
139  fhicl::ParameterSet ps;
140  ps.put<int>("board_id", 1);
141  ps.put<int>("fragment_id", 1);
143  artdaq::FragmentPtrs fps;
144  auto sts = testGen.getNext(fps);
145  BOOST_REQUIRE_EQUAL(sts, true);
146  BOOST_REQUIRE_EQUAL(fps.size(), 1u);
147  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
148  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
149  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
150  TLOG_INFO("CommandableFragmentGenerator_t") << "Simple test case END" << TLOG_ENDL;
151 }
152 
153 BOOST_AUTO_TEST_CASE(IgnoreRequests)
154 {
155  artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
156  TLOG_INFO("CommandableFragmentGenerator_t") << "IgnoreRequests test case BEGIN" << TLOG_ENDL;
157  const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
158  const int DELAY_TIME = 1;
159  fhicl::ParameterSet ps;
160  ps.put<int>("board_id", 1);
161  ps.put<int>("fragment_id", 1);
162  ps.put<int>("request_port", REQUEST_PORT);
163 #if MULTICAST_MODE
164  ps.put<std::string>("request_address", "227.18.12.29");
165 #else
166  ps.put<std::string>("request_address", "localhost");
167 #endif
168  ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
169  ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 0);
170  ps.put<bool>("separate_data_thread", true);
171  ps.put<bool>("separate_monitoring_thread", false);
172  ps.put<int64_t>("hardware_poll_interval_us", 0);
173  ps.put<std::string>("request_mode", "ignored");
174  ps.put("request_delay_ms", DELAY_TIME);
175  ps.put("send_requests", true);
176 
177  artdaq::RequestSender t(ps);
179  gen.StartCmd(1, 0xFFFFFFFF, 1);
180  t.AddRequest(53, 35);
181 
182  artdaq::FragmentPtrs fps;
183  auto sts = gen.getNext(fps);
184  BOOST_REQUIRE_EQUAL(sts, true);
185  BOOST_REQUIRE_EQUAL(fps.size(), 1u);
186  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
187  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
188  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
189  gen.StopCmd(0xFFFFFFFF, 1);
190  gen.joinThreads();
191  TLOG_INFO("CommandableFragmentGenerator_t") << "IgnoreRequests test case END" << TLOG_ENDL;
192 }
193 
194 BOOST_AUTO_TEST_CASE(SingleMode)
195 {
196  artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
197  TLOG_INFO("CommandableFragmentGenerator_t") << "SingleMode test case BEGIN" << TLOG_ENDL;
198  const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
199  const int DELAY_TIME = 100;
200  fhicl::ParameterSet ps;
201  ps.put<int>("board_id", 1);
202  ps.put<int>("fragment_id", 1);
203  ps.put<int>("request_port", REQUEST_PORT);
204 #if MULTICAST_MODE
205  ps.put<std::string>("request_address", "227.18.12.30");
206 #else
207  ps.put<std::string>("request_address", "localhost");
208 #endif
209  ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
210  ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 0);
211  ps.put<bool>("separate_data_thread", true);
212  ps.put<bool>("separate_monitoring_thread", false);
213  ps.put<int64_t>("hardware_poll_interval_us", 0);
214  ps.put<std::string>("request_mode", "single");
215  ps.put("request_delay_ms", DELAY_TIME);
216  ps.put("send_requests", true);
217 
218  artdaq::RequestSender t(ps);
219  t.AddRequest(1, 1);
220 
222  gen.StartCmd(1, 0xFFFFFFFF, 1);
223  gen.waitForFrags();
224 
225  artdaq::FragmentPtrs fps;
226  auto sts = gen.getNext(fps);
227  auto type = artdaq::Fragment::FirstUserFragmentType;
228  BOOST_REQUIRE_EQUAL(sts, true);
229  BOOST_REQUIRE_EQUAL(fps.size(), 1u);
230  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
231  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
232  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
233  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
234  fps.clear();
235 
236  t.AddRequest(2, 5);
237  sts = gen.getNext(fps);
238  BOOST_REQUIRE_EQUAL(sts, true);
239  BOOST_REQUIRE_EQUAL(fps.size(), 1u);
240  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
241  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 5);
242  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
243  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
244  fps.clear();
245 
246  gen.setFireCount(2);
247  gen.waitForFrags();
248  t.AddRequest(4, 7);
249  sts = gen.getNext(fps);
250  BOOST_REQUIRE_EQUAL(sts, true);
251  BOOST_REQUIRE_EQUAL(fps.size(), 2);
252  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
253  auto ts = artdaq::Fragment::InvalidTimestamp;
254  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), ts);
255  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 3);
256  auto emptyType = artdaq::Fragment::EmptyFragmentType;
257  BOOST_REQUIRE_EQUAL(fps.front()->type(), emptyType);
258  fps.pop_front();
259  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
260  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 7);
261  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 4);
262  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
263  fps.clear();
264 
265  gen.StopCmd(0xFFFFFFFF, 1);
266  gen.joinThreads();
267  TLOG_INFO("CommandableFragmentGenerator_t") << "SingleMode test case END" << TLOG_ENDL;
268 }
269 
270 BOOST_AUTO_TEST_CASE(BufferMode)
271 {
272  artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
273  TLOG_INFO("CommandableFragmentGenerator_t") << "BufferMode test case BEGIN" << TLOG_ENDL;
274  const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
275  const int DELAY_TIME = 100;
276  fhicl::ParameterSet ps;
277  ps.put<int>("board_id", 1);
278  ps.put<int>("fragment_id", 1);
279  ps.put<int>("request_port", REQUEST_PORT);
280 #if MULTICAST_MODE
281  ps.put<std::string>("request_address", "227.18.12.31");
282 #else
283  ps.put<std::string>("request_address", "localhost");
284 #endif
285  ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
286  ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 0);
287  ps.put<bool>("separate_data_thread", true);
288  ps.put<bool>("separate_monitoring_thread", false);
289  ps.put<int64_t>("hardware_poll_interval_us", 0);
290  ps.put<std::string>("request_mode", "buffer");
291  ps.put("request_delay_ms", DELAY_TIME);
292  ps.put("send_requests", true);
293 
294  artdaq::RequestSender t(ps);
295  t.AddRequest(1, 1);
296 
298  gen.StartCmd(1, 0xFFFFFFFF, 1);
299 
300 
301  artdaq::FragmentPtrs fps;
302  auto sts = gen.getNext(fps);
303  BOOST_REQUIRE_EQUAL(sts, true);
304  BOOST_REQUIRE_EQUAL(fps.size(), 1u);
305  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
306  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
307  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
308  auto type = artdaq::Fragment::ContainerFragmentType;
309  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
310  BOOST_REQUIRE_GE(fps.front()->sizeBytes(), 2 * sizeof(artdaq::detail::RawEventHeader) + sizeof(artdaq::ContainerFragment::Metadata));
311  auto cf = artdaq::ContainerFragment(*fps.front());
312  BOOST_REQUIRE_EQUAL(cf.block_count(), 1);
313  BOOST_REQUIRE_EQUAL(cf.missing_data(), false);
314  type = artdaq::Fragment::FirstUserFragmentType;
315  BOOST_REQUIRE_EQUAL(cf.fragment_type(), type);
316  fps.clear();
317 
318  t.AddRequest(2, 5);
319  sts = gen.getNext(fps);
320  BOOST_REQUIRE_EQUAL(sts, true);
321  BOOST_REQUIRE_EQUAL(fps.size(), 1u);
322  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
323  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 5);
324  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
325  type = artdaq::Fragment::ContainerFragmentType;
326  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
327  auto cf2 = artdaq::ContainerFragment(*fps.front());
328  BOOST_REQUIRE_EQUAL(cf2.block_count(), 0);
329  BOOST_REQUIRE_EQUAL(cf2.missing_data(), false);
330  type = artdaq::Fragment::EmptyFragmentType;
331  BOOST_REQUIRE_EQUAL(cf2.fragment_type(), type);
332  fps.clear();
333 
334  gen.setFireCount(2);
335  gen.waitForFrags();
336  t.AddRequest(4, 7);
337  sts = gen.getNext(fps);
338  BOOST_REQUIRE_EQUAL(sts, true);
339  BOOST_REQUIRE_EQUAL(fps.size(), 2);
340 
341  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
342  auto ts = artdaq::Fragment::InvalidTimestamp;
343  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), ts);
344  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 3);
345  auto emptyType = artdaq::Fragment::EmptyFragmentType;
346  BOOST_REQUIRE_EQUAL(fps.front()->type(), emptyType);
347  BOOST_REQUIRE_EQUAL(fps.front()->size(), artdaq::detail::RawFragmentHeader::num_words());
348  fps.pop_front();
349  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
350  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 7);
351  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 4);
352  type = artdaq::Fragment::ContainerFragmentType;
353  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
354  auto cf3 = artdaq::ContainerFragment(*fps.front());
355  BOOST_REQUIRE_EQUAL(cf3.block_count(), 2);
356  BOOST_REQUIRE_EQUAL(cf3.missing_data(), false);
357  type = artdaq::Fragment::FirstUserFragmentType;
358  BOOST_REQUIRE_EQUAL(cf3.fragment_type(), type);
359  fps.clear();
360 
361 
362  gen.StopCmd(0xFFFFFFFF, 1);
363  gen.joinThreads();
364 
365 
366  TLOG_INFO("CommandableFragmentGenerator_t") << "BufferMode test case END" << TLOG_ENDL;
367 }
368 
369 BOOST_AUTO_TEST_CASE(WindowMode_Function)
370 {
371  artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
372  TLOG_INFO("CommandableFragmentGenerator_t") << "WindowMode_Function test case BEGIN" << TLOG_ENDL;
373  const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
374  const int DELAY_TIME = 100;
375  fhicl::ParameterSet ps;
376  ps.put<int>("board_id", 1);
377  ps.put<int>("fragment_id", 1);
378  ps.put<int>("request_port", REQUEST_PORT);
379 #if MULTICAST_MODE
380  ps.put<std::string>("request_address", "227.18.12.32");
381 #else
382  ps.put<std::string>("request_address", "localhost");
383 #endif
384  ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
385  ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 0);
386  ps.put<bool>("separate_data_thread", true);
387  ps.put<bool>("separate_monitoring_thread", false);
388  ps.put<int64_t>("hardware_poll_interval_us", 0);
389  ps.put<size_t>("data_buffer_depth_fragments", 5);
390  ps.put<std::string>("request_mode", "window");
391  ps.put("request_delay_ms", DELAY_TIME);
392  ps.put("send_requests", true);
393 
394  artdaq::RequestSender t(ps);
395  t.AddRequest(1, 1);
396 
398  gen.StartCmd(1, 0xFFFFFFFF, 1);
399 
400  artdaq::FragmentPtrs fps;
401  auto sts = gen.getNext(fps);
402  BOOST_REQUIRE_EQUAL(sts, true);
403  BOOST_REQUIRE_EQUAL(fps.size(), 1u);
404  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
405  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
406  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
407  auto type = artdaq::Fragment::ContainerFragmentType;
408  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
409  BOOST_REQUIRE_GE(fps.front()->sizeBytes(), 2 * sizeof(artdaq::detail::RawEventHeader) + sizeof(artdaq::ContainerFragment::Metadata));
410  auto cf = artdaq::ContainerFragment(*fps.front());
411  BOOST_REQUIRE_EQUAL(cf.block_count(), 1);
412  BOOST_REQUIRE_EQUAL(cf.missing_data(), false);
413  type = artdaq::Fragment::FirstUserFragmentType;
414  BOOST_REQUIRE_EQUAL(cf.fragment_type(), type);
415  fps.clear();
416 
417  // No data for request
418  t.AddRequest(2, 2);
419  sts = gen.getNext(fps);
420  BOOST_REQUIRE_EQUAL(sts, true);
421  BOOST_REQUIRE_EQUAL(fps.size(), 0);
422 
423  gen.setFireCount(1);
424  gen.waitForFrags();
425  sts = gen.getNext(fps);
426  BOOST_REQUIRE_EQUAL(sts, true);
427  BOOST_REQUIRE_EQUAL(fps.size(), 1);
428  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
429  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 2);
430  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
431  type = artdaq::Fragment::ContainerFragmentType;
432  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
433  auto cf2 = artdaq::ContainerFragment(*fps.front());
434  BOOST_REQUIRE_EQUAL(cf2.block_count(), 1);
435  BOOST_REQUIRE_EQUAL(cf2.missing_data(), false);
436  type = artdaq::Fragment::FirstUserFragmentType;
437  BOOST_REQUIRE_EQUAL(cf2.fragment_type(), type);
438  fps.clear();
439 
440  // Missing Request Timeout
441  gen.setFireCount(2);
442  gen.waitForFrags();
443  t.AddRequest(4, 3);
444  sts = gen.getNext(fps);
445  BOOST_REQUIRE_EQUAL(sts, true);
446  BOOST_REQUIRE_EQUAL(fps.size(), 0);
447 
448  usleep(1500000);
449  sts = gen.getNext(fps);
450  BOOST_REQUIRE_EQUAL(sts, true);
451  BOOST_REQUIRE_EQUAL(fps.size(), 2);
452 
453 
454  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
455  auto ts = artdaq::Fragment::InvalidTimestamp;
456  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), ts);
457  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 3);
458  auto emptyType = artdaq::Fragment::EmptyFragmentType;
459  BOOST_REQUIRE_EQUAL(fps.front()->type(), emptyType);
460  BOOST_REQUIRE_EQUAL(fps.front()->size(), artdaq::detail::RawFragmentHeader::num_words());
461  fps.pop_front();
462  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
463  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 3);
464  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 4);
465  type = artdaq::Fragment::ContainerFragmentType;
466  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
467  auto cf3 = artdaq::ContainerFragment(*fps.front());
468  BOOST_REQUIRE_EQUAL(cf3.block_count(), 1);
469  BOOST_REQUIRE_EQUAL(cf3.missing_data(), false);
470  type = artdaq::Fragment::FirstUserFragmentType;
471  BOOST_REQUIRE_EQUAL(cf3.fragment_type(), type);
472  fps.clear();
473 
474  // Data-taking has passed request
475  gen.setFireCount(10);
476  gen.waitForFrags();
477  t.AddRequest(5, 4);
478  sts = gen.getNext(fps);
479  BOOST_REQUIRE_EQUAL(sts, true);
480  BOOST_REQUIRE_EQUAL(fps.size(), 1);
481  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
482  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 4);
483  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 5);
484  type = artdaq::Fragment::ContainerFragmentType;
485  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
486  auto cf4 = artdaq::ContainerFragment(*fps.front());
487  BOOST_REQUIRE_EQUAL(cf4.block_count(), 0);
488  BOOST_REQUIRE_EQUAL(cf4.missing_data(), true);
489  type = artdaq::Fragment::EmptyFragmentType;
490  BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
491  fps.clear();
492 
493  gen.StopCmd(0xFFFFFFFF, 1);
494  TLOG_INFO("CommandableFragmentGenerator_t") << "WindowMode_Function test case END" << TLOG_ENDL;
495  gen.joinThreads();
496 
497 }
498 
499 // 1. Both start and end before any data in buffer "RequestBeforeBuffer"
500 // 2. Start before buffer, end in buffer "RequestStartsBeforeBuffer"
501 // 3. Start befoer buffer, end after buffer "RequestOutsideBuffer"
502 // 4. Start and end in buffer "RequestInBuffer"
503 // 5. Start in buffer, end after buffer "RequestEndsAfterBuffer"
504 // 6. Start and end after buffer "RequestAfterBuffer"
505 BOOST_AUTO_TEST_CASE(WindowMode_RequestBeforeBuffer)
506 {
507  artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
508  TLOG_INFO("CommandableFragmentGenerator_t") << "WindowMode_RequestBeforeBuffer test case BEGIN" << TLOG_ENDL;
509  const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
510  const int DELAY_TIME = 100;
511  fhicl::ParameterSet ps;
512  ps.put<int>("board_id", 1);
513  ps.put<int>("fragment_id", 1);
514  ps.put<int>("request_port", REQUEST_PORT);
515 #if MULTICAST_MODE
516  ps.put<std::string>("request_address", "227.18.12.32");
517 #else
518  ps.put<std::string>("request_address", "localhost");
519 #endif
520  ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
521  ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 3);
522  ps.put<bool>("separate_data_thread", true);
523  ps.put<bool>("separate_monitoring_thread", false);
524  ps.put<int64_t>("hardware_poll_interval_us", 0);
525  ps.put<size_t>("data_buffer_depth_fragments", 5);
526  ps.put<std::string>("request_mode", "window");
527  ps.put("request_delay_ms", DELAY_TIME);
528  ps.put("send_requests", true);
529 
530  artdaq::RequestSender t(ps);
531 
533  gen.StartCmd(1, 0xFFFFFFFF, 1);
534 
535  artdaq::FragmentPtrs fps;
536  int sts;
537  artdaq::Fragment::type_t type;
538 
539  // 1. Both start and end before any data in buffer
540  // -- Should return ContainerFragment with MissingData bit set and zero Fragments
541  gen.setFireCount(9); // Buffer start is at ts 6, end at 10
542  gen.waitForFrags();
543  t.AddRequest(1, 1); // Requesting data from ts 1 to 3
544 
545  sts = gen.getNext(fps);
546  BOOST_REQUIRE_EQUAL(sts, true);
547  BOOST_REQUIRE_EQUAL(fps.size(), 1);
548  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
549  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
550  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
551  type = artdaq::Fragment::ContainerFragmentType;
552  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
553  auto cf4 = artdaq::ContainerFragment(*fps.front());
554  BOOST_REQUIRE_EQUAL(cf4.block_count(), 0);
555  BOOST_REQUIRE_EQUAL(cf4.missing_data(), true);
556  type = artdaq::Fragment::EmptyFragmentType;
557  BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
558 
559  gen.StopCmd(0xFFFFFFFF, 1);
560  TLOG_INFO("CommandableFragmentGenerator_t") << "WindowMode_RequestBeforeBuffer test case END" << TLOG_ENDL;
561 
562 }
564 {
565  artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
566  TLOG_INFO("CommandableFragmentGenerator_t") << "WindowMode_RequestStartsBeforeBuffer test case BEGIN" << TLOG_ENDL;
567  const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
568  const int DELAY_TIME = 100;
569  fhicl::ParameterSet ps;
570  ps.put<int>("board_id", 1);
571  ps.put<int>("fragment_id", 1);
572  ps.put<int>("request_port", REQUEST_PORT);
573 #if MULTICAST_MODE
574  ps.put<std::string>("request_address", "227.18.12.32");
575 #else
576  ps.put<std::string>("request_address", "localhost");
577 #endif
578  ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
579  ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 3);
580  ps.put<bool>("separate_data_thread", true);
581  ps.put<bool>("separate_monitoring_thread", false);
582  ps.put<int64_t>("hardware_poll_interval_us", 0);
583  ps.put<size_t>("data_buffer_depth_fragments", 5);
584  ps.put<std::string>("request_mode", "window");
585  ps.put("request_delay_ms", DELAY_TIME);
586  ps.put("send_requests", true);
587 
588  artdaq::RequestSender t(ps);
589 
591  gen.StartCmd(1, 0xFFFFFFFF, 1);
592 
593  artdaq::FragmentPtrs fps;
594  int sts;
595  artdaq::Fragment::type_t type;
596 
597  gen.waitForFrags();
598  gen.setFireCount(9); // Buffer contains 6 to 10
599  gen.waitForFrags();
600 
601  // 2. Start before buffer, end in buffer
602  // -- Should return ContainerFragment with MissingData bit set and one or more Fragments
603  t.AddRequest(1, 4); // Requesting data from ts 4 to 6
604 
605  sts = gen.getNext(fps);
606  BOOST_REQUIRE_EQUAL(sts, true);
607  BOOST_REQUIRE_EQUAL(fps.size(), 1);
608  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
609  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 4);
610  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
611  type = artdaq::Fragment::ContainerFragmentType;
612  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
613  auto cf4 = artdaq::ContainerFragment(*fps.front());
614  BOOST_REQUIRE_EQUAL(cf4.block_count(), 1);
615  BOOST_REQUIRE_EQUAL(cf4.missing_data(), true);
616  type = artdaq::Fragment::FirstUserFragmentType;
617  BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
618 
619  gen.StopCmd(0xFFFFFFFF, 1);
620  gen.joinThreads();
621  TLOG_INFO("CommandableFragmentGenerator_t") << "WindowMode_RequestStartsBeforeBuffer test case END" << TLOG_ENDL;
622 
623 }
624 BOOST_AUTO_TEST_CASE(WindowMode_RequestOutsideBuffer)
625 {
626  artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
627  TLOG_INFO("CommandableFragmentGenerator_t") << "WindowMode_RequestOutsideBuffer test case BEGIN" << TLOG_ENDL;
628  const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
629  const int DELAY_TIME = 100;
630  fhicl::ParameterSet ps;
631  ps.put<int>("board_id", 1);
632  ps.put<int>("fragment_id", 1);
633  ps.put<int>("request_port", REQUEST_PORT);
634 #if MULTICAST_MODE
635  ps.put<std::string>("request_address", "227.18.12.32");
636 #else
637  ps.put<std::string>("request_address", "localhost");
638 #endif
639  ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
640  ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 4);
641  ps.put<size_t>("window_close_timeout_us", 500000);
642  ps.put<bool>("separate_data_thread", true);
643  ps.put<bool>("separate_monitoring_thread", false);
644  ps.put<int64_t>("hardware_poll_interval_us", 0);
645  ps.put<size_t>("data_buffer_depth_fragments", 5);
646  ps.put<std::string>("request_mode", "window");
647  ps.put("request_delay_ms", DELAY_TIME);
648  ps.put("send_requests", true);
649 
650  artdaq::RequestSender t(ps);
651 
653  gen.StartCmd(1, 0xFFFFFFFF, 1);
654 
655  artdaq::FragmentPtrs fps;
656  int sts;
657  artdaq::Fragment::type_t type;
658 
659  gen.waitForFrags();
660  gen.setFireCount(9); // Buffer contains 6 to 10
661  gen.waitForFrags();
662 
663  // 3. Start before buffer, end after buffer
664  // -- Should not return until buffer passes end or timeout (check both cases), MissingData bit set
665 
666  t.AddRequest(1, 6); // Requesting data from ts 6 to 9, buffer will contain 10
667  sts = gen.getNext(fps);
668  BOOST_REQUIRE_EQUAL(sts, true);
669  BOOST_REQUIRE_EQUAL(fps.size(), 1);
670  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
671  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 6);
672  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
673  type = artdaq::Fragment::ContainerFragmentType;
674  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
675  auto cf = artdaq::ContainerFragment(*fps.front());
676  BOOST_REQUIRE_EQUAL(cf.block_count(), 4);
677  BOOST_REQUIRE_EQUAL(cf.missing_data(), false);
678  type = artdaq::Fragment::FirstUserFragmentType;
679  BOOST_REQUIRE_EQUAL(cf.fragment_type(), type);
680  fps.clear();
681 
682  t.AddRequest(2, 9); // Requesting data from ts 9 to 12
683  sts = gen.getNext(fps);
684  BOOST_REQUIRE_EQUAL(sts, true);
685  BOOST_REQUIRE_EQUAL(fps.size(), 0);
686 
687  gen.setFireCount(3); // Buffer start is at ts 10, end at 13
688  gen.waitForFrags();
689 
690  sts = gen.getNext(fps);
691  BOOST_REQUIRE_EQUAL(sts, true);
692  BOOST_REQUIRE_EQUAL(fps.size(), 1);
693  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
694  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 9);
695  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
696  type = artdaq::Fragment::ContainerFragmentType;
697  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
698  auto cf2 = artdaq::ContainerFragment(*fps.front());
699  BOOST_REQUIRE_EQUAL(cf2.block_count(), 3);
700  BOOST_REQUIRE_EQUAL(cf2.missing_data(), true);
701  type = artdaq::Fragment::FirstUserFragmentType;
702  BOOST_REQUIRE_EQUAL(cf2.fragment_type(), type);
703  fps.clear();
704 
705 
706 
707  t.AddRequest(3, 12); // Requesting data from ts 11 to 14
708 
709  sts = gen.getNext(fps);
710  BOOST_REQUIRE_EQUAL(sts, true);
711  BOOST_REQUIRE_EQUAL(fps.size(), 0);
712 
713  usleep(550000);
714 
715  sts = gen.getNext(fps);
716  BOOST_REQUIRE_EQUAL(sts, true);
717  BOOST_REQUIRE_EQUAL(fps.size(), 1);
718  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
719  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 12);
720  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 3);
721  type = artdaq::Fragment::ContainerFragmentType;
722  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
723  auto cf4 = artdaq::ContainerFragment(*fps.front());
724  BOOST_REQUIRE_EQUAL(cf4.block_count(), 1);
725  BOOST_REQUIRE_EQUAL(cf4.missing_data(), true);
726  type = artdaq::Fragment::FirstUserFragmentType;
727  BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
728 
729  gen.StopCmd(0xFFFFFFFF, 1);
730  gen.joinThreads();
731  TLOG_INFO("CommandableFragmentGenerator_t") << "WindowMode_RequestOutsideBuffer test case END" << TLOG_ENDL;
732 
733 }
734 BOOST_AUTO_TEST_CASE(WindowMode_RequestInBuffer)
735 {
736  artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
737  TLOG_INFO("CommandableFragmentGenerator_t") << "WindowMode_RequestInBuffer test case BEGIN" << TLOG_ENDL;
738  const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
739  const int DELAY_TIME = 100;
740  fhicl::ParameterSet ps;
741  ps.put<int>("board_id", 1);
742  ps.put<int>("fragment_id", 1);
743  ps.put<int>("request_port", REQUEST_PORT);
744 #if MULTICAST_MODE
745  ps.put<std::string>("request_address", "227.18.12.32");
746 #else
747  ps.put<std::string>("request_address", "localhost");
748 #endif
749  ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
750  ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 3);
751  ps.put<bool>("separate_data_thread", true);
752  ps.put<bool>("separate_monitoring_thread", false);
753  ps.put<int64_t>("hardware_poll_interval_us", 0);
754  ps.put<size_t>("data_buffer_depth_fragments", 5);
755  ps.put<std::string>("request_mode", "window");
756  ps.put("request_delay_ms", DELAY_TIME);
757  ps.put("send_requests", true);
758 
759  artdaq::RequestSender t(ps);
760 
762  gen.StartCmd(1, 0xFFFFFFFF, 1);
763 
764  artdaq::FragmentPtrs fps;
765  int sts;
766  artdaq::Fragment::type_t type;
767  gen.waitForFrags();
768 
769  // 4. Start and end in buffer
770  // -- Should return ContainerFragment with one or more Fragments
771  gen.setFireCount(5); // Buffer start is at ts 2, end at 6
772  gen.waitForFrags();
773  t.AddRequest(1, 3); // Requesting data from ts 3 to 5
774 
775  sts = gen.getNext(fps);
776  BOOST_REQUIRE_EQUAL(sts, true);
777  BOOST_REQUIRE_EQUAL(fps.size(), 1);
778  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
779  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 3);
780  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
781  type = artdaq::Fragment::ContainerFragmentType;
782  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
783  auto cf4 = artdaq::ContainerFragment(*fps.front());
784  BOOST_REQUIRE_EQUAL(cf4.block_count(), 3);
785  BOOST_REQUIRE_EQUAL(cf4.missing_data(), false);
786  type = artdaq::Fragment::FirstUserFragmentType;
787  BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
788 
789  gen.StopCmd(0xFFFFFFFF, 1);
790  TLOG_INFO("CommandableFragmentGenerator_t") << "WindowMode_RequestInBuffer test case END" << TLOG_ENDL;
791 
792 }
794 {
795  artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
796  TLOG_INFO("CommandableFragmentGenerator_t") << "WindowMode_RequestEndsAfterBuffer test case BEGIN" << TLOG_ENDL;
797  const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
798  const int DELAY_TIME = 100;
799  fhicl::ParameterSet ps;
800  ps.put<int>("board_id", 1);
801  ps.put<int>("fragment_id", 1);
802  ps.put<int>("request_port", REQUEST_PORT);
803 #if MULTICAST_MODE
804  ps.put<std::string>("request_address", "227.18.12.32");
805 #else
806  ps.put<std::string>("request_address", "localhost");
807 #endif
808  ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
809  ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 3);
810  ps.put<size_t>("window_close_timeout_us", 500000);
811  ps.put<bool>("separate_data_thread", true);
812  ps.put<bool>("separate_monitoring_thread", false);
813  ps.put<int64_t>("hardware_poll_interval_us", 0);
814  ps.put<size_t>("data_buffer_depth_fragments", 5);
815  ps.put<std::string>("request_mode", "window");
816  ps.put("request_delay_ms", DELAY_TIME);
817  ps.put("send_requests", true);
818 
819  artdaq::RequestSender t(ps);
820 
822  gen.StartCmd(1, 0xFFFFFFFF, 1);
823 
824  artdaq::FragmentPtrs fps;
825  int sts;
826  artdaq::Fragment::type_t type;
827  gen.waitForFrags();
828  gen.setFireCount(5); // Buffer contains 2 to 6
829  gen.waitForFrags();
830 
831  // 5. Start in buffer, end after buffer
832  // -- Should not return until buffer passes end or timeout (check both cases). MissingData bit set if timeout
833  t.AddRequest(1, 5); // Requesting data from ts 5 to 7
834  sts = gen.getNext(fps);
835  BOOST_REQUIRE_EQUAL(sts, true);
836  BOOST_REQUIRE_EQUAL(fps.size(), 0);
837 
838  gen.setFireCount(2); // Buffer contains 4 to 8
839  gen.waitForFrags();
840  sts = gen.getNext(fps);
841  BOOST_REQUIRE_EQUAL(sts, true);
842  BOOST_REQUIRE_EQUAL(fps.size(), 1);
843  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
844  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 5);
845  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
846  type = artdaq::Fragment::ContainerFragmentType;
847  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
848  auto cf = artdaq::ContainerFragment(*fps.front());
849  BOOST_REQUIRE_EQUAL(cf.block_count(), 3);
850  BOOST_REQUIRE_EQUAL(cf.missing_data(), false);
851  type = artdaq::Fragment::FirstUserFragmentType;
852  BOOST_REQUIRE_EQUAL(cf.fragment_type(), type);
853  fps.clear();
854 
855  t.AddRequest(2, 8); // Requesting data from ts 8 to 10
856 
857  sts = gen.getNext(fps);
858  BOOST_REQUIRE_EQUAL(sts, true);
859  BOOST_REQUIRE_EQUAL(fps.size(), 0);
860 
861  usleep(550000);
862 
863  sts = gen.getNext(fps);
864  BOOST_REQUIRE_EQUAL(sts, true);
865  BOOST_REQUIRE_EQUAL(fps.size(), 1);
866  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
867  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 8);
868  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
869  type = artdaq::Fragment::ContainerFragmentType;
870  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
871  auto cf4 = artdaq::ContainerFragment(*fps.front());
872  BOOST_REQUIRE_EQUAL(cf4.block_count(), 1);
873  BOOST_REQUIRE_EQUAL(cf4.missing_data(), true);
874  type = artdaq::Fragment::FirstUserFragmentType;
875  BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
876 
877  gen.StopCmd(0xFFFFFFFF, 1);
878  gen.joinThreads();
879  TLOG_INFO("CommandableFragmentGenerator_t") << "WindowMode_RequestEndsAfterBuffer test case END" << TLOG_ENDL;
880 
881 }
882 BOOST_AUTO_TEST_CASE(WindowMode_RequestAfterBuffer)
883 {
884  artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
885  TLOG_INFO("CommandableFragmentGenerator_t") << "WindowMode_RequestAfterBuffer test case BEGIN" << TLOG_ENDL;
886  const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
887  const int DELAY_TIME = 100;
888  fhicl::ParameterSet ps;
889  ps.put<int>("board_id", 1);
890  ps.put<int>("fragment_id", 1);
891  ps.put<int>("request_port", REQUEST_PORT);
892 #if MULTICAST_MODE
893  ps.put<std::string>("request_address", "227.18.12.32");
894 #else
895  ps.put<std::string>("request_address", "localhost");
896 #endif
897  ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
898  ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 3);
899  ps.put<size_t>("window_close_timeout_us", 500000);
900  ps.put<bool>("separate_data_thread", true);
901  ps.put<bool>("separate_monitoring_thread", false);
902  ps.put<int64_t>("hardware_poll_interval_us", 0);
903  ps.put<size_t>("data_buffer_depth_fragments", 5);
904  ps.put<std::string>("request_mode", "window");
905  ps.put("request_delay_ms", DELAY_TIME);
906  ps.put("send_requests", true);
907 
908  artdaq::RequestSender t(ps);
909 
911  gen.StartCmd(1, 0xFFFFFFFF, 1);
912 
913  artdaq::FragmentPtrs fps;
914  int sts;
915  artdaq::Fragment::type_t type;
916  gen.waitForFrags();
917 
918  // 6. Start and end after buffer
919  // -- Should not return until buffer passes end or timeout (check both cases). MissingData bit set if timeout
920  gen.setFireCount(9); // Buffer start is 6, end at 10
921  gen.waitForFrags();
922  t.AddRequest(1, 11); // Requesting data from ts 11 to 13
923 
924  sts = gen.getNext(fps);
925  BOOST_REQUIRE_EQUAL(sts, true);
926  BOOST_REQUIRE_EQUAL(fps.size(), 0);
927  gen.setFireCount(1); // Buffer start is 7, end at 11
928  gen.waitForFrags();
929  sts = gen.getNext(fps);
930  BOOST_REQUIRE_EQUAL(sts, true);
931  BOOST_REQUIRE_EQUAL(fps.size(), 0);
932 
933  gen.setFireCount(3); // Buffer start is 10, end at 14
934  gen.waitForFrags();
935  sts = gen.getNext(fps);
936  BOOST_REQUIRE_EQUAL(sts, true);
937  BOOST_REQUIRE_EQUAL(fps.size(), 1);
938  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
939  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 11);
940  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
941  type = artdaq::Fragment::ContainerFragmentType;
942  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
943  auto cf = artdaq::ContainerFragment(*fps.front());
944  BOOST_REQUIRE_EQUAL(cf.block_count(), 3);
945  BOOST_REQUIRE_EQUAL(cf.missing_data(), false);
946  type = artdaq::Fragment::FirstUserFragmentType;
947  BOOST_REQUIRE_EQUAL(cf.fragment_type(), type);
948  fps.clear();
949 
950  t.AddRequest(2, 16); // Requesting data from ts 15 to 17
951  sts = gen.getNext(fps);
952  BOOST_REQUIRE_EQUAL(sts, true);
953  BOOST_REQUIRE_EQUAL(fps.size(), 0);
954 
955  usleep(550000);
956 
957  sts = gen.getNext(fps);
958  BOOST_REQUIRE_EQUAL(sts, true);
959  BOOST_REQUIRE_EQUAL(fps.size(), 1);
960  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
961  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 16);
962  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
963  type = artdaq::Fragment::ContainerFragmentType;
964  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
965  auto cf4 = artdaq::ContainerFragment(*fps.front());
966  BOOST_REQUIRE_EQUAL(cf4.block_count(), 0);
967  BOOST_REQUIRE_EQUAL(cf4.missing_data(), true);
968  type = artdaq::Fragment::EmptyFragmentType;
969  BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
970 
971  gen.StopCmd(0xFFFFFFFF, 1);
972  gen.joinThreads();
973  TLOG_INFO("CommandableFragmentGenerator_t") << "WindowMode_RequestAfterBuffer test case END" << TLOG_ENDL;
974 
975 }
976 
977 BOOST_AUTO_TEST_CASE(HardwareFailure_NonThreaded)
978 {
979  artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
980  TLOG_INFO("CommandableFragmentGenerator_t") << "HardwareFailure_NonThreaded test case BEGIN" << TLOG_ENDL;
981  fhicl::ParameterSet ps;
982  ps.put<int>("board_id", 1);
983  ps.put<int>("fragment_id", 1);
984  ps.put<bool>("separate_data_thread", false);
985  ps.put<bool>("separate_monitoring_thread", false);
986  ps.put<int64_t>("hardware_poll_interval_us", 10);
987 
989  gen.StartCmd(1, 0xFFFFFFFF, 1);
990 
991  artdaq::FragmentPtrs fps;
992  auto sts = gen.getNext(fps);
993  BOOST_REQUIRE_EQUAL(sts, true);
994  BOOST_REQUIRE_EQUAL(fps.size(), 1u);
995  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
996  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
997  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
998  fps.clear();
999 
1000  gen.setFireCount(1);
1001  gen.setHwFail();
1002  usleep(10000);
1003  sts = gen.getNext(fps);
1004  BOOST_REQUIRE_EQUAL(sts, false);
1005  BOOST_REQUIRE_EQUAL(fps.size(), 0);
1006 
1007  gen.StopCmd(0xFFFFFFFF, 1);
1008  gen.joinThreads();
1009  TLOG_INFO("CommandableFragmentGenerator_t") << "HardwareFailure_NonThreaded test case END" << TLOG_ENDL;
1010 }
1011 
1012 BOOST_AUTO_TEST_CASE(HardwareFailure_Threaded)
1013 {
1014  artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
1015  TLOG_INFO("CommandableFragmentGenerator_t") << "HardwareFailure_Threaded test case BEGIN" << TLOG_ENDL;
1016  fhicl::ParameterSet ps;
1017  ps.put<int>("board_id", 1);
1018  ps.put<int>("fragment_id", 1);
1019  ps.put<bool>("separate_data_thread", true);
1020  ps.put<bool>("separate_monitoring_thread", true);
1021  ps.put<int64_t>("hardware_poll_interval_us", 750000);
1022 
1024  gen.StartCmd(1, 0xFFFFFFFF, 1);
1025 
1026 
1027 
1028  artdaq::FragmentPtrs fps;
1029  auto sts = gen.getNext(fps);
1030  BOOST_REQUIRE_EQUAL(sts, true);
1031  BOOST_REQUIRE_EQUAL(fps.size(), 1u);
1032  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
1033  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
1034  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
1035  fps.clear();
1036 
1037  gen.setFireCount(1);
1038  gen.setHwFail();
1039  sts = gen.getNext(fps);
1040  BOOST_REQUIRE_EQUAL(sts, true);
1041  BOOST_REQUIRE_EQUAL(fps.size(), 1);
1042  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
1043  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 2);
1044  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
1045 
1046  fps.clear();
1047  sleep(1);
1048  gen.setFireCount(1);
1049  sts = gen.getNext(fps);
1050  BOOST_REQUIRE_EQUAL(sts, false);
1051  BOOST_REQUIRE_EQUAL(fps.size(), 0);
1052 
1053  gen.StopCmd(0xFFFFFFFF, 1);
1054  gen.joinThreads();
1055  TLOG_INFO("CommandableFragmentGenerator_t") << "HardwareFailure_Threaded test case END" << TLOG_ENDL;
1056 }
1057 
1058 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 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.