From 090b770d7e7dd66648c8b6d789154a7b27b5dbda Mon Sep 17 00:00:00 2001 From: amzn-sj Date: Mon, 24 May 2021 14:01:41 -0700 Subject: [PATCH] Fix segfault in failing tests on Linux --- Code/Framework/Tests/BehaviorEntityTests.cpp | 6 +++--- .../tests/applicationManagerTests.cpp | 18 +++++++++++++++--- .../platformconfigurationtests.cpp | 17 +++++++++++++---- .../platformconfigurationtests.h | 3 ++- .../Tests/Builders/MaterialBuilderTests.cpp | 17 ++++++++++++++--- 5 files changed, 47 insertions(+), 14 deletions(-) diff --git a/Code/Framework/Tests/BehaviorEntityTests.cpp b/Code/Framework/Tests/BehaviorEntityTests.cpp index 398d472d6b..8cb85db20a 100644 --- a/Code/Framework/Tests/BehaviorEntityTests.cpp +++ b/Code/Framework/Tests/BehaviorEntityTests.cpp @@ -89,15 +89,15 @@ class BehaviorEntityTest protected: void SetUp() override { + m_appDescriptor.m_enableScriptReflection = true; + FrameworkApplicationFixture::SetUp(); + AZ::SettingsRegistryInterface* registry = AZ::SettingsRegistry::Get(); auto projectPathKey = AZ::SettingsRegistryInterface::FixedValueString(AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey) + "/project_path"; registry->Set(projectPathKey, "AutomatedTesting"); AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddRuntimeFilePaths(*registry); - m_appDescriptor.m_enableScriptReflection = true; - FrameworkApplicationFixture::SetUp(); - m_application->RegisterComponentDescriptor(HatComponent::CreateDescriptor()); m_application->RegisterComponentDescriptor(EarComponent::CreateDescriptor()); m_application->RegisterComponentDescriptor(DeactivateDuringActivationComponent::CreateDescriptor()); diff --git a/Code/Tools/AssetBundler/tests/applicationManagerTests.cpp b/Code/Tools/AssetBundler/tests/applicationManagerTests.cpp index 56d0ef615f..497e28d3ec 100644 --- a/Code/Tools/AssetBundler/tests/applicationManagerTests.cpp +++ b/Code/Tools/AssetBundler/tests/applicationManagerTests.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -57,12 +58,22 @@ namespace AssetBundler UnitTest::ScopedAllocatorSetupFixture::SetUp(); m_data = AZStd::make_unique(); - AZ::SettingsRegistryInterface* registry = AZ::SettingsRegistry::Get(); - auto projectPathKey = - AZ::SettingsRegistryInterface::FixedValueString(AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey) + "/project_path"; + AZ::SettingsRegistryInterface* registry = nullptr; + if (!AZ::SettingsRegistry::Get()) + { + AZ::SettingsRegistry::Register(&m_registry); + registry = &m_registry; + } + else + { + registry = AZ::SettingsRegistry::Get(); + } + auto projectPathKey = AZ::SettingsRegistryInterface::FixedValueString(AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey) + + "/project_path"; registry->Set(projectPathKey, "AutomatedTesting"); AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddRuntimeFilePaths(*registry); + m_data->m_applicationManager.reset(aznew MockApplicationManagerTest(0, 0)); m_data->m_applicationManager->Start(AzFramework::Application::Descriptor()); @@ -105,6 +116,7 @@ namespace AssetBundler }; AZStd::unique_ptr m_data; + AZ::SettingsRegistryImpl m_registry; }; TEST_F(ApplicationManagerTest, ValidatePlatformFlags_ReadConfigFiles_OK) diff --git a/Code/Tools/AssetProcessor/native/tests/platformconfiguration/platformconfigurationtests.cpp b/Code/Tools/AssetProcessor/native/tests/platformconfiguration/platformconfigurationtests.cpp index 08c5ef7ff4..d11650cbb1 100644 --- a/Code/Tools/AssetProcessor/native/tests/platformconfiguration/platformconfigurationtests.cpp +++ b/Code/Tools/AssetProcessor/native/tests/platformconfiguration/platformconfigurationtests.cpp @@ -35,12 +35,21 @@ PlatformConfigurationUnitTests::PlatformConfigurationUnitTests() void PlatformConfigurationUnitTests::SetUp() { - AZ::SettingsRegistryInterface* registry = AZ::SettingsRegistry::Get(); - auto projectPathKey = - AZ::SettingsRegistryInterface::FixedValueString(AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey) + "/project_path"; + AZ::SettingsRegistryInterface* registry = nullptr; + if (!AZ::SettingsRegistry::Get()) + { + AZ::SettingsRegistry::Register(&m_registry); + registry = &m_registry; + } + else + { + registry = AZ::SettingsRegistry::Get(); + } + auto projectPathKey = AZ::SettingsRegistryInterface::FixedValueString(AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey) + + "/project_path"; registry->Set(projectPathKey, "AutomatedTesting"); AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddRuntimeFilePaths(*registry); - + using namespace AssetProcessor; m_qApp = new QCoreApplication(m_argc, m_argv); AssetProcessorTest::SetUp(); diff --git a/Code/Tools/AssetProcessor/native/tests/platformconfiguration/platformconfigurationtests.h b/Code/Tools/AssetProcessor/native/tests/platformconfiguration/platformconfigurationtests.h index fe669460a8..24b6fad1b0 100644 --- a/Code/Tools/AssetProcessor/native/tests/platformconfiguration/platformconfigurationtests.h +++ b/Code/Tools/AssetProcessor/native/tests/platformconfiguration/platformconfigurationtests.h @@ -13,6 +13,7 @@ #pragma once #include +#include #include #include "native/tests/AssetProcessorTest.h" #include "native/unittests/UnitTestRunner.h" @@ -37,6 +38,6 @@ private: int m_argc; char** m_argv; QCoreApplication* m_qApp; - + AZ::SettingsRegistryImpl m_registry; }; diff --git a/Gems/LmbrCentral/Code/Tests/Builders/MaterialBuilderTests.cpp b/Gems/LmbrCentral/Code/Tests/Builders/MaterialBuilderTests.cpp index 0868a7f147..2a66882e06 100644 --- a/Gems/LmbrCentral/Code/Tests/Builders/MaterialBuilderTests.cpp +++ b/Gems/LmbrCentral/Code/Tests/Builders/MaterialBuilderTests.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -36,9 +37,18 @@ protected: { UnitTest::AllocatorsTestFixture::SetUp(); - AZ::SettingsRegistryInterface* registry = AZ::SettingsRegistry::Get(); - auto projectPathKey = - AZ::SettingsRegistryInterface::FixedValueString(AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey) + "/project_path"; + AZ::SettingsRegistryInterface* registry = nullptr; + if (!AZ::SettingsRegistry::Get()) + { + AZ::SettingsRegistry::Register(&m_registry); + registry = &m_registry; + } + else + { + registry = AZ::SettingsRegistry::Get(); + } + auto projectPathKey = AZ::SettingsRegistryInterface::FixedValueString(AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey) + + "/project_path"; registry->Set(projectPathKey, "AutomatedTesting"); AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddRuntimeFilePaths(*registry); @@ -128,6 +138,7 @@ protected: } AZStd::unique_ptr m_app; + AZ::SettingsRegistryImpl m_registry; }; TEST_F(MaterialBuilderTests, MaterialBuilder_EmptyFile_ExpectFailure)