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