CbmRoot
Loading...
Searching...
No Matches
_GTestChannelMapping.cxx
Go to the documentation of this file.
1/* Copyright (C) 2023 FIAS Frankfurt Institute for Advanced Studies, Frankfurt / Main
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: David Gutierrez [committer], Dario Ramirez */
4
7
8#include <array>
9#include <optional>
10
11#include <gtest/gtest-death-test.h>
12#include <gtest/gtest.h>
13
14#define EXPECT_OPT(maybe_val1, val2) \
15 ASSERT_TRUE(maybe_val1.has_value()); \
16 EXPECT_EQ(*maybe_val1, val2)
17
18using namespace cbm::algo;
19using namespace cbm::algo::sts;
20
21TEST(_ChannelMapping, FailOnValueLimits)
22{
23 EXPECT_EQ(Module::ChannelInModule(Module::CHANNELS_PER_ASIC + 1, 0), std::nullopt);
24 EXPECT_EQ(Module::ChannelInModule(0, Module::ASICS_PER_MODULE + 1), std::nullopt);
25}
26
27TEST(_ChannelMapping, ReverseFailOnValueLimits)
28{
29 EXPECT_EQ(Module::ChannelInAsic(Module::CHANNELS_PER_MODULE + 1), std::nullopt);
30}
31
32TEST(_ChannelMapping, ModuleEdgesMapping)
33{
39}
40
41TEST(_ChannelMapping, ReverseModuleEdgesMapping)
42{
43 {
44 const auto expect = std::make_pair<u16, u16>(0, 0);
46 }
47 {
48 const auto expect = std::make_pair<u16, u16>(127, 7);
49 EXPECT_OPT(Module::ChannelInAsic(1023), expect);
50 }
51 {
52 const auto expect = std::make_pair<u16, u16>(127, 8);
53 EXPECT_OPT(Module::ChannelInAsic(2046), expect);
54 }
55 {
56 const auto expect = std::make_pair<u16, u16>(125, 8);
57 EXPECT_OPT(Module::ChannelInAsic(1024), expect);
58 }
59 {
60 const auto expect = std::make_pair<u16, u16>(0, 15);
61 EXPECT_OPT(Module::ChannelInAsic(2047), expect);
62 }
63}
64
65TEST(_ChannelMapping, ExaustiveMapping)
66{
67 for (u16 channel = 0; channel < Module::CHANNELS_PER_MODULE; channel++) {
68 const auto maybe_hw = Module::ChannelInAsic(channel);
69 ASSERT_TRUE(maybe_hw.has_value());
70
71 const auto maybe_sh = Module::ChannelInModule(maybe_hw->first, maybe_hw->second);
72 EXPECT_OPT(maybe_sh, channel);
73 }
74}
75
76TEST(_ChannelMapping, Compatibility)
77{
78 for (u16 asic = 0; asic < Module::ASICS_PER_MODULE / 2; asic++) { // n side
79 for (u16 chn = 0; chn < Module::CHANNELS_PER_ASIC; chn++) {
80 const auto legacy = asic * Module::CHANNELS_PER_ASIC + chn;
81 const auto maybe_sw = Module::ChannelInModule(chn, asic);
82 EXPECT_OPT(maybe_sw, legacy);
83 }
84 }
85
86 for (u16 asic = Module::ASICS_PER_MODULE / 2; asic < Module::ASICS_PER_MODULE; asic++) { // p side
87 for (u16 chn = 0; chn < Module::CHANNELS_PER_ASIC; chn += 2) { // even channels
88 const auto legacy = (asic + 1) * Module::CHANNELS_PER_ASIC - chn - 1;
89 const auto maybe_sw = Module::ChannelInModule(chn, asic);
90 EXPECT_OPT(maybe_sw, legacy);
91 }
92
93 for (u16 chn = 1; chn < Module::CHANNELS_PER_ASIC; chn += 2) { // odd channels
94 const auto legacy = (asic + 1) * Module::CHANNELS_PER_ASIC - chn - 1;
95 const auto maybe_sw = Module::ChannelInModule(chn, asic);
96
97 if ((asic == 8) && (chn == 127)) { // z-strip
98 EXPECT_OPT(maybe_sw, 2046);
99 EXPECT_EQ(1024, legacy);
100 }
101 else {
102 EXPECT_OPT(maybe_sw, legacy - 2);
103 }
104 }
105 }
106}
107
108TEST(_ChannelMapping, Completness)
109{
110 std::array<bool, Module::CHANNELS_PER_MODULE> visited = {false};
111
112 for (u16 asic = 0; asic < Module::ASICS_PER_MODULE; asic++) {
113 for (u16 chn = 0; chn < Module::CHANNELS_PER_ASIC; chn++) {
114 const auto maybe_sw = Module::ChannelInModule(chn, asic);
115 ASSERT_TRUE(maybe_sw.has_value());
116 ASSERT_LT(*maybe_sw, visited.size());
117 visited[*maybe_sw] = true;
118 }
119 }
120
121 for (const auto chn : visited) {
122 EXPECT_TRUE(chn);
123 }
124}
#define EXPECT_OPT(maybe_val1, val2)
TEST(_ChannelMapping, FailOnValueLimits)
static std::optional< std::pair< u16, u16 > > ChannelInAsic(const u16 channel)
Channel SW to HW conversion.
static constexpr u16 CHANNELS_PER_MODULE
static constexpr u16 CHANNELS_PER_ASIC
static constexpr u16 ASICS_PER_MODULE
static std::optional< u16 > ChannelInModule(const u16 elink_chn, const u16 asic_idx)
Channel HW to SW conversion.
uint16_t u16
Definition Definitions.h:19