ctest_driver_test.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. Self-tests for ctest_driver.py.
  6. Expects you to have generated a folder using cmake and to pass in that folder name
  7. as the only param
  8. """
  9. import os
  10. import subprocess
  11. import sys
  12. import argparse
  13. from ctest_driver import SUITES_AND_DESCRIPTIONS
  14. def main(build_path, ctest_executable, config):
  15. script_folder = os.path.dirname(__file__)
  16. # -N prevents tests from running, just lists them:
  17. base_args = [sys.executable, os.path.join(script_folder,'ctest_driver.py'), "--build-path", build_path, "--config", config, '-N']
  18. if ctest_executable:
  19. base_args.append("--ctest-executable")
  20. base_args.append(ctest_executable)
  21. base_args.append("-R") # limit it to only the sanity tests, faster
  22. base_args.append("pytest_sanity_.*")
  23. for suite in SUITES_AND_DESCRIPTIONS:
  24. for gpu_option in [None, True, False]:
  25. args_to_send = base_args.copy()
  26. args_to_send.append("--suite")
  27. args_to_send.append(suite)
  28. print(f"----- Test case: [suite = {suite}, gpu = {gpu_option}] ----")
  29. if gpu_option is not None:
  30. if gpu_option:
  31. args_to_send.append("--only-gpu")
  32. else:
  33. args_to_send.append("--no-gpu")
  34. result = subprocess.check_output(args_to_send, shell=False, cwd=build_path, stderr=sys.stderr)
  35. output = result.decode('utf-8')
  36. # ensure that the appropriate suites are filtered in and out
  37. for suite_name in SUITES_AND_DESCRIPTIONS.keys():
  38. if (f"pytest_sanity_{suite_name}_" in output and suite != suite_name):
  39. print(output)
  40. print("Test failed - executed a test not in the currently selected suite.")
  41. return -1
  42. gpu_test_present = "_requires_gpu" in output
  43. non_gpu_test_present = "_no_gpu" in output
  44. if gpu_option is not None:
  45. if gpu_option and non_gpu_test_present:
  46. print("Test failed - required gpu only, and a non-gpu tes was run")
  47. print(output)
  48. return -1
  49. if not gpu_option and gpu_test_present:
  50. print("Test failed - executed a gpu test when forbidden")
  51. print(output)
  52. return -1
  53. else:
  54. if not (gpu_test_present and non_gpu_test_present):
  55. print("Test failed - expected both kinds of tests (gpu and non gpu)")
  56. print(output)
  57. return -1
  58. print("All passed.")
  59. return 0
  60. if __name__ == '__main__':
  61. parser = argparse.ArgumentParser(
  62. description="CTest CLI driver self-tests.")
  63. parser.add_argument('-x', '--ctest-executable',
  64. help="Override path to the CTest executable (will use PATH env otherwise)")
  65. parser.add_argument('-b', '--build-path',
  66. required=True,
  67. help="Path to a CMake build folder (generated by running cmake)")
  68. parser.add_argument('-c', '--config',
  69. required=True,
  70. help="Configuration to run")
  71. args = parser.parse_args()
  72. sys.exit(main(args.build_path, args.ctest_executable, args.config))