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 "SharedMemoryTestShims.hh"
9 #include "cetlib/quiet_unit_test.hpp"
10 #include "cetlib_except/exception.h"
12 BOOST_AUTO_TEST_SUITE(SharedMemoryFragmentManager_test)
14 BOOST_AUTO_TEST_CASE(Construct)
17 TLOG(TLVL_INFO) <<
"BEGIN TEST Construct";
19 BOOST_REQUIRE_EQUAL(man.IsValid(),
true);
20 BOOST_REQUIRE_EQUAL(man.GetMyId(), 0);
21 BOOST_REQUIRE_EQUAL(man.size(), 10);
22 BOOST_REQUIRE_EQUAL(man.GetAttachedCount(), 1);
23 TLOG(TLVL_INFO) <<
"END TEST Construct";
26 BOOST_AUTO_TEST_CASE(Attach)
28 TLOG(TLVL_INFO) <<
"BEGIN TEST Attach";
29 uint32_t key = GetRandomKey(0xF4A6);
33 BOOST_REQUIRE_EQUAL(man.IsValid(),
true);
34 BOOST_REQUIRE_EQUAL(man.GetMyId(), 0);
35 BOOST_REQUIRE_EQUAL(man.size(), 10);
36 BOOST_REQUIRE_EQUAL(man.GetAttachedCount(), 2);
38 BOOST_REQUIRE_EQUAL(man2.IsValid(),
true);
39 BOOST_REQUIRE_EQUAL(man2.GetMyId(), 1);
40 BOOST_REQUIRE_EQUAL(man2.size(), 10);
41 BOOST_REQUIRE_EQUAL(man2.GetAttachedCount(), 2);
42 TLOG(TLVL_INFO) <<
"END TEST Attach";
45 BOOST_AUTO_TEST_CASE(Reattach)
47 TLOG(TLVL_INFO) <<
"BEGIN TEST Reattach";
48 uint32_t key = GetRandomKey(0xF4A6);
52 BOOST_REQUIRE_EQUAL(man->IsValid(),
true);
53 BOOST_REQUIRE_EQUAL(man->GetMyId(), 0);
54 BOOST_REQUIRE_EQUAL(man->size(), 10);
55 BOOST_REQUIRE_EQUAL(man->GetAttachedCount(), 2);
57 BOOST_REQUIRE_EQUAL(man2->IsValid(),
true);
58 BOOST_REQUIRE_EQUAL(man2->GetMyId(), 1);
59 BOOST_REQUIRE_EQUAL(man2->size(), 10);
60 BOOST_REQUIRE_EQUAL(man2->GetAttachedCount(), 2);
63 BOOST_REQUIRE_EQUAL(man->IsValid(),
true);
64 BOOST_REQUIRE_EQUAL(man->GetAttachedCount(), 1);
67 BOOST_REQUIRE_EQUAL(man->IsValid(),
true);
68 BOOST_REQUIRE_EQUAL(man->GetMyId(), 0);
69 BOOST_REQUIRE_EQUAL(man->size(), 10);
70 BOOST_REQUIRE_EQUAL(man->GetAttachedCount(), 2);
72 BOOST_REQUIRE_EQUAL(man2->IsValid(),
true);
73 BOOST_REQUIRE_EQUAL(man2->GetMyId(), 2);
74 BOOST_REQUIRE_EQUAL(man2->size(), 10);
75 BOOST_REQUIRE_EQUAL(man2->GetAttachedCount(), 2);
78 BOOST_REQUIRE_EQUAL(man2->IsValid(),
true);
79 BOOST_REQUIRE_EQUAL(man2->IsEndOfData(),
true);
80 BOOST_REQUIRE_EQUAL(man2->GetMyId(), 2);
81 BOOST_REQUIRE_EQUAL(man2->size(), 10);
82 BOOST_REQUIRE_EQUAL(man2->GetAttachedCount(), 1);
85 BOOST_REQUIRE_EQUAL(man2->IsValid(),
false);
88 BOOST_REQUIRE_EQUAL(man->IsValid(),
true);
89 BOOST_REQUIRE_EQUAL(man->GetMyId(), 0);
90 BOOST_REQUIRE_EQUAL(man->size(), 10);
91 BOOST_REQUIRE_EQUAL(man->GetAttachedCount(), 1);
94 BOOST_REQUIRE_EQUAL(man2->IsValid(),
true);
95 BOOST_REQUIRE_EQUAL(man2->GetMyId(), 1);
96 BOOST_REQUIRE_EQUAL(man2->size(), 10);
97 BOOST_REQUIRE_EQUAL(man->GetAttachedCount(), 2);
98 BOOST_REQUIRE_EQUAL(man2->GetAttachedCount(), 2);
100 TLOG(TLVL_INFO) <<
"END TEST Reattach";
103 BOOST_AUTO_TEST_CASE(DataFlow)
105 TLOG(TLVL_INFO) <<
"BEGIN TEST DataFlow";
106 TLOG(TLVL_DEBUG) <<
"Initializing SharedMemoryFragmentManagers for DataFlow test";
107 uint32_t key = GetRandomKey(0xF4A6);
113 TLOG(TLVL_DEBUG) <<
"Creating test Fragment";
115 frag.setSequenceID(0x10);
116 frag.setFragmentID(0x20);
118 frag.setSystemType(type);
119 frag.setTimestamp(0x30);
120 for (
size_t ii = 0; ii < fragSizeWords; ++ii)
122 *(frag.dataBegin() + ii) = ii;
125 TLOG(TLVL_DEBUG) <<
"Writing Test Fragment to Shared Memory";
126 man.WriteFragment(std::move(frag),
false, 0);
128 TLOG(TLVL_DEBUG) <<
"Reading Test Fragment Header";
130 auto sts = man2.ReadFragmentHeader(header);
132 TLOG(TLVL_DEBUG) <<
"Checking Test Fragment Header Contents";
133 BOOST_REQUIRE_EQUAL(sts, 0);
134 BOOST_REQUIRE_EQUAL(header.
word_count, frag.size());
137 BOOST_REQUIRE_EQUAL(header.
type, type);
138 BOOST_REQUIRE_EQUAL(header.
timestamp, 0x30);
140 TLOG(TLVL_DEBUG) <<
"Reading Test Fragment data";
144 TLOG(TLVL_DEBUG) <<
"Checking Test Fragment contents";
145 BOOST_REQUIRE_EQUAL(sts, 0);
146 for (
size_t ii = 0; ii < fragSizeWords; ++ii)
148 BOOST_REQUIRE_EQUAL(*(frag.dataBegin() + ii), *(frag2.dataBegin() + ii));
150 TLOG(TLVL_DEBUG) <<
"SharedMemoryFragmentManager DataFlow test complete";
151 TLOG(TLVL_INFO) <<
"END TEST DataFlow";
154 BOOST_AUTO_TEST_CASE(WholeFragment)
156 TLOG(TLVL_INFO) <<
"BEGIN TEST WholeFragment";
157 TLOG(TLVL_DEBUG) <<
"Initializing SharedMemoryFragmentManagers for WholeFragment Test";
158 uint32_t key = GetRandomKey(0xF4A6);
164 TLOG(TLVL_DEBUG) <<
"Creating test Fragment";
166 frag.setSequenceID(0x10);
167 frag.setFragmentID(0x20);
169 frag.setSystemType(type);
170 frag.setTimestamp(0x30);
171 for (
size_t ii = 0; ii < fragSizeWords; ++ii)
173 *(frag.dataBegin() + ii) = ii;
176 TLOG(TLVL_DEBUG) <<
"Writing Test Fragment to Shared Memory";
177 man.WriteFragment(std::move(frag),
false, 0);
179 TLOG(TLVL_DEBUG) <<
"Reading Test Fragment Header";
181 auto sts = man2.ReadFragment(recvdFrag);
183 TLOG(TLVL_DEBUG) <<
"Checking Test Fragment Header Contents";
184 BOOST_REQUIRE_EQUAL(sts, 0);
185 BOOST_REQUIRE_EQUAL(recvdFrag.
size(), frag.size());
186 BOOST_REQUIRE_EQUAL(recvdFrag.
sequenceID(), 0x10);
187 BOOST_REQUIRE_EQUAL(recvdFrag.
fragmentID(), 0x20);
188 BOOST_REQUIRE_EQUAL(recvdFrag.
type(), type);
189 BOOST_REQUIRE_EQUAL(recvdFrag.
timestamp(), 0x30);
191 TLOG(TLVL_DEBUG) <<
"Checking Test Fragment Data Contents";
192 for (
size_t ii = 0; ii < fragSizeWords; ++ii)
195 BOOST_REQUIRE_EQUAL(*(frag.dataBegin() + ii), *(recvdFrag.
dataBegin() + ii));
197 TLOG(TLVL_DEBUG) <<
"SharedMemoryFragmentManager WholeFragment test complete";
198 TLOG(TLVL_INFO) <<
"END TEST WholeFragment";
201 BOOST_AUTO_TEST_CASE(Timeout)
203 TLOG(TLVL_INFO) <<
"BEGIN TEST Timeout";
204 TLOG(TLVL_DEBUG) <<
"Initializing SharedMemoryFragmentManagers for Timeout Test";
205 uint32_t key = GetRandomKey(0xF4A6);
210 TLOG(TLVL_DEBUG) <<
"Creating test Fragment";
212 frag.setSequenceID(0x10);
213 frag.setFragmentID(0x20);
215 frag.setSystemType(type);
216 frag.setTimestamp(0x30);
217 for (
size_t ii = 0; ii < fragSizeWords; ++ii)
219 *(frag.dataBegin() + ii) = ii;
222 TLOG(TLVL_DEBUG) <<
"Reserving buffer to cause timeout to happen";
223 auto ret = man.GetBufferForWriting(
true);
224 BOOST_REQUIRE_EQUAL(ret, 0);
226 TLOG(TLVL_DEBUG) <<
"Attempting to write Fragment to Shared Memory. This should time out.";
227 auto start_time = std::chrono::steady_clock::now();
228 ret = man.WriteFragment(std::move(frag),
true, 100000);
231 BOOST_REQUIRE_EQUAL(ret, -3);
232 BOOST_REQUIRE_GE(duration, 100000);
234 TLOG(TLVL_DEBUG) <<
"SharedMemoryFragmentManager Timeout test complete";
235 TLOG(TLVL_INFO) <<
"END TEST Timeout";
238 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.