Files
compute-runtime/unit_tests/helpers/ptr_math_tests.cpp
Filip Hazubski 8b57d28116 clang-format: enable sorting includes
Include files are now grouped and sorted in following order:
1. Header file of the class the current file implements
2. Project files
3. Third party files
4. Standard library

Change-Id: If31af05652184169f7fee1d7ad08f1b2ed602cf0
Signed-off-by: Filip Hazubski <filip.hazubski@intel.com>
2019-02-27 11:50:07 +01:00

48 lines
1.3 KiB
C++

/*
* Copyright (C) 2017-2019 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "runtime/helpers/ptr_math.h"
#include "gtest/gtest.h"
TEST(PtrMath, ptrOffset) {
auto addrBefore = (uintptr_t)ptrGarbage;
auto ptrBefore = addrBefore;
size_t offset = 0x1234;
auto ptrAfter = ptrOffset(ptrBefore, offset);
auto addrAfter = ptrAfter;
EXPECT_EQ(offset, addrAfter - addrBefore);
}
TEST(PtrMath, ptrDiff) {
size_t offset = 0x1234;
auto addrBefore = (uintptr_t)ptrGarbage;
auto addrAfter = addrBefore + offset;
EXPECT_EQ(offset, ptrDiff(addrAfter, addrBefore));
}
TEST(PtrMath, addrToPtr) {
uint32_t addr32Bit = 0x3456;
uint64_t addr64Bit = 0xf000000000003456;
void *ptr32BitAddr = (void *)((uintptr_t)addr32Bit);
void *ptr64BitAddr = (void *)((uintptr_t)addr64Bit);
EXPECT_EQ(ptr32BitAddr, addrToPtr(addr32Bit));
EXPECT_EQ(ptr64BitAddr, addrToPtr(addr64Bit));
}
TEST(PtrMath, givenCastToUint64FunctionWhenItIsCalledThenProperValueIsReturned) {
uintptr_t address = 0xf0000000;
void *addressWithTrailingBitSet = reinterpret_cast<void *>(address);
uint64_t expectedUint64Address = 0xf0000000;
auto uintAddress = castToUint64(addressWithTrailingBitSet);
EXPECT_EQ(uintAddress, expectedUint64Address);
}