1 /* 2 * Copyright (C) 2018-2021 Intel Corporation 3 * 4 * SPDX-License-Identifier: MIT 5 * 6 */ 7 8 #include "shared/source/helpers/hash.h" 9 10 #include "gtest/gtest.h" 11 12 using namespace NEO; 13 TEST(HashTests,givenSamePointersWhenHashIsCalculatedThenSame32BitValuesAreGenerated)14TEST(HashTests, givenSamePointersWhenHashIsCalculatedThenSame32BitValuesAreGenerated) { 15 uintptr_t ptr1UI = 1; 16 uintptr_t ptr2UI = 1; 17 void *ptr1 = reinterpret_cast<void *>(ptr1UI); 18 void *ptr2 = reinterpret_cast<void *>(ptr2UI); 19 20 uint32_t hash1 = hashPtrToU32(ptr1); 21 uint32_t hash2 = hashPtrToU32(ptr2); 22 23 EXPECT_EQ(hash1, hash2); 24 } 25 TEST(HashTests,givenDifferentPointersWhenHashIsCalculatedThenUnique32BitValuesAreGenerated)26TEST(HashTests, givenDifferentPointersWhenHashIsCalculatedThenUnique32BitValuesAreGenerated) { 27 uintptr_t ptr1UI = 1; 28 uintptr_t ptr2UI = ptr1UI | (ptr1UI << ((sizeof(uintptr_t) / 2) * 8)); 29 void *ptr1 = reinterpret_cast<void *>(ptr1UI); 30 void *ptr2 = reinterpret_cast<void *>(ptr2UI); 31 32 uint32_t hash1 = hashPtrToU32(ptr1); 33 uint32_t hash2 = hashPtrToU32(ptr2); 34 35 EXPECT_NE(hash1, hash2); 36 } 37