28#include <gtest/gtest.h>
57 return !(*
this == other);
75 "Range [%#x,%#x) outside of [%#x,%#x).",
81 ::testing::AssertionResult
85 return ::testing::AssertionFailure() <<
"index " << idx <<
90 return ::testing::AssertionFailure() <<
"access[" << idx <<
91 "] was " <<
accesses[idx] <<
", expected " << other;
93 return ::testing::AssertionSuccess();
96 ::testing::AssertionResult
100 return ::testing::AssertionFailure() <<
101 "Wrong number of accesses, was " <<
accesses.size() <<
105 auto failure = ::testing::AssertionFailure();
108 for (
size_t idx = 0; idx <
expected.size(); idx++) {
111 failure << result.message();
120 return ::testing::AssertionSuccess();
127 accesses.emplace_back(
false, ptr, size);
135 accesses.emplace_back(
true, ptr, size);
140::testing::AssertionResult
147#define EXPECT_ACCESSES(store, ...) \
149 Accesses expected({__VA_ARGS__}); \
150 EXPECT_PRED_FORMAT2(accessed, store, expected); \
151 store.accesses.clear(); \
222 *test_ptr = 0xa5a5a5a5;
228 EXPECT_EQ(store.
store[0x100], 0xa5);
229 EXPECT_EQ(store.
store[0x101], 0xa5);
230 EXPECT_EQ(store.
store[0x102], 0xa5);
231 EXPECT_EQ(store.
store[0x103], 0xa5);
239 store.
store[0x100] = 0xa5;
240 store.
store[0x101] = 0xa5;
241 store.
store[0x102] = 0xa5;
242 store.
store[0x103] = 0xa5;
247 EXPECT_EQ(store.
store[0x100], 0xa5);
248 EXPECT_EQ(store.
store[0x101], 0xa5);
249 EXPECT_EQ(store.
store[0x102], 0xa5);
250 EXPECT_EQ(store.
store[0x103], 0xa5);
253 *test_ptr = 0x5a5a5a5a;
256 EXPECT_EQ(store.
store[0x100], 0xa5);
257 EXPECT_EQ(store.
store[0x101], 0xa5);
258 EXPECT_EQ(store.
store[0x102], 0xa5);
259 EXPECT_EQ(store.
store[0x103], 0xa5);
265 EXPECT_EQ(store.
store[0x100], 0x5a);
266 EXPECT_EQ(store.
store[0x101], 0x5a);
267 EXPECT_EQ(store.
store[0x102], 0x5a);
268 EXPECT_EQ(store.
store[0x103], 0x5a);
271 store.
store[0x100] = 0xaa;
275 EXPECT_EQ(store.
store[0x100], 0xaa);
278 test_ptr.
flush(
true);
281 EXPECT_EQ(store.
store[0x100], 0x5a);
284 store.
store[0x100] = 0xa5;
285 store.
store[0x101] = 0xa5;
286 store.
store[0x102] = 0xa5;
287 store.
store[0x103] = 0xa5;
290 EXPECT_EQ(*(
const uint32_t *)test_ptr, 0x5a5a5a5a);
294 EXPECT_EQ(*(
const uint32_t *)test_ptr, 0xa5a5a5a5);
303 const Addr addr1 = 0x1100;
304 const Addr addr2 = 0x1200;
306 using PtrType = uint32_t;
309 EXPECT_EQ(test_ptr1.
addr(), addr1);
312 EXPECT_EQ(test_ptr2.
addr(), addr2);
315 auto next_ptr = test_ptr1 + 2;
316 EXPECT_EQ(next_ptr.addr(), addr1 + 2 *
sizeof(PtrType));
318 auto reverse_next_ptr = 2 + test_ptr1;
319 EXPECT_EQ(reverse_next_ptr.addr(), addr1 + 2 *
sizeof(PtrType));
321 auto prev_ptr = test_ptr1 - 2;
322 EXPECT_EQ(prev_ptr.addr(), addr1 - 2 *
sizeof(PtrType));
325 auto diff = test_ptr2 - test_ptr1;
326 EXPECT_EQ(diff, (addr2 - addr1) /
sizeof(PtrType));
330 EXPECT_EQ(target.
addr(), addr2);
333 EXPECT_EQ(target.
addr(), addr1);
336 EXPECT_TRUE(test_ptr1);
340 EXPECT_NE((
const PtrType *)test_ptr1,
nullptr);
341 EXPECT_EQ((
const PtrType *)null,
nullptr);
344 is_same = std::is_same_v<
decltype(*test_ptr1),
const PtrType &>;
345 EXPECT_TRUE(is_same);
347 store.
store[0x100] = 0x55;
348 store.
store[0x101] = 0x55;
349 store.
store[0x102] = 0x55;
350 store.
store[0x103] = 0x55;
355 EXPECT_EQ(*test_ptr1, 0x55555555);
357 store.
store[0x100] = 0x11;
358 store.
store[0x101] = 0x22;
359 store.
store[0x102] = 0x33;
360 store.
store[0x103] = 0x44;
371 EXPECT_EQ(struct_ptr->a, 0x11);
372 EXPECT_EQ(struct_ptr->b, 0x22);
373 EXPECT_EQ(struct_ptr->c, 0x33);
374 EXPECT_EQ(struct_ptr->d, 0x44);
376 is_same = std::is_same_v<
decltype((struct_ptr->a)),
const uint8_t &>;
377 EXPECT_TRUE(is_same);
386 const Addr addr1 = 0x1100;
387 const Addr addr2 = 0x1200;
389 using PtrType = uint32_t;
392 EXPECT_EQ(test_ptr1.
addr(), addr1);
395 EXPECT_EQ(test_ptr2.
addr(), addr2);
398 auto next_ptr = test_ptr1 + 2;
399 EXPECT_EQ(next_ptr.addr(), addr1 + 2 *
sizeof(PtrType));
401 auto reverse_next_ptr = 2 + test_ptr1;
402 EXPECT_EQ(reverse_next_ptr.addr(), addr1 + 2 *
sizeof(PtrType));
404 auto prev_ptr = test_ptr1 - 2;
405 EXPECT_EQ(prev_ptr.addr(), addr1 - 2 *
sizeof(PtrType));
408 auto diff = test_ptr2 - test_ptr1;
409 EXPECT_EQ(diff, (addr2 - addr1) /
sizeof(PtrType));
413 EXPECT_EQ(target.
addr(), addr2);
416 EXPECT_EQ(target.
addr(), addr1);
419 EXPECT_TRUE(test_ptr1);
423 EXPECT_NE((PtrType *)test_ptr1,
nullptr);
424 EXPECT_EQ((PtrType *)null,
nullptr);
425 EXPECT_NE((
const PtrType *)test_ptr1,
nullptr);
426 EXPECT_EQ((
const PtrType *)null,
nullptr);
429 is_same = std::is_same_v<
decltype(*test_ptr1), PtrType &>;
430 EXPECT_TRUE(is_same);
435 store.
store[0x100] = 0x55;
436 store.
store[0x101] = 0x55;
437 store.
store[0x102] = 0x55;
438 store.
store[0x103] = 0x55;
443 EXPECT_EQ(*test_ptr1, 0x55555555);
445 store.
store[0x100] = 0x11;
446 store.
store[0x101] = 0x22;
447 store.
store[0x102] = 0x33;
448 store.
store[0x103] = 0x44;
459 EXPECT_EQ(struct_ptr->a, 0x11);
460 EXPECT_EQ(struct_ptr->b, 0x22);
461 EXPECT_EQ(struct_ptr->c, 0x33);
462 EXPECT_EQ(struct_ptr->d, 0x44);
464 is_same = std::is_same_v<
decltype((struct_ptr->a)), uint8_t &>;
465 EXPECT_TRUE(is_same);
500 EXPECT_EQ(ptr.
addr(), 0x1000);
507 EXPECT_EQ(ptr.
addr(), 0x1000);
std::vector< uint8_t > store
::testing::AssertionResult expect_accesses(Accesses expected) const
BackingStore(Addr _base, size_t _size)
::testing::AssertionResult expect_access(size_t idx, const Access &other) const
void readBlob(Addr ptr, void *data, int size)
void rangeCheck(Addr addr, Addr size)
void writeBlob(Addr ptr, const void *data, int size)
void readBlob(Addr ptr, void *data, int size)
TestProxy(BackingStore &_store)
void writeBlob(Addr ptr, const void *data, int size)
TestProxy(ThreadContext *tc)
void flush(bool force=false)
ThreadContext is the external interface to all thread state for anything outside of the CPU.
std::vector< SwitchingFiber * > expected({ &a, &b, &a, &a, &a, &b, &c, &a, &c, &c, &c })
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
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.
Ret invokeSimcall(ThreadContext *tc, std::function< Ret(ThreadContext *, Args...)> target)
static std::ostream & operator<<(std::ostream &os, const DummyMatRegContainer &d)
void ccprintf(cp::Print &print)
void abiTestFunc(ThreadContext *tc, TestPtr< uint8_t > ptr)
void abiTestFuncConst(ThreadContext *tc, ConstTestPtr< uint8_t > ptr)
::testing::AssertionResult accessed(const char *expr1, const char *expr2, const BackingStore &store, const Accesses &expected)
#define EXPECT_ACCESSES(store,...)
bool operator==(const Access &other) const
bool operator!=(const Access &other) const
Access(bool _read, Addr _addr, Addr _size)
static Addr get(ThreadContext *tc, typename TestABI::State &state)