1#include <gmock/gmock.h>
2#include <gtest/gtest.h>
15using tracegen::TestTraceContainer;
20TEST(RegistersConstrainingTest, EmptyRow)
25TEST(RegistersConstrainingTest, EffectiveRegOpSelectorNoReadNoWrite)
28 TestTraceContainer
trace({ {
29 { C::execution_sel_should_read_registers, 0 },
30 { C::execution_sel_should_write_registers, 0 },
32 { C::execution_sel_mem_op_reg_0_, 1 },
33 { C::execution_rw_reg_0_, 0 },
34 { C::execution_sel_op_reg_effective_0_, 0 },
36 { C::execution_sel_mem_op_reg_1_, 1 },
37 { C::execution_rw_reg_1_, 1 },
38 { C::execution_sel_op_reg_effective_1_, 0 },
40 { C::execution_sel_mem_op_reg_2_, 0 },
41 { C::execution_rw_reg_2_, 0 },
42 { C::execution_sel_op_reg_effective_2_, 0 },
44 { C::execution_sel_mem_op_reg_3_, 0 },
45 { C::execution_rw_reg_3_, 1 },
46 { C::execution_sel_op_reg_effective_3_, 0 },
48 check_relation<registers>(
trace,
60 { C::execution_sel_op_reg_effective_0_, 1 },
61 { C::execution_sel_op_reg_effective_1_, 1 },
62 { C::execution_sel_op_reg_effective_2_, 1 },
63 { C::execution_sel_op_reg_effective_3_, 1 },
66 "SEL_OP_REG_EFFECTIVE_0");
68 "SEL_OP_REG_EFFECTIVE_1");
70 "SEL_OP_REG_EFFECTIVE_2");
72 "SEL_OP_REG_EFFECTIVE_3");
75TEST(RegistersConstrainingTest, EffectiveRegOpSelectorOnlyRead)
78 TestTraceContainer
trace({ {
79 { C::execution_sel_should_read_registers, 1 },
80 { C::execution_sel_should_write_registers, 0 },
82 { C::execution_sel_mem_op_reg_0_, 1 },
83 { C::execution_rw_reg_0_, 0 },
84 { C::execution_sel_op_reg_effective_0_, 1 },
86 { C::execution_sel_mem_op_reg_1_, 1 },
87 { C::execution_rw_reg_1_, 1 },
88 { C::execution_sel_op_reg_effective_1_, 0 },
90 { C::execution_sel_mem_op_reg_2_, 0 },
91 { C::execution_rw_reg_2_, 0 },
92 { C::execution_sel_op_reg_effective_2_, 0 },
94 { C::execution_sel_mem_op_reg_3_, 0 },
95 { C::execution_rw_reg_3_, 1 },
96 { C::execution_sel_op_reg_effective_3_, 0 },
98 check_relation<registers>(
trace,
110 { C::execution_sel_op_reg_effective_0_, 0 },
111 { C::execution_sel_op_reg_effective_1_, 1 },
112 { C::execution_sel_op_reg_effective_2_, 1 },
113 { C::execution_sel_op_reg_effective_3_, 1 },
116 "SEL_OP_REG_EFFECTIVE_0");
118 "SEL_OP_REG_EFFECTIVE_1");
120 "SEL_OP_REG_EFFECTIVE_2");
122 "SEL_OP_REG_EFFECTIVE_3");
125TEST(RegistersConstrainingTest, EffectiveRegOpSelectorReadThenWrite)
128 TestTraceContainer
trace({ {
129 { C::execution_sel_should_read_registers, 1 },
130 { C::execution_sel_should_write_registers, 1 },
132 { C::execution_sel_mem_op_reg_0_, 1 },
133 { C::execution_rw_reg_0_, 0 },
134 { C::execution_sel_op_reg_effective_0_, 1 },
136 { C::execution_sel_mem_op_reg_1_, 1 },
137 { C::execution_rw_reg_1_, 1 },
138 { C::execution_sel_op_reg_effective_1_, 1 },
140 { C::execution_sel_mem_op_reg_2_, 0 },
141 { C::execution_rw_reg_2_, 0 },
142 { C::execution_sel_op_reg_effective_2_, 0 },
144 { C::execution_sel_mem_op_reg_3_, 0 },
145 { C::execution_rw_reg_3_, 1 },
146 { C::execution_sel_op_reg_effective_3_, 0 },
148 check_relation<registers>(
trace,
160 { C::execution_sel_op_reg_effective_0_, 0 },
161 { C::execution_sel_op_reg_effective_1_, 0 },
162 { C::execution_sel_op_reg_effective_2_, 1 },
163 { C::execution_sel_op_reg_effective_3_, 1 },
166 "SEL_OP_REG_EFFECTIVE_0");
168 "SEL_OP_REG_EFFECTIVE_1");
170 "SEL_OP_REG_EFFECTIVE_2");
172 "SEL_OP_REG_EFFECTIVE_3");
175TEST(RegistersConstrainingTest, TagCheckNoFailure)
177 TestTraceContainer
trace({
179 { C::execution_sel_should_read_registers, 1 },
181 { C::execution_sel_tag_check_reg_0_, 1 },
182 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::U8) },
183 { C::execution_expected_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::U8) },
185 { C::execution_sel_tag_check_reg_1_, 1 },
186 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::U16) },
187 { C::execution_expected_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::U16) },
189 { C::execution_sel_tag_check_reg_2_, 0 },
190 { C::execution_mem_tag_reg_2_,
static_cast<uint8_t
>(
MemoryTag::FF) },
191 { C::execution_expected_tag_reg_2_,
static_cast<uint8_t
>(
MemoryTag::U8) },
193 { C::execution_batched_tags_diff_inv_reg, 0 },
195 { C::execution_sel_register_read_error, 0 },
199 check_relation<registers>(
trace);
202 trace.
set(C::execution_sel_register_read_error, 0, 1);
204 "REGISTER_READ_TAG_CHECK");
207TEST(RegistersConstrainingTest, TagCheckSingleFailure)
209 FF batched_tags_diff =
212 TestTraceContainer
trace({
214 { C::execution_sel_should_read_registers, 1 },
216 { C::execution_sel_tag_check_reg_0_, 1 },
217 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
218 { C::execution_expected_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::U8) },
220 { C::execution_sel_register_read_error, 1 },
221 { C::execution_batched_tags_diff_inv_reg, batched_tags_diff.invert() },
225 check_relation<registers>(
trace);
228 trace.
set(C::execution_sel_register_read_error, 0, 0);
230 "REGISTER_READ_TAG_CHECK");
233 trace.
set(C::execution_batched_tags_diff_inv_reg, 0, 0);
235 "REGISTER_READ_TAG_CHECK");
238TEST(RegistersConstrainingTest, TagCheckIgnoresFailureWhenNotReading)
240 TestTraceContainer
trace({
242 { C::execution_sel_should_read_registers, 0 },
244 { C::execution_sel_tag_check_reg_0_, 1 },
245 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
246 { C::execution_expected_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::U8) },
248 { C::execution_sel_register_read_error, 0 },
249 { C::execution_batched_tags_diff_inv_reg, 0 },
252 check_relation<registers>(
trace);
255 trace.
set(C::execution_sel_register_read_error, 0, 1);
257 "REGISTER_READ_TAG_CHECK");
260TEST(RegistersConstrainingTest, TagCheckMultipleFailures)
262 FF batched_tags_diff =
266 TestTraceContainer
trace({
268 { C::execution_sel_should_read_registers, 1 },
270 { C::execution_sel_tag_check_reg_0_, 1 },
271 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
272 { C::execution_expected_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::U8) },
274 { C::execution_sel_tag_check_reg_1_, 1 },
275 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::U16) },
276 { C::execution_expected_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::U32) },
278 { C::execution_sel_tag_check_reg_2_, 1 },
279 { C::execution_mem_tag_reg_2_,
static_cast<uint8_t
>(
MemoryTag::U8) },
280 { C::execution_expected_tag_reg_2_,
static_cast<uint8_t
>(
MemoryTag::U8) },
282 { C::execution_sel_register_read_error, 1 },
283 { C::execution_batched_tags_diff_inv_reg, batched_tags_diff.invert() },
286 check_relation<registers>(
trace);
289 trace.
set(C::execution_sel_register_read_error, 0, 0);
291 "REGISTER_READ_TAG_CHECK");
294 trace.
set(C::execution_batched_tags_diff_inv_reg, 0, 0);
296 "REGISTER_READ_TAG_CHECK");
static constexpr size_t SR_SEL_OP_REG_EFFECTIVE_1
static constexpr size_t SR_REGISTER_READ_TAG_CHECK
static constexpr size_t SR_SEL_OP_REG_EFFECTIVE_3
static constexpr size_t SR_SEL_OP_REG_EFFECTIVE_0
static constexpr size_t SR_SEL_OP_REG_EFFECTIVE_6
static constexpr size_t SR_SEL_OP_REG_EFFECTIVE_5
static constexpr size_t SR_SEL_OP_REG_EFFECTIVE_2
static constexpr size_t SR_SEL_OP_REG_EFFECTIVE_4
void set(Column col, uint32_t row, const FF &value)
#define EXPECT_THROW_WITH_MESSAGE(code, expectedMessage)
TEST(TxExecutionConstrainingTest, WriteTreeValue)
TestTraceContainer empty_trace()