Project
Loading...
Searching...
No Matches
test_RawParser.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#include <catch_amalgamated.hpp>
13#include "DPLUtils/RawParser.h"
14
15namespace o2::framework
16{
17
18constexpr size_t PageSize = 8192;
23
24template <typename RDH, typename Container>
25void fillPages(Container& buffer)
26{
27 RDH defaultHeader;
28 size_t const NofPages = buffer.size() / PageSize;
29 memset(buffer.data(), 0, buffer.size());
30 for (int pageNo = 0; pageNo < NofPages; pageNo++) {
31 auto* rdh = reinterpret_cast<RDH*>(buffer.data() + pageNo * PageSize);
32 rdh->version = defaultHeader.version;
33 rdh->headerSize = sizeof(RDH);
34 rdh->offsetToNext = PageSize;
35 rdh->memorySize = PageSize;
36 rdh->pageCnt = pageNo;
37 rdh->packetCounter = pageNo;
38 rdh->stop = pageNo + 1 == NofPages;
39 auto* data = reinterpret_cast<size_t*>(buffer.data() + pageNo * PageSize + rdh->headerSize);
40 *data = pageNo;
41 }
42}
43
44TEMPLATE_TEST_CASE("test_RawParser", "[RDH][template]", V5, V6, V7)
45{
46 constexpr size_t NofPages = 3;
47 std::array<unsigned char, NofPages * PageSize> buffer;
48 fillPages<TestType>(buffer);
49
50 size_t count = 0;
51 auto processor = [&count](auto data, size_t size) {
52 REQUIRE(size == PageSize - sizeof(TestType));
53 REQUIRE(*reinterpret_cast<size_t const*>(data) == count);
54 INFO("Processing block of size " << size);
55 count++;
56 };
57 RawParser parser(buffer.data(), buffer.size());
58 parser.parse(processor);
59 REQUIRE(count == NofPages);
60
61 parser.reset();
62
63 INFO(parser);
64 count = 0;
65 for (auto it = parser.begin(), end = parser.end(); it != end; ++it, ++count) {
66 REQUIRE(it.size() == PageSize - sizeof(TestType));
67 REQUIRE(*reinterpret_cast<size_t const*>(it.data()) == count);
68 // FIXME: there is a problem with invoking get_if<T>, but only if the code is templatized
69 // and called from within boost unit test macros.
70 // expected primary-expression before ‘>’ token
71 // BOOST_CHECK(it.get_if<RDH>() != nullptr);
72 // ^
73 // That's why the type is deduced by argument until the problem is understood.
74 REQUIRE(it.get_if((TestType*)nullptr) != nullptr);
75 if constexpr (std::is_same<TestType, V4>::value == false) {
76 REQUIRE(it.get_if((V4*)nullptr) == nullptr);
77 } else {
78 REQUIRE(it.get_if((V5*)nullptr) == nullptr);
79 }
80 REQUIRE(it.raw() + it.offset() == it.data());
81 INFO(it << ": block size " << it.size());
82 }
83}
84
85} // namespace o2::framework
Generic parser for consecutive raw pages.
const_iterator begin() const
Definition RawParser.h:618
bool reset()
Reset parser and set position to beginning of buffer.
Definition RawParser.h:495
const_iterator end() const
Definition RawParser.h:623
void parse(Processor &&processor)
Parse complete raw buffer and call processor on payload data for each page.
Definition RawParser.h:485
GLint GLsizei count
Definition glcorearb.h:399
GLuint buffer
Definition glcorearb.h:655
GLsizeiptr size
Definition glcorearb.h:659
GLuint GLuint end
Definition glcorearb.h:469
GLboolean * data
Definition glcorearb.h:298
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
constexpr size_t PageSize
void fillPages(Container &buffer)
TEMPLATE_TEST_CASE("test_RawParser", "[RDH][template]", V5, V6, V7)