40#pragma GCC diagnostic push
45# if (defined(__clang__) && __GNUC__ >= 10) || \
46 (!defined(__clang__) && __GNUC__ >= 9)
47# pragma GCC diagnostic ignored "-Wdeprecated-copy"
51#include <gmock/gmock.h>
52#include <gtest/gtest.h>
54#pragma GCC diagnostic pop
64using testing::ElementsAre;
66using testing::ElementsAreArray;
69using testing::HasSubstr;
83 std::array<uint8_t, BufSize>
buf;
84 RegisterBankLE::RegisterRaz
raz;
96 EXPECT_EQ(
raz.name(),
"raz");
101 EXPECT_EQ(
raz.size(), RazSize);
107 raz.write(buf.data() + BufOffset);
108 raz.read(buf.data() + BufOffset);
109 EXPECT_THAT(buf, ElementsAreArray({0xff, 0xff, 0xff, 0xff,
110 0x00, 0x00, 0x00, 0x00,
111 0xff, 0xff, 0xff, 0xff}));
117 raz.write(buf.data() + BufOffset, 1, 3);
118 raz.read(buf.data() + BufOffset, 1, 3);
119 EXPECT_THAT(buf, ElementsAreArray({0xff, 0xff, 0xff, 0xff,
120 0x00, 0x00, 0x00, 0xff,
121 0xff, 0xff, 0xff, 0xff}));
127 raz.write(buf.data() + BufOffset, 0, 3);
128 raz.read(buf.data() + BufOffset, 0, 3);
129 EXPECT_THAT(buf, ElementsAreArray({0xff, 0xff, 0xff, 0xff,
130 0x00, 0x00, 0x00, 0xff,
131 0xff, 0xff, 0xff, 0xff}));
137 raz.write(buf.data() + BufOffset, 1, 2);
138 raz.read(buf.data() + BufOffset, 1, 2);
139 EXPECT_THAT(buf, ElementsAreArray({0xff, 0xff, 0xff, 0xff,
140 0x00, 0x00, 0xff, 0xff,
141 0xff, 0xff, 0xff, 0xff}));
146 std::ostringstream
os;
148 EXPECT_EQ(
os.str(),
"");
154 EXPECT_TRUE(
raz.unserialize(
s));
169 std::array<uint8_t, BufSize>
buf;
170 RegisterBankLE::RegisterRao
rao;
182 EXPECT_EQ(rao.name(),
"rao");
187 EXPECT_EQ(rao.size(), RaoSize);
193 rao.write(buf.data() + BufOffset);
194 rao.read(buf.data() + BufOffset);
195 EXPECT_THAT(buf, ElementsAreArray({0x00, 0x00, 0x00, 0x00,
196 0xff, 0xff, 0xff, 0xff,
197 0x00, 0x00, 0x00, 0x00}));
203 rao.write(buf.data() + BufOffset, 1, 3);
204 rao.read(buf.data() + BufOffset, 1, 3);
205 EXPECT_THAT(buf, ElementsAreArray({0x00, 0x00, 0x00, 0x00,
206 0xff, 0xff, 0xff, 0x00,
207 0x00, 0x00, 0x00, 0x00}));
213 rao.write(buf.data() + BufOffset, 0, 3);
214 rao.read(buf.data() + BufOffset, 0, 3);
215 EXPECT_THAT(buf, ElementsAreArray({0x00, 0x00, 0x00, 0x00,
216 0xff, 0xff, 0xff, 0x00,
217 0x00, 0x00, 0x00, 0x00}));
223 rao.write(buf.data() + BufOffset, 1, 2);
224 rao.read(buf.data() + BufOffset, 1, 2);
225 EXPECT_THAT(buf, ElementsAreArray({0x00, 0x00, 0x00, 0x00,
226 0xff, 0xff, 0x00, 0x00,
227 0x00, 0x00, 0x00, 0x00}));
232 std::ostringstream
os;
234 EXPECT_EQ(
os.str(),
"");
240 EXPECT_TRUE(rao.unserialize(
s));
253 std::array<uint8_t, RegSize * 3>
buf;
256 RegisterBankLE::RegisterBuf
reg;
260 :
buf{0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc},
261 backing{0x10, 0x20, 0x30, 0x40, 0x50, 0x60,
262 0x70, 0x80, 0x90, 0xa0, 0xb0, 0xc0},
271 EXPECT_EQ(
reg.name(),
"buf_reg");
276 EXPECT_EQ(
reg.size(), RegSize);
282 reg.read(buf.data() + RegSize);
283 EXPECT_THAT(buf, ElementsAreArray({0x1, 0x2, 0x3, 0x4,
284 0x50, 0x60, 0x70, 0x80,
285 0x9, 0xa, 0xb, 0xc}));
286 EXPECT_THAT(backing, ElementsAreArray({0x10, 0x20, 0x30, 0x40,
287 0x50, 0x60, 0x70, 0x80,
288 0x90, 0xa0, 0xb0, 0xc0}));
294 reg.write(buf.data() + RegSize);
295 EXPECT_THAT(buf, ElementsAreArray({0x1, 0x2, 0x3, 0x4,
297 0x9, 0xa, 0xb, 0xc}));
298 EXPECT_THAT(backing, ElementsAreArray({0x10, 0x20, 0x30, 0x40,
300 0x90, 0xa0, 0xb0, 0xc0}));
306 reg.read(buf.data() + RegSize, 1, 3);
307 EXPECT_THAT(buf, ElementsAreArray({0x1, 0x2, 0x3, 0x4,
308 0x60, 0x70, 0x80, 0x8,
309 0x9, 0xa, 0xb, 0xc}));
310 EXPECT_THAT(backing, ElementsAreArray({0x10, 0x20, 0x30, 0x40,
311 0x50, 0x60, 0x70, 0x80,
312 0x90, 0xa0, 0xb0, 0xc0}));
318 reg.write(buf.data() + RegSize, 1, 3);
319 EXPECT_THAT(buf, ElementsAreArray({0x1, 0x2, 0x3, 0x4,
321 0x9, 0xa, 0xb, 0xc}));
322 EXPECT_THAT(backing, ElementsAreArray({0x10, 0x20, 0x30, 0x40,
324 0x90, 0xa0, 0xb0, 0xc0}));
330 reg.read(buf.data() + RegSize, 0, 3);
331 EXPECT_THAT(buf, ElementsAreArray({0x1, 0x2, 0x3, 0x4,
332 0x50, 0x60, 0x70, 0x8,
333 0x9, 0xa, 0xb, 0xc}));
334 EXPECT_THAT(backing, ElementsAreArray({0x10, 0x20, 0x30, 0x40,
335 0x50, 0x60, 0x70, 0x80,
336 0x90, 0xa0, 0xb0, 0xc0}));
342 reg.write(buf.data() + RegSize, 0, 3);
343 EXPECT_THAT(buf, ElementsAreArray({0x1, 0x2, 0x3, 0x4,
345 0x9, 0xa, 0xb, 0xc}));
346 EXPECT_THAT(backing, ElementsAreArray({0x10, 0x20, 0x30, 0x40,
348 0x90, 0xa0, 0xb0, 0xc0}));
354 reg.read(buf.data() + RegSize, 1, 2);
355 EXPECT_THAT(buf, ElementsAreArray({0x1, 0x2, 0x3, 0x4,
356 0x60, 0x70, 0x7, 0x8,
357 0x9, 0xa, 0xb, 0xc}));
358 EXPECT_THAT(backing, ElementsAreArray({0x10, 0x20, 0x30, 0x40,
359 0x50, 0x60, 0x70, 0x80,
360 0x90, 0xa0, 0xb0, 0xc0}));
366 reg.write(buf.data() + RegSize, 1, 2);
367 EXPECT_THAT(buf, ElementsAreArray({0x1, 0x2, 0x3, 0x4,
369 0x9, 0xa, 0xb, 0xc}));
370 EXPECT_THAT(backing, ElementsAreArray({0x10, 0x20, 0x30, 0x40,
371 0x50, 0x5, 0x6, 0x80,
372 0x90, 0xa0, 0xb0, 0xc0}));
377 std::ostringstream
os;
379 EXPECT_EQ(
os.str(),
"");
385 EXPECT_TRUE(
reg.unserialize(
s));
400 RegisterBankLE::RegisterLBuf<12>
reg;
406 reg.buffer.fill(0xff);
412 EXPECT_EQ(
reg.name(),
"lbuf_reg");
417 reg.write(to_write.data(), 4, 4);
418 EXPECT_THAT(
reg.buffer, ElementsAreArray({0xff, 0xff, 0xff, 0xff,
420 0xff, 0xff, 0xff, 0xff}));
425 std::ostringstream
os;
426 for (
int i = 0;
i <
reg.buffer.size();
i++)
429 EXPECT_EQ(
os.str(),
"0 1 2 3 4 5 6 7 8 9 10 11");
434 std::string
s =
"0 1 2 3 4 5 6 7 8 9 10 11";
435 EXPECT_TRUE(
reg.unserialize(
s));
436 EXPECT_THAT(
reg.buffer, ElementsAreArray({0, 1, 2, 3, 4, 5,
437 6, 7, 8, 9, 10, 11}));
442 std::string
s =
"0 1 2 3 4 5 6 7 8 9 10";
443 EXPECT_FALSE(
reg.unserialize(
s));
444 EXPECT_THAT(
reg.buffer, ElementsAreArray({0xff, 0xff, 0xff, 0xff,
445 0xff, 0xff, 0xff, 0xff,
446 0xff, 0xff, 0xff, 0xff}));
463 RegisterBankLE::Register<BackingType>
reg;
466 std::array<uint8_t, RegSize * 3>
buf;
469 buf{0x1, 0x2, 0x3, 0x4, 0x5, 0x6}
477 RegisterBankLE::Register<uint32_t> def(
"def");
478 EXPECT_EQ(def.get(), 0);
483 EXPECT_EQ(
reg.name(),
"le_reg");
488 EXPECT_EQ(
reg.size(), RegSize);
494 EXPECT_EQ(
reg.writeable(), 0xffff);
500 EXPECT_EQ(
reg.get(), 0x1122);
506 EXPECT_EQ(
reg.get(), 0x1020);
508 EXPECT_EQ(
reg.get(), 0x3040);
514 regBE.read(buf.data() + RegSize);
515 EXPECT_EQ(regBE.get(), 0x1122);
516 EXPECT_THAT(buf, ElementsAre(0x1, 0x2, 0x11, 0x22, 0x5, 0x6));
522 regBE.write(buf.data() + RegSize);
523 EXPECT_EQ(regBE.get(), 0x0304);
524 EXPECT_THAT(buf, ElementsAre(0x1, 0x2, 0x3, 0x4, 0x5, 0x6));
530 regBE.read(buf.data() + RegSize, 0, 1);
531 EXPECT_EQ(regBE.get(), 0x1122);
532 EXPECT_THAT(buf, ElementsAre(0x1, 0x2, 0x11, 0x4, 0x5, 0x6));
538 regBE.read(buf.data() + RegSize, 1, 1);
539 EXPECT_EQ(regBE.get(), 0x1122);
540 EXPECT_THAT(buf, ElementsAre(0x1, 0x2, 0x22, 0x4, 0x5, 0x6));
546 regBE.write(buf.data() + RegSize, 0, 1);
547 EXPECT_EQ(regBE.get(), 0x0322);
548 EXPECT_THAT(buf, ElementsAre(0x1, 0x2, 0x3, 0x4, 0x5, 0x6));
554 regBE.write(buf.data() + RegSize, 1, 1);
555 EXPECT_EQ(regBE.get(), 0x1103);
556 EXPECT_THAT(buf, ElementsAre(0x1, 0x2, 0x3, 0x4, 0x5, 0x6));
562 reg.read(buf.data() + RegSize);
563 EXPECT_EQ(
reg.get(), 0x1122);
564 EXPECT_THAT(buf, ElementsAre(0x1, 0x2, 0x22, 0x11, 0x5, 0x6));
570 reg.write(buf.data() + RegSize);
571 EXPECT_EQ(
reg.get(), 0x0403);
572 EXPECT_THAT(buf, ElementsAre(0x1, 0x2, 0x3, 0x4, 0x5, 0x6));
578 reg.read(buf.data() + RegSize, 0, 1);
579 EXPECT_EQ(
reg.get(), 0x1122);
580 EXPECT_THAT(buf, ElementsAre(0x1, 0x2, 0x22, 0x4, 0x5, 0x6));
586 reg.read(buf.data() + RegSize, 1, 1);
587 EXPECT_EQ(
reg.get(), 0x1122);
588 EXPECT_THAT(buf, ElementsAre(0x1, 0x2, 0x11, 0x4, 0x5, 0x6));
594 reg.write(buf.data() + RegSize, 0, 1);
595 EXPECT_EQ(
reg.get(), 0x1103);
596 EXPECT_THAT(buf, ElementsAre(0x1, 0x2, 0x3, 0x4, 0x5, 0x6));
602 reg.write(buf.data() + RegSize, 1, 1);
603 EXPECT_EQ(
reg.get(), 0x0322);
604 EXPECT_THAT(buf, ElementsAre(0x1, 0x2, 0x3, 0x4, 0x5, 0x6));
610 reg.writeable(0xff00);
611 reg.write(buf.data() + RegSize);
612 EXPECT_EQ(
reg.get(), 0x0422);
614 regBE.writeable(0xff00);
615 regBE.write(buf.data() + RegSize);
616 EXPECT_EQ(regBE.get(), 0x0322);
623 reg.write(buf.data() + RegSize);
624 EXPECT_EQ(
reg.get(), 0x1122);
630 reg.update(0xeeee, 0x0ff0);
631 EXPECT_EQ(
reg.get(), 0x1ee2);
637 reg.writeable(0xf00f);
639 EXPECT_EQ(
reg.get(), 0xe12e);
645 RegisterBankLE::Register<BackingType> *reg_ptr =
nullptr;
646 BackingType ret = 0x3344;
648 reg.reader([®_ptr, &ret](
auto &
r){
653 reg.read(buf.data() + RegSize);
654 EXPECT_THAT(buf, ElementsAre(0x1, 0x2, 0x44, 0x33, 0x5, 0x6));
655 EXPECT_EQ(reg_ptr, &
reg);
661 using Reg = RegisterBankLE::Register<BackingType>;
665 Reg *reg_ptr =
nullptr;
666 BackingType ret = 0x3344;
676 reg.reader(&read_struct, &ReadStruct::reader);
678 reg.read(buf.data() + RegSize);
679 EXPECT_THAT(buf, ElementsAre(0x1, 0x2, 0x44, 0x33, 0x5, 0x6));
680 EXPECT_EQ(read_struct.reg_ptr, &
reg);
686 RegisterBankLE::Register<BackingType> *reg_ptr =
nullptr;
687 BackingType value = 0;
689 reg.writer([®_ptr, &value](
auto &
r,
const BackingType &
v) {
694 reg.write(buf.data() + RegSize);
695 EXPECT_EQ(reg_ptr, &
reg);
696 EXPECT_EQ(value, 0x0403);
702 using Reg = RegisterBankLE::Register<BackingType>;
706 Reg *reg_ptr =
nullptr;
707 BackingType value = 0;
717 reg.writer(&write_struct, &WriteStruct::writer);
719 reg.write(buf.data() + RegSize);
720 EXPECT_EQ(write_struct.reg_ptr, &
reg);
721 EXPECT_THAT(write_struct.value, 0x0403);
727 RegisterBankLE::Register<BackingType> *reg_ptr =
nullptr;
730 BackingType ret = 0x3344;
732 reg.partialReader([®_ptr, &first, &last, ret](
auto &
r,
int f,
int l) {
739 reg.read(buf.data() + RegSize, 1, 1);
740 EXPECT_THAT(buf, ElementsAre(0x1, 0x2, 0x33, 0x4, 0x5, 0x6));
741 EXPECT_EQ(reg_ptr, &
reg);
742 EXPECT_EQ(first, 15);
749 using Reg = RegisterBankLE::Register<BackingType>;
753 Reg *reg_ptr =
nullptr;
756 BackingType ret = 0x3344;
759 reader(
Reg &
r,
int f,
int l)
768 reg.partialReader(&read_struct, &ReadStruct::reader);
770 reg.read(buf.data() + RegSize, 1, 1);
771 EXPECT_THAT(buf, ElementsAre(0x1, 0x2, 0x33, 0x4, 0x5, 0x6));
772 EXPECT_EQ(read_struct.reg_ptr, &
reg);
773 EXPECT_EQ(read_struct.first, 15);
774 EXPECT_EQ(read_struct.last, 8);
780 RegisterBankLE::Register<BackingType> *reg_ptr =
nullptr;
781 BackingType value = 0;
785 reg.partialWriter([®_ptr, &value, &first, &last](
786 auto &
r,
const BackingType &
v,
int f,
int l) {
793 reg.write(buf.data() + RegSize, 1, 1);
794 EXPECT_EQ(reg_ptr, &
reg);
795 EXPECT_EQ(value, 0x300);
796 EXPECT_EQ(first, 15);
803 using Reg = RegisterBankLE::Register<BackingType>;
807 Reg *reg_ptr =
nullptr;
808 BackingType value = 0;
822 reg.partialWriter(&write_struct, &WriteStruct::writer);
824 reg.write(buf.data() + RegSize, 1, 1);
825 EXPECT_EQ(write_struct.reg_ptr, &
reg);
826 EXPECT_EQ(write_struct.value, 0x300);
827 EXPECT_EQ(write_struct.first, 15);
828 EXPECT_EQ(write_struct.last, 8);
834 RegisterBankLE::Register<BackingType> *reg_ptr =
nullptr;
835 BackingType ret = 0x3344;
837 reg.reader([®_ptr, &ret](
auto &
r){
842 reg.read(buf.data() + RegSize, 1, 1);
843 EXPECT_THAT(buf, ElementsAre(0x1, 0x2, 0x33, 0x4, 0x5, 0x6));
844 EXPECT_EQ(reg_ptr, &
reg);
850 RegisterBankLE::Register<BackingType> *read_reg_ptr =
nullptr;
851 BackingType read_ret = 0x3344;
853 RegisterBankLE::Register<BackingType> *write_reg_ptr =
nullptr;
854 BackingType write_value = 0;
856 reg.reader([&read_reg_ptr, read_ret](
auto &
r){
859 }).
writer([&write_reg_ptr, &write_value](
auto &
r,
const BackingType &
v) {
864 reg.write(buf.data() + RegSize, 1, 1);
865 EXPECT_THAT(buf, ElementsAre(0x1, 0x2, 0x3, 0x4, 0x5, 0x6));
866 EXPECT_EQ(read_reg_ptr, &
reg);
867 EXPECT_EQ(write_reg_ptr, &
reg);
868 EXPECT_EQ(write_value, 0x0344);
874 BackingType initial_value =
reg.get();
876 reg.get() = initial_value + 1;
877 EXPECT_EQ(
reg.get(), initial_value + 1);
881 EXPECT_EQ(
reg.get(), initial_value);
887 BackingType initial_value =
reg.get();
888 BackingType new_initial_value = initial_value + 1;
890 reg.get() = new_initial_value;
891 reg.resetInitialValue();
893 EXPECT_EQ(
reg.get(), new_initial_value);
894 EXPECT_EQ(
reg.initialValue(), new_initial_value);
896 reg.get() = new_initial_value + 1;
897 EXPECT_EQ(
reg.get(), new_initial_value + 1);
898 EXPECT_EQ(
reg.initialValue(), new_initial_value);
902 EXPECT_EQ(
reg.get(), new_initial_value);
903 EXPECT_EQ(
reg.initialValue(), new_initial_value);
909 RegisterBankLE::Register<BackingType> *reg_ptr =
nullptr;
911 reg.resetter([®_ptr](
auto &
r) {
917 EXPECT_EQ(reg_ptr, &
reg);
923 using Reg = RegisterBankLE::Register<BackingType>;
927 Reg *reg_ptr =
nullptr;
936 reg.resetter(&reset_struct, &ResetStruct::resetter);
940 EXPECT_EQ(reset_struct.reg_ptr, &
reg);
945 std::ostringstream
os;
947 EXPECT_EQ(
os.str(),
"4386");
952 std::string
s =
"1234";
953 EXPECT_TRUE(
reg.unserialize(
s));
954 EXPECT_EQ(
reg.get(), 1234);
959 std::string
s =
"not_a_number";
960 EXPECT_FALSE(
reg.unserialize(
s));
996 int _first,
int _last, uint32_t _ret) :
1016 TestReg(
const std::string &new_name, uint32_t initial) :
1019 reader([
this](
auto &
r) {
1021 access.
ret = defaultReader(
r);
1025 writer([
this](
auto &
r,
const uint32_t &
v) {
1028 defaultWriter(
r,
v);
1031 partialReader([
this](
auto &
r,
int f,
int l) {
1035 access.
ret = defaultPartialReader(
r,
f,
l);
1039 partialWriter([
this](
auto &
r,
const uint32_t &
v,
int f,
int l) {
1044 defaultPartialWriter(
r,
v,
f,
l);
1056 reg0(
"reg0", 0xd3d2d1d0),
reg1(
"reg1", 0xe3e2e1e0),
1057 reg2(
"reg2", 0xf3f2f1f0),
1059 buf{0x11, 0x22, 0x33, 0x44, 0x55, 0x66,
1060 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc}
1070 EXPECT_EQ(emptyBank.name(),
"empty");
1071 EXPECT_EQ(fullBank.name(),
"full");
1076 EXPECT_EQ(emptyBank.base(), 0x12345);
1077 EXPECT_EQ(fullBank.base(), 0x1000);
1083 EXPECT_EQ(emptyBank.size(), 0);
1084 emptyBank.addRegister(reg0);
1085 EXPECT_EQ(emptyBank.size(), 4);
1086 emptyBank.addRegisters({reg1, reg2});
1087 EXPECT_EQ(emptyBank.size(), 12);
1092 emptyBank.addRegister({0x12345});
1093 EXPECT_EQ(emptyBank.size(), 0);
1094 emptyBank.addRegister({0x12345, reg0});
1095 EXPECT_EQ(emptyBank.size(), 4);
1096 emptyBank.addRegister({0x12349});
1097 EXPECT_EQ(emptyBank.size(), 4);
1099 emptyBank.addRegisters({{0x12349, reg1}, {0x1234d}, {0x1234d, reg2}});
1100 EXPECT_EQ(emptyBank.size(), 12);
1118 auto base = emptyBank.base();
1120 emptyBank.addRegistersAt<RegisterBankLE::RegisterRao>(
1121 {{base + 0x0, reg0},
1123 {base + 0x4, reg2}}));
1126 EXPECT_THAT(actual, HasSubstr(
"Overlapping register"));
1127 EXPECT_THAT(actual, HasSubstr(
"reg1"));
1143 auto base = emptyBank.base();
1144 EXPECT_EQ(emptyBank.size(), 0);
1145 emptyBank.addRegistersAt<RegisterBankLE::RegisterRao>(
1146 {{
base + 0x0, reg0},
1148 {
base + 0x8, reg2}});
1149 EXPECT_EQ(emptyBank.size(), 0xc);
1166 auto base = emptyBank.base();
1167 EXPECT_EQ(emptyBank.size(), 0);
1168 emptyBank.addRegistersAt<RegisterBankLE::RegisterRao>(
1169 {{
base + 0x0, reg0},
1171 {
base + 0x10, reg2}});
1172 EXPECT_EQ(emptyBank.size(), 0x14);
1174 emptyBank.read(
base + 0x0, buf.data(), 4);
1175 EXPECT_EQ(reg0.get(), *
reinterpret_cast<uint32_t*
>(buf.data()));
1177 emptyBank.read(
base + 0x4, buf.data(), 4);
1178 EXPECT_EQ(0xffffffff, *
reinterpret_cast<uint32_t*
>(buf.data()));
1180 emptyBank.read(
base + 0x8, buf.data(), 4);
1181 EXPECT_EQ(reg1.get(), *
reinterpret_cast<uint32_t*
>(buf.data()));
1183 emptyBank.read(
base + 0xc, buf.data(), 4);
1184 EXPECT_EQ(0xffffffff, *
reinterpret_cast<uint32_t*
>(buf.data()));
1186 emptyBank.read(
base + 0x10, buf.data(), 4);
1187 EXPECT_EQ(reg2.get(), *
reinterpret_cast<uint32_t*
>(buf.data()));
1193 EXPECT_ANY_THROW(emptyBank.addRegisters({{0xabcd, reg0}, reg1}));
1196 EXPECT_THAT(actual, HasSubstr(
"empty.reg0"));
1197 EXPECT_THAT(actual, HasSubstr(
"to be 0xabcd"));
1198 EXPECT_THAT(actual, HasSubstr(
"is 0x12345"));
1204 EXPECT_ANY_THROW(emptyBank.addRegisters({{0xabcd}, reg0}));
1207 EXPECT_THAT(actual, HasSubstr(
"empty "));
1208 EXPECT_THAT(actual, HasSubstr(
"to be 0xabcd"));
1209 EXPECT_THAT(actual, HasSubstr(
"is 0x12345"));
1216 fullBank.read(0x1000, buf.data() + 4, 4);
1217 EXPECT_THAT(buf, ElementsAreArray({0x11, 0x22, 0x33, 0x44,
1218 0xd0, 0xd1, 0xd2, 0xd3,
1219 0x99, 0xaa, 0xbb, 0xcc}));
1220 EXPECT_THAT(reg0.accesses, ElementsAre(
1221 Access(Read, 0, 0, 0, 0xd3d2d1d0)
1223 EXPECT_TRUE(reg1.accesses.empty());
1224 EXPECT_TRUE(reg2.accesses.empty());
1229 fullBank.read(0x1004, buf.data() + 4, 4);
1230 EXPECT_THAT(buf, ElementsAreArray({0x11, 0x22, 0x33, 0x44,
1231 0xe0, 0xe1, 0xe2, 0xe3,
1232 0x99, 0xaa, 0xbb, 0xcc}));
1233 EXPECT_TRUE(reg0.accesses.empty());
1234 EXPECT_THAT(reg1.accesses, ElementsAre(
1235 Access(Read, 0, 0, 0, 0xe3e2e1e0)
1237 EXPECT_TRUE(reg2.accesses.empty());
1242 fullBank.read(0x1008, buf.data() + 4, 4);
1243 EXPECT_THAT(buf, ElementsAreArray({0x11, 0x22, 0x33, 0x44,
1244 0xf0, 0xf1, 0xf2, 0xf3,
1245 0x99, 0xaa, 0xbb, 0xcc}));
1246 EXPECT_TRUE(reg0.accesses.empty());
1247 EXPECT_TRUE(reg1.accesses.empty());
1248 EXPECT_THAT(reg2.accesses, ElementsAre(
1249 Access(Read, 0, 0, 0, 0xf3f2f1f0)
1255 fullBank.read(0x1004, buf.data() + 2, 8);
1256 EXPECT_THAT(buf, ElementsAreArray({0x11, 0x22, 0xe0, 0xe1,
1257 0xe2, 0xe3, 0xf0, 0xf1,
1258 0xf2, 0xf3, 0xbb, 0xcc}));
1259 EXPECT_TRUE(reg0.accesses.empty());
1260 EXPECT_THAT(reg1.accesses, ElementsAre(
1261 Access(Read, 0, 0, 0, 0xe3e2e1e0)
1263 EXPECT_THAT(reg2.accesses, ElementsAre(
1264 Access(Read, 0, 0, 0, 0xf3f2f1f0)
1270 fullBank.read(0x1001, buf.data() + 4, 2);
1271 EXPECT_THAT(buf, ElementsAreArray({0x11, 0x22, 0x33, 0x44,
1272 0xd1, 0xd2, 0x77, 0x88,
1273 0x99, 0xaa, 0xbb, 0xcc}));
1274 EXPECT_THAT(reg0.accesses, ElementsAre(
1275 Access(Read, 0, 0, 0, 0xd3d2d1d0),
1276 Access(PartialRead, 0, 23, 8, 0x00d2d100)
1278 EXPECT_TRUE(reg1.accesses.empty());
1279 EXPECT_TRUE(reg2.accesses.empty());
1284 fullBank.read(0x1002, buf.data() + 4, 4);
1285 EXPECT_THAT(buf, ElementsAreArray({0x11, 0x22, 0x33, 0x44,
1286 0xd2, 0xd3, 0xe0, 0xe1,
1287 0x99, 0xaa, 0xbb, 0xcc}));
1288 EXPECT_THAT(reg0.accesses, ElementsAre(
1289 Access(Read, 0, 0, 0, 0xd3d2d1d0),
1290 Access(PartialRead, 0, 31, 16, 0xd3d20000)
1292 EXPECT_THAT(reg1.accesses, ElementsAre(
1293 Access(Read, 0, 0, 0, 0xe3e2e1e0),
1294 Access(PartialRead, 0, 15, 0, 0x0000e1e0)
1296 EXPECT_TRUE(reg2.accesses.empty());
1301 fullBank.read(0x1002, buf.data() + 2, 8);
1302 EXPECT_THAT(buf, ElementsAreArray({0x11, 0x22, 0xd2, 0xd3,
1303 0xe0, 0xe1, 0xe2, 0xe3,
1304 0xf0, 0xf1, 0xbb, 0xcc}));
1305 EXPECT_THAT(reg0.accesses, ElementsAre(
1306 Access(Read, 0, 0, 0, 0xd3d2d1d0),
1307 Access(PartialRead, 0, 31, 16, 0xd3d20000)
1309 EXPECT_THAT(reg1.accesses, ElementsAre(
1310 Access(Read, 0, 0, 0, 0xe3e2e1e0)
1312 EXPECT_THAT(reg2.accesses, ElementsAre(
1313 Access(Read, 0, 0, 0, 0xf3f2f1f0),
1314 Access(PartialRead, 0, 15, 0, 0x0000f1f0)
1320 fullBank.read(0x1002, buf.data() + 4, 6);
1321 EXPECT_THAT(buf, ElementsAreArray({0x11, 0x22, 0x33, 0x44,
1322 0xd2, 0xd3, 0xe0, 0xe1,
1323 0xe2, 0xe3, 0xbb, 0xcc}));
1324 EXPECT_THAT(reg0.accesses, ElementsAre(
1325 Access(Read, 0, 0, 0, 0xd3d2d1d0),
1326 Access(PartialRead, 0, 31, 16, 0xd3d20000)
1328 EXPECT_THAT(reg1.accesses, ElementsAre(
1329 Access(Read, 0, 0, 0, 0xe3e2e1e0)
1331 EXPECT_TRUE(reg2.accesses.empty());
1336 fullBank.read(0x1004, buf.data() + 4, 6);
1337 EXPECT_THAT(buf, ElementsAreArray({0x11, 0x22, 0x33, 0x44,
1338 0xe0, 0xe1, 0xe2, 0xe3,
1339 0xf0, 0xf1, 0xbb, 0xcc}));
1340 EXPECT_TRUE(reg0.accesses.empty());
1341 EXPECT_THAT(reg1.accesses, ElementsAre(
1342 Access(Read, 0, 0, 0, 0xe3e2e1e0)
1344 EXPECT_THAT(reg2.accesses, ElementsAre(
1345 Access(Read, 0, 0, 0, 0xf3f2f1f0),
1346 Access(PartialRead, 0, 15, 0, 0x0000f1f0)
1352 fullBank.read(0x100a, buf.data() + 4, 2);
1353 EXPECT_THAT(buf, ElementsAreArray({0x11, 0x22, 0x33, 0x44,
1354 0xf2, 0xf3, 0x77, 0x88,
1355 0x99, 0xaa, 0xbb, 0xcc}));
1356 EXPECT_TRUE(reg0.accesses.empty());
1357 EXPECT_TRUE(reg1.accesses.empty());
1358 EXPECT_THAT(reg2.accesses, ElementsAre(
1359 Access(Read, 0, 0, 0, 0xf3f2f1f0),
1360 Access(PartialRead, 0, 31, 16, 0xf3f20000)
1368 fullBank.write(0x1000, buf.data() + 4, 4);
1369 EXPECT_EQ(reg0.get(), 0x88776655);
1370 EXPECT_EQ(reg1.get(), 0xe3e2e1e0);
1371 EXPECT_EQ(reg2.get(), 0xf3f2f1f0);
1372 EXPECT_THAT(reg0.accesses, ElementsAre(
1373 Access(Write, 0x88776655, 0, 0, 0)
1375 EXPECT_TRUE(reg1.accesses.empty());
1376 EXPECT_TRUE(reg2.accesses.empty());
1381 fullBank.write(0x1004, buf.data() + 4, 4);
1382 EXPECT_EQ(reg0.get(), 0xd3d2d1d0);
1383 EXPECT_EQ(reg1.get(), 0x88776655);
1384 EXPECT_EQ(reg2.get(), 0xf3f2f1f0);
1385 EXPECT_TRUE(reg0.accesses.empty());
1386 EXPECT_THAT(reg1.accesses, ElementsAre(
1387 Access(Write, 0x88776655, 0, 0, 0)
1389 EXPECT_TRUE(reg2.accesses.empty());
1394 fullBank.write(0x1008, buf.data() + 4, 4);
1395 EXPECT_EQ(reg0.get(), 0xd3d2d1d0);
1396 EXPECT_EQ(reg1.get(), 0xe3e2e1e0);
1397 EXPECT_EQ(reg2.get(), 0x88776655);
1398 EXPECT_TRUE(reg0.accesses.empty());
1399 EXPECT_TRUE(reg1.accesses.empty());
1400 EXPECT_THAT(reg2.accesses, ElementsAre(
1401 Access(Write, 0x88776655, 0, 0, 0)
1407 fullBank.write(0x1004, buf.data() + 2, 8);
1408 EXPECT_EQ(reg0.get(), 0xd3d2d1d0);
1409 EXPECT_EQ(reg1.get(), 0x66554433);
1410 EXPECT_EQ(reg2.get(), 0xaa998877);
1411 EXPECT_TRUE(reg0.accesses.empty());
1412 EXPECT_THAT(reg1.accesses, ElementsAre(
1413 Access(Write, 0x66554433, 0, 0, 0)
1415 EXPECT_THAT(reg2.accesses, ElementsAre(
1416 Access(Write, 0xaa998877, 0, 0, 0)
1422 fullBank.write(0x1001, buf.data() + 4, 2);
1423 EXPECT_EQ(reg0.get(), 0xd36655d0);
1424 EXPECT_EQ(reg1.get(), 0xe3e2e1e0);
1425 EXPECT_EQ(reg2.get(), 0xf3f2f1f0);
1426 EXPECT_THAT(reg0.accesses, ElementsAre(
1427 Access(Read, 0, 0, 0, 0xd3d2d1d0),
1428 Access(Write, 0xd36655d0, 0, 0, 0),
1429 Access(PartialWrite, 0x00665500, 23, 8, 0)
1431 EXPECT_TRUE(reg1.accesses.empty());
1432 EXPECT_TRUE(reg2.accesses.empty());
1437 fullBank.write(0x1002, buf.data() + 4, 4);
1438 EXPECT_EQ(reg0.get(), 0x6655d1d0);
1439 EXPECT_EQ(reg1.get(), 0xe3e28877);
1440 EXPECT_EQ(reg2.get(), 0xf3f2f1f0);
1441 EXPECT_THAT(reg0.accesses, ElementsAre(
1442 Access(Read, 0, 0, 0, 0xd3d2d1d0),
1443 Access(Write, 0x6655d1d0, 0, 0, 0),
1444 Access(PartialWrite, 0x66550000, 31, 16, 0)
1446 EXPECT_THAT(reg1.accesses, ElementsAre(
1447 Access(Read, 0, 0, 0, 0xe3e2e1e0),
1448 Access(Write, 0xe3e28877, 0, 0, 0),
1449 Access(PartialWrite, 0x00008877, 15, 0, 0)
1451 EXPECT_TRUE(reg2.accesses.empty());
1456 fullBank.write(0x1002, buf.data() + 2, 8);
1457 EXPECT_EQ(reg0.get(), 0x4433d1d0);
1458 EXPECT_EQ(reg1.get(), 0x88776655);
1459 EXPECT_EQ(reg2.get(), 0xf3f2aa99);
1460 EXPECT_THAT(reg0.accesses, ElementsAre(
1461 Access(Read, 0, 0, 0, 0xd3d2d1d0),
1462 Access(Write, 0x4433d1d0, 0, 0, 0),
1463 Access(PartialWrite, 0x44330000, 31, 16, 0)
1465 EXPECT_THAT(reg1.accesses, ElementsAre(
1466 Access(Write, 0x88776655, 0, 0, 0)
1468 EXPECT_THAT(reg2.accesses, ElementsAre(
1469 Access(Read, 0, 0, 0, 0xf3f2f1f0),
1470 Access(Write, 0xf3f2aa99, 0, 0, 0),
1471 Access(PartialWrite, 0x0000aa99, 15, 0, 0)
1477 fullBank.write(0x1002, buf.data() + 4, 6);
1478 EXPECT_EQ(reg0.get(), 0x6655d1d0);
1479 EXPECT_EQ(reg1.get(), 0xaa998877);
1480 EXPECT_EQ(reg2.get(), 0xf3f2f1f0);
1481 EXPECT_THAT(reg0.accesses, ElementsAre(
1482 Access(Read, 0, 0, 0, 0xd3d2d1d0),
1483 Access(Write, 0x6655d1d0, 0, 0, 0),
1484 Access(PartialWrite, 0x66550000, 31, 16, 0)
1486 EXPECT_THAT(reg1.accesses, ElementsAre(
1487 Access(Write, 0xaa998877, 0, 0, 0)
1489 EXPECT_TRUE(reg2.accesses.empty());
1494 fullBank.write(0x1004, buf.data() + 4, 6);
1495 EXPECT_EQ(reg0.get(), 0xd3d2d1d0);
1496 EXPECT_EQ(reg1.get(), 0x88776655);
1497 EXPECT_EQ(reg2.get(), 0xf3f2aa99);
1498 EXPECT_TRUE(reg0.accesses.empty());
1499 EXPECT_THAT(reg1.accesses, ElementsAre(
1500 Access(Write, 0x88776655, 0, 0, 0)
1502 EXPECT_THAT(reg2.accesses, ElementsAre(
1503 Access(Read, 0, 0, 0, 0xf3f2f1f0),
1504 Access(Write, 0xf3f2aa99, 0, 0, 0),
1505 Access(PartialWrite, 0x0000aa99, 15, 0, 0)
TestRegBank(const std::string &new_name, Addr new_base)
TestReg(const std::string &new_name, uint32_t initial)
std::vector< Access > accesses
std::array< uint8_t, 12 > buf
std::array< uint8_t, RegSize *3 > buf
std::array< uint8_t, RegSize *3 > backing
static constexpr size_t RegSize
RegisterBankLE::RegisterBuf reg
static constexpr size_t RegSize
std::array< uint8_t, 4 > to_write
RegisterBankLE::RegisterLBuf< 12 > reg
static constexpr size_t BufOffset
std::array< uint8_t, BufSize > buf
static constexpr size_t RaoSize
RegisterBankLE::RegisterRao rao
static constexpr size_t BufSize
std::array< uint8_t, BufSize > buf
static constexpr size_t BufSize
RegisterBankLE::RegisterRaz raz
static constexpr size_t RazSize
static constexpr size_t BufOffset
RegisterBankBE::Register< BackingType > regBE
static constexpr size_t RegSize
std::array< uint8_t, RegSize *3 > buf
RegisterBankLE::Register< BackingType > reg
void addRegisters(std::initializer_list< RegisterAdder > adders)
Register< uint32_t > Register32
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
thread_local GTestLogOutput gtestLogOutput
TEST_F(RegisterRazTest, Name)
bool operator==(const Access &other) const
Access(AccessType _type, uint32_t _value, int _first, int _last, uint32_t _ret)