1 #define TRACE_NAME "SharedMemoryEventManager_t"
3 #include "artdaq-core/Core/SharedMemoryEventReceiver.hh"
4 #include "artdaq-core/Data/Fragment.hh"
5 #include "artdaq/DAQrate/SharedMemoryEventManager.hh"
7 #define BOOST_TEST_MODULE SharedMemoryEventManager_t
8 #include "cetlib/quiet_unit_test.hpp"
9 #include "cetlib_except/exception.h"
11 BOOST_AUTO_TEST_SUITE(SharedMemoryEventManager_test)
13 BOOST_AUTO_TEST_CASE(Construct)
15 TLOG(TLVL_INFO) <<
"Test Construct BEGIN";
16 fhicl::ParameterSet pset;
17 pset.put(
"use_art",
false);
18 pset.put(
"buffer_count", 2);
19 pset.put(
"max_event_size_bytes", 1000);
20 pset.put(
"expected_fragments_per_event", 2);
23 BOOST_REQUIRE_EQUAL(t.runID(), 0);
24 BOOST_REQUIRE_EQUAL(t.GetSubrunForSequenceID(1), 1);
25 BOOST_REQUIRE_EQUAL(t.GetLockedBufferCount(), 0);
26 TLOG(TLVL_INFO) <<
"Test Construct END";
29 BOOST_AUTO_TEST_CASE(AddFragment)
31 TLOG(TLVL_INFO) <<
"Test AddFragment BEGIN";
33 fhicl::ParameterSet pset;
34 pset.put(
"use_art",
false);
35 pset.put(
"buffer_count", 2);
36 pset.put(
"max_event_size_bytes", 1000);
37 pset.put(
"expected_fragments_per_event", 2);
40 artdaq::FragmentPtr frag(
new artdaq::Fragment(1, 0, artdaq::Fragment::FirstUserFragmentType, 0UL)), tmpFrag;
42 for (
auto ii = 0; ii < 4; ++ii)
44 *(frag->dataBegin() + ii) = ii;
47 bool sts = t.AddFragment(std::move(frag), 1000000, tmpFrag);
48 BOOST_REQUIRE_EQUAL(sts,
true);
49 BOOST_REQUIRE_EQUAL(t.GetIncompleteEventCount(), 1);
50 BOOST_REQUIRE_EQUAL(t.GetFragmentCount(1), 1);
51 TLOG(TLVL_INFO) <<
"Test AddFragment END";
54 BOOST_AUTO_TEST_CASE(DataFlow)
56 TLOG(TLVL_INFO) <<
"Test DataFlow BEGIN";
57 fhicl::ParameterSet pset;
58 pset.put(
"use_art",
false);
59 pset.put(
"buffer_count", 2);
60 pset.put(
"max_event_size_bytes", 1000);
61 pset.put(
"expected_fragments_per_event", 3);
64 artdaq::FragmentPtr frag(
new artdaq::Fragment(1, 0, artdaq::Fragment::FirstUserFragmentType, 0UL)), tmpFrag;
66 for (
auto ii = 0; ii < 4; ++ii)
68 *(frag->dataBegin() + ii) = ii;
71 auto hdr = *
reinterpret_cast<artdaq::detail::RawFragmentHeader*
>(frag->headerAddress());
72 auto fragLoc = t.WriteFragmentHeader(hdr);
73 memcpy(fragLoc, frag->dataBegin(), 4 *
sizeof(artdaq::RawDataType));
74 t.DoneWritingFragment(hdr);
75 BOOST_REQUIRE_EQUAL(t.GetIncompleteEventCount(), 1);
76 BOOST_REQUIRE_EQUAL(t.GetFragmentCount(1), 1);
78 frag->setFragmentID(1);
79 hdr = *
reinterpret_cast<artdaq::detail::RawFragmentHeader*
>(frag->headerAddress());
80 auto fragLoc2 = t.WriteFragmentHeader(hdr);
81 memcpy(fragLoc2, frag->dataBegin(), 4 *
sizeof(artdaq::RawDataType));
82 t.DoneWritingFragment(hdr);
83 BOOST_REQUIRE_EQUAL(t.GetIncompleteEventCount(), 1);
84 BOOST_REQUIRE_EQUAL(t.GetFragmentCount(1), 2);
85 BOOST_REQUIRE_EQUAL(fragLoc + frag->size(), fragLoc2);
87 frag->setFragmentID(2);
88 hdr = *
reinterpret_cast<artdaq::detail::RawFragmentHeader*
>(frag->headerAddress());
89 auto fragLoc3 = t.WriteFragmentHeader(hdr);
90 memcpy(fragLoc3, frag->dataBegin(), 4 *
sizeof(artdaq::RawDataType));
91 t.DoneWritingFragment(hdr);
92 BOOST_REQUIRE_EQUAL(fragLoc2 + frag->size(), fragLoc3);
93 BOOST_REQUIRE_EQUAL(t.GetIncompleteEventCount(), 0);
94 BOOST_REQUIRE_EQUAL(t.GetArtEventCount(), 1);
96 TLOG(TLVL_INFO) <<
"Test DataFlow END";
468 BOOST_AUTO_TEST_CASE(ConsumeDroppedData_Active)
470 TLOG(TLVL_INFO) <<
"Test ConsumeDroppedData_Active BEGIN";
471 fhicl::ParameterSet pset;
472 pset.put(
"use_art",
false);
473 pset.put(
"buffer_count", 20);
474 pset.put(
"max_event_size_bytes", 1000);
475 pset.put(
"expected_fragments_per_event", 2);
476 pset.put(
"stale_buffer_timeout_usec", 100000);
478 artdaq::FragmentPtr frag(
new artdaq::Fragment(1, 0, artdaq::Fragment::FirstUserFragmentType, 0UL)), tmpFrag;
480 for (
auto ii = 0; ii < 4; ++ii)
482 *(frag->dataBegin() + ii) = ii;
487 auto hdr = *
reinterpret_cast<artdaq::detail::RawFragmentHeader*
>(frag->headerAddress());
488 auto fragLoc = t.WriteFragmentHeader(hdr);
489 memcpy(fragLoc, frag->dataBegin(), 4 *
sizeof(artdaq::RawDataType));
490 t.DoneWritingFragment(hdr);
491 BOOST_REQUIRE_EQUAL(t.GetIncompleteEventCount(), 1);
493 BOOST_REQUIRE_EQUAL(t.GetFragmentCount(1), 1);
494 BOOST_REQUIRE_EQUAL(t.GetArtEventCount(), 0);
497 frag->setSequenceID(2);
498 frag->setFragmentID(0);
500 auto hdr = *
reinterpret_cast<artdaq::detail::RawFragmentHeader*
>(frag->headerAddress());
501 auto fragLoc = t.WriteFragmentHeader(hdr);
502 memcpy(fragLoc, frag->dataBegin(), 4 *
sizeof(artdaq::RawDataType));
503 t.DoneWritingFragment(hdr);
504 BOOST_REQUIRE_EQUAL(t.GetIncompleteEventCount(), 2);
506 BOOST_REQUIRE_EQUAL(t.GetFragmentCount(2), 1);
507 BOOST_REQUIRE_EQUAL(t.GetArtEventCount(), 0);
509 frag->setFragmentID(1);
510 hdr = *
reinterpret_cast<artdaq::detail::RawFragmentHeader*
>(frag->headerAddress());
511 auto fragLoc2 = t.WriteFragmentHeader(hdr);
512 memcpy(fragLoc2, frag->dataBegin(), 4 *
sizeof(artdaq::RawDataType));
513 t.DoneWritingFragment(hdr);
514 BOOST_REQUIRE_EQUAL(t.GetPendingEventCount(), 0);
515 BOOST_REQUIRE_EQUAL(t.GetIncompleteEventCount(), 1);
518 BOOST_REQUIRE_EQUAL(t.GetArtEventCount(), 1);
519 BOOST_REQUIRE_EQUAL(fragLoc + frag->size(), fragLoc2);
522 frag->setSequenceID(3);
523 frag->setFragmentID(0);
525 auto hdr = *
reinterpret_cast<artdaq::detail::RawFragmentHeader*
>(frag->headerAddress());
526 auto fragLoc = t.WriteFragmentHeader(hdr);
527 memcpy(fragLoc, frag->dataBegin(), 4 *
sizeof(artdaq::RawDataType));
528 t.DoneWritingFragment(hdr);
529 BOOST_REQUIRE_EQUAL(t.GetIncompleteEventCount(), 2);
531 BOOST_REQUIRE_EQUAL(t.GetFragmentCount(3), 1);
532 BOOST_REQUIRE_EQUAL(t.GetArtEventCount(), 1);
534 frag->setFragmentID(1);
535 hdr = *
reinterpret_cast<artdaq::detail::RawFragmentHeader*
>(frag->headerAddress());
536 auto fragLoc2 = t.WriteFragmentHeader(hdr);
537 memcpy(fragLoc2, frag->dataBegin(), 4 *
sizeof(artdaq::RawDataType));
538 t.DoneWritingFragment(hdr);
539 BOOST_REQUIRE_EQUAL(t.GetPendingEventCount(), 0);
541 BOOST_REQUIRE_EQUAL(t.GetIncompleteEventCount(), 1);
542 BOOST_REQUIRE_EQUAL(t.GetArtEventCount(), 2);
548 BOOST_REQUIRE_EQUAL(t.GetArtEventCount(), 2);
549 frag->setSequenceID(4);
550 frag->setFragmentID(1);
551 auto hdr = *
reinterpret_cast<artdaq::detail::RawFragmentHeader*
>(frag->headerAddress());
552 auto fragLoc = t.WriteFragmentHeader(hdr);
553 memcpy(fragLoc, frag->dataBegin(), 4 *
sizeof(artdaq::RawDataType));
554 t.DoneWritingFragment(hdr);
555 BOOST_REQUIRE_EQUAL(t.GetPendingEventCount(), 0);
557 BOOST_REQUIRE_EQUAL(t.GetIncompleteEventCount(), 1);
558 BOOST_REQUIRE_EQUAL(t.GetArtEventCount(), 3);
560 frag->setFragmentID(1);
561 hdr = *
reinterpret_cast<artdaq::detail::RawFragmentHeader*
>(frag->headerAddress());
562 auto fragLoc2 = t.WriteFragmentHeader(hdr);
563 memcpy(fragLoc2, frag->dataBegin(), 4 *
sizeof(artdaq::RawDataType));
564 t.DoneWritingFragment(hdr);
565 BOOST_REQUIRE_EQUAL(t.GetPendingEventCount(), 0);
566 BOOST_REQUIRE_EQUAL(t.GetIncompleteEventCount(), 0);
567 BOOST_REQUIRE_EQUAL(t.GetArtEventCount(), 4);
570 frag->setSequenceID(1);
571 frag->setFragmentID(1);
572 auto hdr = *
reinterpret_cast<artdaq::detail::RawFragmentHeader*
>(frag->headerAddress());
573 auto fragLoc2 = t.WriteFragmentHeader(hdr);
574 #if !ART_SUPPORTS_DUPLICATE_EVENTS
575 BOOST_REQUIRE_EQUAL(fragLoc2, t.GetDroppedDataAddress(1));
577 memcpy(fragLoc2, frag->dataBegin(), 4 *
sizeof(artdaq::RawDataType));
578 t.DoneWritingFragment(hdr);
579 BOOST_REQUIRE_EQUAL(t.GetPendingEventCount(), 0);
581 BOOST_REQUIRE_EQUAL(t.GetIncompleteEventCount(), 0);
582 #if ART_SUPPORTS_DUPLICATE_EVENTS
583 BOOST_REQUIRE_EQUAL(t.GetArtEventCount(), 5);
585 BOOST_REQUIRE_EQUAL(t.GetArtEventCount(), 4);
589 TLOG(TLVL_INFO) <<
"Test ConsumeDroppedData_Active END";
703 BOOST_AUTO_TEST_CASE(RunNumbers)
705 TLOG(TLVL_INFO) <<
"Test RunNumbers BEGIN";
706 fhicl::ParameterSet pset;
707 pset.put(
"use_art",
false);
708 pset.put(
"buffer_count", 2);
709 pset.put(
"max_event_size_bytes", 1000);
710 pset.put(
"expected_fragments_per_event", 2);
714 BOOST_REQUIRE_EQUAL(t.runID(), 1);
715 BOOST_REQUIRE_EQUAL(t.GetCurrentSubrun(), 1);
717 BOOST_REQUIRE_EQUAL(t.runID(), 1);
718 BOOST_REQUIRE_EQUAL(t.GetCurrentSubrun(), 2);
720 BOOST_REQUIRE_EQUAL(t.runID(), 1);
721 BOOST_REQUIRE_EQUAL(t.GetCurrentSubrun(), 3);
723 BOOST_REQUIRE_EQUAL(t.runID(), 3);
724 BOOST_REQUIRE_EQUAL(t.GetCurrentSubrun(), 1);
726 artdaq::SharedMemoryEventReceiver r(t.GetKey(), t.GetBroadcastKey());
727 bool errflag =
false;
730 bool sts = r.ReadyForRead();
731 BOOST_REQUIRE_EQUAL(sts,
true);
732 auto hdr = r.ReadHeader(errflag);
733 BOOST_REQUIRE_EQUAL(errflag,
false);
734 BOOST_REQUIRE(hdr !=
nullptr);
737 BOOST_REQUIRE_EQUAL(hdr->is_complete,
true);
738 BOOST_REQUIRE_EQUAL(hdr->run_id, 3);
739 BOOST_REQUIRE_EQUAL(hdr->subrun_id, 1);
741 auto frags = r.GetFragmentsByType(errflag, artdaq::Fragment::EndOfRunFragmentType);
742 BOOST_REQUIRE_EQUAL(errflag,
false);
743 BOOST_REQUIRE_EQUAL(frags->size(), 1);
746 TLOG(TLVL_INFO) <<
"Test RunNumbers END";
749 BOOST_AUTO_TEST_SUITE_END()
The SharedMemoryEventManager is a SharedMemoryManger which tracks events as they are built...