-
Notifications
You must be signed in to change notification settings - Fork 507
Expand file tree
/
Copy pathtest_RawParser.cxx
More file actions
90 lines (80 loc) · 3.16 KB
/
Copy pathtest_RawParser.cxx
File metadata and controls
90 lines (80 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#define BOOST_TEST_MODULE Test Framework Utils RawParser
#define BOOST_TEST_MAIN
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include <boost/mpl/list.hpp>
#include "DPLUtils/RawParser.h"
#include <iostream>
namespace o2::framework
{
constexpr size_t PageSize = 8192;
using V6 = header::RAWDataHeaderV6;
using V5 = header::RAWDataHeaderV5;
using V4 = header::RAWDataHeaderV4;
template <typename RDH, typename Container>
void fillPages(Container& buffer)
{
RDH defaultHeader;
size_t const NofPages = buffer.size() / PageSize;
memset(buffer.data(), 0, buffer.size());
for (int pageNo = 0; pageNo < NofPages; pageNo++) {
auto* rdh = reinterpret_cast<RDH*>(buffer.data() + pageNo * PageSize);
rdh->version = defaultHeader.version;
rdh->headerSize = sizeof(RDH);
rdh->offsetToNext = PageSize;
rdh->memorySize = PageSize;
rdh->pageCnt = NofPages;
rdh->packetCounter = pageNo;
rdh->stop = pageNo + 1 == NofPages;
auto* data = reinterpret_cast<size_t*>(buffer.data() + pageNo * PageSize + rdh->headerSize);
*data = pageNo;
}
}
typedef boost::mpl::list<V5, V6> testTypes;
BOOST_AUTO_TEST_CASE_TEMPLATE(test_RawParser, RDH, testTypes)
{
constexpr size_t NofPages = 3;
std::array<unsigned char, NofPages * PageSize> buffer;
fillPages<RDH>(buffer);
size_t count = 0;
auto processor = [&count](auto data, size_t size) {
BOOST_CHECK(size == PageSize - sizeof(RDH));
BOOST_CHECK(*reinterpret_cast<size_t const*>(data) == count);
std::cout << "Processing block of size " << size << std::endl;
count++;
};
RawParser parser(buffer.data(), buffer.size());
parser.parse(processor);
BOOST_CHECK(count == NofPages);
parser.reset();
std::cout << parser << std::endl;
count = 0;
for (auto it = parser.begin(), end = parser.end(); it != end; ++it, ++count) {
BOOST_CHECK(it.size() == PageSize - sizeof(RDH));
BOOST_CHECK(*reinterpret_cast<size_t const*>(it.data()) == count);
// FIXME: there is a problem with invoking get_if<T>, but only if the code is templatized
// and called from within boost unit test macros.
// expected primary-expression before ‘>’ token
// BOOST_CHECK(it.get_if<RDH>() != nullptr);
// ^
// That's why the type is deduced by argument until the problem is understood.
BOOST_CHECK(it.get_if((RDH*)nullptr) != nullptr);
if constexpr (std::is_same<RDH, V4>::value == false) {
BOOST_CHECK(it.get_if((V4*)nullptr) == nullptr);
} else {
BOOST_CHECK(it.get_if((V5*)nullptr) == nullptr);
}
BOOST_CHECK(it.raw() + it.offset() == it.data());
std::cout << it << ": block size " << it.size() << std::endl;
}
}
} // namespace o2::framework