artdaq  v3_00_03
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(), 1);
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  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 3);
456  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 4);
457  type = artdaq::Fragment::ContainerFragmentType;
458  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
459  auto cf3 = artdaq::ContainerFragment(*fps.front());
460  BOOST_REQUIRE_EQUAL(cf3.block_count(), 1);
461  BOOST_REQUIRE_EQUAL(cf3.missing_data(), false);
462  type = artdaq::Fragment::FirstUserFragmentType;
463  BOOST_REQUIRE_EQUAL(cf3.fragment_type(), type);
464  fps.pop_front();
465 
466  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
467  auto ts = artdaq::Fragment::InvalidTimestamp;
468  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), ts);
469  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 3);
470  auto emptyType = artdaq::Fragment::EmptyFragmentType;
471  BOOST_REQUIRE_EQUAL(fps.front()->type(), emptyType);
472  BOOST_REQUIRE_EQUAL(fps.front()->size(), artdaq::detail::RawFragmentHeader::num_words());
473  fps.clear();
474 
475  // Data-taking has passed request
476  gen.setFireCount(10);
477  gen.waitForFrags();
478  t.AddRequest(5, 4);
479  sts = gen.getNext(fps);
480  BOOST_REQUIRE_EQUAL(sts, true);
481  BOOST_REQUIRE_EQUAL(fps.size(), 1);
482  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
483  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 4);
484  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 5);
485  type = artdaq::Fragment::ContainerFragmentType;
486  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
487  auto cf4 = artdaq::ContainerFragment(*fps.front());
488  BOOST_REQUIRE_EQUAL(cf4.block_count(), 0);
489  BOOST_REQUIRE_EQUAL(cf4.missing_data(), true);
490  type = artdaq::Fragment::EmptyFragmentType;
491  BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
492  fps.clear();
493 
494  gen.StopCmd(0xFFFFFFFF, 1);
495  TLOG_INFO("CommandableFragmentGenerator_t") << "WindowMode_Function test case END" << TLOG_ENDL;
496  gen.joinThreads();
497 
498 }
499 
500 // 1. Both start and end before any data in buffer "RequestBeforeBuffer"
501 // 2. Start before buffer, end in buffer "RequestStartsBeforeBuffer"
502 // 3. Start befoer buffer, end after buffer "RequestOutsideBuffer"
503 // 4. Start and end in buffer "RequestInBuffer"
504 // 5. Start in buffer, end after buffer "RequestEndsAfterBuffer"
505 // 6. Start and end after buffer "RequestAfterBuffer"
506 BOOST_AUTO_TEST_CASE(WindowMode_RequestBeforeBuffer)
507 {
508  artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
509  TLOG_INFO("CommandableFragmentGenerator_t") << "WindowMode_RequestBeforeBuffer test case BEGIN" << TLOG_ENDL;
510  const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
511  const int DELAY_TIME = 100;
512  fhicl::ParameterSet ps;
513  ps.put<int>("board_id", 1);
514  ps.put<int>("fragment_id", 1);
515  ps.put<int>("request_port", REQUEST_PORT);
516 #if MULTICAST_MODE
517  ps.put<std::string>("request_address", "227.18.12.32");
518 #else
519  ps.put<std::string>("request_address", "localhost");
520 #endif
521  ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
522  ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 3);
523  ps.put<bool>("separate_data_thread", true);
524  ps.put<bool>("separate_monitoring_thread", false);
525  ps.put<int64_t>("hardware_poll_interval_us", 0);
526  ps.put<size_t>("data_buffer_depth_fragments", 5);
527  ps.put<std::string>("request_mode", "window");
528  ps.put("request_delay_ms", DELAY_TIME);
529  ps.put("send_requests", true);
530 
531  artdaq::RequestSender t(ps);
532 
534  gen.StartCmd(1, 0xFFFFFFFF, 1);
535 
536  artdaq::FragmentPtrs fps;
537  int sts;
538  artdaq::Fragment::type_t type;
539 
540  // 1. Both start and end before any data in buffer
541  // -- Should return ContainerFragment with MissingData bit set and zero Fragments
542  gen.setFireCount(9); // Buffer start is at ts 6, end at 10
543  gen.waitForFrags();
544  t.AddRequest(1, 1); // Requesting data from ts 1 to 3
545 
546  sts = gen.getNext(fps);
547  BOOST_REQUIRE_EQUAL(sts, true);
548  BOOST_REQUIRE_EQUAL(fps.size(), 1);
549  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
550  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
551  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
552  type = artdaq::Fragment::ContainerFragmentType;
553  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
554  auto cf4 = artdaq::ContainerFragment(*fps.front());
555  BOOST_REQUIRE_EQUAL(cf4.block_count(), 0);
556  BOOST_REQUIRE_EQUAL(cf4.missing_data(), true);
557  type = artdaq::Fragment::EmptyFragmentType;
558  BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
559 
560  gen.StopCmd(0xFFFFFFFF, 1);
561  TLOG_INFO("CommandableFragmentGenerator_t") << "WindowMode_RequestBeforeBuffer test case END" << TLOG_ENDL;
562 
563 }
565 {
566  artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
567  TLOG_INFO("CommandableFragmentGenerator_t") << "WindowMode_RequestStartsBeforeBuffer test case BEGIN" << TLOG_ENDL;
568  const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
569  const int DELAY_TIME = 100;
570  fhicl::ParameterSet ps;
571  ps.put<int>("board_id", 1);
572  ps.put<int>("fragment_id", 1);
573  ps.put<int>("request_port", REQUEST_PORT);
574 #if MULTICAST_MODE
575  ps.put<std::string>("request_address", "227.18.12.32");
576 #else
577  ps.put<std::string>("request_address", "localhost");
578 #endif
579  ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
580  ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 3);
581  ps.put<bool>("separate_data_thread", true);
582  ps.put<bool>("separate_monitoring_thread", false);
583  ps.put<int64_t>("hardware_poll_interval_us", 0);
584  ps.put<size_t>("data_buffer_depth_fragments", 5);
585  ps.put<std::string>("request_mode", "window");
586  ps.put("request_delay_ms", DELAY_TIME);
587  ps.put("send_requests", true);
588 
589  artdaq::RequestSender t(ps);
590 
592  gen.StartCmd(1, 0xFFFFFFFF, 1);
593 
594  artdaq::FragmentPtrs fps;
595  int sts;
596  artdaq::Fragment::type_t type;
597 
598  gen.waitForFrags();
599  gen.setFireCount(9); // Buffer contains 6 to 10
600  gen.waitForFrags();
601 
602  // 2. Start before buffer, end in buffer
603  // -- Should return ContainerFragment with MissingData bit set and one or more Fragments
604  t.AddRequest(1, 4); // Requesting data from ts 4 to 6
605 
606  sts = gen.getNext(fps);
607  BOOST_REQUIRE_EQUAL(sts, true);
608  BOOST_REQUIRE_EQUAL(fps.size(), 1);
609  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
610  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 4);
611  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
612  type = artdaq::Fragment::ContainerFragmentType;
613  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
614  auto cf4 = artdaq::ContainerFragment(*fps.front());
615  BOOST_REQUIRE_EQUAL(cf4.block_count(), 1);
616  BOOST_REQUIRE_EQUAL(cf4.missing_data(), true);
617  type = artdaq::Fragment::FirstUserFragmentType;
618  BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
619 
620  gen.StopCmd(0xFFFFFFFF, 1);
621  gen.joinThreads();
622  TLOG_INFO("CommandableFragmentGenerator_t") << "WindowMode_RequestStartsBeforeBuffer test case END" << TLOG_ENDL;
623 
624 }
625 BOOST_AUTO_TEST_CASE(WindowMode_RequestOutsideBuffer)
626 {
627  artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
628  TLOG_INFO("CommandableFragmentGenerator_t") << "WindowMode_RequestOutsideBuffer test case BEGIN" << TLOG_ENDL;
629  const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
630  const int DELAY_TIME = 100;
631  fhicl::ParameterSet ps;
632  ps.put<int>("board_id", 1);
633  ps.put<int>("fragment_id", 1);
634  ps.put<int>("request_port", REQUEST_PORT);
635 #if MULTICAST_MODE
636  ps.put<std::string>("request_address", "227.18.12.32");
637 #else
638  ps.put<std::string>("request_address", "localhost");
639 #endif
640  ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
641  ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 4);
642  ps.put<size_t>("window_close_timeout_us", 500000);
643  ps.put<bool>("separate_data_thread", true);
644  ps.put<bool>("separate_monitoring_thread", false);
645  ps.put<int64_t>("hardware_poll_interval_us", 0);
646  ps.put<size_t>("data_buffer_depth_fragments", 5);
647  ps.put<std::string>("request_mode", "window");
648  ps.put("request_delay_ms", DELAY_TIME);
649  ps.put("send_requests", true);
650 
651  artdaq::RequestSender t(ps);
652 
654  gen.StartCmd(1, 0xFFFFFFFF, 1);
655 
656  artdaq::FragmentPtrs fps;
657  int sts;
658  artdaq::Fragment::type_t type;
659 
660  gen.waitForFrags();
661  gen.setFireCount(9); // Buffer contains 6 to 10
662  gen.waitForFrags();
663 
664  // 3. Start before buffer, end after buffer
665  // -- Should not return until buffer passes end or timeout (check both cases), MissingData bit set
666 
667  t.AddRequest(1, 6); // Requesting data from ts 6 to 9, buffer will contain 10
668  sts = gen.getNext(fps);
669  BOOST_REQUIRE_EQUAL(sts, true);
670  BOOST_REQUIRE_EQUAL(fps.size(), 1);
671  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
672  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 6);
673  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
674  type = artdaq::Fragment::ContainerFragmentType;
675  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
676  auto cf = artdaq::ContainerFragment(*fps.front());
677  BOOST_REQUIRE_EQUAL(cf.block_count(), 4);
678  BOOST_REQUIRE_EQUAL(cf.missing_data(), false);
679  type = artdaq::Fragment::FirstUserFragmentType;
680  BOOST_REQUIRE_EQUAL(cf.fragment_type(), type);
681  fps.clear();
682 
683  t.AddRequest(2, 9); // Requesting data from ts 9 to 12
684  sts = gen.getNext(fps);
685  BOOST_REQUIRE_EQUAL(sts, true);
686  BOOST_REQUIRE_EQUAL(fps.size(), 0);
687 
688  gen.setFireCount(3); // Buffer start is at ts 10, end at 13
689  gen.waitForFrags();
690 
691  sts = gen.getNext(fps);
692  BOOST_REQUIRE_EQUAL(sts, true);
693  BOOST_REQUIRE_EQUAL(fps.size(), 1);
694  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
695  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 9);
696  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
697  type = artdaq::Fragment::ContainerFragmentType;
698  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
699  auto cf2 = artdaq::ContainerFragment(*fps.front());
700  BOOST_REQUIRE_EQUAL(cf2.block_count(), 3);
701  BOOST_REQUIRE_EQUAL(cf2.missing_data(), true);
702  type = artdaq::Fragment::FirstUserFragmentType;
703  BOOST_REQUIRE_EQUAL(cf2.fragment_type(), type);
704  fps.clear();
705 
706 
707 
708  t.AddRequest(3, 12); // Requesting data from ts 11 to 14
709 
710  sts = gen.getNext(fps);
711  BOOST_REQUIRE_EQUAL(sts, true);
712  BOOST_REQUIRE_EQUAL(fps.size(), 0);
713 
714  usleep(550000);
715 
716  sts = gen.getNext(fps);
717  BOOST_REQUIRE_EQUAL(sts, true);
718  BOOST_REQUIRE_EQUAL(fps.size(), 1);
719  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
720  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 12);
721  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 3);
722  type = artdaq::Fragment::ContainerFragmentType;
723  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
724  auto cf4 = artdaq::ContainerFragment(*fps.front());
725  BOOST_REQUIRE_EQUAL(cf4.block_count(), 1);
726  BOOST_REQUIRE_EQUAL(cf4.missing_data(), true);
727  type = artdaq::Fragment::FirstUserFragmentType;
728  BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
729 
730  gen.StopCmd(0xFFFFFFFF, 1);
731  gen.joinThreads();
732  TLOG_INFO("CommandableFragmentGenerator_t") << "WindowMode_RequestOutsideBuffer test case END" << TLOG_ENDL;
733 
734 }
735 BOOST_AUTO_TEST_CASE(WindowMode_RequestInBuffer)
736 {
737  artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
738  TLOG_INFO("CommandableFragmentGenerator_t") << "WindowMode_RequestInBuffer test case BEGIN" << TLOG_ENDL;
739  const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
740  const int DELAY_TIME = 100;
741  fhicl::ParameterSet ps;
742  ps.put<int>("board_id", 1);
743  ps.put<int>("fragment_id", 1);
744  ps.put<int>("request_port", REQUEST_PORT);
745 #if MULTICAST_MODE
746  ps.put<std::string>("request_address", "227.18.12.32");
747 #else
748  ps.put<std::string>("request_address", "localhost");
749 #endif
750  ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
751  ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 3);
752  ps.put<bool>("separate_data_thread", true);
753  ps.put<bool>("separate_monitoring_thread", false);
754  ps.put<int64_t>("hardware_poll_interval_us", 0);
755  ps.put<size_t>("data_buffer_depth_fragments", 5);
756  ps.put<std::string>("request_mode", "window");
757  ps.put("request_delay_ms", DELAY_TIME);
758  ps.put("send_requests", true);
759 
760  artdaq::RequestSender t(ps);
761 
763  gen.StartCmd(1, 0xFFFFFFFF, 1);
764 
765  artdaq::FragmentPtrs fps;
766  int sts;
767  artdaq::Fragment::type_t type;
768  gen.waitForFrags();
769 
770  // 4. Start and end in buffer
771  // -- Should return ContainerFragment with one or more Fragments
772  gen.setFireCount(5); // Buffer start is at ts 2, end at 6
773  gen.waitForFrags();
774  t.AddRequest(1, 3); // Requesting data from ts 3 to 5
775 
776  sts = gen.getNext(fps);
777  BOOST_REQUIRE_EQUAL(sts, true);
778  BOOST_REQUIRE_EQUAL(fps.size(), 1);
779  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
780  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 3);
781  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
782  type = artdaq::Fragment::ContainerFragmentType;
783  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
784  auto cf4 = artdaq::ContainerFragment(*fps.front());
785  BOOST_REQUIRE_EQUAL(cf4.block_count(), 3);
786  BOOST_REQUIRE_EQUAL(cf4.missing_data(), false);
787  type = artdaq::Fragment::FirstUserFragmentType;
788  BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
789 
790  gen.StopCmd(0xFFFFFFFF, 1);
791  TLOG_INFO("CommandableFragmentGenerator_t") << "WindowMode_RequestInBuffer test case END" << TLOG_ENDL;
792 
793 }
795 {
796  artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
797  TLOG_INFO("CommandableFragmentGenerator_t") << "WindowMode_RequestEndsAfterBuffer test case BEGIN" << TLOG_ENDL;
798  const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
799  const int DELAY_TIME = 100;
800  fhicl::ParameterSet ps;
801  ps.put<int>("board_id", 1);
802  ps.put<int>("fragment_id", 1);
803  ps.put<int>("request_port", REQUEST_PORT);
804 #if MULTICAST_MODE
805  ps.put<std::string>("request_address", "227.18.12.32");
806 #else
807  ps.put<std::string>("request_address", "localhost");
808 #endif
809  ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
810  ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 3);
811  ps.put<size_t>("window_close_timeout_us", 500000);
812  ps.put<bool>("separate_data_thread", true);
813  ps.put<bool>("separate_monitoring_thread", false);
814  ps.put<int64_t>("hardware_poll_interval_us", 0);
815  ps.put<size_t>("data_buffer_depth_fragments", 5);
816  ps.put<std::string>("request_mode", "window");
817  ps.put("request_delay_ms", DELAY_TIME);
818  ps.put("send_requests", true);
819 
820  artdaq::RequestSender t(ps);
821 
823  gen.StartCmd(1, 0xFFFFFFFF, 1);
824 
825  artdaq::FragmentPtrs fps;
826  int sts;
827  artdaq::Fragment::type_t type;
828  gen.waitForFrags();
829  gen.setFireCount(5); // Buffer contains 2 to 6
830  gen.waitForFrags();
831 
832  // 5. Start in buffer, end after buffer
833  // -- Should not return until buffer passes end or timeout (check both cases). MissingData bit set if timeout
834  t.AddRequest(1, 5); // Requesting data from ts 5 to 7
835  sts = gen.getNext(fps);
836  BOOST_REQUIRE_EQUAL(sts, true);
837  BOOST_REQUIRE_EQUAL(fps.size(), 0);
838 
839  gen.setFireCount(2); // Buffer contains 4 to 8
840  gen.waitForFrags();
841  sts = gen.getNext(fps);
842  BOOST_REQUIRE_EQUAL(sts, true);
843  BOOST_REQUIRE_EQUAL(fps.size(), 1);
844  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
845  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 5);
846  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
847  type = artdaq::Fragment::ContainerFragmentType;
848  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
849  auto cf = artdaq::ContainerFragment(*fps.front());
850  BOOST_REQUIRE_EQUAL(cf.block_count(), 3);
851  BOOST_REQUIRE_EQUAL(cf.missing_data(), false);
852  type = artdaq::Fragment::FirstUserFragmentType;
853  BOOST_REQUIRE_EQUAL(cf.fragment_type(), type);
854  fps.clear();
855 
856  t.AddRequest(2, 8); // Requesting data from ts 8 to 10
857 
858  sts = gen.getNext(fps);
859  BOOST_REQUIRE_EQUAL(sts, true);
860  BOOST_REQUIRE_EQUAL(fps.size(), 0);
861 
862  usleep(550000);
863 
864  sts = gen.getNext(fps);
865  BOOST_REQUIRE_EQUAL(sts, true);
866  BOOST_REQUIRE_EQUAL(fps.size(), 1);
867  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
868  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 8);
869  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
870  type = artdaq::Fragment::ContainerFragmentType;
871  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
872  auto cf4 = artdaq::ContainerFragment(*fps.front());
873  BOOST_REQUIRE_EQUAL(cf4.block_count(), 1);
874  BOOST_REQUIRE_EQUAL(cf4.missing_data(), true);
875  type = artdaq::Fragment::FirstUserFragmentType;
876  BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
877 
878  gen.StopCmd(0xFFFFFFFF, 1);
879  gen.joinThreads();
880  TLOG_INFO("CommandableFragmentGenerator_t") << "WindowMode_RequestEndsAfterBuffer test case END" << TLOG_ENDL;
881 
882 }
883 BOOST_AUTO_TEST_CASE(WindowMode_RequestAfterBuffer)
884 {
885  artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
886  TLOG_INFO("CommandableFragmentGenerator_t") << "WindowMode_RequestAfterBuffer test case BEGIN" << TLOG_ENDL;
887  const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
888  const int DELAY_TIME = 100;
889  fhicl::ParameterSet ps;
890  ps.put<int>("board_id", 1);
891  ps.put<int>("fragment_id", 1);
892  ps.put<int>("request_port", REQUEST_PORT);
893 #if MULTICAST_MODE
894  ps.put<std::string>("request_address", "227.18.12.32");
895 #else
896  ps.put<std::string>("request_address", "localhost");
897 #endif
898  ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
899  ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 3);
900  ps.put<size_t>("window_close_timeout_us", 500000);
901  ps.put<bool>("separate_data_thread", true);
902  ps.put<bool>("separate_monitoring_thread", false);
903  ps.put<int64_t>("hardware_poll_interval_us", 0);
904  ps.put<size_t>("data_buffer_depth_fragments", 5);
905  ps.put<std::string>("request_mode", "window");
906  ps.put("request_delay_ms", DELAY_TIME);
907  ps.put("send_requests", true);
908 
909  artdaq::RequestSender t(ps);
910 
912  gen.StartCmd(1, 0xFFFFFFFF, 1);
913 
914  artdaq::FragmentPtrs fps;
915  int sts;
916  artdaq::Fragment::type_t type;
917  gen.waitForFrags();
918 
919  // 6. Start and end after buffer
920  // -- Should not return until buffer passes end or timeout (check both cases). MissingData bit set if timeout
921  gen.setFireCount(9); // Buffer start is 6, end at 10
922  gen.waitForFrags();
923  t.AddRequest(1, 11); // Requesting data from ts 11 to 13
924 
925  sts = gen.getNext(fps);
926  BOOST_REQUIRE_EQUAL(sts, true);
927  BOOST_REQUIRE_EQUAL(fps.size(), 0);
928  gen.setFireCount(1); // Buffer start is 7, end at 11
929  gen.waitForFrags();
930  sts = gen.getNext(fps);
931  BOOST_REQUIRE_EQUAL(sts, true);
932  BOOST_REQUIRE_EQUAL(fps.size(), 0);
933 
934  gen.setFireCount(3); // Buffer start is 10, end at 14
935  gen.waitForFrags();
936  sts = gen.getNext(fps);
937  BOOST_REQUIRE_EQUAL(sts, true);
938  BOOST_REQUIRE_EQUAL(fps.size(), 1);
939  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
940  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 11);
941  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
942  type = artdaq::Fragment::ContainerFragmentType;
943  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
944  auto cf = artdaq::ContainerFragment(*fps.front());
945  BOOST_REQUIRE_EQUAL(cf.block_count(), 3);
946  BOOST_REQUIRE_EQUAL(cf.missing_data(), false);
947  type = artdaq::Fragment::FirstUserFragmentType;
948  BOOST_REQUIRE_EQUAL(cf.fragment_type(), type);
949  fps.clear();
950 
951  t.AddRequest(2, 16); // Requesting data from ts 15 to 17
952  sts = gen.getNext(fps);
953  BOOST_REQUIRE_EQUAL(sts, true);
954  BOOST_REQUIRE_EQUAL(fps.size(), 0);
955 
956  usleep(550000);
957 
958  sts = gen.getNext(fps);
959  BOOST_REQUIRE_EQUAL(sts, true);
960  BOOST_REQUIRE_EQUAL(fps.size(), 1);
961  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
962  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 16);
963  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
964  type = artdaq::Fragment::ContainerFragmentType;
965  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
966  auto cf4 = artdaq::ContainerFragment(*fps.front());
967  BOOST_REQUIRE_EQUAL(cf4.block_count(), 0);
968  BOOST_REQUIRE_EQUAL(cf4.missing_data(), true);
969  type = artdaq::Fragment::EmptyFragmentType;
970  BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
971 
972  gen.StopCmd(0xFFFFFFFF, 1);
973  gen.joinThreads();
974  TLOG_INFO("CommandableFragmentGenerator_t") << "WindowMode_RequestAfterBuffer test case END" << TLOG_ENDL;
975 
976 }
977 
978 BOOST_AUTO_TEST_CASE(HardwareFailure_NonThreaded)
979 {
980  artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
981  TLOG_INFO("CommandableFragmentGenerator_t") << "HardwareFailure_NonThreaded test case BEGIN" << TLOG_ENDL;
982  fhicl::ParameterSet ps;
983  ps.put<int>("board_id", 1);
984  ps.put<int>("fragment_id", 1);
985  ps.put<bool>("separate_data_thread", false);
986  ps.put<bool>("separate_monitoring_thread", false);
987  ps.put<int64_t>("hardware_poll_interval_us", 10);
988 
990  gen.StartCmd(1, 0xFFFFFFFF, 1);
991 
992  artdaq::FragmentPtrs fps;
993  auto sts = gen.getNext(fps);
994  BOOST_REQUIRE_EQUAL(sts, true);
995  BOOST_REQUIRE_EQUAL(fps.size(), 1u);
996  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
997  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
998  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
999  fps.clear();
1000 
1001  gen.setFireCount(1);
1002  gen.setHwFail();
1003  usleep(10000);
1004  sts = gen.getNext(fps);
1005  BOOST_REQUIRE_EQUAL(sts, false);
1006  BOOST_REQUIRE_EQUAL(fps.size(), 0);
1007 
1008  gen.StopCmd(0xFFFFFFFF, 1);
1009  gen.joinThreads();
1010  TLOG_INFO("CommandableFragmentGenerator_t") << "HardwareFailure_NonThreaded test case END" << TLOG_ENDL;
1011 }
1012 
1013 BOOST_AUTO_TEST_CASE(HardwareFailure_Threaded)
1014 {
1015  artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
1016  TLOG_INFO("CommandableFragmentGenerator_t") << "HardwareFailure_Threaded test case BEGIN" << TLOG_ENDL;
1017  fhicl::ParameterSet ps;
1018  ps.put<int>("board_id", 1);
1019  ps.put<int>("fragment_id", 1);
1020  ps.put<bool>("separate_data_thread", true);
1021  ps.put<bool>("separate_monitoring_thread", true);
1022  ps.put<int64_t>("hardware_poll_interval_us", 750000);
1023 
1025  gen.StartCmd(1, 0xFFFFFFFF, 1);
1026 
1027 
1028 
1029  artdaq::FragmentPtrs fps;
1030  auto sts = gen.getNext(fps);
1031  BOOST_REQUIRE_EQUAL(sts, true);
1032  BOOST_REQUIRE_EQUAL(fps.size(), 1u);
1033  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
1034  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
1035  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
1036  fps.clear();
1037 
1038  gen.setFireCount(1);
1039  gen.setHwFail();
1040  sts = gen.getNext(fps);
1041  BOOST_REQUIRE_EQUAL(sts, true);
1042  BOOST_REQUIRE_EQUAL(fps.size(), 1);
1043  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
1044  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 2);
1045  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
1046 
1047  fps.clear();
1048  sleep(1);
1049  gen.setFireCount(1);
1050  sts = gen.getNext(fps);
1051  BOOST_REQUIRE_EQUAL(sts, false);
1052  BOOST_REQUIRE_EQUAL(fps.size(), 0);
1053 
1054  gen.StopCmd(0xFFFFFFFF, 1);
1055  gen.joinThreads();
1056  TLOG_INFO("CommandableFragmentGenerator_t") << "HardwareFailure_Threaded test case END" << TLOG_ENDL;
1057 }
1058 
1059 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.