launcher_utils.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 psutil
  7. import ly_test_tools.environment.waiter as waiter
  8. from ly_remote_console.remote_console_commands import send_command_and_expect_response
  9. def run_launcher_tests(launcher, levels, remote_console_instance, null_renderer=False,
  10. port_listener_timeout=120, remote_console_port=4600, launch_ap=True):
  11. """
  12. Runs the launcher with the specified level, and monitors for clean exit code.
  13. :param launcher: Configured launcher object to run test against.
  14. :param levels: List of levels to load in the launcher.
  15. :param remote_console_instance: Configured Remote Console object.
  16. :param null_renderer: Specifies the test does not require the renderer. Defaults to True.
  17. :param port_listener_timeout: Timeout for verifying successful connection to Remote Console.
  18. :param remote_console_port: The port used to communicate with the Remote Console.
  19. :param launch_ap: Whether or not to launch AP. Defaults to True.
  20. """
  21. def _check_for_listening_port(port):
  22. """
  23. Checks to see if the connection to the designated port was established.
  24. :param port: Port to listen to.
  25. :return: True if port is listening.
  26. """
  27. port_listening = False
  28. for conn in psutil.net_connections():
  29. if 'port={}'.format(port) in str(conn):
  30. port_listening = True
  31. return port_listening
  32. if null_renderer:
  33. launcher.args.extend(["-rhi=Null"])
  34. # Start the Launcher
  35. launcher.start(launch_ap=launch_ap)
  36. assert launcher.is_alive(), "Launcher failed to start"
  37. # Ensure Remote Console can be reached
  38. waiter.wait_for(
  39. lambda: _check_for_listening_port(remote_console_port),
  40. port_listener_timeout,
  41. exc=AssertionError("Port {} not listening.".format(remote_console_port)),
  42. )
  43. remote_console_instance.start(timeout=30)
  44. # Load the specified level(s) in the launcher
  45. for level in levels:
  46. send_command_and_expect_response(remote_console_instance,
  47. f"LoadLevel {level}",
  48. f"Level load complete: '{level}'", timeout=30)
  49. remote_console_instance.stop()
  50. # Wait for test script to quit the launcher. If wait_for returns exc, test was not successful
  51. waiter.wait_for(lambda: not launcher.is_alive(), timeout=30)
  52. # Verify launcher quit successfully and did not crash
  53. ret_code = launcher.get_returncode()
  54. assert ret_code == 0, "Test(s) failed. See Game.log for details"