| 21 | namespace tensorrt { |
| 22 | |
| 23 | bool RunTest(const uint64_t alignment, const uint64_t size, |
| 24 | const intptr_t orig_ptr_val, const uint64_t orig_space) { |
| 25 | void* const orig_ptr = reinterpret_cast<void*>(orig_ptr_val); |
| 26 | void* ptr = orig_ptr; |
| 27 | uint64_t space = orig_space; |
| 28 | void* result = Align(alignment, size, ptr, space); |
| 29 | if (result == nullptr) { |
| 30 | EXPECT_EQ(orig_ptr, ptr); |
| 31 | EXPECT_EQ(orig_space, space); |
| 32 | return false; |
| 33 | } else { |
| 34 | EXPECT_EQ(result, ptr); |
| 35 | const intptr_t ptr_val = reinterpret_cast<intptr_t>(ptr); |
| 36 | EXPECT_EQ(0, ptr_val % alignment); |
| 37 | EXPECT_GE(ptr_val, orig_ptr_val); |
| 38 | EXPECT_GE(space, size); |
| 39 | EXPECT_LE(space, orig_space); |
| 40 | EXPECT_EQ(ptr_val + space, orig_ptr_val + orig_space); |
| 41 | return true; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | TEST(TRTAllocatorTest, Align) { |
| 46 | for (const uint64_t space : |
no test coverage detected