28 #include <gtest/gtest.h>
55 return !(*
this == other);
73 "Range [%#x,%#x) outside of [%#x,%#x).",
79 ::testing::AssertionResult
83 return ::testing::AssertionFailure() <<
"index " << idx <<
88 return ::testing::AssertionFailure() <<
"access[" << idx <<
89 "] was " <<
accesses[idx] <<
", expected " << other;
91 return ::testing::AssertionSuccess();
94 ::testing::AssertionResult
98 return ::testing::AssertionFailure() <<
99 "Wrong number of accesses, was " <<
accesses.size() <<
103 auto failure = ::testing::AssertionFailure();
106 for (
size_t idx = 0; idx <
expected.size(); idx++) {
109 failure << result.message();
118 return ::testing::AssertionSuccess();
125 accesses.emplace_back(
false, ptr, size);
133 accesses.emplace_back(
true, ptr, size);
138 ::testing::AssertionResult
145 #define EXPECT_ACCESSES(store, ...) \
147 Accesses expected({__VA_ARGS__}); \
148 EXPECT_PRED_FORMAT2(accessed, store, expected); \
149 store.accesses.clear(); \
182 template <
typename T>
185 template <
typename T>
220 *test_ptr = 0xa5a5a5a5;
237 store.
store[0x100] = 0xa5;
238 store.
store[0x101] = 0xa5;
239 store.
store[0x102] = 0xa5;
240 store.
store[0x103] = 0xa5;
251 *test_ptr = 0x5a5a5a5a;
269 store.
store[0x100] = 0xaa;
276 test_ptr.
flush(
true);
282 store.
store[0x100] = 0xa5;
283 store.
store[0x101] = 0xa5;
284 store.
store[0x102] = 0xa5;
285 store.
store[0x103] = 0xa5;
288 EXPECT_EQ(*(
const uint32_t *)test_ptr, 0x5a5a5a5a);
292 EXPECT_EQ(*(
const uint32_t *)test_ptr, 0xa5a5a5a5);
301 const Addr addr1 = 0x1100;
302 const Addr addr2 = 0x1200;
304 using PtrType = uint32_t;
313 auto next_ptr = test_ptr1 + 2;
314 EXPECT_EQ(next_ptr.addr(), addr1 + 2 *
sizeof(PtrType));
316 auto reverse_next_ptr = 2 + test_ptr1;
317 EXPECT_EQ(reverse_next_ptr.addr(), addr1 + 2 *
sizeof(PtrType));
319 auto prev_ptr = test_ptr1 - 2;
320 EXPECT_EQ(prev_ptr.addr(), addr1 - 2 *
sizeof(PtrType));
323 auto diff = test_ptr2 - test_ptr1;
324 EXPECT_EQ(diff, (addr2 - addr1) /
sizeof(PtrType));
338 EXPECT_NE((
const PtrType *)test_ptr1,
nullptr);
339 EXPECT_EQ((
const PtrType *)
null,
nullptr);
342 is_same = std::is_same<decltype(*test_ptr1),
const PtrType &>::value;
345 store.
store[0x100] = 0x55;
346 store.
store[0x101] = 0x55;
347 store.
store[0x102] = 0x55;
348 store.
store[0x103] = 0x55;
355 store.
store[0x100] = 0x11;
356 store.
store[0x101] = 0x22;
357 store.
store[0x102] = 0x33;
358 store.
store[0x103] = 0x44;
374 is_same = std::is_same<decltype((struct_ptr->a)),
const uint8_t &>::value;
384 const Addr addr1 = 0x1100;
385 const Addr addr2 = 0x1200;
387 using PtrType = uint32_t;
396 auto next_ptr = test_ptr1 + 2;
397 EXPECT_EQ(next_ptr.addr(), addr1 + 2 *
sizeof(PtrType));
399 auto reverse_next_ptr = 2 + test_ptr1;
400 EXPECT_EQ(reverse_next_ptr.addr(), addr1 + 2 *
sizeof(PtrType));
402 auto prev_ptr = test_ptr1 - 2;
403 EXPECT_EQ(prev_ptr.addr(), addr1 - 2 *
sizeof(PtrType));
406 auto diff = test_ptr2 - test_ptr1;
407 EXPECT_EQ(diff, (addr2 - addr1) /
sizeof(PtrType));
421 EXPECT_NE((PtrType *)test_ptr1,
nullptr);
423 EXPECT_NE((
const PtrType *)test_ptr1,
nullptr);
424 EXPECT_EQ((
const PtrType *)
null,
nullptr);
427 is_same = std::is_same<decltype(*test_ptr1), PtrType &>::value;
433 store.
store[0x100] = 0x55;
434 store.
store[0x101] = 0x55;
435 store.
store[0x102] = 0x55;
436 store.
store[0x103] = 0x55;
443 store.
store[0x100] = 0x11;
444 store.
store[0x101] = 0x22;
445 store.
store[0x102] = 0x33;
446 store.
store[0x103] = 0x44;
462 is_same = std::is_same<decltype((struct_ptr->a)), uint8_t &>::value;