$treeview $search $mathjax $extrastylesheet
artdaq
v3_04_01
$projectbrief
|
$projectbrief
|
$searchbox |
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.SetRunNumber(1); 00225 t.AddRequest(1, 1); 00226 00227 artdaqtest::CommandableFragmentGeneratorTest gen(ps); 00228 gen.StartCmd(1, 0xFFFFFFFF, 1); 00229 gen.waitForFrags(); 00230 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 1); 00231 00232 artdaq::FragmentPtrs fps; 00233 auto sts = gen.getNext(fps); 00234 auto type = artdaq::Fragment::FirstUserFragmentType; 00235 BOOST_REQUIRE_EQUAL(sts, true); 00236 BOOST_REQUIRE_EQUAL(fps.size(), 1u); 00237 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1); 00238 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1); 00239 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1); 00240 BOOST_REQUIRE_EQUAL(fps.front()->type(), type); 00241 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 2); 00242 fps.clear(); 00243 00244 t.AddRequest(2, 5); 00245 sts = gen.getNext(fps); 00246 BOOST_REQUIRE_EQUAL(sts, true); 00247 BOOST_REQUIRE_EQUAL(fps.size(), 1u); 00248 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1); 00249 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 5); 00250 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2); 00251 BOOST_REQUIRE_EQUAL(fps.front()->type(), type); 00252 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 3); 00253 fps.clear(); 00254 00255 gen.setFireCount(2); 00256 gen.waitForFrags(); 00257 t.AddRequest(4, 7); 00258 sts = gen.getNext(fps); 00259 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 5); 00260 BOOST_REQUIRE_EQUAL(sts, true); 00261 BOOST_REQUIRE_EQUAL(fps.size(), 2); 00262 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1); 00263 auto ts = artdaq::Fragment::InvalidTimestamp; 00264 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), ts); 00265 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 3); 00266 auto emptyType = artdaq::Fragment::EmptyFragmentType; 00267 BOOST_REQUIRE_EQUAL(fps.front()->type(), emptyType); 00268 fps.pop_front(); 00269 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1); 00270 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 7); 00271 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 4); 00272 BOOST_REQUIRE_EQUAL(fps.front()->type(), type); 00273 fps.clear(); 00274 00275 gen.StopCmd(0xFFFFFFFF, 1); 00276 gen.joinThreads(); 00277 TLOG(TLVL_INFO) << "SingleMode test case END" ; 00278 } 00279 00280 BOOST_AUTO_TEST_CASE(BufferMode) 00281 { 00282 artdaq::configureMessageFacility("CommandableFragmentGenerator_t"); 00283 TLOG(TLVL_INFO) << "BufferMode test case BEGIN" ; 00284 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024; 00285 const int DELAY_TIME = 100; 00286 fhicl::ParameterSet ps; 00287 ps.put<int>("board_id", 1); 00288 ps.put<int>("fragment_id", 1); 00289 ps.put<int>("request_port", REQUEST_PORT); 00290 #if MULTICAST_MODE 00291 ps.put<std::string>("request_address", "227.18.12.31"); 00292 #else 00293 ps.put<std::string>("request_address", "localhost"); 00294 #endif 00295 ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0); 00296 ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 0); 00297 ps.put<bool>("separate_data_thread", true); 00298 ps.put<bool>("separate_monitoring_thread", false); 00299 ps.put<int64_t>("hardware_poll_interval_us", 0); 00300 ps.put<std::string>("request_mode", "buffer"); 00301 ps.put("request_delay_ms", DELAY_TIME); 00302 ps.put("send_requests", true); 00303 00304 artdaq::RequestSender t(ps); 00305 t.SetRunNumber(1); 00306 t.AddRequest(1, 1); 00307 00308 artdaqtest::CommandableFragmentGeneratorTest gen(ps); 00309 gen.StartCmd(1, 0xFFFFFFFF, 1); 00310 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 1); 00311 00312 00313 artdaq::FragmentPtrs fps; 00314 auto sts = gen.getNext(fps); 00315 BOOST_REQUIRE_EQUAL(sts, true); 00316 BOOST_REQUIRE_EQUAL(fps.size(), 1u); 00317 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1); 00318 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1); 00319 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1); 00320 auto type = artdaq::Fragment::ContainerFragmentType; 00321 BOOST_REQUIRE_EQUAL(fps.front()->type(), type); 00322 BOOST_REQUIRE_GE(fps.front()->sizeBytes(), 2 * sizeof(artdaq::detail::RawFragmentHeader) + sizeof(artdaq::ContainerFragment::Metadata)); 00323 auto cf = artdaq::ContainerFragment(*fps.front()); 00324 BOOST_REQUIRE_EQUAL(cf.block_count(), 1); 00325 BOOST_REQUIRE_EQUAL(cf.missing_data(), false); 00326 type = artdaq::Fragment::FirstUserFragmentType; 00327 BOOST_REQUIRE_EQUAL(cf.fragment_type(), type); 00328 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 2); 00329 fps.clear(); 00330 00331 t.AddRequest(2, 5); 00332 sts = gen.getNext(fps); 00333 BOOST_REQUIRE_EQUAL(sts, true); 00334 BOOST_REQUIRE_EQUAL(fps.size(), 1u); 00335 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1); 00336 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 5); 00337 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2); 00338 type = artdaq::Fragment::ContainerFragmentType; 00339 BOOST_REQUIRE_EQUAL(fps.front()->type(), type); 00340 auto cf2 = artdaq::ContainerFragment(*fps.front()); 00341 BOOST_REQUIRE_EQUAL(cf2.block_count(), 0); 00342 BOOST_REQUIRE_EQUAL(cf2.missing_data(), false); 00343 type = artdaq::Fragment::EmptyFragmentType; 00344 BOOST_REQUIRE_EQUAL(cf2.fragment_type(), type); 00345 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 3); 00346 fps.clear(); 00347 00348 gen.setFireCount(2); 00349 gen.waitForFrags(); 00350 t.AddRequest(4, 7); 00351 sts = gen.getNext(fps); 00352 BOOST_REQUIRE_EQUAL(sts, true); 00353 BOOST_REQUIRE_EQUAL(fps.size(), 2); 00354 00355 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1); 00356 auto ts = artdaq::Fragment::InvalidTimestamp; 00357 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), ts); 00358 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 3); 00359 auto emptyType = artdaq::Fragment::EmptyFragmentType; 00360 BOOST_REQUIRE_EQUAL(fps.front()->type(), emptyType); 00361 BOOST_REQUIRE_EQUAL(fps.front()->size(), artdaq::detail::RawFragmentHeader::num_words()); 00362 fps.pop_front(); 00363 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1); 00364 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 7); 00365 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 4); 00366 type = artdaq::Fragment::ContainerFragmentType; 00367 BOOST_REQUIRE_EQUAL(fps.front()->type(), type); 00368 auto cf3 = artdaq::ContainerFragment(*fps.front()); 00369 BOOST_REQUIRE_EQUAL(cf3.block_count(), 2); 00370 BOOST_REQUIRE_EQUAL(cf3.missing_data(), false); 00371 type = artdaq::Fragment::FirstUserFragmentType; 00372 BOOST_REQUIRE_EQUAL(cf3.fragment_type(), type); 00373 fps.clear(); 00374 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 5); 00375 00376 00377 gen.StopCmd(0xFFFFFFFF, 1); 00378 gen.joinThreads(); 00379 00380 00381 TLOG(TLVL_INFO) << "BufferMode test case END" ; 00382 } 00383 00384 BOOST_AUTO_TEST_CASE(CircularBufferMode) 00385 { 00386 artdaq::configureMessageFacility("CommandableFragmentGenerator_t"); 00387 TLOG(TLVL_INFO) << "CircularBufferMode test case BEGIN"; 00388 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024; 00389 const int DELAY_TIME = 100; 00390 fhicl::ParameterSet ps; 00391 ps.put<int>("board_id", 1); 00392 ps.put<int>("fragment_id", 1); 00393 ps.put<int>("request_port", REQUEST_PORT); 00394 #if MULTICAST_MODE 00395 ps.put<std::string>("request_address", "227.18.12.31"); 00396 #else 00397 ps.put<std::string>("request_address", "localhost"); 00398 #endif 00399 ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0); 00400 ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 0); 00401 ps.put<bool>("separate_data_thread", true); 00402 ps.put<bool>("circular_buffer_mode", true); 00403 ps.put<int>("data_buffer_depth_fragments", 3); 00404 ps.put<bool>("separate_monitoring_thread", false); 00405 ps.put<int64_t>("hardware_poll_interval_us", 0); 00406 ps.put<std::string>("request_mode", "buffer"); 00407 ps.put("request_delay_ms", DELAY_TIME); 00408 ps.put("send_requests", true); 00409 00410 artdaq::RequestSender t(ps); 00411 t.SetRunNumber(1); 00412 t.AddRequest(1, 1); 00413 00414 artdaqtest::CommandableFragmentGeneratorTest gen(ps); 00415 gen.StartCmd(1, 0xFFFFFFFF, 1); 00416 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 1); 00417 00418 00419 artdaq::FragmentPtrs fps; 00420 auto sts = gen.getNext(fps); 00421 BOOST_REQUIRE_EQUAL(sts, true); 00422 BOOST_REQUIRE_EQUAL(fps.size(), 1u); 00423 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1); 00424 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1); 00425 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1); 00426 auto type = artdaq::Fragment::ContainerFragmentType; 00427 BOOST_REQUIRE_EQUAL(fps.front()->type(), type); 00428 BOOST_REQUIRE_GE(fps.front()->sizeBytes(), 2 * sizeof(artdaq::detail::RawFragmentHeader) + sizeof(artdaq::ContainerFragment::Metadata)); 00429 auto cf = artdaq::ContainerFragment(*fps.front()); 00430 BOOST_REQUIRE_EQUAL(cf.block_count(), 1); 00431 BOOST_REQUIRE_EQUAL(cf.missing_data(), false); 00432 type = artdaq::Fragment::FirstUserFragmentType; 00433 BOOST_REQUIRE_EQUAL(cf.fragment_type(), type); 00434 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 2); 00435 fps.clear(); 00436 00437 t.AddRequest(2, 5); 00438 sts = gen.getNext(fps); 00439 BOOST_REQUIRE_EQUAL(sts, true); 00440 BOOST_REQUIRE_EQUAL(fps.size(), 1u); 00441 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1); 00442 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 5); 00443 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2); 00444 type = artdaq::Fragment::ContainerFragmentType; 00445 BOOST_REQUIRE_EQUAL(fps.front()->type(), type); 00446 auto cf2 = artdaq::ContainerFragment(*fps.front()); 00447 BOOST_REQUIRE_EQUAL(cf2.block_count(), 0); 00448 BOOST_REQUIRE_EQUAL(cf2.missing_data(), false); 00449 type = artdaq::Fragment::EmptyFragmentType; 00450 BOOST_REQUIRE_EQUAL(cf2.fragment_type(), type); 00451 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 3); 00452 fps.clear(); 00453 00454 gen.setFireCount(3); 00455 gen.waitForFrags(); 00456 t.AddRequest(4, 7); 00457 sts = gen.getNext(fps); 00458 BOOST_REQUIRE_EQUAL(sts, true); 00459 BOOST_REQUIRE_EQUAL(fps.size(), 2); 00460 00461 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1); 00462 auto ts = artdaq::Fragment::InvalidTimestamp; 00463 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), ts); 00464 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 3); 00465 auto emptyType = artdaq::Fragment::EmptyFragmentType; 00466 BOOST_REQUIRE_EQUAL(fps.front()->type(), emptyType); 00467 BOOST_REQUIRE_EQUAL(fps.front()->size(), artdaq::detail::RawFragmentHeader::num_words()); 00468 fps.pop_front(); 00469 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1); 00470 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 7); 00471 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 4); 00472 type = artdaq::Fragment::ContainerFragmentType; 00473 BOOST_REQUIRE_EQUAL(fps.front()->type(), type); 00474 auto cf3 = artdaq::ContainerFragment(*fps.front()); 00475 BOOST_REQUIRE_EQUAL(cf3.block_count(), 3); 00476 BOOST_REQUIRE_EQUAL(cf3.missing_data(), false); 00477 type = artdaq::Fragment::FirstUserFragmentType; 00478 BOOST_REQUIRE_EQUAL(cf3.fragment_type(), type); 00479 fps.clear(); 00480 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 5); 00481 00482 00483 00484 gen.setFireCount(5); 00485 gen.waitForFrags(); 00486 t.AddRequest(5, 8); 00487 sts = gen.getNext(fps); 00488 BOOST_REQUIRE_EQUAL(sts, true); 00489 BOOST_REQUIRE_EQUAL(fps.size(), 1); 00490 00491 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1); 00492 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 8); 00493 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 5); 00494 type = artdaq::Fragment::ContainerFragmentType; 00495 BOOST_REQUIRE_EQUAL(fps.front()->type(), type); 00496 auto cf4 = artdaq::ContainerFragment(*fps.front()); 00497 BOOST_REQUIRE_EQUAL(cf4.block_count(), 3); 00498 BOOST_REQUIRE_EQUAL(cf4.missing_data(), false); 00499 type = artdaq::Fragment::FirstUserFragmentType; 00500 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type); 00501 BOOST_REQUIRE_EQUAL(cf4.at(0)->timestamp(), 7); 00502 BOOST_REQUIRE_EQUAL(cf4.at(1)->timestamp(), 8); 00503 BOOST_REQUIRE_EQUAL(cf4.at(2)->timestamp(), 9); 00504 fps.clear(); 00505 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 6); 00506 00507 00508 gen.StopCmd(0xFFFFFFFF, 1); 00509 gen.joinThreads(); 00510 00511 00512 TLOG(TLVL_INFO) << "CircularBufferMode test case END"; 00513 } 00514 00515 BOOST_AUTO_TEST_CASE(WindowMode_Function) 00516 { 00517 artdaq::configureMessageFacility("CommandableFragmentGenerator_t"); 00518 TLOG(TLVL_INFO) << "WindowMode_Function test case BEGIN" ; 00519 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024; 00520 const int DELAY_TIME = 100; 00521 fhicl::ParameterSet ps; 00522 ps.put<int>("board_id", 1); 00523 ps.put<int>("fragment_id", 1); 00524 ps.put<int>("request_port", REQUEST_PORT); 00525 #if MULTICAST_MODE 00526 ps.put<std::string>("request_address", "227.18.12.32"); 00527 #else 00528 ps.put<std::string>("request_address", "localhost"); 00529 #endif 00530 ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0); 00531 ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 0); 00532 ps.put<bool>("separate_data_thread", true); 00533 ps.put<bool>("separate_monitoring_thread", false); 00534 ps.put<int64_t>("hardware_poll_interval_us", 0); 00535 ps.put<size_t>("data_buffer_depth_fragments", 5); 00536 ps.put<std::string>("request_mode", "window"); 00537 ps.put<size_t>("missing_request_window_timeout_us", 500000); 00538 ps.put<size_t>("window_close_timeout_us", 500000); 00539 ps.put("request_delay_ms", DELAY_TIME); 00540 ps.put("send_requests", true); 00541 00542 artdaq::RequestSender t(ps); 00543 t.SetRunNumber(1); 00544 t.AddRequest(1, 1); 00545 00546 artdaqtest::CommandableFragmentGeneratorTest gen(ps); 00547 gen.StartCmd(1, 0xFFFFFFFF, 1); 00548 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 1); 00549 00550 artdaq::FragmentPtrs fps; 00551 auto sts = gen.getNext(fps); 00552 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 2); 00553 BOOST_REQUIRE_EQUAL(sts, true); 00554 BOOST_REQUIRE_EQUAL(fps.size(), 1u); 00555 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1); 00556 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1); 00557 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1); 00558 auto type = artdaq::Fragment::ContainerFragmentType; 00559 BOOST_REQUIRE_EQUAL(fps.front()->type(), type); 00560 BOOST_REQUIRE_GE(fps.front()->sizeBytes(), 2 * sizeof(artdaq::detail::RawFragmentHeader) + sizeof(artdaq::ContainerFragment::Metadata)); 00561 auto cf = artdaq::ContainerFragment(*fps.front()); 00562 BOOST_REQUIRE_EQUAL(cf.block_count(), 1); 00563 BOOST_REQUIRE_EQUAL(cf.missing_data(), false); 00564 type = artdaq::Fragment::FirstUserFragmentType; 00565 BOOST_REQUIRE_EQUAL(cf.fragment_type(), type); 00566 fps.clear(); 00567 00568 // No data for request 00569 t.AddRequest(2, 2); 00570 sts = gen.getNext(fps); 00571 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 2); 00572 BOOST_REQUIRE_EQUAL(sts, true); 00573 BOOST_REQUIRE_EQUAL(fps.size(), 0); 00574 00575 gen.setFireCount(1); 00576 gen.waitForFrags(); 00577 sts = gen.getNext(fps); 00578 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 3); 00579 BOOST_REQUIRE_EQUAL(sts, true); 00580 BOOST_REQUIRE_EQUAL(fps.size(), 1); 00581 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1); 00582 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 2); 00583 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2); 00584 type = artdaq::Fragment::ContainerFragmentType; 00585 BOOST_REQUIRE_EQUAL(fps.front()->type(), type); 00586 auto cf2 = artdaq::ContainerFragment(*fps.front()); 00587 BOOST_REQUIRE_EQUAL(cf2.block_count(), 1); 00588 BOOST_REQUIRE_EQUAL(cf2.missing_data(), false); 00589 type = artdaq::Fragment::FirstUserFragmentType; 00590 BOOST_REQUIRE_EQUAL(cf2.fragment_type(), type); 00591 fps.clear(); 00592 00593 // Request Timeout 00594 t.AddRequest(4, 3); 00595 sts = gen.getNext(fps); 00596 BOOST_REQUIRE_EQUAL(sts, true); 00597 BOOST_REQUIRE_EQUAL(fps.size(), 0); 00598 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 3); 00599 00600 00601 usleep(1500000); 00602 sts = gen.getNext(fps); 00603 BOOST_REQUIRE_EQUAL(sts, true); 00604 BOOST_REQUIRE_EQUAL(fps.size(), 1); 00605 00606 // Also, missing request timeout 00607 auto list = gen.getOutOfOrderWindowList(); 00608 BOOST_REQUIRE_EQUAL(list.size(), 1); 00609 BOOST_REQUIRE_EQUAL(list.begin()->first, 4); 00610 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 3); 00611 00612 usleep(1500000); 00613 00614 00615 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1); 00616 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 3); 00617 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 4); 00618 type = artdaq::Fragment::ContainerFragmentType; 00619 BOOST_REQUIRE_EQUAL(fps.front()->type(), type); 00620 auto cf3 = artdaq::ContainerFragment(*fps.front()); 00621 BOOST_REQUIRE_EQUAL(cf3.block_count(), 0); 00622 BOOST_REQUIRE_EQUAL(cf3.missing_data(), true); 00623 type = artdaq::Fragment::EmptyFragmentType; 00624 BOOST_REQUIRE_EQUAL(cf3.fragment_type(), type); 00625 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 3); 00626 fps.clear(); 00627 00628 // Data-taking has passed request 00629 gen.setFireCount(12); 00630 gen.waitForFrags(); 00631 t.AddRequest(5, 4); 00632 list = gen.getOutOfOrderWindowList(); // Out-of-order list is only updated in getNext calls 00633 BOOST_REQUIRE_EQUAL(list.size(), 1); 00634 sts = gen.getNext(fps); 00635 list = gen.getOutOfOrderWindowList(); // Out-of-order list is only updated in getNext calls 00636 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 6); 00637 BOOST_REQUIRE_EQUAL(list.size(), 0); 00638 BOOST_REQUIRE_EQUAL(sts, true); 00639 BOOST_REQUIRE_EQUAL(fps.size(), 1); 00640 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1); 00641 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 4); 00642 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 5); 00643 type = artdaq::Fragment::ContainerFragmentType; 00644 BOOST_REQUIRE_EQUAL(fps.front()->type(), type); 00645 auto cf4 = artdaq::ContainerFragment(*fps.front()); 00646 BOOST_REQUIRE_EQUAL(cf4.block_count(), 0); 00647 BOOST_REQUIRE_EQUAL(cf4.missing_data(), true); 00648 type = artdaq::Fragment::EmptyFragmentType; 00649 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type); 00650 fps.clear(); 00651 00652 00653 // Out-of-order windows 00654 t.AddRequest(7, 13); 00655 sts = gen.getNext(fps); 00656 BOOST_REQUIRE_EQUAL(sts, true); 00657 BOOST_REQUIRE_EQUAL(fps.size(), 1); 00658 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1); 00659 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 13); 00660 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 7); 00661 type = artdaq::Fragment::ContainerFragmentType; 00662 BOOST_REQUIRE_EQUAL(fps.front()->type(), type); 00663 auto cf5 = artdaq::ContainerFragment(*fps.front()); 00664 BOOST_REQUIRE_EQUAL(cf5.block_count(), 1); 00665 BOOST_REQUIRE_EQUAL(cf5.missing_data(), false); 00666 type = artdaq::Fragment::FirstUserFragmentType; 00667 BOOST_REQUIRE_EQUAL(cf5.fragment_type(), type); 00668 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 6); 00669 fps.clear(); 00670 00671 list = gen.getOutOfOrderWindowList(); 00672 BOOST_REQUIRE_EQUAL(list.size(), 1); 00673 BOOST_REQUIRE_EQUAL(list.begin()->first, 7); 00674 00675 t.AddRequest(6, 12); 00676 sts = gen.getNext(fps); 00677 BOOST_REQUIRE_EQUAL(sts, true); 00678 BOOST_REQUIRE_EQUAL(fps.size(), 1); 00679 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1); 00680 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 12); 00681 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 6); 00682 type = artdaq::Fragment::ContainerFragmentType; 00683 BOOST_REQUIRE_EQUAL(fps.front()->type(), type); 00684 auto cf6 = artdaq::ContainerFragment(*fps.front()); 00685 BOOST_REQUIRE_EQUAL(cf6.block_count(), 1); 00686 BOOST_REQUIRE_EQUAL(cf6.missing_data(), false); 00687 type = artdaq::Fragment::FirstUserFragmentType; 00688 BOOST_REQUIRE_EQUAL(cf6.fragment_type(), type); 00689 fps.clear(); 00690 BOOST_REQUIRE_EQUAL(gen.ev_counter(), 8); 00691 00692 list = gen.getOutOfOrderWindowList(); 00693 BOOST_REQUIRE_EQUAL(list.size(), 0); 00694 00695 usleep(1500000); 00696 00697 gen.StopCmd(0xFFFFFFFF, 1); 00698 TLOG(TLVL_INFO) << "WindowMode_Function test case END" ; 00699 gen.joinThreads(); 00700 00701 } 00702 00703 // 1. Both start and end before any data in buffer "RequestBeforeBuffer" 00704 // 2. Start before buffer, end in buffer "RequestStartsBeforeBuffer" 00705 // 3. Start befoer buffer, end after buffer "RequestOutsideBuffer" 00706 // 4. Start and end in buffer "RequestInBuffer" 00707 // 5. Start in buffer, end after buffer "RequestEndsAfterBuffer" 00708 // 6. Start and end after buffer "RequestAfterBuffer" 00709 BOOST_AUTO_TEST_CASE(WindowMode_RequestBeforeBuffer) 00710 { 00711 artdaq::configureMessageFacility("CommandableFragmentGenerator_t"); 00712 TLOG(TLVL_INFO) << "WindowMode_RequestBeforeBuffer test case BEGIN" ; 00713 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024; 00714 const int DELAY_TIME = 100; 00715 fhicl::ParameterSet ps; 00716 ps.put<int>("board_id", 1); 00717 ps.put<int>("fragment_id", 1); 00718 ps.put<int>("request_port", REQUEST_PORT); 00719 #if MULTICAST_MODE 00720 ps.put<std::string>("request_address", "227.18.12.32"); 00721 #else 00722 ps.put<std::string>("request_address", "localhost"); 00723 #endif 00724 ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0); 00725 ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 3); 00726 ps.put<bool>("separate_data_thread", true); 00727 ps.put<bool>("separate_monitoring_thread", false); 00728 ps.put<int64_t>("hardware_poll_interval_us", 0); 00729 ps.put<size_t>("data_buffer_depth_fragments", 5); 00730 ps.put<std::string>("request_mode", "window"); 00731 ps.put("request_delay_ms", DELAY_TIME); 00732 ps.put("send_requests", true); 00733 00734 artdaq::RequestSender t(ps); 00735 t.SetRunNumber(1); 00736 00737 artdaqtest::CommandableFragmentGeneratorTest gen(ps); 00738 gen.StartCmd(1, 0xFFFFFFFF, 1); 00739 00740 artdaq::FragmentPtrs fps; 00741 int sts; 00742 artdaq::Fragment::type_t type; 00743 00744 // 1. Both start and end before any data in buffer 00745 // -- Should return ContainerFragment with MissingData bit set and zero Fragments 00746 gen.setFireCount(9); // Buffer start is at ts 6, end at 10 00747 gen.waitForFrags(); 00748 t.AddRequest(1, 1); // Requesting data from ts 1 to 3 00749 00750 sts = gen.getNext(fps); 00751 BOOST_REQUIRE_EQUAL(sts, true); 00752 BOOST_REQUIRE_EQUAL(fps.size(), 1); 00753 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1); 00754 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1); 00755 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1); 00756 type = artdaq::Fragment::ContainerFragmentType; 00757 BOOST_REQUIRE_EQUAL(fps.front()->type(), type); 00758 auto cf4 = artdaq::ContainerFragment(*fps.front()); 00759 BOOST_REQUIRE_EQUAL(cf4.block_count(), 0); 00760 BOOST_REQUIRE_EQUAL(cf4.missing_data(), true); 00761 type = artdaq::Fragment::EmptyFragmentType; 00762 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type); 00763 00764 gen.StopCmd(0xFFFFFFFF, 1); 00765 TLOG(TLVL_INFO) << "WindowMode_RequestBeforeBuffer test case END" ; 00766 00767 } 00768 BOOST_AUTO_TEST_CASE(WindowMode_RequestStartsBeforeBuffer) 00769 { 00770 artdaq::configureMessageFacility("CommandableFragmentGenerator_t"); 00771 TLOG(TLVL_INFO) << "WindowMode_RequestStartsBeforeBuffer test case BEGIN" ; 00772 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024; 00773 const int DELAY_TIME = 100; 00774 fhicl::ParameterSet ps; 00775 ps.put<int>("board_id", 1); 00776 ps.put<int>("fragment_id", 1); 00777 ps.put<int>("request_port", REQUEST_PORT); 00778 #if MULTICAST_MODE 00779 ps.put<std::string>("request_address", "227.18.12.32"); 00780 #else 00781 ps.put<std::string>("request_address", "localhost"); 00782 #endif 00783 ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0); 00784 ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 3); 00785 ps.put<bool>("separate_data_thread", true); 00786 ps.put<bool>("separate_monitoring_thread", false); 00787 ps.put<int64_t>("hardware_poll_interval_us", 0); 00788 ps.put<size_t>("data_buffer_depth_fragments", 5); 00789 ps.put<std::string>("request_mode", "window"); 00790 ps.put("request_delay_ms", DELAY_TIME); 00791 ps.put("send_requests", true); 00792 00793 artdaq::RequestSender t(ps); 00794 t.SetRunNumber(1); 00795 00796 artdaqtest::CommandableFragmentGeneratorTest gen(ps); 00797 gen.StartCmd(1, 0xFFFFFFFF, 1); 00798 00799 artdaq::FragmentPtrs fps; 00800 int sts; 00801 artdaq::Fragment::type_t type; 00802 00803 gen.waitForFrags(); 00804 gen.setFireCount(9); // Buffer contains 6 to 10 00805 gen.waitForFrags(); 00806 00807 // 2. Start before buffer, end in buffer 00808 // -- Should return ContainerFragment with MissingData bit set and one or more Fragments 00809 t.AddRequest(1, 4); // Requesting data from ts 4 to 6 00810 00811 sts = gen.getNext(fps); 00812 BOOST_REQUIRE_EQUAL(sts, true); 00813 BOOST_REQUIRE_EQUAL(fps.size(), 1); 00814 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1); 00815 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 4); 00816 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1); 00817 type = artdaq::Fragment::ContainerFragmentType; 00818 BOOST_REQUIRE_EQUAL(fps.front()->type(), type); 00819 auto cf4 = artdaq::ContainerFragment(*fps.front()); 00820 BOOST_REQUIRE_EQUAL(cf4.block_count(), 1); 00821 BOOST_REQUIRE_EQUAL(cf4.missing_data(), true); 00822 type = artdaq::Fragment::FirstUserFragmentType; 00823 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type); 00824 00825 gen.StopCmd(0xFFFFFFFF, 1); 00826 gen.joinThreads(); 00827 TLOG(TLVL_INFO) << "WindowMode_RequestStartsBeforeBuffer test case END" ; 00828 00829 } 00830 BOOST_AUTO_TEST_CASE(WindowMode_RequestOutsideBuffer) 00831 { 00832 artdaq::configureMessageFacility("CommandableFragmentGenerator_t"); 00833 TLOG(TLVL_INFO) << "WindowMode_RequestOutsideBuffer test case BEGIN" ; 00834 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024; 00835 const int DELAY_TIME = 100; 00836 fhicl::ParameterSet ps; 00837 ps.put<int>("board_id", 1); 00838 ps.put<int>("fragment_id", 1); 00839 ps.put<int>("request_port", REQUEST_PORT); 00840 #if MULTICAST_MODE 00841 ps.put<std::string>("request_address", "227.18.12.32"); 00842 #else 00843 ps.put<std::string>("request_address", "localhost"); 00844 #endif 00845 ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0); 00846 ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 4); 00847 ps.put<size_t>("window_close_timeout_us", 500000); 00848 ps.put<bool>("separate_data_thread", true); 00849 ps.put<bool>("separate_monitoring_thread", false); 00850 ps.put<int64_t>("hardware_poll_interval_us", 0); 00851 ps.put<size_t>("data_buffer_depth_fragments", 5); 00852 ps.put<std::string>("request_mode", "window"); 00853 ps.put("request_delay_ms", DELAY_TIME); 00854 ps.put("send_requests", true); 00855 00856 artdaq::RequestSender t(ps); 00857 t.SetRunNumber(1); 00858 00859 artdaqtest::CommandableFragmentGeneratorTest gen(ps); 00860 gen.StartCmd(1, 0xFFFFFFFF, 1); 00861 00862 artdaq::FragmentPtrs fps; 00863 int sts; 00864 artdaq::Fragment::type_t type; 00865 00866 gen.waitForFrags(); 00867 gen.setFireCount(9); // Buffer contains 6 to 10 00868 gen.waitForFrags(); 00869 00870 // 3. Start before buffer, end after buffer 00871 // -- Should not return until buffer passes end or timeout (check both cases), MissingData bit set 00872 00873 t.AddRequest(1, 6); // Requesting data from ts 6 to 9, buffer will contain 10 00874 sts = gen.getNext(fps); 00875 BOOST_REQUIRE_EQUAL(sts, true); 00876 BOOST_REQUIRE_EQUAL(fps.size(), 1); 00877 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1); 00878 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 6); 00879 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1); 00880 type = artdaq::Fragment::ContainerFragmentType; 00881 BOOST_REQUIRE_EQUAL(fps.front()->type(), type); 00882 auto cf = artdaq::ContainerFragment(*fps.front()); 00883 BOOST_REQUIRE_EQUAL(cf.block_count(), 4); 00884 BOOST_REQUIRE_EQUAL(cf.missing_data(), false); 00885 type = artdaq::Fragment::FirstUserFragmentType; 00886 BOOST_REQUIRE_EQUAL(cf.fragment_type(), type); 00887 fps.clear(); 00888 00889 t.AddRequest(2, 9); // Requesting data from ts 9 to 12 00890 sts = gen.getNext(fps); 00891 BOOST_REQUIRE_EQUAL(sts, true); 00892 BOOST_REQUIRE_EQUAL(fps.size(), 0); 00893 00894 gen.setFireCount(3); // Buffer start is at ts 10, end at 13 00895 gen.waitForFrags(); 00896 00897 sts = gen.getNext(fps); 00898 BOOST_REQUIRE_EQUAL(sts, true); 00899 BOOST_REQUIRE_EQUAL(fps.size(), 1); 00900 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1); 00901 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 9); 00902 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2); 00903 type = artdaq::Fragment::ContainerFragmentType; 00904 BOOST_REQUIRE_EQUAL(fps.front()->type(), type); 00905 auto cf2 = artdaq::ContainerFragment(*fps.front()); 00906 BOOST_REQUIRE_EQUAL(cf2.block_count(), 3); 00907 BOOST_REQUIRE_EQUAL(cf2.missing_data(), true); 00908 type = artdaq::Fragment::FirstUserFragmentType; 00909 BOOST_REQUIRE_EQUAL(cf2.fragment_type(), type); 00910 fps.clear(); 00911 00912 00913 00914 t.AddRequest(3, 12); // Requesting data from ts 11 to 14 00915 00916 sts = gen.getNext(fps); 00917 BOOST_REQUIRE_EQUAL(sts, true); 00918 BOOST_REQUIRE_EQUAL(fps.size(), 0); 00919 00920 usleep(550000); 00921 00922 sts = gen.getNext(fps); 00923 BOOST_REQUIRE_EQUAL(sts, true); 00924 BOOST_REQUIRE_EQUAL(fps.size(), 1); 00925 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1); 00926 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 12); 00927 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 3); 00928 type = artdaq::Fragment::ContainerFragmentType; 00929 BOOST_REQUIRE_EQUAL(fps.front()->type(), type); 00930 auto cf4 = artdaq::ContainerFragment(*fps.front()); 00931 BOOST_REQUIRE_EQUAL(cf4.block_count(), 1); 00932 BOOST_REQUIRE_EQUAL(cf4.missing_data(), true); 00933 type = artdaq::Fragment::FirstUserFragmentType; 00934 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type); 00935 00936 gen.StopCmd(0xFFFFFFFF, 1); 00937 gen.joinThreads(); 00938 TLOG(TLVL_INFO) << "WindowMode_RequestOutsideBuffer test case END" ; 00939 00940 } 00941 BOOST_AUTO_TEST_CASE(WindowMode_RequestInBuffer) 00942 { 00943 artdaq::configureMessageFacility("CommandableFragmentGenerator_t"); 00944 TLOG(TLVL_INFO) << "WindowMode_RequestInBuffer test case BEGIN" ; 00945 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024; 00946 const int DELAY_TIME = 100; 00947 fhicl::ParameterSet ps; 00948 ps.put<int>("board_id", 1); 00949 ps.put<int>("fragment_id", 1); 00950 ps.put<int>("request_port", REQUEST_PORT); 00951 #if MULTICAST_MODE 00952 ps.put<std::string>("request_address", "227.18.12.32"); 00953 #else 00954 ps.put<std::string>("request_address", "localhost"); 00955 #endif 00956 ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0); 00957 ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 3); 00958 ps.put<bool>("separate_data_thread", true); 00959 ps.put<bool>("separate_monitoring_thread", false); 00960 ps.put<int64_t>("hardware_poll_interval_us", 0); 00961 ps.put<size_t>("data_buffer_depth_fragments", 5); 00962 ps.put<std::string>("request_mode", "window"); 00963 ps.put("request_delay_ms", DELAY_TIME); 00964 ps.put("send_requests", true); 00965 00966 artdaq::RequestSender t(ps); 00967 t.SetRunNumber(1); 00968 00969 artdaqtest::CommandableFragmentGeneratorTest gen(ps); 00970 gen.StartCmd(1, 0xFFFFFFFF, 1); 00971 00972 artdaq::FragmentPtrs fps; 00973 int sts; 00974 artdaq::Fragment::type_t type; 00975 gen.waitForFrags(); 00976 00977 // 4. Start and end in buffer 00978 // -- Should return ContainerFragment with one or more Fragments 00979 gen.setFireCount(5); // Buffer start is at ts 2, end at 6 00980 gen.waitForFrags(); 00981 t.AddRequest(1, 3); // Requesting data from ts 3 to 5 00982 00983 sts = gen.getNext(fps); 00984 BOOST_REQUIRE_EQUAL(sts, true); 00985 BOOST_REQUIRE_EQUAL(fps.size(), 1); 00986 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1); 00987 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 3); 00988 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1); 00989 type = artdaq::Fragment::ContainerFragmentType; 00990 BOOST_REQUIRE_EQUAL(fps.front()->type(), type); 00991 auto cf4 = artdaq::ContainerFragment(*fps.front()); 00992 BOOST_REQUIRE_EQUAL(cf4.block_count(), 3); 00993 BOOST_REQUIRE_EQUAL(cf4.missing_data(), false); 00994 type = artdaq::Fragment::FirstUserFragmentType; 00995 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type); 00996 00997 gen.StopCmd(0xFFFFFFFF, 1); 00998 TLOG(TLVL_INFO) << "WindowMode_RequestInBuffer test case END" ; 00999 01000 } 01001 BOOST_AUTO_TEST_CASE(WindowMode_RequestEndsAfterBuffer) 01002 { 01003 artdaq::configureMessageFacility("CommandableFragmentGenerator_t"); 01004 TLOG(TLVL_INFO) << "WindowMode_RequestEndsAfterBuffer test case BEGIN" ; 01005 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024; 01006 const int DELAY_TIME = 100; 01007 fhicl::ParameterSet ps; 01008 ps.put<int>("board_id", 1); 01009 ps.put<int>("fragment_id", 1); 01010 ps.put<int>("request_port", REQUEST_PORT); 01011 #if MULTICAST_MODE 01012 ps.put<std::string>("request_address", "227.18.12.32"); 01013 #else 01014 ps.put<std::string>("request_address", "localhost"); 01015 #endif 01016 ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0); 01017 ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 3); 01018 ps.put<size_t>("window_close_timeout_us", 500000); 01019 ps.put<bool>("separate_data_thread", true); 01020 ps.put<bool>("separate_monitoring_thread", false); 01021 ps.put<int64_t>("hardware_poll_interval_us", 0); 01022 ps.put<size_t>("data_buffer_depth_fragments", 5); 01023 ps.put<std::string>("request_mode", "window"); 01024 ps.put("request_delay_ms", DELAY_TIME); 01025 ps.put("send_requests", true); 01026 01027 artdaq::RequestSender t(ps); 01028 t.SetRunNumber(1); 01029 01030 artdaqtest::CommandableFragmentGeneratorTest gen(ps); 01031 gen.StartCmd(1, 0xFFFFFFFF, 1); 01032 01033 artdaq::FragmentPtrs fps; 01034 int sts; 01035 artdaq::Fragment::type_t type; 01036 gen.waitForFrags(); 01037 gen.setFireCount(5); // Buffer contains 2 to 6 01038 gen.waitForFrags(); 01039 01040 // 5. Start in buffer, end after buffer 01041 // -- Should not return until buffer passes end or timeout (check both cases). MissingData bit set if timeout 01042 t.AddRequest(1, 5); // Requesting data from ts 5 to 7 01043 sts = gen.getNext(fps); 01044 BOOST_REQUIRE_EQUAL(sts, true); 01045 BOOST_REQUIRE_EQUAL(fps.size(), 0); 01046 01047 gen.setFireCount(2); // Buffer contains 4 to 8 01048 gen.waitForFrags(); 01049 sts = gen.getNext(fps); 01050 BOOST_REQUIRE_EQUAL(sts, true); 01051 BOOST_REQUIRE_EQUAL(fps.size(), 1); 01052 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1); 01053 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 5); 01054 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1); 01055 type = artdaq::Fragment::ContainerFragmentType; 01056 BOOST_REQUIRE_EQUAL(fps.front()->type(), type); 01057 auto cf = artdaq::ContainerFragment(*fps.front()); 01058 BOOST_REQUIRE_EQUAL(cf.block_count(), 3); 01059 BOOST_REQUIRE_EQUAL(cf.missing_data(), false); 01060 type = artdaq::Fragment::FirstUserFragmentType; 01061 BOOST_REQUIRE_EQUAL(cf.fragment_type(), type); 01062 fps.clear(); 01063 01064 t.AddRequest(2, 8); // Requesting data from ts 8 to 10 01065 01066 sts = gen.getNext(fps); 01067 BOOST_REQUIRE_EQUAL(sts, true); 01068 BOOST_REQUIRE_EQUAL(fps.size(), 0); 01069 01070 usleep(550000); 01071 01072 sts = gen.getNext(fps); 01073 BOOST_REQUIRE_EQUAL(sts, true); 01074 BOOST_REQUIRE_EQUAL(fps.size(), 1); 01075 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1); 01076 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 8); 01077 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2); 01078 type = artdaq::Fragment::ContainerFragmentType; 01079 BOOST_REQUIRE_EQUAL(fps.front()->type(), type); 01080 auto cf4 = artdaq::ContainerFragment(*fps.front()); 01081 BOOST_REQUIRE_EQUAL(cf4.block_count(), 1); 01082 BOOST_REQUIRE_EQUAL(cf4.missing_data(), true); 01083 type = artdaq::Fragment::FirstUserFragmentType; 01084 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type); 01085 01086 gen.StopCmd(0xFFFFFFFF, 1); 01087 gen.joinThreads(); 01088 TLOG(TLVL_INFO) << "WindowMode_RequestEndsAfterBuffer test case END" ; 01089 01090 } 01091 BOOST_AUTO_TEST_CASE(WindowMode_RequestAfterBuffer) 01092 { 01093 artdaq::configureMessageFacility("CommandableFragmentGenerator_t"); 01094 TLOG(TLVL_INFO) << "WindowMode_RequestAfterBuffer test case BEGIN" ; 01095 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024; 01096 const int DELAY_TIME = 100; 01097 fhicl::ParameterSet ps; 01098 ps.put<int>("board_id", 1); 01099 ps.put<int>("fragment_id", 1); 01100 ps.put<int>("request_port", REQUEST_PORT); 01101 #if MULTICAST_MODE 01102 ps.put<std::string>("request_address", "227.18.12.32"); 01103 #else 01104 ps.put<std::string>("request_address", "localhost"); 01105 #endif 01106 ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0); 01107 ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 3); 01108 ps.put<size_t>("window_close_timeout_us", 500000); 01109 ps.put<bool>("separate_data_thread", true); 01110 ps.put<bool>("separate_monitoring_thread", false); 01111 ps.put<int64_t>("hardware_poll_interval_us", 0); 01112 ps.put<size_t>("data_buffer_depth_fragments", 5); 01113 ps.put<std::string>("request_mode", "window"); 01114 ps.put("request_delay_ms", DELAY_TIME); 01115 ps.put("send_requests", true); 01116 01117 artdaq::RequestSender t(ps); 01118 t.SetRunNumber(1); 01119 01120 artdaqtest::CommandableFragmentGeneratorTest gen(ps); 01121 gen.StartCmd(1, 0xFFFFFFFF, 1); 01122 01123 artdaq::FragmentPtrs fps; 01124 int sts; 01125 artdaq::Fragment::type_t type; 01126 gen.waitForFrags(); 01127 01128 // 6. Start and end after buffer 01129 // -- Should not return until buffer passes end or timeout (check both cases). MissingData bit set if timeout 01130 gen.setFireCount(9); // Buffer start is 6, end at 10 01131 gen.waitForFrags(); 01132 t.AddRequest(1, 11); // Requesting data from ts 11 to 13 01133 01134 sts = gen.getNext(fps); 01135 BOOST_REQUIRE_EQUAL(sts, true); 01136 BOOST_REQUIRE_EQUAL(fps.size(), 0); 01137 gen.setFireCount(1); // Buffer start is 7, end at 11 01138 gen.waitForFrags(); 01139 sts = gen.getNext(fps); 01140 BOOST_REQUIRE_EQUAL(sts, true); 01141 BOOST_REQUIRE_EQUAL(fps.size(), 0); 01142 01143 gen.setFireCount(3); // Buffer start is 10, end at 14 01144 gen.waitForFrags(); 01145 sts = gen.getNext(fps); 01146 BOOST_REQUIRE_EQUAL(sts, true); 01147 BOOST_REQUIRE_EQUAL(fps.size(), 1); 01148 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1); 01149 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 11); 01150 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1); 01151 type = artdaq::Fragment::ContainerFragmentType; 01152 BOOST_REQUIRE_EQUAL(fps.front()->type(), type); 01153 auto cf = artdaq::ContainerFragment(*fps.front()); 01154 BOOST_REQUIRE_EQUAL(cf.block_count(), 3); 01155 BOOST_REQUIRE_EQUAL(cf.missing_data(), false); 01156 type = artdaq::Fragment::FirstUserFragmentType; 01157 BOOST_REQUIRE_EQUAL(cf.fragment_type(), type); 01158 fps.clear(); 01159 01160 t.AddRequest(2, 16); // Requesting data from ts 15 to 17 01161 sts = gen.getNext(fps); 01162 BOOST_REQUIRE_EQUAL(sts, true); 01163 BOOST_REQUIRE_EQUAL(fps.size(), 0); 01164 01165 usleep(550000); 01166 01167 sts = gen.getNext(fps); 01168 BOOST_REQUIRE_EQUAL(sts, true); 01169 BOOST_REQUIRE_EQUAL(fps.size(), 1); 01170 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1); 01171 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 16); 01172 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2); 01173 type = artdaq::Fragment::ContainerFragmentType; 01174 BOOST_REQUIRE_EQUAL(fps.front()->type(), type); 01175 auto cf4 = artdaq::ContainerFragment(*fps.front()); 01176 BOOST_REQUIRE_EQUAL(cf4.block_count(), 0); 01177 BOOST_REQUIRE_EQUAL(cf4.missing_data(), true); 01178 type = artdaq::Fragment::EmptyFragmentType; 01179 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type); 01180 01181 gen.StopCmd(0xFFFFFFFF, 1); 01182 gen.joinThreads(); 01183 TLOG(TLVL_INFO) << "WindowMode_RequestAfterBuffer test case END" ; 01184 01185 } 01186 01187 BOOST_AUTO_TEST_CASE(HardwareFailure_NonThreaded) 01188 { 01189 artdaq::configureMessageFacility("CommandableFragmentGenerator_t"); 01190 TLOG(TLVL_INFO) << "HardwareFailure_NonThreaded test case BEGIN" ; 01191 fhicl::ParameterSet ps; 01192 ps.put<int>("board_id", 1); 01193 ps.put<int>("fragment_id", 1); 01194 ps.put<bool>("separate_data_thread", false); 01195 ps.put<bool>("separate_monitoring_thread", false); 01196 ps.put<int64_t>("hardware_poll_interval_us", 10); 01197 01198 artdaqtest::CommandableFragmentGeneratorTest gen(ps); 01199 gen.StartCmd(1, 0xFFFFFFFF, 1); 01200 01201 artdaq::FragmentPtrs fps; 01202 auto sts = gen.getNext(fps); 01203 BOOST_REQUIRE_EQUAL(sts, true); 01204 BOOST_REQUIRE_EQUAL(fps.size(), 1u); 01205 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1); 01206 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1); 01207 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1); 01208 fps.clear(); 01209 01210 gen.setFireCount(1); 01211 gen.setHwFail(); 01212 usleep(10000); 01213 sts = gen.getNext(fps); 01214 BOOST_REQUIRE_EQUAL(sts, false); 01215 BOOST_REQUIRE_EQUAL(fps.size(), 0); 01216 01217 gen.StopCmd(0xFFFFFFFF, 1); 01218 gen.joinThreads(); 01219 TLOG(TLVL_INFO) << "HardwareFailure_NonThreaded test case END" ; 01220 } 01221 01222 BOOST_AUTO_TEST_CASE(HardwareFailure_Threaded) 01223 { 01224 artdaq::configureMessageFacility("CommandableFragmentGenerator_t"); 01225 TLOG(TLVL_INFO) << "HardwareFailure_Threaded test case BEGIN" ; 01226 fhicl::ParameterSet ps; 01227 ps.put<int>("board_id", 1); 01228 ps.put<int>("fragment_id", 1); 01229 ps.put<bool>("separate_data_thread", true); 01230 ps.put<bool>("separate_monitoring_thread", true); 01231 ps.put<int64_t>("hardware_poll_interval_us", 750000); 01232 01233 artdaqtest::CommandableFragmentGeneratorTest gen(ps); 01234 gen.StartCmd(1, 0xFFFFFFFF, 1); 01235 01236 01237 01238 artdaq::FragmentPtrs fps; 01239 auto sts = gen.getNext(fps); 01240 BOOST_REQUIRE_EQUAL(sts, true); 01241 BOOST_REQUIRE_EQUAL(fps.size(), 1u); 01242 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1); 01243 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1); 01244 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1); 01245 fps.clear(); 01246 01247 gen.setHwFail(); 01248 //gen.setFireCount(1); 01249 //sts = gen.getNext(fps); 01250 //BOOST_REQUIRE_EQUAL(sts, true); 01251 //BOOST_REQUIRE_EQUAL(fps.size(), 1); 01252 //BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1); 01253 //BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 2); 01254 //BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1); 01255 //fps.clear(); 01256 01257 sleep(1); 01258 01259 gen.setFireCount(1); 01260 sts = gen.getNext(fps); 01261 BOOST_REQUIRE_EQUAL(sts, false); 01262 BOOST_REQUIRE_EQUAL(fps.size(), 0); 01263 01264 gen.StopCmd(0xFFFFFFFF, 1); 01265 gen.joinThreads(); 01266 TLOG(TLVL_INFO) << "HardwareFailure_Threaded test case END" ; 01267 } 01268 01269 BOOST_AUTO_TEST_SUITE_END()