Adding support for ASan (Windows/MSVC) and fixing AzCore

This commit is contained in:
Esteban Papp
2021-08-19 14:17:14 -07:00
committed by GitHub
40 changed files with 368 additions and 276 deletions
@@ -13,6 +13,7 @@
#include <AzCore/RTTI/TypeInfoSimple.h>
#include <AzCore/std/limits.h>
#include <AzCore/std/string/string_view.h>
#include <AzCore/Casting/numeric_cast.h>
namespace AZ::Debug
{
@@ -12,6 +12,7 @@
#include <AzCore/Math/MathUtils.h>
#include <AzCore/std/typetraits/is_const.h>
#include <AzCore/std/typetraits/has_member_function.h>
#include <AzCore/Casting/numeric_cast.h>
namespace AZ
{
@@ -11,6 +11,7 @@
#include <AzCore/IO/SystemFile.h>
#include <AzCore/IO/IOUtils.h>
#include <AzCore/std/algorithm.h>
#include <AzCore/Casting/numeric_cast.h>
namespace AZ::IO
{
@@ -10,6 +10,7 @@
#include <AzCore/std/containers/array.h>
#include <AzCore/std/string/wildcard.h>
#include <AzCore/Casting/numeric_cast.h>
// extern instantiations of Path templates to prevent implicit instantiations
namespace AZ::IO
@@ -17,15 +17,23 @@
#include <AzCore/Debug/Profiler.h>
#define AZCORE_SYS_ALLOCATOR_HPPA // If you disable this make sure you start building the heapschema.cpp
//#define AZCORE_SYS_ALLOCATOR_MALLOC
#define AZCORE_SYSTEM_ALLOCATOR_HPHA 1
#define AZCORE_SYSTEM_ALLOCATOR_MALLOC 2
#define AZCORE_SYSTEM_ALLOCATOR_HEAP 3
#ifdef AZCORE_SYS_ALLOCATOR_HPPA
# include <AzCore/Memory/HphaSchema.h>
#elif defined(AZCORE_SYS_ALLOCATOR_MALLOC)
#include <AzCore/Memory/MallocSchema.h>
#if !defined(AZCORE_SYSTEM_ALLOCATOR)
// define the default
#define AZCORE_SYSTEM_ALLOCATOR AZCORE_SYSTEM_ALLOCATOR_HPHA
#endif
#if AZCORE_SYSTEM_ALLOCATOR == AZCORE_SYSTEM_ALLOCATOR_HPHA
#include <AzCore/Memory/HphaSchema.h>
#elif AZCORE_SYSTEM_ALLOCATOR == AZCORE_SYSTEM_ALLOCATOR_MALLOC
#include <AzCore/Memory/MallocSchema.h>
#elif AZCORE_SYSTEM_ALLOCATOR == AZCORE_SYSTEM_ALLOCATOR_HEAP
#include <AzCore/Memory/HeapSchema.h>
#else
# include <AzCore/Memory/HeapSchema.h>
#error "Invalid allocator selected for SystemAllocator"
#endif
@@ -34,12 +42,12 @@ using namespace AZ;
//////////////////////////////////////////////////////////////////////////
// Globals - we use global storage for the first memory schema, since we can't use dynamic memory!
static bool g_isSystemSchemaUsed = false;
#ifdef AZCORE_SYS_ALLOCATOR_HPPA
static AZStd::aligned_storage<sizeof(HphaSchema), AZStd::alignment_of<HphaSchema>::value>::type g_systemSchema;
#elif defined(AZCORE_SYS_ALLOCATOR_MALLOC)
static AZStd::aligned_storage<sizeof(MallocSchema), AZStd::alignment_of<MallocSchema>::value>::type g_systemSchema;
#else
static AZStd::aligned_storage<sizeof(HeapSchema), AZStd::alignment_of<HeapSchema>::value>::type g_systemSchema;
#if AZCORE_SYSTEM_ALLOCATOR == AZCORE_SYSTEM_ALLOCATOR_HPHA
static AZStd::aligned_storage<sizeof(HphaSchema), AZStd::alignment_of<HphaSchema>::value>::type g_systemSchema;
#elif AZCORE_SYSTEM_ALLOCATOR == AZCORE_SYSTEM_ALLOCATOR_MALLOC
static AZStd::aligned_storage<sizeof(MallocSchema), AZStd::alignment_of<MallocSchema>::value>::type g_systemSchema;
#elif AZCORE_SYSTEM_ALLOCATOR == AZCORE_SYSTEM_ALLOCATOR_HEAP
static AZStd::aligned_storage<sizeof(HeapSchema), AZStd::alignment_of<HeapSchema>::value>::type g_systemSchema;
#endif
//////////////////////////////////////////////////////////////////////////
@@ -97,9 +105,9 @@ SystemAllocator::Create(const Descriptor& desc)
else
{
m_isCustom = false;
#ifdef AZCORE_SYS_ALLOCATOR_HPPA
HphaSchema::Descriptor heapDesc;
heapDesc.m_pageSize = desc.m_heap.m_pageSize;
#if AZCORE_SYSTEM_ALLOCATOR == AZCORE_SYSTEM_ALLOCATOR_HPHA
HphaSchema::Descriptor heapDesc;
heapDesc.m_pageSize = desc.m_heap.m_pageSize;
heapDesc.m_poolPageSize = desc.m_heap.m_poolPageSize;
AZ_Assert(desc.m_heap.m_numFixedMemoryBlocks <= 1, "We support max1 memory block at the moment!");
if (desc.m_heap.m_numFixedMemoryBlocks > 0)
@@ -111,11 +119,10 @@ SystemAllocator::Create(const Descriptor& desc)
heapDesc.m_isPoolAllocations = desc.m_heap.m_isPoolAllocations;
// Fix SystemAllocator from growing in small chunks
heapDesc.m_systemChunkSize = desc.m_heap.m_systemChunkSize;
#elif defined(AZCORE_SYS_ALLOCATOR_MALLOC)
#elif AZCORE_SYSTEM_ALLOCATOR == AZCORE_SYSTEM_ALLOCATOR_MALLOC
MallocSchema::Descriptor heapDesc;
#else
HeapSchema::Descriptor heapDesc;
#elif AZCORE_SYSTEM_ALLOCATOR == AZCORE_SYSTEM_ALLOCATOR_HEAP
HeapSchema::Descriptor heapDesc;
memcpy(heapDesc.m_memoryBlocks, desc.m_heap.m_memoryBlocks, sizeof(heapDesc.m_memoryBlocks));
memcpy(heapDesc.m_memoryBlocksByteSize, desc.m_heap.m_memoryBlocksByteSize, sizeof(heapDesc.m_memoryBlocksByteSize));
heapDesc.m_numMemoryBlocks = desc.m_heap.m_numMemoryBlocks;
@@ -124,11 +131,11 @@ SystemAllocator::Create(const Descriptor& desc)
{
AZ_Assert(!g_isSystemSchemaUsed, "AZ::SystemAllocator MUST be created first! It's the source of all allocations!");
#ifdef AZCORE_SYS_ALLOCATOR_HPPA
#if AZCORE_SYSTEM_ALLOCATOR == AZCORE_SYSTEM_ALLOCATOR_HPHA
m_allocator = new(&g_systemSchema)HphaSchema(heapDesc);
#elif defined(AZCORE_SYS_ALLOCATOR_MALLOC)
#elif AZCORE_SYSTEM_ALLOCATOR == AZCORE_SYSTEM_ALLOCATOR_MALLOC
m_allocator = new(&g_systemSchema)MallocSchema(heapDesc);
#else
#elif AZCORE_SYSTEM_ALLOCATOR == AZCORE_SYSTEM_ALLOCATOR_HEAP
m_allocator = new(&g_systemSchema)HeapSchema(heapDesc);
#endif
g_isSystemSchemaUsed = true;
@@ -139,14 +146,13 @@ SystemAllocator::Create(const Descriptor& desc)
// this class should be inheriting from SystemAllocator
AZ_Assert(AllocatorInstance<SystemAllocator>::IsReady(), "System allocator must be created before any other allocator! They allocate from it.");
#ifdef AZCORE_SYS_ALLOCATOR_HPPA
#if AZCORE_SYSTEM_ALLOCATOR == AZCORE_SYSTEM_ALLOCATOR_HPHA
m_allocator = azcreate(HphaSchema, (heapDesc), SystemAllocator);
#elif defined(AZCORE_SYS_ALLOCATOR_MALLOC)
#elif AZCORE_SYSTEM_ALLOCATOR == AZCORE_SYSTEM_ALLOCATOR_MALLOC
m_allocator = azcreate(MallocSchema, (heapDesc), SystemAllocator);
#else
#elif AZCORE_SYSTEM_ALLOCATOR == AZCORE_SYSTEM_ALLOCATOR_HEAP
m_allocator = azcreate(HeapSchema, (heapDesc), SystemAllocator);
#endif
if (m_allocator == NULL)
{
isReady = false;
@@ -178,11 +184,11 @@ SystemAllocator::Destroy()
{
if ((void*)m_allocator == (void*)&g_systemSchema)
{
#ifdef AZCORE_SYS_ALLOCATOR_HPPA
#if AZCORE_SYSTEM_ALLOCATOR == AZCORE_SYSTEM_ALLOCATOR_HPHA
static_cast<HphaSchema*>(m_allocator)->~HphaSchema();
#elif defined(AZCORE_SYS_ALLOCATOR_MALLOC)
#elif AZCORE_SYSTEM_ALLOCATOR == AZCORE_SYSTEM_ALLOCATOR_MALLOC
static_cast<MallocSchema*>(m_allocator)->~MallocSchema();
#else
#elif AZCORE_SYSTEM_ALLOCATOR == AZCORE_SYSTEM_ALLOCATOR_HEAP
static_cast<HeapSchema*>(m_allocator)->~HeapSchema();
#endif
g_isSystemSchemaUsed = false;
@@ -36,10 +36,13 @@ namespace AZ
void NameData::release()
{
// this could be released after we decrement the counter, therefore we will
// base the release on the hash which is stable
Hash hash = m_hash;
AZ_Assert(m_useCount > 0, "m_useCount is already 0!");
if (m_useCount.fetch_sub(1) == 1)
{
AZ::NameDictionary::Instance().TryReleaseName(this);
AZ::NameDictionary::Instance().TryReleaseName(hash);
}
}
}
+6
View File
@@ -10,6 +10,11 @@
#include <AzCore/Name/Internal/NameData.h>
namespace UnitTest
{
class NameTest;
}
namespace AZ
{
class NameDictionary;
@@ -29,6 +34,7 @@ namespace AZ
class Name
{
friend NameDictionary;
friend UnitTest::NameTest;
public:
using Hash = Internal::NameData::Hash;
@@ -166,7 +166,7 @@ namespace AZ
}
}
void NameDictionary::TryReleaseName(Internal::NameData* nameData)
void NameDictionary::TryReleaseName(Name::Hash hash)
{
// Note that we don't remove NameData from the dictionary if it has been involved in a collision.
// This avoids specific edge cases where a Name object could get an incorrect hash value. Consider
@@ -179,15 +179,24 @@ namespace AZ
// the dictionary *again*, this time with hash value 1000. Name objects pointing to the original
// entry and Name objects pointing to the new entry will fail comparison operations.
// Early exit to avoid locking the mutex unnecessarily.
if (nameData->m_hashCollision)
{
return;
}
AZStd::unique_lock<AZStd::shared_mutex> lock(m_sharedMutex);
// Check m_hashCollision again inside the m_sharedMutex because a new collision could have happened
auto dictIt = m_dictionary.find(hash);
if (dictIt == m_dictionary.end())
{
// This check is to safeguard around the following scenario
// T1, gets into TryReleaseName
// T2 gets into MakeName, acquires the lock, returns a new Name that increments the counter
// T2 deletes the Name decrements the counter, gets into TryReleaseName
// T1 gets the lock, goes to the compare_exchange if and has a counter of 0, deletes
// Then T2 continues, gets the lock and crashes because nameData was deleted
return;
}
Internal::NameData* nameData = dictIt->second;
// Check m_hashCollision inside the m_sharedMutex because a new collision could have happened
// on another thread before taking the lock.
if (nameData->m_hashCollision)
{
@@ -83,7 +83,7 @@ namespace AZ
// Attempts to release the name from the dictionary, but checks to make sure
// a reference wasn't taken by another thread.
void TryReleaseName(Internal::NameData* data);
void TryReleaseName(Name::Hash hash);
//////////////////////////////////////////////////////////////////////////
@@ -7,7 +7,6 @@
*/
#pragma once
#include <AzCore/Casting/numeric_cast.h>
#include <AzCore/std/createdestroy.h>
#include <AzCore/std/iterator.h>
@@ -46,6 +45,10 @@ namespace AZStd
return npos;
}
size_t foundIndex = searchIndex + charFindIndex;
if (foundIndex + count > size)
{
return npos; // the rest of the string doesnt fit in the remainder of the data buffer
}
if (Traits::compare(&data[foundIndex], ptr, count) == 0)
{
return foundIndex;
+9
View File
@@ -53,6 +53,15 @@ ly_add_source_properties(
VALUES ${LY_PAL_TOOLS_DEFINES}
)
if(LY_BUILD_WITH_ADDRESS_SANITIZER)
# Default to use Malloc schema so ASan works well
ly_add_source_properties(
SOURCES AzCore/Memory/SystemAllocator.cpp
PROPERTY COMPILE_DEFINITIONS
VALUES AZCORE_SYSTEM_ALLOCATOR=AZCORE_SYSTEM_ALLOCATOR_MALLOC
)
endif()
################################################################################
# Tests
################################################################################
@@ -109,6 +109,19 @@
#define AZ_TRAIT_USE_ERRNO_T_TYPEDEF 1
#define AZ_TRAIT_USE_POSIX_TEMP_FOLDER 0
// wchar_t/char formatting
// Reason: https://docs.microsoft.com/en-us/cpp/c-runtime-library/format-specification-syntax-printf-and-wprintf-functions?view=msvc-160
// The Z type character, and the behavior of the c, C, s, and S type characters when they're used with the printf and wprintf functions,
// are Microsoft extensions. The ISO C standard uses c and s consistently for narrow characters and strings, and C and S for wide characters
// and strings, in all formatting functions.
#define AZ_TRAIT_FORMAT_STRING_PRINTF_CHAR "%c"
#define AZ_TRAIT_FORMAT_STRING_PRINTF_WCHAR "%C"
#define AZ_TRAIT_FORMAT_STRING_WPRINTF_CHAR "%c"
#define AZ_TRAIT_FORMAT_STRING_WPRINTF_WCHAR "%C"
#define AZ_TRAIT_FORMAT_STRING_PRINTF_STRING "%s"
#define AZ_TRAIT_FORMAT_STRING_PRINTF_WSTRING "%S"
#define AZ_TRAIT_FORMAT_STRING_WPRINTF_STRING "%s"
#define AZ_TRAIT_FORMAT_STRING_WPRINTF_WSTRING "%S"
// Legacy traits ...
#define AZ_TRAIT_LEGACY_CRYCOMMON_USE_WINDOWS_STUBS 1
#define AZ_TRAIT_LEGACY_CRYPAK_UNIX_LIKE_FILE_SYSTEM 1
@@ -109,6 +109,20 @@
#define AZ_TRAIT_USE_ERRNO_T_TYPEDEF 1
#define AZ_TRAIT_USE_POSIX_TEMP_FOLDER 1
// wchar_t/char formatting
// Reason: https://docs.microsoft.com/en-us/cpp/c-runtime-library/format-specification-syntax-printf-and-wprintf-functions?view=msvc-160
// The Z type character, and the behavior of the c, C, s, and S type characters when they're used with the printf and wprintf functions,
// are Microsoft extensions. The ISO C standard uses c and s consistently for narrow characters and strings, and C and S for wide characters
// and strings, in all formatting functions.
#define AZ_TRAIT_FORMAT_STRING_PRINTF_CHAR "%c"
#define AZ_TRAIT_FORMAT_STRING_PRINTF_WCHAR "%C"
#define AZ_TRAIT_FORMAT_STRING_WPRINTF_CHAR "%c"
#define AZ_TRAIT_FORMAT_STRING_WPRINTF_WCHAR "%C"
#define AZ_TRAIT_FORMAT_STRING_PRINTF_STRING "%s"
#define AZ_TRAIT_FORMAT_STRING_PRINTF_WSTRING "%S"
#define AZ_TRAIT_FORMAT_STRING_WPRINTF_STRING "%s"
#define AZ_TRAIT_FORMAT_STRING_WPRINTF_WSTRING "%S"
// Legacy traits ...
#define AZ_TRAIT_LEGACY_CRYCOMMON_USE_WINDOWS_STUBS 1
#define AZ_TRAIT_LEGACY_CRYPAK_UNIX_LIKE_FILE_SYSTEM 1
@@ -109,6 +109,20 @@
#define AZ_TRAIT_USE_ERRNO_T_TYPEDEF 0
#define AZ_TRAIT_USE_POSIX_TEMP_FOLDER 1
// wchar_t/char formatting
// Reason: https://docs.microsoft.com/en-us/cpp/c-runtime-library/format-specification-syntax-printf-and-wprintf-functions?view=msvc-160
// The Z type character, and the behavior of the c, C, s, and S type characters when they're used with the printf and wprintf functions,
// are Microsoft extensions. The ISO C standard uses c and s consistently for narrow characters and strings, and C and S for wide characters
// and strings, in all formatting functions.
#define AZ_TRAIT_FORMAT_STRING_PRINTF_CHAR "%c"
#define AZ_TRAIT_FORMAT_STRING_PRINTF_WCHAR "%C"
#define AZ_TRAIT_FORMAT_STRING_WPRINTF_CHAR "%c"
#define AZ_TRAIT_FORMAT_STRING_WPRINTF_WCHAR "%C"
#define AZ_TRAIT_FORMAT_STRING_PRINTF_STRING "%s"
#define AZ_TRAIT_FORMAT_STRING_PRINTF_WSTRING "%S"
#define AZ_TRAIT_FORMAT_STRING_WPRINTF_STRING "%s"
#define AZ_TRAIT_FORMAT_STRING_WPRINTF_WSTRING "%S"
// Legacy traits ...
#define AZ_TRAIT_LEGACY_CRYCOMMON_USE_WINDOWS_STUBS 1
#define AZ_TRAIT_LEGACY_CRYPAK_UNIX_LIKE_FILE_SYSTEM 1
@@ -109,6 +109,20 @@
#define AZ_TRAIT_USE_ERRNO_T_TYPEDEF 0
#define AZ_TRAIT_USE_POSIX_TEMP_FOLDER 0
// wchar_t/char formatting
// Reason: https://docs.microsoft.com/en-us/cpp/c-runtime-library/format-specification-syntax-printf-and-wprintf-functions?view=msvc-160
// The Z type character, and the behavior of the c, C, s, and S type characters when they're used with the printf and wprintf functions,
// are Microsoft extensions. The ISO C standard uses c and s consistently for narrow characters and strings, and C and S for wide characters
// and strings, in all formatting functions.
#define AZ_TRAIT_FORMAT_STRING_PRINTF_CHAR "%c"
#define AZ_TRAIT_FORMAT_STRING_PRINTF_WCHAR "%C"
#define AZ_TRAIT_FORMAT_STRING_WPRINTF_CHAR "%C"
#define AZ_TRAIT_FORMAT_STRING_WPRINTF_WCHAR "%c"
#define AZ_TRAIT_FORMAT_STRING_PRINTF_STRING "%s"
#define AZ_TRAIT_FORMAT_STRING_PRINTF_WSTRING "%S"
#define AZ_TRAIT_FORMAT_STRING_WPRINTF_STRING "%S"
#define AZ_TRAIT_FORMAT_STRING_WPRINTF_WSTRING "%s"
// Legacy traits ...
#define AZ_TRAIT_LEGACY_CRYCOMMON_USE_WINDOWS_STUBS 0
#define AZ_TRAIT_LEGACY_CRYPAK_UNIX_LIKE_FILE_SYSTEM 0
@@ -110,6 +110,20 @@
#define AZ_TRAIT_USE_ERRNO_T_TYPEDEF 0
#define AZ_TRAIT_USE_POSIX_TEMP_FOLDER 0
// wchar_t/char formatting
// Reason: https://docs.microsoft.com/en-us/cpp/c-runtime-library/format-specification-syntax-printf-and-wprintf-functions?view=msvc-160
// The Z type character, and the behavior of the c, C, s, and S type characters when they're used with the printf and wprintf functions,
// are Microsoft extensions. The ISO C standard uses c and s consistently for narrow characters and strings, and C and S for wide characters
// and strings, in all formatting functions.
#define AZ_TRAIT_FORMAT_STRING_PRINTF_CHAR "%c"
#define AZ_TRAIT_FORMAT_STRING_PRINTF_WCHAR "%C"
#define AZ_TRAIT_FORMAT_STRING_WPRINTF_CHAR "%c"
#define AZ_TRAIT_FORMAT_STRING_WPRINTF_WCHAR "%C"
#define AZ_TRAIT_FORMAT_STRING_PRINTF_STRING "%s"
#define AZ_TRAIT_FORMAT_STRING_PRINTF_WSTRING "%S"
#define AZ_TRAIT_FORMAT_STRING_WPRINTF_STRING "%s"
#define AZ_TRAIT_FORMAT_STRING_WPRINTF_WSTRING "%S"
// Legacy traits ...
#define AZ_TRAIT_LEGACY_CRYCOMMON_USE_WINDOWS_STUBS 1
#define AZ_TRAIT_LEGACY_CRYPAK_UNIX_LIKE_FILE_SYSTEM 1
+4 -4
View File
@@ -1458,17 +1458,17 @@ namespace UnitTest
constexpr double v15 = 0;
constexpr const char* v16 = "Hello";
constexpr const wchar_t* v17 = L"Hello";
constexpr void* v18 = 0;
constexpr void* v18 = nullptr;
// This shouldn't give a compile error
AZStd::string::format(
"%i %c %uc %c %c %i %i %u %i %lu %li %llu %lli %f %f %s %ls %p",
"%i %c %uc " AZ_TRAIT_FORMAT_STRING_PRINTF_CHAR AZ_TRAIT_FORMAT_STRING_PRINTF_WCHAR " %i %i %u %i %lu %li %llu %lli %f %f " AZ_TRAIT_FORMAT_STRING_PRINTF_STRING AZ_TRAIT_FORMAT_STRING_PRINTF_WSTRING " %p",
v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18);
// This shouldn't give a compile error
AZStd::wstring::format(
L"%i %c %uc %c %lc %i %i %u %i %lu %li %llu %lli %f %f %s %ls %p",
v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18);
L"%i %c %uc " AZ_TRAIT_FORMAT_STRING_WPRINTF_CHAR AZ_TRAIT_FORMAT_STRING_WPRINTF_WCHAR " %i %i %u %i %lu %li %llu %lli %f %f " AZ_TRAIT_FORMAT_STRING_WPRINTF_STRING AZ_TRAIT_FORMAT_STRING_WPRINTF_WSTRING " %p",
v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18);
class WrappedInt
{
@@ -8,6 +8,7 @@
#include <AzCore/Math/Sfmt.h>
#include <AzCore/UnitTest/TestTypes.h>
#include <AzCore/Math/Vector4.h>
using namespace AZ;
@@ -27,8 +28,8 @@ namespace UnitTest
void SetUp() override
{
AllocatorsFixture::SetUp();
array1 = (AZ::u64*)azmalloc(sizeof(AZ::u64) * 2 * (BLOCK_SIZE / 4), AZStd::alignment_of<AZ::u64>::value);
array2 = (AZ::u64*)azmalloc(sizeof(AZ::u64) * 2 * (10000 / 4), AZStd::alignment_of<AZ::u64>::value);
array1 = (AZ::u64*)azmalloc(sizeof(AZ::u64) * 2 * (BLOCK_SIZE / 4), AZStd::alignment_of<AZ::Vector4>::value);
array2 = (AZ::u64*)azmalloc(sizeof(AZ::u64) * 2 * (10000 / 4), AZStd::alignment_of<AZ::Vector4>::value);
}
void TearDown() override
+28 -11
View File
@@ -171,7 +171,17 @@ namespace UnitTest
azsnprintf(buffer, RandomStringBufferSize, "%d", m_random.GetRandom());
return buffer;
}
AZ::Internal::NameData* GetNameData(AZ::Name& name)
{
return name.m_data.get();
}
void FreeMemoryFromNameData(AZ::Internal::NameData* nameData)
{
delete nameData;
}
AZ::SimpleLcgRandom m_random;
};
@@ -488,13 +498,20 @@ namespace UnitTest
TEST_F(NameTest, ReportLeakedNames)
{
AZ::Name leakedName{"hello"};
AZ_TEST_START_TRACE_SUPPRESSION;
AZ::NameDictionary::Destroy();
AZ_TEST_STOP_TRACE_SUPPRESSION(1);
AZ::Internal::NameData* leakedNameData = nullptr;
{
AZ::Name leakedName{ "hello" };
AZ_TEST_START_TRACE_SUPPRESSION;
AZ::NameDictionary::Destroy();
AZ_TEST_STOP_TRACE_SUPPRESSION(1);
// Create the dictionary again to avoid error in TearDown()
AZ::NameDictionary::Create();
leakedNameData = GetNameData(leakedName);
// Create the dictionary again to avoid crash when the intrusive_ptr in Name tries to access NameDictionary to free it
AZ::NameDictionary::Create();
}
FreeMemoryFromNameData(leakedNameData); // free it to avoid memory system reporting the leak
}
TEST_F(NameTest, NullTerminatedTest)
@@ -587,7 +604,7 @@ namespace UnitTest
AZ::NameDictionary::Create();
// 3 threads per name effectively makes two readers and one writer (the first to run will write in the dictionary)
RunConcurrencyTest<ThreadCreatesOneName>(AZ_TRAIT_UNIT_TEST_NAME_COUNT, 3);
RunConcurrencyTest<ThreadCreatesOneName>(AZStd::thread::hardware_concurrency(), 3);
}
TEST_F(NameTest, ConcurrencyDataTest_EachThreadCreatesOneName_HighCollisions)
@@ -597,7 +614,7 @@ namespace UnitTest
AZ::NameDictionary::Create();
// 3 threads per name effectively makes two readers and one writer (the first to run will write in the dictionary)
RunConcurrencyTest<ThreadCreatesOneName>(AZ_TRAIT_UNIT_TEST_NAME_COUNT, 3);
RunConcurrencyTest<ThreadCreatesOneName>(AZStd::thread::hardware_concurrency() / 2, 3);
}
TEST_F(NameTest, ConcurrencyDataTest_EachThreadRepeatedlyCreatesAndReleasesOneName_NoCollision)
@@ -624,7 +641,7 @@ namespace UnitTest
TEST_F(NameTest, DISABLED_NameVsStringPerf_Creation)
{
constexpr int CreateCount = AZ_TRAIT_UNIT_TEST_NAME_COUNT;
constexpr int CreateCount = 1000;
char buffer[RandomStringBufferSize];
@@ -633,7 +650,7 @@ namespace UnitTest
AZStd::sys_time_t stringTime;
{
const size_t dictionaryNoiseSize = AZ_TRAIT_UNIT_TEST_NAME_COUNT;
const size_t dictionaryNoiseSize = 1000;
AZStd::vector<AZ::Name> existingNames;
existingNames.reserve(dictionaryNoiseSize);