TestSuite_Periodic_GPU.py 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. import logging
  7. import os
  8. import sys
  9. import tempfile
  10. import json
  11. import pytest
  12. from ly_test_tools.environment import process_utils
  13. from ly_test_tools.launchers import launcher_helper
  14. from ly_test_tools.log.log_monitor import LogMonitor
  15. import ly_test_tools.environment.waiter as waiter
  16. logger = logging.getLogger(__name__)
  17. expected_lines = [
  18. "screenshot compare passed. Diff score is"
  19. ]
  20. unexpected_lines = [
  21. "screenshot compare failed. Diff score",
  22. "screenshot compare error. Error",
  23. "Level not found",
  24. "Failed to load level"
  25. ]
  26. atom_feature_test_list = [
  27. pytest.param(
  28. "Atom_DepthOfField", # test name
  29. "depth_of_field_screenshot1.png", # names to capture the screenshots to, also the names of the comparison images. Comma separated list
  30. "@gemroot:ScriptAutomation@/Assets/AutomationScripts/GenericRenderScreenshotTest.lua", # test control script
  31. "levels/atomscreenshottests/feature/depthoffield/depthoffield.spawnable", # level to load
  32. "Level D", # image comparison tolerance level. Comma separated list
  33. "Camera" # camera names for the screenshots. Comma separated list
  34. ),
  35. pytest.param(
  36. "Atom_AreaLights", # test name
  37. "sphere_screenshot.png,disk_screenshot.png", # names to capture the screenshots to, also the names of the comparison images. Comma separated list
  38. "@gemroot:ScriptAutomation@/Assets/AutomationScripts/GenericRenderScreenshotTest.lua", # test control script
  39. "levels/atomscreenshottests/feature/arealight/arealight.spawnable", # level to load
  40. "Level E,Level E", # image comparison tolerance level. Comma separated list
  41. "TestCameraPointLights,TestCameraDiskLights" # camera names for the screenshots. Comma separated list
  42. )
  43. ]
  44. atom_render_pipeline_list = [
  45. pytest.param("passes/MainRenderPipeline.azasset"),
  46. pytest.param("passes/LowEndRenderPipeline.azasset")
  47. ]
  48. # default names are windows
  49. launcher_name = "AutomatedTesting.GameLauncher.exe"
  50. ap_name = "AssetProcessor.exe"
  51. WINDOWS = sys.platform.startswith('win')
  52. LINUX = sys.platform == "linux"
  53. #MAC = sys.platform == "darwin"
  54. if LINUX:
  55. launcher_name = "AutomatedTesting.GameLauncher"
  56. ap_name = "AssetProcessor"
  57. def run_test(workspace, rhi, test_name, screenshot_name, test_script, level_path, compare_tolerance, camera_name, render_pipeline):
  58. # build SettingRegistry patch for the test
  59. run_settings= {
  60. "O3DE" : {
  61. "ScriptAutomation" : {
  62. "ImageCapture" : {
  63. "LevelPath" : level_path,
  64. "TestGroupName" : test_name,
  65. "ImageName" : screenshot_name,
  66. "ImageComparisonLevel" : compare_tolerance,
  67. "CaptureCameraName" : camera_name
  68. }
  69. }
  70. }
  71. }
  72. run_json = json.dumps(run_settings, indent=4)
  73. # Generate a temp file
  74. setreg_file = tempfile.NamedTemporaryFile('w+t', delete=False, suffix='.setreg')
  75. # write the json to the settings registry patch file
  76. setreg_file.write(run_json)
  77. setreg_file.flush()
  78. setreg_file.close()
  79. # launch the test
  80. game_launcher = launcher_helper.create_game_launcher(workspace)
  81. game_launcher.args.extend([ f'--rhi={rhi} ',
  82. f'--run-automation-suite={test_script} ',
  83. '--exit-on-automation-end ',
  84. f'--r_renderPipelinePath={render_pipeline}',
  85. f'--regset-file={setreg_file.name}'])
  86. game_launcher.start()
  87. waiter.wait_for(lambda: process_utils.process_exists(launcher_name, ignore_extensions=True))
  88. game_launcher_log_file = os.path.join(game_launcher.workspace.paths.project_log(), 'Game.log')
  89. game_launcher_log_monitor = LogMonitor(game_launcher, game_launcher_log_file)
  90. # test may do multiple image capture & compare so don't halt on unexpected
  91. try:
  92. game_launcher_log_monitor.monitor_log_for_lines(expected_lines, unexpected_lines, halt_on_unexpected=False, timeout=400)
  93. finally:
  94. process_utils.kill_processes_named(ap_name, ignore_extensions=True)
  95. @pytest.mark.SUITE_smoke
  96. @pytest.mark.REQUIRES_gpu
  97. @pytest.mark.skipif(not WINDOWS, reason="DX12 is only supported on windows")
  98. @pytest.mark.parametrize("project", ["AutomatedTesting"])
  99. @pytest.mark.parametrize("launcher_platform", ["windows"])
  100. @pytest.mark.parametrize("render_pipeline", atom_render_pipeline_list)
  101. class TestPeriodicSuite_DX12_GPU(object):
  102. @pytest.mark.parametrize("test_name, screenshot_name, test_script, level_path, compare_tolerance, camera_name", atom_feature_test_list)
  103. def test_Atom_FeatureTests_DX12(
  104. self, workspace, launcher_platform, test_name, screenshot_name, test_script, level_path, compare_tolerance, camera_name, render_pipeline):
  105. """
  106. Run Atom on DX12 and screen capture tests on parameterised levels
  107. """
  108. run_test(workspace, "dx12", test_name, screenshot_name, test_script, level_path, compare_tolerance, camera_name, render_pipeline)
  109. @pytest.mark.SUITE_smoke
  110. @pytest.mark.REQUIRES_gpu
  111. @pytest.mark.skipif(not WINDOWS and not LINUX, reason="Vulkan is only supported on windows, linux, & android")
  112. @pytest.mark.parametrize("project", ["AutomatedTesting"])
  113. @pytest.mark.parametrize("launcher_platform", ["windows, linux"])
  114. @pytest.mark.parametrize("render_pipeline", atom_render_pipeline_list)
  115. class TestPeriodicSuite_Vulkan_GPU(object):
  116. @pytest.mark.parametrize("test_name, screenshot_name, test_script, level_path, compare_tolerance, camera_name", atom_feature_test_list)
  117. def test_Atom_FeatureTests_Vulkan(
  118. self, workspace, launcher_platform, test_name, screenshot_name, test_script, level_path, compare_tolerance, camera_name, render_pipeline):
  119. """
  120. Run Atom on Vulkan and screen capture tests on parameterised levels
  121. """
  122. run_test(workspace, "vulkan", test_name, screenshot_name, test_script, level_path, compare_tolerance, camera_name, render_pipeline)