13 #pragma GCC diagnostic push 14 #pragma GCC diagnostic ignored "-Wsign-compare" 16 #define BOOST_TEST_MODULE(MilliSliceFragment_t) 20 BOOST_AUTO_TEST_SUITE(MilliSliceFragment_test)
24 const uint16_t CHANNEL_NUMBER = 123;
25 const uint32_t MILLISLICE_BUFFER_WORDS = 2000;
26 const uint32_t MICROSLICE_BUFFER_SIZE = 1024;
27 const uint32_t NANOSLICE_BUFFER_SIZE = 128;
28 const uint16_t SAMPLE1 = 0x1234;
29 const uint16_t SAMPLE2 = 0xc3c3;
30 const uint16_t SAMPLE3 = 0xbeef;
31 const uint16_t SAMPLE4 = 0xfe87;
32 const uint16_t SAMPLE5 = 0x5a5a;
33 std::unique_ptr<dune::MicroSlice> microslice_ptr;
34 std::shared_ptr<dune::MicroSliceWriter> microslice_writer_ptr;
35 std::shared_ptr<dune::NanoSliceWriter> nanoslice_writer_ptr;
41 artdaq::Fragment fragment(MILLISLICE_BUFFER_WORDS);
43 millislice_writer(fragment, MILLISLICE_BUFFER_WORDS *
sizeof(artdaq::RawDataType));
46 microslice_ptr = millislice_writer.
microSlice(0);
47 BOOST_REQUIRE(microslice_ptr.get() == 0);
48 microslice_ptr = millislice_writer.
microSlice(999);
49 BOOST_REQUIRE(microslice_ptr.get() == 0);
54 bool threw_exception =
false;
58 +
sizeof(artdaq::RawDataType));
60 threw_exception =
true;
63 BOOST_REQUIRE_EQUAL(threw_exception,
true);
67 microslice_writer_ptr = millislice_writer.
reserveMicroSlice(MICROSLICE_BUFFER_SIZE);
68 BOOST_REQUIRE(microslice_writer_ptr.get() != 0);
69 BOOST_REQUIRE_EQUAL(millislice_writer.
size(),
72 if (microslice_writer_ptr.get() != 0) {
73 nanoslice_writer_ptr = microslice_writer_ptr->reserveNanoSlice(NANOSLICE_BUFFER_SIZE);
74 BOOST_REQUIRE(nanoslice_writer_ptr.get() != 0);
75 BOOST_REQUIRE_EQUAL(microslice_writer_ptr->size(),
77 BOOST_REQUIRE_EQUAL(microslice_writer_ptr->nanoSliceCount(), 1);
78 if (nanoslice_writer_ptr.get() != 0) {
79 nanoslice_writer_ptr->setChannelNumber(CHANNEL_NUMBER);
80 nanoslice_writer_ptr->addSample(SAMPLE1);
84 microslice_writer_ptr = millislice_writer.
reserveMicroSlice(MICROSLICE_BUFFER_SIZE);
85 BOOST_REQUIRE(microslice_writer_ptr.get() != 0);
88 sizeof(uint16_t) + MICROSLICE_BUFFER_SIZE);
90 if (microslice_writer_ptr.get() != 0) {
91 nanoslice_writer_ptr = microslice_writer_ptr->reserveNanoSlice(NANOSLICE_BUFFER_SIZE);
92 BOOST_REQUIRE(nanoslice_writer_ptr.get() != 0);
93 BOOST_REQUIRE_EQUAL(microslice_writer_ptr->size(),
95 BOOST_REQUIRE_EQUAL(microslice_writer_ptr->nanoSliceCount(), 1);
96 if (nanoslice_writer_ptr.get() != 0) {
97 nanoslice_writer_ptr->setChannelNumber(CHANNEL_NUMBER+1);
98 nanoslice_writer_ptr->addSample(SAMPLE2);
101 nanoslice_writer_ptr = microslice_writer_ptr->reserveNanoSlice(NANOSLICE_BUFFER_SIZE);
102 BOOST_REQUIRE(nanoslice_writer_ptr.get() != 0);
105 NANOSLICE_BUFFER_SIZE);
106 BOOST_REQUIRE_EQUAL(microslice_writer_ptr->nanoSliceCount(), 2);
107 if (nanoslice_writer_ptr.get() != 0) {
108 nanoslice_writer_ptr->setChannelNumber(CHANNEL_NUMBER+1);
109 nanoslice_writer_ptr->addSample(SAMPLE3);
113 microslice_writer_ptr = millislice_writer.
reserveMicroSlice(MICROSLICE_BUFFER_SIZE);
114 BOOST_REQUIRE(microslice_writer_ptr.get() != 0);
117 3*
sizeof(uint16_t) + MICROSLICE_BUFFER_SIZE);
119 if (microslice_writer_ptr.get() != 0) {
120 nanoslice_writer_ptr = microslice_writer_ptr->reserveNanoSlice(NANOSLICE_BUFFER_SIZE);
121 BOOST_REQUIRE(nanoslice_writer_ptr.get() != 0);
122 BOOST_REQUIRE_EQUAL(microslice_writer_ptr->size(),
124 BOOST_REQUIRE_EQUAL(microslice_writer_ptr->nanoSliceCount(), 1);
125 if (nanoslice_writer_ptr.get() != 0) {
126 nanoslice_writer_ptr->setChannelNumber(CHANNEL_NUMBER+2);
127 nanoslice_writer_ptr->addSample(SAMPLE4);
128 nanoslice_writer_ptr->addSample(SAMPLE5);
135 int32_t size_diff = millislice_writer.
finalize();
136 BOOST_REQUIRE_EQUAL(size_diff, MILLISLICE_BUFFER_WORDS*
sizeof(artdaq::RawDataType) -
142 bool threw_exception =
false;
147 threw_exception =
true;
150 BOOST_REQUIRE_EQUAL(threw_exception,
true);
163 BOOST_REQUIRE(microslice_ptr.get() != 0);
164 if (microslice_ptr.get() != 0) {
165 BOOST_REQUIRE_EQUAL(microslice_ptr->nanoSliceCount(), 2);
166 std::unique_ptr<dune::NanoSlice> nanoslice_ptr = microslice_ptr->nanoSlice(1);
167 BOOST_REQUIRE(nanoslice_ptr.get() != 0);
168 if (nanoslice_ptr.get() != 0) {
169 BOOST_REQUIRE_EQUAL(nanoslice_ptr->sampleCount(), 1);
170 BOOST_REQUIRE(nanoslice_ptr->sampleValue(0, value));
171 BOOST_REQUIRE_EQUAL(value, SAMPLE3);
176 BOOST_REQUIRE(microslice_ptr.get() != 0);
177 if (microslice_ptr.get() != 0) {
178 BOOST_REQUIRE_EQUAL(microslice_ptr->nanoSliceCount(), 1);
179 std::unique_ptr<dune::NanoSlice> nanoslice_ptr = microslice_ptr->nanoSlice(0);
180 BOOST_REQUIRE(nanoslice_ptr.get() != 0);
181 if (nanoslice_ptr.get() != 0) {
182 BOOST_REQUIRE_EQUAL(nanoslice_ptr->sampleCount(), 2);
183 BOOST_REQUIRE(nanoslice_ptr->sampleValue(0, value));
184 BOOST_REQUIRE_EQUAL(value, SAMPLE4);
185 BOOST_REQUIRE(nanoslice_ptr->sampleValue(1, value));
186 BOOST_REQUIRE_EQUAL(value, SAMPLE5);
215 BOOST_AUTO_TEST_SUITE_END()
217 #pragma GCC diagnostic pop
std::shared_ptr< MicroSliceWriter > reserveMicroSlice(uint32_t ms_max_bytes)
std::unique_ptr< MicroSlice > microSlice(uint32_t index) const
Header::microslice_count_t microSliceCount() const
BOOST_AUTO_TEST_CASE(BaselineTest)
Header::millislice_size_t size() const
cet::coded_exception< error, detail::translate > exception