test_process_utils_linux.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 subprocess
  7. import pytest
  8. import ly_test_tools.environment.process_utils as process_utils
  9. import ly_test_tools.environment.waiter as waiter
  10. from ly_test_tools import LINUX
  11. if LINUX:
  12. pytestmark = pytest.mark.SUITE_smoke
  13. else:
  14. pytestmark = pytest.mark.skipif(not LINUX, reason="Only runs on Linux")
  15. class TestProcessUtils(object):
  16. def test_KillLinuxProcess_ProcessStarted_KilledSuccessfully(self):
  17. # Construct a simple timeout command
  18. linux_executable = 'timeout'
  19. command = [linux_executable, '5s', 'echo']
  20. # Verification function for the waiter to call
  21. def process_killed():
  22. return not process_utils.process_exists(linux_executable, ignore_extensions=True)
  23. # Create a new process with no output in a new session
  24. with subprocess.Popen(command, stdout=subprocess.DEVNULL, start_new_session=True):
  25. # Ensure that the process was started
  26. assert process_utils.process_exists(linux_executable, ignore_extensions=True), \
  27. f"Process '{linux_executable}' was expected to exist, but could not be found."
  28. # Kill the process using the process_utils module
  29. process_utils.kill_processes_named(linux_executable, ignore_extensions=True)
  30. # Verify that the process was killed
  31. waiter.wait_for(process_killed, timeout=2) # Raises exception if the process is alive.