00001 #define TRACE_NAME "CommandableFragmentGenerator_t"
00002
00003 #define BOOST_TEST_MODULE CommandableFragmentGenerator_t
00004 #include <boost/test/auto_unit_test.hpp>
00005
00006 #include "artdaq-core/Data/Fragment.hh"
00007 #include "artdaq-core/Data/ContainerFragment.hh"
00008 #include "artdaq/Application/CommandableFragmentGenerator.hh"
00009 #include "artdaq/DAQrate/RequestSender.hh"
00010
00011 #define MULTICAST_MODE 0
00012
00013 namespace artdaqtest
00014 {
00015 class CommandableFragmentGeneratorTest;
00016 }
00017
00021 class artdaqtest::CommandableFragmentGeneratorTest :
00022 public artdaq::CommandableFragmentGenerator
00023 {
00024 public:
00028 explicit CommandableFragmentGeneratorTest(const fhicl::ParameterSet& ps);
00029
00030 virtual ~CommandableFragmentGeneratorTest() { joinThreads(); };
00031
00032 protected:
00040 bool getNext_(artdaq::FragmentPtrs& frags) override;
00041
00046 bool checkHWStatus_() override { return !hwFail_.load(); }
00047
00051 void start() override;
00052
00056 void stopNoMutex() override;
00057
00061 void stop() override;
00062
00066 void pause() override;
00067
00071 void resume() override;
00072
00073 public:
00078 void setFireCount(size_t count) { fireCount_ = count; }
00079
00083 void setHwFail() { hwFail_ = true; }
00084
00088 void waitForFrags() {
00089 auto start_time = std::chrono::steady_clock::now();
00090 while (fireCount_ > 0) { usleep(1000); }
00091 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" ;
00092 }
00093 private:
00094 std::atomic<size_t> fireCount_;
00095 std::atomic<bool> hwFail_;
00096 artdaq::Fragment::timestamp_t ts_;
00097 std::atomic<bool> hw_stop_;
00098 };
00099
00100 artdaqtest::CommandableFragmentGeneratorTest::CommandableFragmentGeneratorTest(const fhicl::ParameterSet& ps)
00101 : CommandableFragmentGenerator(ps)
00102 , fireCount_(1)
00103 , hwFail_(false)
00104 , ts_(0)
00105 , hw_stop_(false)
00106 {
00107 metricMan->initialize(ps);
00108 metricMan->do_start();
00109 }
00110
00111 bool
00112 artdaqtest::CommandableFragmentGeneratorTest::getNext_(artdaq::FragmentPtrs& frags)
00113 {
00114 while (fireCount_ > 0)
00115 {
00116 frags.emplace_back(new artdaq::Fragment(ev_counter(), fragment_id(), artdaq::Fragment::FirstUserFragmentType, ++ts_));
00117 fireCount_--;
00118 }
00119
00120 return !hw_stop_;
00121 }
00122
00123 void
00124 artdaqtest::CommandableFragmentGeneratorTest::start() { hw_stop_ = false; }
00125
00126 void
00127 artdaqtest::CommandableFragmentGeneratorTest::stopNoMutex() {}
00128
00129 void
00130 artdaqtest::CommandableFragmentGeneratorTest::stop() { hw_stop_ = true; }
00131
00132 void
00133 artdaqtest::CommandableFragmentGeneratorTest::pause() {}
00134
00135 void
00136 artdaqtest::CommandableFragmentGeneratorTest::resume() {}
00137
00138 BOOST_AUTO_TEST_SUITE(CommandableFragmentGenerator_t)
00139
00140 BOOST_AUTO_TEST_CASE(Simple)
00141 {
00142 artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
00143 TLOG(TLVL_INFO) << "Simple test case BEGIN" ;
00144 fhicl::ParameterSet ps;
00145 ps.put<int>("board_id", 1);
00146 ps.put<int>("fragment_id", 1);
00147 artdaqtest::CommandableFragmentGeneratorTest testGen(ps);
00148 artdaq::FragmentPtrs fps;
00149 auto sts = testGen.getNext(fps);
00150 BOOST_REQUIRE_EQUAL(sts, true);
00151 BOOST_REQUIRE_EQUAL(fps.size(), 1u);
00152 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
00153 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
00154 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
00155 TLOG(TLVL_INFO) << "Simple test case END" ;
00156 }
00157
00158 BOOST_AUTO_TEST_CASE(IgnoreRequests)
00159 {
00160 artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
00161 TLOG(TLVL_INFO) << "IgnoreRequests test case BEGIN" ;
00162 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
00163 const int DELAY_TIME = 1;
00164 fhicl::ParameterSet ps;
00165 ps.put<int>("board_id", 1);
00166 ps.put<int>("fragment_id", 1);
00167 ps.put<int>("request_port", REQUEST_PORT);
00168 #if MULTICAST_MODE
00169 ps.put<std::string>("request_address", "227.18.12.29");
00170 #else
00171 ps.put<std::string>("request_address", "localhost");
00172 #endif
00173 ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
00174 ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 0);
00175 ps.put<bool>("separate_data_thread", true);
00176 ps.put<bool>("separate_monitoring_thread", false);
00177 ps.put<int64_t>("hardware_poll_interval_us", 0);
00178 ps.put<std::string>("request_mode", "ignored");
00179 ps.put("request_delay_ms", DELAY_TIME);
00180 ps.put("send_requests", true);
00181
00182 artdaq::RequestSender t(ps);
00183 artdaqtest::CommandableFragmentGeneratorTest gen(ps);
00184 gen.StartCmd(1, 0xFFFFFFFF, 1);
00185 t.AddRequest(53, 35);
00186
00187 artdaq::FragmentPtrs fps;
00188 auto sts = gen.getNext(fps);
00189 BOOST_REQUIRE_EQUAL(sts, true);
00190 BOOST_REQUIRE_EQUAL(fps.size(), 1u);
00191 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
00192 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
00193 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
00194 gen.StopCmd(0xFFFFFFFF, 1);
00195 gen.joinThreads();
00196 TLOG(TLVL_INFO) << "IgnoreRequests test case END" ;
00197 }
00198
00199 BOOST_AUTO_TEST_CASE(SingleMode)
00200 {
00201 artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
00202 TLOG(TLVL_INFO) << "SingleMode test case BEGIN" ;
00203 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
00204 const int DELAY_TIME = 100;
00205 fhicl::ParameterSet ps;
00206 ps.put<int>("board_id", 1);
00207 ps.put<int>("fragment_id", 1);
00208 ps.put<int>("request_port", REQUEST_PORT);
00209 #if MULTICAST_MODE
00210 ps.put<std::string>("request_address", "227.18.12.30");
00211 #else
00212 ps.put<std::string>("request_address", "localhost");
00213 #endif
00214 ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
00215 ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 0);
00216 ps.put<bool>("separate_data_thread", true);
00217 ps.put<bool>("separate_monitoring_thread", false);
00218 ps.put<int64_t>("hardware_poll_interval_us", 0);
00219 ps.put<std::string>("request_mode", "single");
00220 ps.put("request_delay_ms", DELAY_TIME);
00221 ps.put("send_requests", true);
00222
00223 artdaq::RequestSender t(ps);
00224 t.AddRequest(1, 1);
00225
00226 artdaqtest::CommandableFragmentGeneratorTest gen(ps);
00227 gen.StartCmd(1, 0xFFFFFFFF, 1);
00228 gen.waitForFrags();
00229 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 1);
00230
00231 artdaq::FragmentPtrs fps;
00232 auto sts = gen.getNext(fps);
00233 auto type = artdaq::Fragment::FirstUserFragmentType;
00234 BOOST_REQUIRE_EQUAL(sts, true);
00235 BOOST_REQUIRE_EQUAL(fps.size(), 1u);
00236 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
00237 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
00238 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
00239 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
00240 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 2);
00241 fps.clear();
00242
00243 t.AddRequest(2, 5);
00244 sts = gen.getNext(fps);
00245 BOOST_REQUIRE_EQUAL(sts, true);
00246 BOOST_REQUIRE_EQUAL(fps.size(), 1u);
00247 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
00248 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 5);
00249 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
00250 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
00251 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 3);
00252 fps.clear();
00253
00254 gen.setFireCount(2);
00255 gen.waitForFrags();
00256 t.AddRequest(4, 7);
00257 sts = gen.getNext(fps);
00258 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 5);
00259 BOOST_REQUIRE_EQUAL(sts, true);
00260 BOOST_REQUIRE_EQUAL(fps.size(), 2);
00261 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
00262 auto ts = artdaq::Fragment::InvalidTimestamp;
00263 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), ts);
00264 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 3);
00265 auto emptyType = artdaq::Fragment::EmptyFragmentType;
00266 BOOST_REQUIRE_EQUAL(fps.front()->type(), emptyType);
00267 fps.pop_front();
00268 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
00269 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 7);
00270 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 4);
00271 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
00272 fps.clear();
00273
00274 gen.StopCmd(0xFFFFFFFF, 1);
00275 gen.joinThreads();
00276 TLOG(TLVL_INFO) << "SingleMode test case END" ;
00277 }
00278
00279 BOOST_AUTO_TEST_CASE(BufferMode)
00280 {
00281 artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
00282 TLOG(TLVL_INFO) << "BufferMode test case BEGIN" ;
00283 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
00284 const int DELAY_TIME = 100;
00285 fhicl::ParameterSet ps;
00286 ps.put<int>("board_id", 1);
00287 ps.put<int>("fragment_id", 1);
00288 ps.put<int>("request_port", REQUEST_PORT);
00289 #if MULTICAST_MODE
00290 ps.put<std::string>("request_address", "227.18.12.31");
00291 #else
00292 ps.put<std::string>("request_address", "localhost");
00293 #endif
00294 ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
00295 ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 0);
00296 ps.put<bool>("separate_data_thread", true);
00297 ps.put<bool>("separate_monitoring_thread", false);
00298 ps.put<int64_t>("hardware_poll_interval_us", 0);
00299 ps.put<std::string>("request_mode", "buffer");
00300 ps.put("request_delay_ms", DELAY_TIME);
00301 ps.put("send_requests", true);
00302
00303 artdaq::RequestSender t(ps);
00304 t.AddRequest(1, 1);
00305
00306 artdaqtest::CommandableFragmentGeneratorTest gen(ps);
00307 gen.StartCmd(1, 0xFFFFFFFF, 1);
00308 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 1);
00309
00310
00311 artdaq::FragmentPtrs fps;
00312 auto sts = gen.getNext(fps);
00313 BOOST_REQUIRE_EQUAL(sts, true);
00314 BOOST_REQUIRE_EQUAL(fps.size(), 1u);
00315 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
00316 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
00317 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
00318 auto type = artdaq::Fragment::ContainerFragmentType;
00319 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
00320 BOOST_REQUIRE_GE(fps.front()->sizeBytes(), 2 * sizeof(artdaq::detail::RawFragmentHeader) + sizeof(artdaq::ContainerFragment::Metadata));
00321 auto cf = artdaq::ContainerFragment(*fps.front());
00322 BOOST_REQUIRE_EQUAL(cf.block_count(), 1);
00323 BOOST_REQUIRE_EQUAL(cf.missing_data(), false);
00324 type = artdaq::Fragment::FirstUserFragmentType;
00325 BOOST_REQUIRE_EQUAL(cf.fragment_type(), type);
00326 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 2);
00327 fps.clear();
00328
00329 t.AddRequest(2, 5);
00330 sts = gen.getNext(fps);
00331 BOOST_REQUIRE_EQUAL(sts, true);
00332 BOOST_REQUIRE_EQUAL(fps.size(), 1u);
00333 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
00334 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 5);
00335 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
00336 type = artdaq::Fragment::ContainerFragmentType;
00337 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
00338 auto cf2 = artdaq::ContainerFragment(*fps.front());
00339 BOOST_REQUIRE_EQUAL(cf2.block_count(), 0);
00340 BOOST_REQUIRE_EQUAL(cf2.missing_data(), false);
00341 type = artdaq::Fragment::EmptyFragmentType;
00342 BOOST_REQUIRE_EQUAL(cf2.fragment_type(), type);
00343 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 3);
00344 fps.clear();
00345
00346 gen.setFireCount(2);
00347 gen.waitForFrags();
00348 t.AddRequest(4, 7);
00349 sts = gen.getNext(fps);
00350 BOOST_REQUIRE_EQUAL(sts, true);
00351 BOOST_REQUIRE_EQUAL(fps.size(), 2);
00352
00353 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
00354 auto ts = artdaq::Fragment::InvalidTimestamp;
00355 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), ts);
00356 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 3);
00357 auto emptyType = artdaq::Fragment::EmptyFragmentType;
00358 BOOST_REQUIRE_EQUAL(fps.front()->type(), emptyType);
00359 BOOST_REQUIRE_EQUAL(fps.front()->size(), artdaq::detail::RawFragmentHeader::num_words());
00360 fps.pop_front();
00361 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
00362 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 7);
00363 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 4);
00364 type = artdaq::Fragment::ContainerFragmentType;
00365 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
00366 auto cf3 = artdaq::ContainerFragment(*fps.front());
00367 BOOST_REQUIRE_EQUAL(cf3.block_count(), 2);
00368 BOOST_REQUIRE_EQUAL(cf3.missing_data(), false);
00369 type = artdaq::Fragment::FirstUserFragmentType;
00370 BOOST_REQUIRE_EQUAL(cf3.fragment_type(), type);
00371 fps.clear();
00372 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 5);
00373
00374
00375 gen.StopCmd(0xFFFFFFFF, 1);
00376 gen.joinThreads();
00377
00378
00379 TLOG(TLVL_INFO) << "BufferMode test case END" ;
00380 }
00381
00382 BOOST_AUTO_TEST_CASE(CircularBufferMode)
00383 {
00384 artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
00385 TLOG(TLVL_INFO) << "CircularBufferMode test case BEGIN";
00386 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
00387 const int DELAY_TIME = 100;
00388 fhicl::ParameterSet ps;
00389 ps.put<int>("board_id", 1);
00390 ps.put<int>("fragment_id", 1);
00391 ps.put<int>("request_port", REQUEST_PORT);
00392 #if MULTICAST_MODE
00393 ps.put<std::string>("request_address", "227.18.12.31");
00394 #else
00395 ps.put<std::string>("request_address", "localhost");
00396 #endif
00397 ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
00398 ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 0);
00399 ps.put<bool>("separate_data_thread", true);
00400 ps.put<bool>("circular_buffer_mode", true);
00401 ps.put<int>("data_buffer_depth_fragments", 3);
00402 ps.put<bool>("separate_monitoring_thread", false);
00403 ps.put<int64_t>("hardware_poll_interval_us", 0);
00404 ps.put<std::string>("request_mode", "buffer");
00405 ps.put("request_delay_ms", DELAY_TIME);
00406 ps.put("send_requests", true);
00407
00408 artdaq::RequestSender t(ps);
00409 t.AddRequest(1, 1);
00410
00411 artdaqtest::CommandableFragmentGeneratorTest gen(ps);
00412 gen.StartCmd(1, 0xFFFFFFFF, 1);
00413 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 1);
00414
00415
00416 artdaq::FragmentPtrs fps;
00417 auto sts = gen.getNext(fps);
00418 BOOST_REQUIRE_EQUAL(sts, true);
00419 BOOST_REQUIRE_EQUAL(fps.size(), 1u);
00420 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
00421 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
00422 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
00423 auto type = artdaq::Fragment::ContainerFragmentType;
00424 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
00425 BOOST_REQUIRE_GE(fps.front()->sizeBytes(), 2 * sizeof(artdaq::detail::RawFragmentHeader) + sizeof(artdaq::ContainerFragment::Metadata));
00426 auto cf = artdaq::ContainerFragment(*fps.front());
00427 BOOST_REQUIRE_EQUAL(cf.block_count(), 1);
00428 BOOST_REQUIRE_EQUAL(cf.missing_data(), false);
00429 type = artdaq::Fragment::FirstUserFragmentType;
00430 BOOST_REQUIRE_EQUAL(cf.fragment_type(), type);
00431 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 2);
00432 fps.clear();
00433
00434 t.AddRequest(2, 5);
00435 sts = gen.getNext(fps);
00436 BOOST_REQUIRE_EQUAL(sts, true);
00437 BOOST_REQUIRE_EQUAL(fps.size(), 1u);
00438 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
00439 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 5);
00440 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
00441 type = artdaq::Fragment::ContainerFragmentType;
00442 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
00443 auto cf2 = artdaq::ContainerFragment(*fps.front());
00444 BOOST_REQUIRE_EQUAL(cf2.block_count(), 0);
00445 BOOST_REQUIRE_EQUAL(cf2.missing_data(), false);
00446 type = artdaq::Fragment::EmptyFragmentType;
00447 BOOST_REQUIRE_EQUAL(cf2.fragment_type(), type);
00448 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 3);
00449 fps.clear();
00450
00451 gen.setFireCount(3);
00452 gen.waitForFrags();
00453 t.AddRequest(4, 7);
00454 sts = gen.getNext(fps);
00455 BOOST_REQUIRE_EQUAL(sts, true);
00456 BOOST_REQUIRE_EQUAL(fps.size(), 2);
00457
00458 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
00459 auto ts = artdaq::Fragment::InvalidTimestamp;
00460 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), ts);
00461 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 3);
00462 auto emptyType = artdaq::Fragment::EmptyFragmentType;
00463 BOOST_REQUIRE_EQUAL(fps.front()->type(), emptyType);
00464 BOOST_REQUIRE_EQUAL(fps.front()->size(), artdaq::detail::RawFragmentHeader::num_words());
00465 fps.pop_front();
00466 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
00467 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 7);
00468 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 4);
00469 type = artdaq::Fragment::ContainerFragmentType;
00470 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
00471 auto cf3 = artdaq::ContainerFragment(*fps.front());
00472 BOOST_REQUIRE_EQUAL(cf3.block_count(), 3);
00473 BOOST_REQUIRE_EQUAL(cf3.missing_data(), false);
00474 type = artdaq::Fragment::FirstUserFragmentType;
00475 BOOST_REQUIRE_EQUAL(cf3.fragment_type(), type);
00476 fps.clear();
00477 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 5);
00478
00479
00480
00481 gen.setFireCount(5);
00482 gen.waitForFrags();
00483 t.AddRequest(5, 8);
00484 sts = gen.getNext(fps);
00485 BOOST_REQUIRE_EQUAL(sts, true);
00486 BOOST_REQUIRE_EQUAL(fps.size(), 1);
00487
00488 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
00489 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 8);
00490 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 5);
00491 type = artdaq::Fragment::ContainerFragmentType;
00492 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
00493 auto cf4 = artdaq::ContainerFragment(*fps.front());
00494 BOOST_REQUIRE_EQUAL(cf4.block_count(), 3);
00495 BOOST_REQUIRE_EQUAL(cf4.missing_data(), false);
00496 type = artdaq::Fragment::FirstUserFragmentType;
00497 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
00498 BOOST_REQUIRE_EQUAL(cf4.at(0)->timestamp(), 7);
00499 BOOST_REQUIRE_EQUAL(cf4.at(1)->timestamp(), 8);
00500 BOOST_REQUIRE_EQUAL(cf4.at(2)->timestamp(), 9);
00501 fps.clear();
00502 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 6);
00503
00504
00505 gen.StopCmd(0xFFFFFFFF, 1);
00506 gen.joinThreads();
00507
00508
00509 TLOG(TLVL_INFO) << "CircularBufferMode test case END";
00510 }
00511
00512 BOOST_AUTO_TEST_CASE(WindowMode_Function)
00513 {
00514 artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
00515 TLOG(TLVL_INFO) << "WindowMode_Function test case BEGIN" ;
00516 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
00517 const int DELAY_TIME = 100;
00518 fhicl::ParameterSet ps;
00519 ps.put<int>("board_id", 1);
00520 ps.put<int>("fragment_id", 1);
00521 ps.put<int>("request_port", REQUEST_PORT);
00522 #if MULTICAST_MODE
00523 ps.put<std::string>("request_address", "227.18.12.32");
00524 #else
00525 ps.put<std::string>("request_address", "localhost");
00526 #endif
00527 ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
00528 ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 0);
00529 ps.put<bool>("separate_data_thread", true);
00530 ps.put<bool>("separate_monitoring_thread", false);
00531 ps.put<int64_t>("hardware_poll_interval_us", 0);
00532 ps.put<size_t>("data_buffer_depth_fragments", 5);
00533 ps.put<std::string>("request_mode", "window");
00534 ps.put<size_t>("missing_request_window_timeout_us", 500000);
00535 ps.put<size_t>("window_close_timeout_us", 500000);
00536 ps.put("request_delay_ms", DELAY_TIME);
00537 ps.put("send_requests", true);
00538
00539 artdaq::RequestSender t(ps);
00540 t.AddRequest(1, 1);
00541
00542 artdaqtest::CommandableFragmentGeneratorTest gen(ps);
00543 gen.StartCmd(1, 0xFFFFFFFF, 1);
00544 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 1);
00545
00546 artdaq::FragmentPtrs fps;
00547 auto sts = gen.getNext(fps);
00548 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 2);
00549 BOOST_REQUIRE_EQUAL(sts, true);
00550 BOOST_REQUIRE_EQUAL(fps.size(), 1u);
00551 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
00552 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
00553 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
00554 auto type = artdaq::Fragment::ContainerFragmentType;
00555 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
00556 BOOST_REQUIRE_GE(fps.front()->sizeBytes(), 2 * sizeof(artdaq::detail::RawFragmentHeader) + sizeof(artdaq::ContainerFragment::Metadata));
00557 auto cf = artdaq::ContainerFragment(*fps.front());
00558 BOOST_REQUIRE_EQUAL(cf.block_count(), 1);
00559 BOOST_REQUIRE_EQUAL(cf.missing_data(), false);
00560 type = artdaq::Fragment::FirstUserFragmentType;
00561 BOOST_REQUIRE_EQUAL(cf.fragment_type(), type);
00562 fps.clear();
00563
00564
00565 t.AddRequest(2, 2);
00566 sts = gen.getNext(fps);
00567 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 2);
00568 BOOST_REQUIRE_EQUAL(sts, true);
00569 BOOST_REQUIRE_EQUAL(fps.size(), 0);
00570
00571 gen.setFireCount(1);
00572 gen.waitForFrags();
00573 sts = gen.getNext(fps);
00574 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 3);
00575 BOOST_REQUIRE_EQUAL(sts, true);
00576 BOOST_REQUIRE_EQUAL(fps.size(), 1);
00577 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
00578 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 2);
00579 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
00580 type = artdaq::Fragment::ContainerFragmentType;
00581 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
00582 auto cf2 = artdaq::ContainerFragment(*fps.front());
00583 BOOST_REQUIRE_EQUAL(cf2.block_count(), 1);
00584 BOOST_REQUIRE_EQUAL(cf2.missing_data(), false);
00585 type = artdaq::Fragment::FirstUserFragmentType;
00586 BOOST_REQUIRE_EQUAL(cf2.fragment_type(), type);
00587 fps.clear();
00588
00589
00590 t.AddRequest(4, 3);
00591 sts = gen.getNext(fps);
00592 BOOST_REQUIRE_EQUAL(sts, true);
00593 BOOST_REQUIRE_EQUAL(fps.size(), 0);
00594 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 3);
00595
00596
00597 usleep(1500000);
00598 sts = gen.getNext(fps);
00599 BOOST_REQUIRE_EQUAL(sts, true);
00600 BOOST_REQUIRE_EQUAL(fps.size(), 1);
00601
00602
00603 auto list = gen.getOutOfOrderWindowList();
00604 BOOST_REQUIRE_EQUAL(list.size(), 1);
00605 BOOST_REQUIRE_EQUAL(list.begin()->first, 4);
00606 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 3);
00607
00608 usleep(1500000);
00609
00610
00611 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
00612 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 3);
00613 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 4);
00614 type = artdaq::Fragment::ContainerFragmentType;
00615 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
00616 auto cf3 = artdaq::ContainerFragment(*fps.front());
00617 BOOST_REQUIRE_EQUAL(cf3.block_count(), 0);
00618 BOOST_REQUIRE_EQUAL(cf3.missing_data(), true);
00619 type = artdaq::Fragment::EmptyFragmentType;
00620 BOOST_REQUIRE_EQUAL(cf3.fragment_type(), type);
00621 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 3);
00622 fps.clear();
00623
00624
00625 gen.setFireCount(12);
00626 gen.waitForFrags();
00627 t.AddRequest(5, 4);
00628 list = gen.getOutOfOrderWindowList();
00629 BOOST_REQUIRE_EQUAL(list.size(), 1);
00630 sts = gen.getNext(fps);
00631 list = gen.getOutOfOrderWindowList();
00632 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 6);
00633 BOOST_REQUIRE_EQUAL(list.size(), 0);
00634 BOOST_REQUIRE_EQUAL(sts, true);
00635 BOOST_REQUIRE_EQUAL(fps.size(), 1);
00636 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
00637 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 4);
00638 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 5);
00639 type = artdaq::Fragment::ContainerFragmentType;
00640 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
00641 auto cf4 = artdaq::ContainerFragment(*fps.front());
00642 BOOST_REQUIRE_EQUAL(cf4.block_count(), 0);
00643 BOOST_REQUIRE_EQUAL(cf4.missing_data(), true);
00644 type = artdaq::Fragment::EmptyFragmentType;
00645 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
00646 fps.clear();
00647
00648
00649
00650 t.AddRequest(7, 13);
00651 sts = gen.getNext(fps);
00652 BOOST_REQUIRE_EQUAL(sts, true);
00653 BOOST_REQUIRE_EQUAL(fps.size(), 1);
00654 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
00655 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 13);
00656 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 7);
00657 type = artdaq::Fragment::ContainerFragmentType;
00658 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
00659 auto cf5 = artdaq::ContainerFragment(*fps.front());
00660 BOOST_REQUIRE_EQUAL(cf5.block_count(), 1);
00661 BOOST_REQUIRE_EQUAL(cf5.missing_data(), false);
00662 type = artdaq::Fragment::FirstUserFragmentType;
00663 BOOST_REQUIRE_EQUAL(cf5.fragment_type(), type);
00664 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 6);
00665 fps.clear();
00666
00667 list = gen.getOutOfOrderWindowList();
00668 BOOST_REQUIRE_EQUAL(list.size(), 1);
00669 BOOST_REQUIRE_EQUAL(list.begin()->first, 7);
00670
00671 t.AddRequest(6, 12);
00672 sts = gen.getNext(fps);
00673 BOOST_REQUIRE_EQUAL(sts, true);
00674 BOOST_REQUIRE_EQUAL(fps.size(), 1);
00675 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
00676 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 12);
00677 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 6);
00678 type = artdaq::Fragment::ContainerFragmentType;
00679 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
00680 auto cf6 = artdaq::ContainerFragment(*fps.front());
00681 BOOST_REQUIRE_EQUAL(cf6.block_count(), 1);
00682 BOOST_REQUIRE_EQUAL(cf6.missing_data(), false);
00683 type = artdaq::Fragment::FirstUserFragmentType;
00684 BOOST_REQUIRE_EQUAL(cf6.fragment_type(), type);
00685 fps.clear();
00686 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 8);
00687
00688 list = gen.getOutOfOrderWindowList();
00689 BOOST_REQUIRE_EQUAL(list.size(), 0);
00690
00691 usleep(1500000);
00692
00693 gen.StopCmd(0xFFFFFFFF, 1);
00694 TLOG(TLVL_INFO) << "WindowMode_Function test case END" ;
00695 gen.joinThreads();
00696
00697 }
00698
00699
00700
00701
00702
00703
00704
00705 BOOST_AUTO_TEST_CASE(WindowMode_RequestBeforeBuffer)
00706 {
00707 artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
00708 TLOG(TLVL_INFO) << "WindowMode_RequestBeforeBuffer test case BEGIN" ;
00709 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
00710 const int DELAY_TIME = 100;
00711 fhicl::ParameterSet ps;
00712 ps.put<int>("board_id", 1);
00713 ps.put<int>("fragment_id", 1);
00714 ps.put<int>("request_port", REQUEST_PORT);
00715 #if MULTICAST_MODE
00716 ps.put<std::string>("request_address", "227.18.12.32");
00717 #else
00718 ps.put<std::string>("request_address", "localhost");
00719 #endif
00720 ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
00721 ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 3);
00722 ps.put<bool>("separate_data_thread", true);
00723 ps.put<bool>("separate_monitoring_thread", false);
00724 ps.put<int64_t>("hardware_poll_interval_us", 0);
00725 ps.put<size_t>("data_buffer_depth_fragments", 5);
00726 ps.put<std::string>("request_mode", "window");
00727 ps.put("request_delay_ms", DELAY_TIME);
00728 ps.put("send_requests", true);
00729
00730 artdaq::RequestSender t(ps);
00731
00732 artdaqtest::CommandableFragmentGeneratorTest gen(ps);
00733 gen.StartCmd(1, 0xFFFFFFFF, 1);
00734
00735 artdaq::FragmentPtrs fps;
00736 int sts;
00737 artdaq::Fragment::type_t type;
00738
00739
00740
00741 gen.setFireCount(9);
00742 gen.waitForFrags();
00743 t.AddRequest(1, 1);
00744
00745 sts = gen.getNext(fps);
00746 BOOST_REQUIRE_EQUAL(sts, true);
00747 BOOST_REQUIRE_EQUAL(fps.size(), 1);
00748 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
00749 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
00750 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
00751 type = artdaq::Fragment::ContainerFragmentType;
00752 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
00753 auto cf4 = artdaq::ContainerFragment(*fps.front());
00754 BOOST_REQUIRE_EQUAL(cf4.block_count(), 0);
00755 BOOST_REQUIRE_EQUAL(cf4.missing_data(), true);
00756 type = artdaq::Fragment::EmptyFragmentType;
00757 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
00758
00759 gen.StopCmd(0xFFFFFFFF, 1);
00760 TLOG(TLVL_INFO) << "WindowMode_RequestBeforeBuffer test case END" ;
00761
00762 }
00763 BOOST_AUTO_TEST_CASE(WindowMode_RequestStartsBeforeBuffer)
00764 {
00765 artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
00766 TLOG(TLVL_INFO) << "WindowMode_RequestStartsBeforeBuffer test case BEGIN" ;
00767 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
00768 const int DELAY_TIME = 100;
00769 fhicl::ParameterSet ps;
00770 ps.put<int>("board_id", 1);
00771 ps.put<int>("fragment_id", 1);
00772 ps.put<int>("request_port", REQUEST_PORT);
00773 #if MULTICAST_MODE
00774 ps.put<std::string>("request_address", "227.18.12.32");
00775 #else
00776 ps.put<std::string>("request_address", "localhost");
00777 #endif
00778 ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
00779 ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 3);
00780 ps.put<bool>("separate_data_thread", true);
00781 ps.put<bool>("separate_monitoring_thread", false);
00782 ps.put<int64_t>("hardware_poll_interval_us", 0);
00783 ps.put<size_t>("data_buffer_depth_fragments", 5);
00784 ps.put<std::string>("request_mode", "window");
00785 ps.put("request_delay_ms", DELAY_TIME);
00786 ps.put("send_requests", true);
00787
00788 artdaq::RequestSender t(ps);
00789
00790 artdaqtest::CommandableFragmentGeneratorTest gen(ps);
00791 gen.StartCmd(1, 0xFFFFFFFF, 1);
00792
00793 artdaq::FragmentPtrs fps;
00794 int sts;
00795 artdaq::Fragment::type_t type;
00796
00797 gen.waitForFrags();
00798 gen.setFireCount(9);
00799 gen.waitForFrags();
00800
00801
00802
00803 t.AddRequest(1, 4);
00804
00805 sts = gen.getNext(fps);
00806 BOOST_REQUIRE_EQUAL(sts, true);
00807 BOOST_REQUIRE_EQUAL(fps.size(), 1);
00808 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
00809 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 4);
00810 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
00811 type = artdaq::Fragment::ContainerFragmentType;
00812 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
00813 auto cf4 = artdaq::ContainerFragment(*fps.front());
00814 BOOST_REQUIRE_EQUAL(cf4.block_count(), 1);
00815 BOOST_REQUIRE_EQUAL(cf4.missing_data(), true);
00816 type = artdaq::Fragment::FirstUserFragmentType;
00817 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
00818
00819 gen.StopCmd(0xFFFFFFFF, 1);
00820 gen.joinThreads();
00821 TLOG(TLVL_INFO) << "WindowMode_RequestStartsBeforeBuffer test case END" ;
00822
00823 }
00824 BOOST_AUTO_TEST_CASE(WindowMode_RequestOutsideBuffer)
00825 {
00826 artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
00827 TLOG(TLVL_INFO) << "WindowMode_RequestOutsideBuffer test case BEGIN" ;
00828 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
00829 const int DELAY_TIME = 100;
00830 fhicl::ParameterSet ps;
00831 ps.put<int>("board_id", 1);
00832 ps.put<int>("fragment_id", 1);
00833 ps.put<int>("request_port", REQUEST_PORT);
00834 #if MULTICAST_MODE
00835 ps.put<std::string>("request_address", "227.18.12.32");
00836 #else
00837 ps.put<std::string>("request_address", "localhost");
00838 #endif
00839 ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
00840 ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 4);
00841 ps.put<size_t>("window_close_timeout_us", 500000);
00842 ps.put<bool>("separate_data_thread", true);
00843 ps.put<bool>("separate_monitoring_thread", false);
00844 ps.put<int64_t>("hardware_poll_interval_us", 0);
00845 ps.put<size_t>("data_buffer_depth_fragments", 5);
00846 ps.put<std::string>("request_mode", "window");
00847 ps.put("request_delay_ms", DELAY_TIME);
00848 ps.put("send_requests", true);
00849
00850 artdaq::RequestSender t(ps);
00851
00852 artdaqtest::CommandableFragmentGeneratorTest gen(ps);
00853 gen.StartCmd(1, 0xFFFFFFFF, 1);
00854
00855 artdaq::FragmentPtrs fps;
00856 int sts;
00857 artdaq::Fragment::type_t type;
00858
00859 gen.waitForFrags();
00860 gen.setFireCount(9);
00861 gen.waitForFrags();
00862
00863
00864
00865
00866 t.AddRequest(1, 6);
00867 sts = gen.getNext(fps);
00868 BOOST_REQUIRE_EQUAL(sts, true);
00869 BOOST_REQUIRE_EQUAL(fps.size(), 1);
00870 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
00871 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 6);
00872 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
00873 type = artdaq::Fragment::ContainerFragmentType;
00874 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
00875 auto cf = artdaq::ContainerFragment(*fps.front());
00876 BOOST_REQUIRE_EQUAL(cf.block_count(), 4);
00877 BOOST_REQUIRE_EQUAL(cf.missing_data(), false);
00878 type = artdaq::Fragment::FirstUserFragmentType;
00879 BOOST_REQUIRE_EQUAL(cf.fragment_type(), type);
00880 fps.clear();
00881
00882 t.AddRequest(2, 9);
00883 sts = gen.getNext(fps);
00884 BOOST_REQUIRE_EQUAL(sts, true);
00885 BOOST_REQUIRE_EQUAL(fps.size(), 0);
00886
00887 gen.setFireCount(3);
00888 gen.waitForFrags();
00889
00890 sts = gen.getNext(fps);
00891 BOOST_REQUIRE_EQUAL(sts, true);
00892 BOOST_REQUIRE_EQUAL(fps.size(), 1);
00893 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
00894 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 9);
00895 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
00896 type = artdaq::Fragment::ContainerFragmentType;
00897 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
00898 auto cf2 = artdaq::ContainerFragment(*fps.front());
00899 BOOST_REQUIRE_EQUAL(cf2.block_count(), 3);
00900 BOOST_REQUIRE_EQUAL(cf2.missing_data(), true);
00901 type = artdaq::Fragment::FirstUserFragmentType;
00902 BOOST_REQUIRE_EQUAL(cf2.fragment_type(), type);
00903 fps.clear();
00904
00905
00906
00907 t.AddRequest(3, 12);
00908
00909 sts = gen.getNext(fps);
00910 BOOST_REQUIRE_EQUAL(sts, true);
00911 BOOST_REQUIRE_EQUAL(fps.size(), 0);
00912
00913 usleep(550000);
00914
00915 sts = gen.getNext(fps);
00916 BOOST_REQUIRE_EQUAL(sts, true);
00917 BOOST_REQUIRE_EQUAL(fps.size(), 1);
00918 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
00919 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 12);
00920 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 3);
00921 type = artdaq::Fragment::ContainerFragmentType;
00922 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
00923 auto cf4 = artdaq::ContainerFragment(*fps.front());
00924 BOOST_REQUIRE_EQUAL(cf4.block_count(), 1);
00925 BOOST_REQUIRE_EQUAL(cf4.missing_data(), true);
00926 type = artdaq::Fragment::FirstUserFragmentType;
00927 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
00928
00929 gen.StopCmd(0xFFFFFFFF, 1);
00930 gen.joinThreads();
00931 TLOG(TLVL_INFO) << "WindowMode_RequestOutsideBuffer test case END" ;
00932
00933 }
00934 BOOST_AUTO_TEST_CASE(WindowMode_RequestInBuffer)
00935 {
00936 artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
00937 TLOG(TLVL_INFO) << "WindowMode_RequestInBuffer test case BEGIN" ;
00938 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
00939 const int DELAY_TIME = 100;
00940 fhicl::ParameterSet ps;
00941 ps.put<int>("board_id", 1);
00942 ps.put<int>("fragment_id", 1);
00943 ps.put<int>("request_port", REQUEST_PORT);
00944 #if MULTICAST_MODE
00945 ps.put<std::string>("request_address", "227.18.12.32");
00946 #else
00947 ps.put<std::string>("request_address", "localhost");
00948 #endif
00949 ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
00950 ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 3);
00951 ps.put<bool>("separate_data_thread", true);
00952 ps.put<bool>("separate_monitoring_thread", false);
00953 ps.put<int64_t>("hardware_poll_interval_us", 0);
00954 ps.put<size_t>("data_buffer_depth_fragments", 5);
00955 ps.put<std::string>("request_mode", "window");
00956 ps.put("request_delay_ms", DELAY_TIME);
00957 ps.put("send_requests", true);
00958
00959 artdaq::RequestSender t(ps);
00960
00961 artdaqtest::CommandableFragmentGeneratorTest gen(ps);
00962 gen.StartCmd(1, 0xFFFFFFFF, 1);
00963
00964 artdaq::FragmentPtrs fps;
00965 int sts;
00966 artdaq::Fragment::type_t type;
00967 gen.waitForFrags();
00968
00969
00970
00971 gen.setFireCount(5);
00972 gen.waitForFrags();
00973 t.AddRequest(1, 3);
00974
00975 sts = gen.getNext(fps);
00976 BOOST_REQUIRE_EQUAL(sts, true);
00977 BOOST_REQUIRE_EQUAL(fps.size(), 1);
00978 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
00979 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 3);
00980 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
00981 type = artdaq::Fragment::ContainerFragmentType;
00982 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
00983 auto cf4 = artdaq::ContainerFragment(*fps.front());
00984 BOOST_REQUIRE_EQUAL(cf4.block_count(), 3);
00985 BOOST_REQUIRE_EQUAL(cf4.missing_data(), false);
00986 type = artdaq::Fragment::FirstUserFragmentType;
00987 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
00988
00989 gen.StopCmd(0xFFFFFFFF, 1);
00990 TLOG(TLVL_INFO) << "WindowMode_RequestInBuffer test case END" ;
00991
00992 }
00993 BOOST_AUTO_TEST_CASE(WindowMode_RequestEndsAfterBuffer)
00994 {
00995 artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
00996 TLOG(TLVL_INFO) << "WindowMode_RequestEndsAfterBuffer test case BEGIN" ;
00997 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
00998 const int DELAY_TIME = 100;
00999 fhicl::ParameterSet ps;
01000 ps.put<int>("board_id", 1);
01001 ps.put<int>("fragment_id", 1);
01002 ps.put<int>("request_port", REQUEST_PORT);
01003 #if MULTICAST_MODE
01004 ps.put<std::string>("request_address", "227.18.12.32");
01005 #else
01006 ps.put<std::string>("request_address", "localhost");
01007 #endif
01008 ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
01009 ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 3);
01010 ps.put<size_t>("window_close_timeout_us", 500000);
01011 ps.put<bool>("separate_data_thread", true);
01012 ps.put<bool>("separate_monitoring_thread", false);
01013 ps.put<int64_t>("hardware_poll_interval_us", 0);
01014 ps.put<size_t>("data_buffer_depth_fragments", 5);
01015 ps.put<std::string>("request_mode", "window");
01016 ps.put("request_delay_ms", DELAY_TIME);
01017 ps.put("send_requests", true);
01018
01019 artdaq::RequestSender t(ps);
01020
01021 artdaqtest::CommandableFragmentGeneratorTest gen(ps);
01022 gen.StartCmd(1, 0xFFFFFFFF, 1);
01023
01024 artdaq::FragmentPtrs fps;
01025 int sts;
01026 artdaq::Fragment::type_t type;
01027 gen.waitForFrags();
01028 gen.setFireCount(5);
01029 gen.waitForFrags();
01030
01031
01032
01033 t.AddRequest(1, 5);
01034 sts = gen.getNext(fps);
01035 BOOST_REQUIRE_EQUAL(sts, true);
01036 BOOST_REQUIRE_EQUAL(fps.size(), 0);
01037
01038 gen.setFireCount(2);
01039 gen.waitForFrags();
01040 sts = gen.getNext(fps);
01041 BOOST_REQUIRE_EQUAL(sts, true);
01042 BOOST_REQUIRE_EQUAL(fps.size(), 1);
01043 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
01044 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 5);
01045 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
01046 type = artdaq::Fragment::ContainerFragmentType;
01047 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
01048 auto cf = artdaq::ContainerFragment(*fps.front());
01049 BOOST_REQUIRE_EQUAL(cf.block_count(), 3);
01050 BOOST_REQUIRE_EQUAL(cf.missing_data(), false);
01051 type = artdaq::Fragment::FirstUserFragmentType;
01052 BOOST_REQUIRE_EQUAL(cf.fragment_type(), type);
01053 fps.clear();
01054
01055 t.AddRequest(2, 8);
01056
01057 sts = gen.getNext(fps);
01058 BOOST_REQUIRE_EQUAL(sts, true);
01059 BOOST_REQUIRE_EQUAL(fps.size(), 0);
01060
01061 usleep(550000);
01062
01063 sts = gen.getNext(fps);
01064 BOOST_REQUIRE_EQUAL(sts, true);
01065 BOOST_REQUIRE_EQUAL(fps.size(), 1);
01066 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
01067 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 8);
01068 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
01069 type = artdaq::Fragment::ContainerFragmentType;
01070 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
01071 auto cf4 = artdaq::ContainerFragment(*fps.front());
01072 BOOST_REQUIRE_EQUAL(cf4.block_count(), 1);
01073 BOOST_REQUIRE_EQUAL(cf4.missing_data(), true);
01074 type = artdaq::Fragment::FirstUserFragmentType;
01075 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
01076
01077 gen.StopCmd(0xFFFFFFFF, 1);
01078 gen.joinThreads();
01079 TLOG(TLVL_INFO) << "WindowMode_RequestEndsAfterBuffer test case END" ;
01080
01081 }
01082 BOOST_AUTO_TEST_CASE(WindowMode_RequestAfterBuffer)
01083 {
01084 artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
01085 TLOG(TLVL_INFO) << "WindowMode_RequestAfterBuffer test case BEGIN" ;
01086 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
01087 const int DELAY_TIME = 100;
01088 fhicl::ParameterSet ps;
01089 ps.put<int>("board_id", 1);
01090 ps.put<int>("fragment_id", 1);
01091 ps.put<int>("request_port", REQUEST_PORT);
01092 #if MULTICAST_MODE
01093 ps.put<std::string>("request_address", "227.18.12.32");
01094 #else
01095 ps.put<std::string>("request_address", "localhost");
01096 #endif
01097 ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
01098 ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 3);
01099 ps.put<size_t>("window_close_timeout_us", 500000);
01100 ps.put<bool>("separate_data_thread", true);
01101 ps.put<bool>("separate_monitoring_thread", false);
01102 ps.put<int64_t>("hardware_poll_interval_us", 0);
01103 ps.put<size_t>("data_buffer_depth_fragments", 5);
01104 ps.put<std::string>("request_mode", "window");
01105 ps.put("request_delay_ms", DELAY_TIME);
01106 ps.put("send_requests", true);
01107
01108 artdaq::RequestSender t(ps);
01109
01110 artdaqtest::CommandableFragmentGeneratorTest gen(ps);
01111 gen.StartCmd(1, 0xFFFFFFFF, 1);
01112
01113 artdaq::FragmentPtrs fps;
01114 int sts;
01115 artdaq::Fragment::type_t type;
01116 gen.waitForFrags();
01117
01118
01119
01120 gen.setFireCount(9);
01121 gen.waitForFrags();
01122 t.AddRequest(1, 11);
01123
01124 sts = gen.getNext(fps);
01125 BOOST_REQUIRE_EQUAL(sts, true);
01126 BOOST_REQUIRE_EQUAL(fps.size(), 0);
01127 gen.setFireCount(1);
01128 gen.waitForFrags();
01129 sts = gen.getNext(fps);
01130 BOOST_REQUIRE_EQUAL(sts, true);
01131 BOOST_REQUIRE_EQUAL(fps.size(), 0);
01132
01133 gen.setFireCount(3);
01134 gen.waitForFrags();
01135 sts = gen.getNext(fps);
01136 BOOST_REQUIRE_EQUAL(sts, true);
01137 BOOST_REQUIRE_EQUAL(fps.size(), 1);
01138 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
01139 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 11);
01140 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
01141 type = artdaq::Fragment::ContainerFragmentType;
01142 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
01143 auto cf = artdaq::ContainerFragment(*fps.front());
01144 BOOST_REQUIRE_EQUAL(cf.block_count(), 3);
01145 BOOST_REQUIRE_EQUAL(cf.missing_data(), false);
01146 type = artdaq::Fragment::FirstUserFragmentType;
01147 BOOST_REQUIRE_EQUAL(cf.fragment_type(), type);
01148 fps.clear();
01149
01150 t.AddRequest(2, 16);
01151 sts = gen.getNext(fps);
01152 BOOST_REQUIRE_EQUAL(sts, true);
01153 BOOST_REQUIRE_EQUAL(fps.size(), 0);
01154
01155 usleep(550000);
01156
01157 sts = gen.getNext(fps);
01158 BOOST_REQUIRE_EQUAL(sts, true);
01159 BOOST_REQUIRE_EQUAL(fps.size(), 1);
01160 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
01161 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 16);
01162 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
01163 type = artdaq::Fragment::ContainerFragmentType;
01164 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
01165 auto cf4 = artdaq::ContainerFragment(*fps.front());
01166 BOOST_REQUIRE_EQUAL(cf4.block_count(), 0);
01167 BOOST_REQUIRE_EQUAL(cf4.missing_data(), true);
01168 type = artdaq::Fragment::EmptyFragmentType;
01169 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
01170
01171 gen.StopCmd(0xFFFFFFFF, 1);
01172 gen.joinThreads();
01173 TLOG(TLVL_INFO) << "WindowMode_RequestAfterBuffer test case END" ;
01174
01175 }
01176
01177 BOOST_AUTO_TEST_CASE(HardwareFailure_NonThreaded)
01178 {
01179 artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
01180 TLOG(TLVL_INFO) << "HardwareFailure_NonThreaded test case BEGIN" ;
01181 fhicl::ParameterSet ps;
01182 ps.put<int>("board_id", 1);
01183 ps.put<int>("fragment_id", 1);
01184 ps.put<bool>("separate_data_thread", false);
01185 ps.put<bool>("separate_monitoring_thread", false);
01186 ps.put<int64_t>("hardware_poll_interval_us", 10);
01187
01188 artdaqtest::CommandableFragmentGeneratorTest gen(ps);
01189 gen.StartCmd(1, 0xFFFFFFFF, 1);
01190
01191 artdaq::FragmentPtrs fps;
01192 auto sts = gen.getNext(fps);
01193 BOOST_REQUIRE_EQUAL(sts, true);
01194 BOOST_REQUIRE_EQUAL(fps.size(), 1u);
01195 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
01196 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
01197 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
01198 fps.clear();
01199
01200 gen.setFireCount(1);
01201 gen.setHwFail();
01202 usleep(10000);
01203 sts = gen.getNext(fps);
01204 BOOST_REQUIRE_EQUAL(sts, false);
01205 BOOST_REQUIRE_EQUAL(fps.size(), 0);
01206
01207 gen.StopCmd(0xFFFFFFFF, 1);
01208 gen.joinThreads();
01209 TLOG(TLVL_INFO) << "HardwareFailure_NonThreaded test case END" ;
01210 }
01211
01212 BOOST_AUTO_TEST_CASE(HardwareFailure_Threaded)
01213 {
01214 artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
01215 TLOG(TLVL_INFO) << "HardwareFailure_Threaded test case BEGIN" ;
01216 fhicl::ParameterSet ps;
01217 ps.put<int>("board_id", 1);
01218 ps.put<int>("fragment_id", 1);
01219 ps.put<bool>("separate_data_thread", true);
01220 ps.put<bool>("separate_monitoring_thread", true);
01221 ps.put<int64_t>("hardware_poll_interval_us", 750000);
01222
01223 artdaqtest::CommandableFragmentGeneratorTest gen(ps);
01224 gen.StartCmd(1, 0xFFFFFFFF, 1);
01225
01226
01227
01228 artdaq::FragmentPtrs fps;
01229 auto sts = gen.getNext(fps);
01230 BOOST_REQUIRE_EQUAL(sts, true);
01231 BOOST_REQUIRE_EQUAL(fps.size(), 1u);
01232 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
01233 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
01234 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
01235 fps.clear();
01236
01237 gen.setHwFail();
01238
01239
01240
01241
01242
01243
01244
01245
01246
01247 sleep(1);
01248
01249 gen.setFireCount(1);
01250 sts = gen.getNext(fps);
01251 BOOST_REQUIRE_EQUAL(sts, false);
01252 BOOST_REQUIRE_EQUAL(fps.size(), 0);
01253
01254 gen.StopCmd(0xFFFFFFFF, 1);
01255 gen.joinThreads();
01256 TLOG(TLVL_INFO) << "HardwareFailure_Threaded test case END" ;
01257 }
01258
01259 BOOST_AUTO_TEST_SUITE_END()