From 9b480f252e663e866cdb288cdda027f480803b13 Mon Sep 17 00:00:00 2001 From: Steve Pham <82231385+spham-amzn@users.noreply.github.com> Date: Wed, 8 Dec 2021 14:28:45 -0800 Subject: [PATCH] Fix and enable failed gradient signal tests on Linux * Fix failure reason for PerlinGradientComponent_GoldenTest: non-standard behavior of std::shuffle producing different results across platforms * Fix failure reason for GradientImageAssetConversionU8SingleScale: Undefined behavior when float casts to a uint8 has overflow Signed-off-by: Steve Pham <82231385+spham-amzn@users.noreply.github.com> --- .../AzTest/Platform/Android/AzTest_Traits_Android.h | 6 ++++++ .../AzTest/AzTest/Platform/Linux/AzTest_Traits_Linux.h | 8 +++++++- .../AzTest/AzTest/Platform/Mac/AzTest_Traits_Mac.h | 6 ++++++ .../AzTest/Platform/Windows/AzTest_Traits_Windows.h | 6 ++++++ .../AzTest/AzTest/Platform/iOS/AzTest_Traits_iOS.h | 6 ++++++ Gems/GradientSignal/Code/Tests/GradientSignalTest.cpp | 9 ++------- Gems/GradientSignal/Code/Tests/ImageAssetTests.cpp | 5 ++++- 7 files changed, 37 insertions(+), 9 deletions(-) diff --git a/Code/Framework/AzTest/AzTest/Platform/Android/AzTest_Traits_Android.h b/Code/Framework/AzTest/AzTest/Platform/Android/AzTest_Traits_Android.h index 3ec3051576..9c22543293 100644 --- a/Code/Framework/AzTest/AzTest/Platform/Android/AzTest_Traits_Android.h +++ b/Code/Framework/AzTest/AzTest/Platform/Android/AzTest_Traits_Android.h @@ -38,3 +38,9 @@ #define AZ_TRAIT_DISABLE_FAILED_VEGETATION_TESTS true #define AZ_TRAIT_DISABLE_LOG_ALWAYS_FUZZ_TEST true + +// Golden perline gradiant values for random seed 7878 for this platform +#define AZ_TRAIT_UNIT_TEST_PERLINE_GRADIANT_GOLDEN_VALUES_7878 0.5000f, 0.5456f, 0.5138f, 0.4801f, \ + 0.4174f, 0.4942f, 0.5493f, 0.5431f, \ + 0.4984f, 0.5204f, 0.5526f, 0.5840f, \ + 0.5251f, 0.5029f, 0.6153f, 0.5802f, diff --git a/Code/Framework/AzTest/AzTest/Platform/Linux/AzTest_Traits_Linux.h b/Code/Framework/AzTest/AzTest/Platform/Linux/AzTest_Traits_Linux.h index 20e67e582b..5593d813a9 100644 --- a/Code/Framework/AzTest/AzTest/Platform/Linux/AzTest_Traits_Linux.h +++ b/Code/Framework/AzTest/AzTest/Platform/Linux/AzTest_Traits_Linux.h @@ -18,7 +18,7 @@ #define AZ_TRAIT_DISABLE_FAILED_FRAMEPROFILER_TEST true #define AZ_TRAIT_DISABLE_FAILED_FRAMEWORK_TESTS true -#define AZ_TRAIT_DISABLE_FAILED_GRADIENT_SIGNAL_TESTS true + #define AZ_TRAIT_DISABLE_FAILED_MULTIPLAYER_GRIDMATE_TESTS true #define AZ_TRAIT_DISABLE_FAILED_NATIVE_WINDOWS_TESTS true #define AZ_TRAIT_DISABLE_FAILED_EMOTION_FX_TESTS true @@ -27,3 +27,9 @@ #define AZ_TRAIT_DISABLE_FAILED_EMOTION_FX_EDITOR_TESTS true #define AZ_TRAIT_DISABLE_FAILED_METRICS_TESTS true +// Golden perline gradiant values for random seed 7878 for this platform +#define AZ_TRAIT_UNIT_TEST_PERLINE_GRADIANT_GOLDEN_VALUES_7878 0.5000f, 0.4455f, 0.4838f, 0.4589f, \ + 0.4539f, 0.5138f, 0.4104f, 0.4618f, \ + 0.4572f, 0.4894f, 0.4767f, 0.4197f, \ + 0.5500f, 0.4635f, 0.5199f, 0.4467f, \ + diff --git a/Code/Framework/AzTest/AzTest/Platform/Mac/AzTest_Traits_Mac.h b/Code/Framework/AzTest/AzTest/Platform/Mac/AzTest_Traits_Mac.h index 69dd592a2b..4915fb9cab 100644 --- a/Code/Framework/AzTest/AzTest/Platform/Mac/AzTest_Traits_Mac.h +++ b/Code/Framework/AzTest/AzTest/Platform/Mac/AzTest_Traits_Mac.h @@ -16,3 +16,9 @@ #define AZ_TRAIT_DISABLE_ASSET_JOB_PARALLEL_TESTS true #define AZ_TRAIT_DISABLE_ASSET_MANAGER_FLOOD_TEST true #define AZ_TRAIT_DISABLE_ASSETCONTAINERDISABLETEST true + +// Golden perline gradiant values for random seed 7878 for this platform +#define AZ_TRAIT_UNIT_TEST_PERLINE_GRADIANT_GOLDEN_VALUES_7878 0.5000f, 0.5456f, 0.5138f, 0.4801f, \ + 0.4174f, 0.4942f, 0.5493f, 0.5431f, \ + 0.4984f, 0.5204f, 0.5526f, 0.5840f, \ + 0.5251f, 0.5029f, 0.6153f, 0.5802f, diff --git a/Code/Framework/AzTest/AzTest/Platform/Windows/AzTest_Traits_Windows.h b/Code/Framework/AzTest/AzTest/Platform/Windows/AzTest_Traits_Windows.h index a11b8586f4..9b3204bb2e 100644 --- a/Code/Framework/AzTest/AzTest/Platform/Windows/AzTest_Traits_Windows.h +++ b/Code/Framework/AzTest/AzTest/Platform/Windows/AzTest_Traits_Windows.h @@ -13,3 +13,9 @@ #define AZ_TRAIT_UNIT_TEST_ASSET_MANAGER_TEST_DEFAULT_TIMEOUT_SECS 5 #define AZ_TRAIT_UNIT_TEST_ENTITY_ID_GEN_TEST_COUNT 10000 #define AZ_TRAIT_UNIT_TEST_DILLER_TRIGGER_EVENT_COUNT 100000 + +// Golden perline gradiant values for random seed 7878 for this platform +#define AZ_TRAIT_UNIT_TEST_PERLINE_GRADIANT_GOLDEN_VALUES_7878 0.5000f, 0.5456f, 0.5138f, 0.4801f, \ + 0.4174f, 0.4942f, 0.5493f, 0.5431f, \ + 0.4984f, 0.5204f, 0.5526f, 0.5840f, \ + 0.5251f, 0.5029f, 0.6153f, 0.5802f, diff --git a/Code/Framework/AzTest/AzTest/Platform/iOS/AzTest_Traits_iOS.h b/Code/Framework/AzTest/AzTest/Platform/iOS/AzTest_Traits_iOS.h index 69dd592a2b..4915fb9cab 100644 --- a/Code/Framework/AzTest/AzTest/Platform/iOS/AzTest_Traits_iOS.h +++ b/Code/Framework/AzTest/AzTest/Platform/iOS/AzTest_Traits_iOS.h @@ -16,3 +16,9 @@ #define AZ_TRAIT_DISABLE_ASSET_JOB_PARALLEL_TESTS true #define AZ_TRAIT_DISABLE_ASSET_MANAGER_FLOOD_TEST true #define AZ_TRAIT_DISABLE_ASSETCONTAINERDISABLETEST true + +// Golden perline gradiant values for random seed 7878 for this platform +#define AZ_TRAIT_UNIT_TEST_PERLINE_GRADIANT_GOLDEN_VALUES_7878 0.5000f, 0.5456f, 0.5138f, 0.4801f, \ + 0.4174f, 0.4942f, 0.5493f, 0.5431f, \ + 0.4984f, 0.5204f, 0.5526f, 0.5840f, \ + 0.5251f, 0.5029f, 0.6153f, 0.5802f, diff --git a/Gems/GradientSignal/Code/Tests/GradientSignalTest.cpp b/Gems/GradientSignal/Code/Tests/GradientSignalTest.cpp index 11407d6be5..78aa4f1ac5 100644 --- a/Gems/GradientSignal/Code/Tests/GradientSignalTest.cpp +++ b/Gems/GradientSignal/Code/Tests/GradientSignalTest.cpp @@ -157,13 +157,6 @@ namespace UnitTest // matches a previously-calculated "golden" set of values. constexpr int dataSize = 4; - AZStd::vector expectedOutput = - { - 0.5000f, 0.5456f, 0.5138f, 0.4801f, - 0.4174f, 0.4942f, 0.5493f, 0.5431f, - 0.4984f, 0.5204f, 0.5526f, 0.5840f, - 0.5251f, 0.5029f, 0.6153f, 0.5802f, - }; GradientSignal::PerlinGradientConfig config; config.m_randomSeed = 7878; @@ -171,6 +164,8 @@ namespace UnitTest config.m_amplitude = 3.0f; config.m_frequency = 1.13f; + AZStd::vector expectedOutput = { AZ_TRAIT_UNIT_TEST_PERLINE_GRADIANT_GOLDEN_VALUES_7878 }; + auto entity = CreateEntity(); CreateComponent(entity.get(), config); diff --git a/Gems/GradientSignal/Code/Tests/ImageAssetTests.cpp b/Gems/GradientSignal/Code/Tests/ImageAssetTests.cpp index c5b003bf3c..0111f10c3a 100644 --- a/Gems/GradientSignal/Code/Tests/ImageAssetTests.cpp +++ b/Gems/GradientSignal/Code/Tests/ImageAssetTests.cpp @@ -111,7 +111,10 @@ namespace constexpr auto numChannels = 1; constexpr auto bytesPerPixel = numChannels * sizeof(AZ::u8); constexpr auto outputSize = imageDimensions * imageDimensions; - constexpr auto scaling = 25; + // Adjust the test scale so that none of the input data overflows the cast to AZ::u8. + // The overflow behavior when casting from float to uint8 is undefined so we want to + // avoid that consistently across all platforms + constexpr auto scaling = 255.0f / aznumeric_cast(imageDimensions * imageDimensions); auto inputData = Detail::GenerateInput(scaling);