3
0

RGAtest.py 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. """
  2. Copyright (c) Contributors to the Open 3D Engine Project.
  3. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. SPDX-License-Identifier: Apache-2.0 OR MIT
  5. """
  6. class Tests():
  7. rga_file_exist = ("rga file exist", "RGA executable doesn't exist! To downlad RGA in O3DE, set O3DE_RADEON_GPU_ANALYZER_ENABLED=true in CmakeCache.txt in build folder, and rerun cmake.")
  8. azshader_was_removed = ("azshader was removed", "Failed to remove azshader")
  9. azshader_was_compiled = ("azshader was compiled", "Failed to compile azshader")
  10. livereg_was_created = ("livereg was created", "Failed to created livereg")
  11. disassem_was_created = ("disassem was created", "Failed to created disassem")
  12. no_error_occurred = ("No errors detected", "Errors were detected")
  13. def RGAtest():
  14. import sys
  15. import os
  16. from Atom.atom_utils.atom_tools_utils import ShaderAssetTestHelper
  17. import azlmbr.legacy.general as general
  18. from editor_python_test_tools.utils import TestHelper as helper
  19. from editor_python_test_tools.utils import Tracer
  20. def _file_exists(file_path):
  21. return os.path.exists(file_path)
  22. # Required for automated tests
  23. helper.init_idle()
  24. game_root_path = os.path.normpath(general.get_game_folder())
  25. game_build_path = os.path.normpath(general.get_build_folder())
  26. game_asset_path = os.path.join(game_root_path, "Assets")
  27. game_cache_path = os.path.join(game_root_path, "Cache")
  28. base_dir = os.path.dirname(__file__)
  29. src_assets_subdir = os.path.join(base_dir, "TestAssets", "ShaderAssetBuilder")
  30. with Tracer() as error_tracer:
  31. # The script drives the execution of the test, to return the flow back to the editor,
  32. # we will tick it one time
  33. general.idle_wait_frames(1)
  34. # This is the order in which the source assets should be deployed
  35. # to avoid source dependency issues with the old MCPP-based CreateJobs.
  36. file_list = [
  37. "RgaShader.shadervariantlist",
  38. "RgaShader.shader",
  39. "RgaShader.azsl"
  40. ]
  41. # Check if rga executable exist
  42. if sys.platform == 'win32':
  43. rga_path = os.path.join(game_build_path, "_deps", "rga-src", "rga.exe")
  44. else:
  45. rga_path = os.path.join(game_build_path, "_deps", "rga-src", "rga")
  46. Report.critical_result(Tests.rga_file_exist, _file_exists(rga_path))
  47. # Remove files
  48. ShaderAssetTestHelper.remove_files(game_asset_path, file_list)
  49. # Wait here until the azshader doesn't exist anymore.
  50. azshader_name = "assets/rgashader.azshader"
  51. helper.wait_for_condition(lambda: not ShaderAssetTestHelper.asset_exists(azshader_name), 5.0)
  52. Report.critical_result(Tests.azshader_was_removed, not ShaderAssetTestHelper.asset_exists(azshader_name))
  53. ShaderAssetTestHelper.copy_tmp_files_in_order(src_assets_subdir, file_list, game_asset_path)
  54. # Give enough time to AP to compile the shader
  55. helper.wait_for_condition(lambda: ShaderAssetTestHelper.asset_exists(azshader_name), 60.0)
  56. Report.critical_result(Tests.azshader_was_compiled, ShaderAssetTestHelper.asset_exists(azshader_name))
  57. # Check analysis data
  58. livereg_path = os.path.normpath(os.path.join(game_cache_path, "pc/assets/gfx1035_livereg_1_frag.txt"))
  59. disassem_path = os.path.normpath(os.path.join(game_cache_path, "pc/assets/gfx1035_disassem_1_frag.txt"))
  60. helper.wait_for_condition(lambda: _file_exists(livereg_path), 5.0)
  61. helper.wait_for_condition(lambda: _file_exists(disassem_path), 5.0)
  62. Report.critical_result(Tests.livereg_was_created, _file_exists(livereg_path))
  63. Report.critical_result(Tests.disassem_was_created, _file_exists(disassem_path))
  64. # All good, let's cleanup leftover files before closing the test.
  65. ShaderAssetTestHelper.remove_files(game_asset_path, file_list)
  66. helper.wait_for_condition(lambda: not ShaderAssetTestHelper.asset_exists(azshader_name), 5.0)
  67. # Look for errors to raise.
  68. helper.wait_for_condition(lambda: error_tracer.has_errors, 1.0)
  69. Report.result(Tests.no_error_occurred, not error_tracer.has_errors)
  70. if __name__ == "__main__":
  71. from editor_python_test_tools.utils import Report
  72. Report.start_test(RGAtest)