1 #define TRACE_NAME "SharedMemoryFragmentManager_t"
3 #include "artdaq-core/Core/SharedMemoryFragmentManager.hh"
4 #include "artdaq-core/Utilities/configureMessageFacility.hh"
7 #define BOOST_TEST_MODULE(SharedMemoryFragmentManager_t)
8 #include "cetlib/quiet_unit_test.hpp"
9 #include "cetlib_except/exception.h"
10 #include "SharedMemoryTestShims.hh"
13 BOOST_AUTO_TEST_SUITE(SharedMemoryFragmentManager_test)
15 BOOST_AUTO_TEST_CASE(Construct)
18 TLOG(TLVL_INFO) <<
"BEGIN TEST Construct" ;
20 BOOST_REQUIRE_EQUAL(man.IsValid(),
true);
21 BOOST_REQUIRE_EQUAL(man.GetMyId(), 0);
22 BOOST_REQUIRE_EQUAL(man.size(), 10);
23 BOOST_REQUIRE_EQUAL(man.GetAttachedCount(), 1);
24 TLOG(TLVL_INFO) <<
"END TEST Construct";
27 BOOST_AUTO_TEST_CASE(Attach)
29 TLOG(TLVL_INFO) <<
"BEGIN TEST Attach";
30 uint32_t key = GetRandomKey(0xF4A6);
34 BOOST_REQUIRE_EQUAL(man.IsValid(),
true);
35 BOOST_REQUIRE_EQUAL(man.GetMyId(), 0);
36 BOOST_REQUIRE_EQUAL(man.size(), 10);
37 BOOST_REQUIRE_EQUAL(man.GetAttachedCount(), 2);
39 BOOST_REQUIRE_EQUAL(man2.IsValid(),
true);
40 BOOST_REQUIRE_EQUAL(man2.GetMyId(), 1);
41 BOOST_REQUIRE_EQUAL(man2.size(), 10);
42 BOOST_REQUIRE_EQUAL(man2.GetAttachedCount(), 2);
43 TLOG(TLVL_INFO) <<
"END TEST Attach";
47 BOOST_AUTO_TEST_CASE(DataFlow)
49 TLOG(TLVL_INFO) <<
"BEGIN TEST DataFlow";
50 TLOG(TLVL_DEBUG) <<
"Initializing SharedMemoryFragmentManagers for DataFlow test" ;
51 uint32_t key = GetRandomKey(0xF4A6);
57 TLOG(TLVL_DEBUG) <<
"Creating test Fragment" ;
59 frag.setSequenceID(0x10);
60 frag.setFragmentID(0x20);
62 frag.setSystemType(type);
63 frag.setTimestamp(0x30);
64 for (
size_t ii = 0; ii < fragSizeWords; ++ii)
66 *(frag.dataBegin() + ii) = ii;
69 TLOG(TLVL_DEBUG) <<
"Writing Test Fragment to Shared Memory" ;
70 man.WriteFragment(std::move(frag),
false, 0);
72 TLOG(TLVL_DEBUG) <<
"Reading Test Fragment Header" ;
74 auto sts = man2.ReadFragmentHeader(header);
76 TLOG(TLVL_DEBUG) <<
"Checking Test Fragment Header Contents" ;
77 BOOST_REQUIRE_EQUAL(sts, 0);
78 BOOST_REQUIRE_EQUAL(header.
word_count, frag.size());
81 BOOST_REQUIRE_EQUAL(header.
type, type);
82 BOOST_REQUIRE_EQUAL(header.
timestamp, 0x30);
84 TLOG(TLVL_DEBUG) <<
"Reading Test Fragment data" ;
88 TLOG(TLVL_DEBUG) <<
"Checking Test Fragment contents" ;
89 BOOST_REQUIRE_EQUAL(sts, 0);
90 for(
size_t ii = 0; ii < fragSizeWords; ++ii)
92 BOOST_REQUIRE_EQUAL(*(frag.dataBegin() + ii), *(frag2.dataBegin() + ii));
94 TLOG(TLVL_DEBUG) <<
"SharedMemoryFragmentManager DataFlow test complete" ;
95 TLOG(TLVL_INFO) <<
"END TEST DataFlow";
98 BOOST_AUTO_TEST_CASE(WholeFragment)
100 TLOG(TLVL_INFO) <<
"BEGIN TEST WholeFragment";
101 TLOG(TLVL_DEBUG) <<
"Initializing SharedMemoryFragmentManagers for WholeFragment Test" ;
102 uint32_t key = GetRandomKey(0xF4A6);
108 TLOG(TLVL_DEBUG) <<
"Creating test Fragment" ;
110 frag.setSequenceID(0x10);
111 frag.setFragmentID(0x20);
113 frag.setSystemType(type);
114 frag.setTimestamp(0x30);
115 for (
size_t ii = 0; ii < fragSizeWords; ++ii)
117 *(frag.dataBegin() + ii) = ii;
120 TLOG(TLVL_DEBUG) <<
"Writing Test Fragment to Shared Memory" ;
121 man.WriteFragment(std::move(frag),
false, 0);
123 TLOG(TLVL_DEBUG) <<
"Reading Test Fragment Header" ;
125 auto sts = man2.ReadFragment(recvdFrag);
127 TLOG(TLVL_DEBUG) <<
"Checking Test Fragment Header Contents" ;
128 BOOST_REQUIRE_EQUAL(sts, 0);
129 BOOST_REQUIRE_EQUAL(recvdFrag.
size(), frag.size());
130 BOOST_REQUIRE_EQUAL(recvdFrag.
sequenceID(), 0x10);
131 BOOST_REQUIRE_EQUAL(recvdFrag.
fragmentID(), 0x20);
132 BOOST_REQUIRE_EQUAL(recvdFrag.
type(), type);
133 BOOST_REQUIRE_EQUAL(recvdFrag.
timestamp(), 0x30);
135 TLOG(TLVL_DEBUG) <<
"Checking Test Fragment Data Contents" ;
136 for (
size_t ii = 0; ii < fragSizeWords; ++ii)
139 BOOST_REQUIRE_EQUAL(*(frag.dataBegin() + ii), *(recvdFrag.
dataBegin() + ii));
141 TLOG(TLVL_DEBUG) <<
"SharedMemoryFragmentManager WholeFragment test complete" ;
142 TLOG(TLVL_INFO) <<
"END TEST WholeFragment";
146 BOOST_AUTO_TEST_CASE(Timeout)
148 TLOG(TLVL_INFO) <<
"BEGIN TEST Timeout";
149 TLOG(TLVL_DEBUG) <<
"Initializing SharedMemoryFragmentManagers for Timeout Test" ;
150 uint32_t key = GetRandomKey(0xF4A6);
155 TLOG(TLVL_DEBUG) <<
"Creating test Fragment" ;
157 frag.setSequenceID(0x10);
158 frag.setFragmentID(0x20);
160 frag.setSystemType(type);
161 frag.setTimestamp(0x30);
162 for (
size_t ii = 0; ii < fragSizeWords; ++ii)
164 *(frag.dataBegin() + ii) = ii;
167 TLOG(TLVL_DEBUG) <<
"Reserving buffer to cause timeout to happen" ;
168 auto ret = man.GetBufferForWriting(
true);
169 BOOST_REQUIRE_EQUAL(ret, 0);
171 TLOG(TLVL_DEBUG) <<
"Attempting to write Fragment to Shared Memory. This should time out." ;
172 auto start_time = std::chrono::steady_clock::now();
173 ret = man.WriteFragment(std::move(frag),
true, 100000);
176 BOOST_REQUIRE_EQUAL(ret, -3);
177 BOOST_REQUIRE_GE(duration, 100000);
179 TLOG(TLVL_DEBUG) <<
"SharedMemoryFragmentManager Timeout test complete" ;
180 TLOG(TLVL_INFO) <<
"END TEST Timeout";
183 BOOST_AUTO_TEST_SUITE_END()
std::size_t size() const
Gets the size of the Fragment, from the Fragment header.
The SharedMemoryFragmentManager is a SharedMemoryManager that deals with Fragment transfers using a S...
sequence_id_t sequenceID() const
Sequence ID of the Fragment, from the Fragment header.
timestamp_t timestamp() const
Timestamp of the Fragment, from the Fragment header.
constexpr size_t GetElapsedTimeMicroseconds(std::chrono::steady_clock::time_point then, std::chrono::steady_clock::time_point now=std::chrono::steady_clock::now())
Gets the number of microseconds in the given time interval
static constexpr type_t DataFragmentType
Copy DataFragmentType from RawFragmentHeader.
iterator dataBegin()
Return an iterator to the beginning of the data payload (after header and metadata) ...
type_t type() const
Type of the Fragment, from the Fragment header.
void configureMessageFacility(char const *progname, bool useConsole=true, bool printDebug=false)
Configure and start the message facility. Provide the program name so that messages will be appropria...
detail::RawFragmentHeader::RawDataType RawDataType
The RawDataType (currently a 64-bit integer) is the basic unit of data representation within artdaq ...
A Fragment contains the data from one piece of the DAQ system for one event The artdaq::Fragment is t...
fragment_id_t fragmentID() const
Fragment ID of the Fragment, from the Fragment header.