sanity_tests.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. A sanity test for the built-in fixtures.
  6. Launch the windows launcher attached to the currently installed instance.
  7. """
  8. # Import any dependencies for the test.
  9. import logging
  10. import pytest
  11. # Import any desired LTT modules from the package `ly_test_tools`. All LTT modules can be viewed at `Tools/LyTestTools/ly_test_tools`.
  12. import ly_test_tools
  13. # The `launchers.launcher_helper` module helps create Launcher objects which control the Open 3D Engine (O3DE) Editor and game clients.
  14. import ly_test_tools.launchers.launcher_helper as launcher_helper
  15. # The `builtin.helpers` module helps create the Workspace object, which controls the testing workspace in LTT.
  16. import ly_test_tools.builtin.helpers as helpers
  17. # The `environment` module contains tools that involve the system's environment such as processes or timed waiters.
  18. import ly_test_tools.environment.process_utils as process_utils
  19. import ly_test_tools.environment.waiter as waiter
  20. # Initialize a logger instance to hook all test logs together. The sub-logger pattern below makes it easy to track which file creates a log line.
  21. logger = logging.getLogger(__name__)
  22. # Note: For device testing, device ids must exist in ~/ly_test_tools/devices.ini, see README.txt for more info.
  23. # First define the class `TestAutomatedTestingProject` to group test functions together.
  24. # The example test contains two test functions: `test_StartGameLauncher_Sanity` and `test_StartEditor_Sanity`.
  25. @pytest.mark.parametrize("project", ["AutomatedTesting"])
  26. # The example test utilizes Pytest parameterization. The following sets the `project` parameter to `AutomatedTesting`
  27. # for both test functions. Notice that the Pytest mark is defined at the class level to affect both test functions.
  28. class TestAutomatedTestingProject(object):
  29. def test_StartGameLauncher_Sanity(self, project):
  30. """
  31. The `test_StartGameLauncher_Sanity` test function verifies that the O3DE game client launches successfully.
  32. Start the test by utilizing the `kill_processes_named` function to close any open O3DE processes that may
  33. interfere with the test. The Workspace object emulates the O3DE package by locating the engine and project
  34. directories. The Launcher object controls the O3DE game client and requires a Workspace object for
  35. initialization. Add the `-rhi=Null` arg to the executable call to disable GPU rendering. This allows the
  36. test to run on instances without a GPU. We launch the game client executable and wait for the process to exist.
  37. A try/finally block ensures proper test cleanup if issues occur during the test.
  38. """
  39. # Kill processes that may interfere with the test
  40. process_utils.kill_processes_named(names=process_utils.LY_PROCESS_KILL_LIST, ignore_extensions=True)
  41. try:
  42. # Create the Workspace object
  43. workspace = helpers.create_builtin_workspace(project=project)
  44. # Create the Launcher object and add args
  45. launcher = launcher_helper.create_game_launcher(workspace)
  46. launcher.args.extend(['-rhi=Null'])
  47. # Call the game client executable
  48. with launcher.start():
  49. # Wait for the process to exist
  50. waiter.wait_for(lambda: process_utils.process_exists(f"{project}.GameLauncher.exe", ignore_extensions=True))
  51. finally:
  52. # Clean up processes after the test is finished
  53. process_utils.kill_processes_named(names=process_utils.LY_PROCESS_KILL_LIST, ignore_extensions=True)
  54. def test_StartServerLauncher_Sanity(self, project):
  55. # Kill processes that may interfere with the test
  56. process_utils.kill_processes_named(names=process_utils.LY_PROCESS_KILL_LIST, ignore_extensions=True)
  57. try:
  58. # Create the Workspace object, this locates the engine and project
  59. workspace = helpers.create_builtin_workspace(project=project)
  60. # Create the Launcher object and add args, such as `-rhi=Null` which disables GPU rendering and allows the
  61. # test to run on nodes without a GPU
  62. launcher = launcher_helper.create_server_launcher(workspace)
  63. launcher.args.extend(['-rhi=Null'])
  64. # Call the game client executable
  65. with launcher.start():
  66. # Wait for the process to exist
  67. waiter.wait_for(lambda: process_utils.process_exists(f"{project}.ServerLauncher.exe", ignore_extensions=True))
  68. finally:
  69. # Clean up processes after the test is finished
  70. process_utils.kill_processes_named(names=process_utils.LY_PROCESS_KILL_LIST, ignore_extensions=True)
  71. def test_StartEditor_Sanity(self, project):
  72. """
  73. The `test_StartEditor_Sanity` test function is similar to the previous example with minor adjustments. A
  74. PyTest mark skips the test if the operating system is not Windows. We use the `create_editor` function instead
  75. of `create_game_launcher` to create an Editor type launcher instead of a game client type launcher. The additional
  76. `-autotest_mode` arg supresses modal dialogs from interfering with our test. We launch the Editor executable and
  77. wait for the process to exist.
  78. """
  79. # Kill processes that may interfere with the test
  80. process_utils.kill_processes_named(names=process_utils.LY_PROCESS_KILL_LIST, ignore_extensions=True)
  81. try:
  82. # Create the Workspace object
  83. workspace = helpers.create_builtin_workspace(project=project)
  84. # Create the Launcher object and add args
  85. editor = launcher_helper.create_editor(workspace)
  86. editor.args.extend(['-rhi=Null', '-autotest_mode'])
  87. # Call the Editor executable
  88. with editor.start():
  89. # Wait for the process to exist
  90. waiter.wait_for(lambda: process_utils.process_exists("Editor.exe", ignore_extensions=True))
  91. finally:
  92. # Clean up processes after the test is finished
  93. process_utils.kill_processes_named(names=process_utils.LY_PROCESS_KILL_LIST, ignore_extensions=True)