Project
Loading...
Searching...
No Matches
tableview.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
16
17#define BOOST_TEST_MODULE Test Algorithm TableView
18#define BOOST_TEST_MAIN
19#define BOOST_TEST_DYN_LINK
20#include <boost/test/unit_test.hpp>
21#include <iostream>
22#include <iomanip>
23#include <cstring> // memcmp
24#include "Headers/DataHeader.h" // hexdump, DataHeader
25#include "Headers/HeartbeatFrame.h" // HeartbeatHeader, HeartbeatTrailer
26#include "../include/Algorithm/TableView.h"
27#include "../include/Algorithm/Parser.h"
29
33
34template <typename... Targs>
35void hexDump(Targs... Fargs)
36{
37 // a simple redirect to enable/disable the hexdump printout
38 o2::header::hexDump(Fargs...);
39}
40
41BOOST_AUTO_TEST_CASE(test_tableview_reverse)
42{
45 // the length of the data is set in the trailer word
46 // the header is used as column description, using slightly different
47 // orbit numbers in the to data sets which will result in two complete
48 // columns at beginning and end, while the two in the middle only have
49 // one row entry
50 TestFrame tf1(FrameT({0x1100000000000000}, "heartbeatdata", {0x510000000000000e}),
51 FrameT({0x1100000000000001}, "test", {0x5100000000000005}),
52 FrameT({0x1100000000000003}, "dummydata", {0x510000000000000a}));
53 TestFrame tf2(FrameT({0x1100000000000000}, "frame2a", {0x5100000000000008}),
54 FrameT({0x1100000000000002}, "frame2b", {0x5100000000000008}),
55 FrameT({0x1100000000000003}, "frame2c", {0x5100000000000008}));
56 hexDump("Test frame 1", tf1.buffer.get(), tf1.size());
57 hexDump("Test frame 2", tf2.buffer.get(), tf2.size());
58
59 // the payload length is set in the trailer, so we need a reverse parser
60 using ParserT = o2::algorithm::ReverseParser<typename FrameT::HeaderType,
61 typename FrameT::TrailerType>;
62
63 // define the view type for DataHeader as row descriptor,
64 // HeartbeatHeader as column descriptor and the reverse parser
67 ParserT>;
68 ViewType heartbeatview;
69
73 dh1.subSpecification = 0;
74 dh1.payloadSize = 0;
75
79 dh2.subSpecification = 0xdeadbeef;
80 dh2.payloadSize = 0;
81
82 heartbeatview.addRow(dh1, (std::byte*)tf1.buffer.get(), tf1.size());
83 heartbeatview.addRow(dh2, (std::byte*)tf2.buffer.get(), tf2.size());
84
85 std::cout << "slots: " << heartbeatview.getNRows()
86 << " columns: " << heartbeatview.getNColumns()
87 << std::endl;
88
89 // definitions for the data check
90 const char* dataset1[] = {
91 "heartbeatdata",
92 "test",
93 "dummydata"};
94 const char* dataset2[] = {
95 "frame2a",
96 "frame2b",
97 "frame2c"};
98
99 // four orbits are populated, 0 and 3 with 2 rows, 1 and 2 with one row
100 BOOST_REQUIRE(heartbeatview.getNColumns() == 4);
101 BOOST_REQUIRE(heartbeatview.getNRows() == 2);
102 unsigned requiredNofRowsInColumn[] = {2, 1, 1, 2};
103
104 unsigned colidx = 0;
105 unsigned dataset1idx = 0;
106 unsigned dataset2idx = 0;
107 for (auto columnIt = heartbeatview.begin(), end = heartbeatview.end();
108 columnIt != end; ++columnIt, ++colidx) {
109 unsigned rowidx = 0;
110 std::cout << "---------------------------------------" << std::endl;
111 for (auto row : columnIt) {
112 auto dataset = (rowidx == 1 || colidx == 2) ? dataset2 : dataset1;
113 auto& datasetidx = (rowidx == 1 || colidx == 2) ? dataset2idx : dataset1idx;
114 hexDump("Entry", row.buffer, row.size);
115 BOOST_CHECK(memcmp(row.buffer, dataset[datasetidx++], row.size) == 0);
116 ++rowidx;
117 }
118 BOOST_CHECK(rowidx == requiredNofRowsInColumn[colidx]);
119 }
120}
121
122BOOST_AUTO_TEST_CASE(test_tableview_formaterror)
123{
126 // note: the length of the data is set in the trailer word
127 // specifying wrong length in the second entry, no frames should be added
128 TestFrame tf1(FrameT({0x1100000000000000}, "heartbeatdata", {0x510000000000000e}),
129 FrameT({0x1100000000000001}, "test", {0x5100000000000004}),
130 FrameT({0x1100000000000003}, "dummydata", {0x510000000000000a}));
131
132 // the payload length is set in the trailer, so we need a reverse parser
133 using ParserT = o2::algorithm::ReverseParser<typename FrameT::HeaderType,
134 typename FrameT::TrailerType>;
135
136 // define the view type for DataHeader as row descriptor,
137 // HeartbeatHeader as column descriptor and the reverse parser
140 ParserT>;
141 ViewType heartbeatview;
142
146 dh.subSpecification = 0;
147 dh.payloadSize = 0;
148
149 heartbeatview.addRow(dh, (std::byte*)tf1.buffer.get(), tf1.size());
150
151 BOOST_CHECK(heartbeatview.getNRows() == 0);
152 BOOST_CHECK(heartbeatview.getNColumns() == 0);
153}
An allocator for static sequences of object types.
GLuint GLuint end
Definition glcorearb.h:469
void hexDump(const char *desc, const void *voidaddr, size_t len, size_t max=0)
helper function to print a hex/ASCII dump of some memory
Descriptor< gSizeDataDescriptionString > DataDescription
Definition DataHeader.h:551
Descriptor< gSizeDataOriginString > DataOrigin
Definition DataHeader.h:550
static const BaseHeader * get(const std::byte *b, size_t=0)
access header in buffer
Definition DataHeader.h:405
constexpr uint32_t size() const noexcept
Definition DataHeader.h:421
the main header struct
Definition DataHeader.h:618
DataDescription dataDescription
Definition DataHeader.h:636
SubSpecificationType subSpecification
Definition DataHeader.h:656
PayloadSizeType payloadSize
Definition DataHeader.h:666
void hexDump(Targs... Fargs)
Definition tableview.cxx:35
BOOST_AUTO_TEST_CASE(test_tableview_reverse)
Definition tableview.cxx:41
BOOST_CHECK(tree)
std::vector< int > row