From 02cd4dbcf42d68139562bc73c4ca99c39f443437 Mon Sep 17 00:00:00 2001 From: Nikita Shulga <2453524+malfet@users.noreply.github.com> Date: Tue, 23 Jul 2024 04:01:13 +0000 Subject: [PATCH] [BE][CI] Get rid of duplicated code (#131406) Followup after https://github.com/pytorch/pytorch/pull/131061 Define `run_if_exists` function that runs cpp test if it exists and prints a warning otherwise. Pull Request resolved: https://github.com/pytorch/pytorch/pull/131406 Approved by: https://github.com/kit1980, https://github.com/atalman --- aten/tools/run_tests.sh | 65 +++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 42 deletions(-) diff --git a/aten/tools/run_tests.sh b/aten/tools/run_tests.sh index 32b220505b8..c8bf6061181 100755 --- a/aten/tools/run_tests.sh +++ b/aten/tools/run_tests.sh @@ -27,48 +27,29 @@ python test/run_test.py --cpp --verbose -i \ cpp/legacy_vmap_test \ cpp/operators_test -if [[ -x ${CPP_TESTS_DIR}/tensor_interop_test ]]; then - python test/run_test.py --cpp --verbose -i cpp/tensor_interop_test -fi -if [[ -x ${CPP_TESTS_DIR}/cudnn_test ]]; then - python test/run_test.py --cpp --verbose -i cpp/cudnn_test -fi -if [[ -x ${CPP_TESTS_DIR}/cuda_generator_test ]]; then - python test/run_test.py --cpp --verbose -i cpp/cuda_generator_test -fi -if [[ -x ${CPP_TESTS_DIR}/apply_test ]]; then - python test/run_test.py --cpp --verbose -i cpp/apply_test -fi -if [[ -x ${CPP_TESTS_DIR}/stream_test ]]; then - python test/run_test.py --cpp --verbose -i cpp/stream_test -fi -if [[ -x ${CPP_TESTS_DIR}/cuda_half_test ]]; then - python test/run_test.py --cpp --verbose -i cpp/cuda_half_test -fi -if [[ -x ${CPP_TESTS_DIR}/cuda_vectorized_test ]]; then - python test/run_test.py --cpp --verbose -i cpp/cuda_vectorized_test -fi -if [[ -x ${CPP_TESTS_DIR}/cuda_distributions_test ]]; then - python test/run_test.py --cpp --verbose -i cpp/cuda_distributions_test -fi -if [[ -x ${CPP_TESTS_DIR}/cuda_optional_test ]]; then - python test/run_test.py --cpp --verbose -i cpp/cuda_optional_test -fi -if [[ -x ${CPP_TESTS_DIR}/cuda_tensor_interop_test ]]; then - python test/run_test.py --cpp --verbose -i cpp/cuda_tensor_interop_test -fi -if [[ -x ${CPP_TESTS_DIR}/cuda_complex_test ]]; then - python test/run_test.py --cpp --verbose -i cpp/cuda_complex_test -fi -if [[ -x ${CPP_TESTS_DIR}/cuda_complex_math_test ]]; then - python test/run_test.py --cpp --verbose -i cpp/cuda_complex_math_test -fi -if [[ -x ${CPP_TESTS_DIR}/cuda_cub_test ]]; then - python test/run_test.py --cpp --verbose -i cpp/cuda_cub_test -fi -if [[ -x ${CPP_TESTS_DIR}/cuda_atomic_ops_test ]]; then - python test/run_test.py --cpp --verbose -i cpp/cuda_atomic_ops_test -fi +run_if_exists() { + local test_name="$1" + if [[ -x "${CPP_TESTS_DIR}/${test_name}" ]]; then + python test/run_test.py --cpp --verbose -i "cpp/${test_name}" + else + echo "Warning: $test_name does not exist." + fi +} + +run_if_exists tensor_interop_test +run_if_exists cudnn_test +run_if_exists cuda_generator_test +run_if_exists apply_test +run_if_exists stream_test +run_if_exists cuda_half_test +run_if_exists cuda_vectorized_test +run_if_exists cuda_distributions_test +run_if_exists cuda_optional_test +run_if_exists cuda_tensor_interop_test +run_if_exists cuda_complex_test +run_if_exists cuda_complex_math_test +run_if_exists cuda_cub_test +run_if_exists cuda_atomic_ops_test if [ "$VALGRIND" == "ON" ]; then # NB: As these tests are invoked by valgrind, let's leave them for now as it's