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
5#include "Definitions.h"
7
8#include <array>
9#include <optional>
10
11#include <gtest.h>
12#include <gtest/gtest-death-test.h>
13#include <gtest/gtest.h>
14
15#define EXPECT_OPT(maybe_val1, val2) \
16 ASSERT_TRUE(maybe_val1.has_value()); \
17 EXPECT_EQ(*maybe_val1, val2)
18
19using namespace cbm::algo;
20using namespace cbm::algo::sts;
21
22TEST(_ChannelMapping, FailOnValueLimits)
23{
24 EXPECT_EQ(Module::ChannelInModule(Module::CHANNELS_PER_ASIC + 1, 0), std::nullopt);
25 EXPECT_EQ(Module::ChannelInModule(0, Module::ASICS_PER_MODULE + 1), std::nullopt);
26}
27
28TEST(_ChannelMapping, ReverseFailOnValueLimits)
29{
30 EXPECT_EQ(Module::ChannelInAsic(Module::CHANNELS_PER_MODULE + 1), std::nullopt);
31}
32
33TEST(_ChannelMapping, ModuleEdgesMapping)
34{
40}
41
42TEST(_ChannelMapping, ReverseModuleEdgesMapping)
43{
44 {
45 const auto expect = std::make_pair<u16, u16>(0, 0);
47 }
48 {
49 const auto expect = std::make_pair<u16, u16>(127, 7);
50 EXPECT_OPT(Module::ChannelInAsic(1023), expect);
51 }
52 {
53 const auto expect = std::make_pair<u16, u16>(127, 8);
54 EXPECT_OPT(Module::ChannelInAsic(2046), expect);
55 }
56 {
57 const auto expect = std::make_pair<u16, u16>(125, 8);
58 EXPECT_OPT(Module::ChannelInAsic(1024), expect);
59 }
60 {
61 const auto expect = std::make_pair<u16, u16>(0, 15);
62 EXPECT_OPT(Module::ChannelInAsic(2047), expect);
63 }
64}
65
66TEST(_ChannelMapping, ExaustiveMapping)
67{
68 for (u16 channel = 0; channel < Module::CHANNELS_PER_MODULE; channel++) {
69 const auto maybe_hw = Module::ChannelInAsic(channel);
70 ASSERT_TRUE(maybe_hw.has_value());
71
72 const auto maybe_sh = Module::ChannelInModule(maybe_hw->first, maybe_hw->second);
73 EXPECT_OPT(maybe_sh, channel);
74 }
75}
76
77TEST(_ChannelMapping, Compatibility)
78{
79 for (u16 asic = 0; asic < Module::ASICS_PER_MODULE / 2; asic++) { // n side
80 for (u16 chn = 0; chn < Module::CHANNELS_PER_ASIC; chn++) {
81 const auto legacy = asic * Module::CHANNELS_PER_ASIC + chn;
82 const auto maybe_sw = Module::ChannelInModule(chn, asic);
83 EXPECT_OPT(maybe_sw, legacy);
84 }
85 }
86
87 for (u16 asic = Module::ASICS_PER_MODULE / 2; asic < Module::ASICS_PER_MODULE; asic++) { // p side
88 for (u16 chn = 0; chn < Module::CHANNELS_PER_ASIC; chn += 2) { // even channels
89 const auto legacy = (asic + 1) * Module::CHANNELS_PER_ASIC - chn - 1;
90 const auto maybe_sw = Module::ChannelInModule(chn, asic);
91 EXPECT_OPT(maybe_sw, legacy);
92 }
93
94 for (u16 chn = 1; chn < Module::CHANNELS_PER_ASIC; chn += 2) { // odd channels
95 const auto legacy = (asic + 1) * Module::CHANNELS_PER_ASIC - chn - 1;
96 const auto maybe_sw = Module::ChannelInModule(chn, asic);
97
98 if ((asic == 8) && (chn == 127)) { // z-strip
99 EXPECT_OPT(maybe_sw, 2046);
100 EXPECT_EQ(1024, legacy);
101 }
102 else {
103 EXPECT_OPT(maybe_sw, legacy - 2);
104 }
105 }
106 }
107}
108
109TEST(_ChannelMapping, Completness)
110{
111 std::array<bool, Module::CHANNELS_PER_MODULE> visited = {false};
112
113 for (u16 asic = 0; asic < Module::ASICS_PER_MODULE; asic++) {
114 for (u16 chn = 0; chn < Module::CHANNELS_PER_ASIC; chn++) {
115 const auto maybe_sw = Module::ChannelInModule(chn, asic);
116 ASSERT_TRUE(maybe_sw.has_value());
117 ASSERT_LT(*maybe_sw, visited.size());
118 visited[*maybe_sw] = true;
119 }
120 }
121
122 for (const auto chn : visited) {
123 EXPECT_TRUE(chn);
124 }
125}
#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.
std::uint16_t u16
Definition Definitions.h:19