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;
226 EXPECT_EQ(store.
store[0x100], 0xa5);
227 EXPECT_EQ(store.
store[0x101], 0xa5);
228 EXPECT_EQ(store.
store[0x102], 0xa5);
229 EXPECT_EQ(store.
store[0x103], 0xa5);
237 store.
store[0x100] = 0xa5;
238 store.
store[0x101] = 0xa5;
239 store.
store[0x102] = 0xa5;
240 store.
store[0x103] = 0xa5;
245 EXPECT_EQ(store.
store[0x100], 0xa5);
246 EXPECT_EQ(store.
store[0x101], 0xa5);
247 EXPECT_EQ(store.
store[0x102], 0xa5);
248 EXPECT_EQ(store.
store[0x103], 0xa5);
251 *test_ptr = 0x5a5a5a5a;
254 EXPECT_EQ(store.
store[0x100], 0xa5);
255 EXPECT_EQ(store.
store[0x101], 0xa5);
256 EXPECT_EQ(store.
store[0x102], 0xa5);
257 EXPECT_EQ(store.
store[0x103], 0xa5);
263 EXPECT_EQ(store.
store[0x100], 0x5a);
264 EXPECT_EQ(store.
store[0x101], 0x5a);
265 EXPECT_EQ(store.
store[0x102], 0x5a);
266 EXPECT_EQ(store.
store[0x103], 0x5a);
269 store.
store[0x100] = 0xaa;
273 EXPECT_EQ(store.
store[0x100], 0xaa);
276 test_ptr.
flush(
true);
279 EXPECT_EQ(store.
store[0x100], 0x5a);
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;
307 EXPECT_EQ(test_ptr1.
addr(), addr1);
310 EXPECT_EQ(test_ptr2.
addr(), addr2);
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));
328 EXPECT_EQ(target.
addr(), addr2);
331 EXPECT_EQ(target.
addr(), addr1);
334 EXPECT_TRUE(test_ptr1);
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;
343 EXPECT_TRUE(is_same);
345 store.
store[0x100] = 0x55;
346 store.
store[0x101] = 0x55;
347 store.
store[0x102] = 0x55;
348 store.
store[0x103] = 0x55;
353 EXPECT_EQ(*test_ptr1, 0x55555555);
355 store.
store[0x100] = 0x11;
356 store.
store[0x101] = 0x22;
357 store.
store[0x102] = 0x33;
358 store.
store[0x103] = 0x44;
369 EXPECT_EQ(struct_ptr->a, 0x11);
370 EXPECT_EQ(struct_ptr->b, 0x22);
371 EXPECT_EQ(struct_ptr->c, 0x33);
372 EXPECT_EQ(struct_ptr->d, 0x44);
374 is_same = std::is_same<decltype((struct_ptr->a)),
const uint8_t &>::value;
375 EXPECT_TRUE(is_same);
384 const Addr addr1 = 0x1100;
385 const Addr addr2 = 0x1200;
387 using PtrType = uint32_t;
390 EXPECT_EQ(test_ptr1.
addr(), addr1);
393 EXPECT_EQ(test_ptr2.
addr(), addr2);
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));
411 EXPECT_EQ(target.
addr(), addr2);
414 EXPECT_EQ(target.
addr(), addr1);
417 EXPECT_TRUE(test_ptr1);
421 EXPECT_NE((PtrType *)test_ptr1,
nullptr);
422 EXPECT_EQ((PtrType *)
null,
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;
428 EXPECT_TRUE(is_same);
433 store.
store[0x100] = 0x55;
434 store.
store[0x101] = 0x55;
435 store.
store[0x102] = 0x55;
436 store.
store[0x103] = 0x55;
441 EXPECT_EQ(*test_ptr1, 0x55555555);
443 store.
store[0x100] = 0x11;
444 store.
store[0x101] = 0x22;
445 store.
store[0x102] = 0x33;
446 store.
store[0x103] = 0x44;
457 EXPECT_EQ(struct_ptr->a, 0x11);
458 EXPECT_EQ(struct_ptr->b, 0x22);
459 EXPECT_EQ(struct_ptr->c, 0x33);
460 EXPECT_EQ(struct_ptr->d, 0x44);
462 is_same = std::is_same<decltype((struct_ptr->a)), uint8_t &>::value;
463 EXPECT_TRUE(is_same);
494 EXPECT_EQ(ptr.
addr(), 0x1000);
501 EXPECT_EQ(ptr.
addr(), 0x1000);