3#include <gmock/gmock.h>
4#include <gtest/gtest.h>
19using ::bb::avm2::testing::InstructionBuilder;
21using ::testing::ElementsAre;
22using ::testing::ReturnRef;
23using ::testing::StrictMock;
25template <
typename T>
auto from = ::bb::avm2::simulation::Operand::from<T>;
27TEST(AvmSimulationAddressingTest, AllDirectAndNonRelative)
38 const auto instr = InstructionBuilder(
SET_8)
48 StrictMock<MockMemory>
memory;
50 const auto operands = addressing.resolve(instr, memory);
54 from<MemoryAddress>(1),
58 instr.operands.at(2)));
61 const auto instr = InstructionBuilder(
ADD_16)
71 StrictMock<MockMemory>
memory;
73 const auto operands = addressing.resolve(instr, memory);
74 EXPECT_THAT(operands, ElementsAre(from<MemoryAddress>(1), from<MemoryAddress>(2), from<MemoryAddress>(3)));
78TEST(AvmSimulationAddressingTest, RelativeAddressing)
87 MemoryValue base_addr = MemoryValue::from<uint32_t>(100);
90 const auto instr = InstructionBuilder(
ADD_8)
101 StrictMock<MockMemory>
memory;
102 EXPECT_CALL(memory,
get(0)).WillOnce(ReturnRef(base_addr));
104 EXPECT_CALL(range_check, assert_range((1ULL << 32) - 110 - 1, 32));
105 EXPECT_CALL(range_check, assert_range((1ULL << 32) - 130 - 1, 32));
107 const auto operands = addressing.resolve(instr, memory);
109 EXPECT_THAT(operands,
112 from<MemoryAddress>(110),
114 from<MemoryAddress>(20),
116 from<MemoryAddress>(130)));
119TEST(AvmSimulationAddressingTest, IndirectAddressing)
128 const auto instr = InstructionBuilder(
ADD_8)
133 .operand<uint8_t>(10)
135 .operand<uint8_t>(15)
139 StrictMock<MockMemory>
memory;
140 MemoryValue addr_5_value = MemoryValue::from<uint32_t>(50);
141 EXPECT_CALL(memory,
get(5)).WillOnce(ReturnRef(addr_5_value));
142 MemoryValue addr_15_value = MemoryValue::from<uint32_t>(60);
143 EXPECT_CALL(memory,
get(15)).WillOnce(ReturnRef(addr_15_value));
145 const auto operands = addressing.resolve(instr, memory);
148 EXPECT_THAT(operands,
151 from<MemoryAddress>(50),
153 from<MemoryAddress>(10),
155 from<MemoryAddress>(60)));
158TEST(AvmSimulationAddressingTest, IndirectAndRelativeAddressing)
166 MemoryValue base_addr = MemoryValue::from<uint32_t>(100);
169 const auto instr = InstructionBuilder(
ADD_8)
175 .operand<uint8_t>(10)
178 .operand<uint8_t>(15)
182 StrictMock<MockMemory>
memory;
183 EXPECT_CALL(memory,
get(0)).WillOnce(ReturnRef(base_addr));
185 MemoryValue addr_105_value = MemoryValue::from<uint32_t>(200);
186 EXPECT_CALL(memory,
get(105)).WillOnce(ReturnRef(addr_105_value));
188 MemoryValue addr_10_value = MemoryValue::from<uint32_t>(60);
189 EXPECT_CALL(memory,
get(10)).WillOnce(ReturnRef(addr_10_value));
191 EXPECT_CALL(range_check, assert_range((1ULL << 32) - 105 - 1, 32));
192 EXPECT_CALL(range_check, assert_range((1ULL << 32) - 115 - 1, 32));
194 const auto operands = addressing.resolve(instr, memory);
197 EXPECT_THAT(operands,
200 from<MemoryAddress>(200),
202 from<MemoryAddress>(60),
204 from<MemoryAddress>(115)));
EventEmitter< DataCopyEvent > event_emitter
InstructionInfoDB instruction_info_db
TEST(EmitUnencryptedLogTest, Basic)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept