From 155fe77f5d0de7288d8b57fff83bff0f17b08a94 Mon Sep 17 00:00:00 2001 From: galibzon <66021303+galibzon@users.noreply.github.com> Date: Wed, 17 Nov 2021 05:47:25 -0600 Subject: [PATCH] ShaderMetricsSystem spawns a lot of warnings (#5661) * ShaderMetricsSystem spawns a lot of warnings when run Atom_RPI.Tests Added @user@ path alias definition. * When running unit tests, using AZ::Utils::GetProjectPath() will resolve to something like: "/data/workspace/o3de/build/linux/External/Atom-9a4d112b/RPI/Code/Cache" The ShaderMetricSystem.cpp writes to the @user@ folder and the following runtime error occurs: "You may not alter data inside the asset cache. Please check the call stack and consider writing into the source asset folder instead." "Attempted write location: /data/workspace/o3de/build/linux/External/Atom-9a4d112b/RPI/Code/Cache/user/shadermetrics.json" To avoid the error We use AZ::Test::GetEngineRootPath(); Signed-off-by: galibzon <66021303+galibzon@users.noreply.github.com> --- Gems/Atom/RPI/Code/Tests/Common/RPITestFixture.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Gems/Atom/RPI/Code/Tests/Common/RPITestFixture.cpp b/Gems/Atom/RPI/Code/Tests/Common/RPITestFixture.cpp index 5343c295d8..8c685656ba 100644 --- a/Gems/Atom/RPI/Code/Tests/Common/RPITestFixture.cpp +++ b/Gems/Atom/RPI/Code/Tests/Common/RPITestFixture.cpp @@ -69,6 +69,19 @@ namespace UnitTest assetPath /= "Cache"; AZ::IO::FileIOBase::GetInstance()->SetAlias("@products@", assetPath.c_str()); + // Remark, AZ::Utils::GetProjectPath() is not used when defining "user" folder, + // instead We use AZ::Test::GetEngineRootPath();. + // Reason: + // When running unit tests, using AZ::Utils::GetProjectPath() will resolve to something like: + // "/data/workspace/o3de/build/linux/External/Atom-9a4d112b/RPI/Code/Cache" + // The ShaderMetricSystem.cpp writes to the @user@ folder and the following runtime error occurs: + // "You may not alter data inside the asset cache. Please check the call stack and consider writing into the source asset folder instead." + // "Attempted write location: /data/workspace/o3de/build/linux/External/Atom-9a4d112b/RPI/Code/Cache/user/shadermetrics.json" + // To avoid the error We use AZ::Test::GetEngineRootPath(); + AZ::IO::Path userPath = AZ::Test::GetEngineRootPath(); + userPath /= "user"; + AZ::IO::FileIOBase::GetInstance()->SetAlias("@user@", userPath.c_str()); + m_jsonRegistrationContext = AZStd::make_unique(); m_jsonSystemComponent = AZStd::make_unique(); m_jsonSystemComponent->Reflect(m_jsonRegistrationContext.get());