From b5d4a1f33dba079f37ec0479b3d22bdec49effa6 Mon Sep 17 00:00:00 2001 From: LoveAn Date: Fri, 11 Dec 2020 17:32:10 +0800 Subject: [PATCH] Add the strategy of skipping cc/cu test compilation and execution in CI (#29499) * Add the strategy of skipping cc/cu test compilation and execution in CI, test=develop * fix if error with CI_SKIP_TEST, test=develop * fix add properties to test error on Linux/MAC, test=develop * fix set test properties of test_code_generator error, test=develop * remove test codes and advance judgment of file modification on Linux, test=develop * rename CI_SKIP_TEST to CI_SKIP_CPP_TEST, test=document_fix * Add branch judgement on Linux, test=develop --- cmake/generic.cmake | 10 ++++++++-- paddle/fluid/framework/CMakeLists.txt | 4 ++-- paddle/fluid/framework/ir/fusion_group/CMakeLists.txt | 2 +- paddle/fluid/memory/allocation/CMakeLists.txt | 6 ++++-- paddle/fluid/memory/detail/CMakeLists.txt | 4 +++- paddle/fluid/operators/distributed/CMakeLists.txt | 8 ++++++-- paddle/fluid/operators/jit/CMakeLists.txt | 4 ++-- paddle/fluid/operators/math/CMakeLists.txt | 4 ++-- paddle/fluid/train/CMakeLists.txt | 10 ++++++---- paddle/scripts/paddle_build.bat | 3 +++ paddle/scripts/paddle_build.sh | 7 +++++++ 11 files changed, 44 insertions(+), 18 deletions(-) diff --git a/cmake/generic.cmake b/cmake/generic.cmake index 9d0d9e7dc4..bb125c9490 100644 --- a/cmake/generic.cmake +++ b/cmake/generic.cmake @@ -431,7 +431,10 @@ function(cc_test_run TARGET_NAME) endfunction() function(cc_test TARGET_NAME) - if(WITH_TESTING) + # The environment variable `CI_SKIP_CPP_TEST` is used to skip the compilation + # and execution of test in CI. `CI_SKIP_CPP_TEST` is set to ON when no files + # other than *.py are modified. + if(WITH_TESTING AND NOT "$ENV{CI_SKIP_CPP_TEST}" STREQUAL "ON") set(oneValueArgs "") set(multiValueArgs SRCS DEPS ARGS) cmake_parse_arguments(cc_test "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) @@ -508,7 +511,10 @@ function(nv_binary TARGET_NAME) endfunction(nv_binary) function(nv_test TARGET_NAME) - if (WITH_GPU AND WITH_TESTING) + # The environment variable `CI_SKIP_CPP_TEST` is used to skip the compilation + # and execution of test in CI. `CI_SKIP_CPP_TEST` is set to ON when no files + # other than *.py are modified. + if (WITH_GPU AND WITH_TESTING AND NOT "$ENV{CI_SKIP_CPP_TEST}" STREQUAL "ON") set(oneValueArgs "") set(multiValueArgs SRCS DEPS) cmake_parse_arguments(nv_test "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) diff --git a/paddle/fluid/framework/CMakeLists.txt b/paddle/fluid/framework/CMakeLists.txt index 2ea89df818..93afbbf323 100644 --- a/paddle/fluid/framework/CMakeLists.txt +++ b/paddle/fluid/framework/CMakeLists.txt @@ -349,6 +349,6 @@ if(APPLE) ${PADDLE_BINARY_DIR}/paddle/fluid/framework/libpaddle_framework.dylib CACHE INTERNAL "Fluid framework lib") endif() -if(WITH_TESTING) -set_tests_properties(selected_rows_test PROPERTIES TIMEOUT 120) +if(WITH_TESTING AND TEST selected_rows_test) + set_tests_properties(selected_rows_test PROPERTIES TIMEOUT 120) endif() diff --git a/paddle/fluid/framework/ir/fusion_group/CMakeLists.txt b/paddle/fluid/framework/ir/fusion_group/CMakeLists.txt index d6be8fb071..8586069cdf 100644 --- a/paddle/fluid/framework/ir/fusion_group/CMakeLists.txt +++ b/paddle/fluid/framework/ir/fusion_group/CMakeLists.txt @@ -9,6 +9,6 @@ cc_library(fusion_group_pass SRCS fusion_group_pass.cc elementwise_group_detector.cc DEPS subgraph_detector fuse_pass_base code_generator device_code) cc_test(test_fusion_group_pass SRCS fusion_group_pass_tester.cc DEPS fusion_group_pass graph_viz_pass) -if(WITH_TESTING) +if(WITH_TESTING AND TEST test_code_generator) set_tests_properties(test_code_generator PROPERTIES TIMEOUT 120) endif() diff --git a/paddle/fluid/memory/allocation/CMakeLists.txt b/paddle/fluid/memory/allocation/CMakeLists.txt index 8a1a1115ad..108e1240c5 100644 --- a/paddle/fluid/memory/allocation/CMakeLists.txt +++ b/paddle/fluid/memory/allocation/CMakeLists.txt @@ -57,11 +57,13 @@ cc_library(allocator_facade SRCS allocator_facade.cc DEPS allocator_strategy) cc_test(retry_allocator_test SRCS retry_allocator_test.cc DEPS retry_allocator locked_allocator cpu_allocator) if (WITH_TESTING) - if (WITH_GPU) + if (WITH_GPU AND TARGET retry_allocator_test) target_link_libraries(retry_allocator_test cuda_allocator) endif() - set_tests_properties(retry_allocator_test PROPERTIES LABELS "RUN_TYPE=EXCLUSIVE") + if (TEST retry_allocator_test) + set_tests_properties(retry_allocator_test PROPERTIES LABELS "RUN_TYPE=EXCLUSIVE") + endif() endif() cc_test(allocator_facade_abs_flags_test SRCS allocator_facade_abs_flags_test.cc DEPS allocator_facade) diff --git a/paddle/fluid/memory/detail/CMakeLists.txt b/paddle/fluid/memory/detail/CMakeLists.txt index ceef7fc66f..8f0988e871 100644 --- a/paddle/fluid/memory/detail/CMakeLists.txt +++ b/paddle/fluid/memory/detail/CMakeLists.txt @@ -34,7 +34,9 @@ FUNCTION(file_download_and_uncompress URL NAME) ENDFUNCTION() if(WITH_TESTING) - set_tests_properties(buddy_allocator_test PROPERTIES LABELS "RUN_TYPE=EXCLUSIVE") + if(TEST buddy_allocator_test) + set_tests_properties(buddy_allocator_test PROPERTIES LABELS "RUN_TYPE=EXCLUSIVE") + endif() set(URL "https://paddle-ci.cdn.bcebos.com/buddy_allocator_test_data.tar") file_download_and_uncompress(URL "buddy_allocator") endif() diff --git a/paddle/fluid/operators/distributed/CMakeLists.txt b/paddle/fluid/operators/distributed/CMakeLists.txt index 5b4d02682f..a8368462b9 100644 --- a/paddle/fluid/operators/distributed/CMakeLists.txt +++ b/paddle/fluid/operators/distributed/CMakeLists.txt @@ -69,6 +69,10 @@ if(WITH_GPU) selected_rows_functor scope math_function) endif() if(WITH_TESTING) -set_tests_properties(rpc_server_test PROPERTIES TIMEOUT 120) -set_tests_properties(heart_beat_monitor_test PROPERTIES TIMEOUT 120) + if(TEST rpc_server_test) + set_tests_properties(rpc_server_test PROPERTIES TIMEOUT 120) + endif() + if(TEST heart_beat_monitor_test) + set_tests_properties(heart_beat_monitor_test PROPERTIES TIMEOUT 120) + endif() endif() diff --git a/paddle/fluid/operators/jit/CMakeLists.txt b/paddle/fluid/operators/jit/CMakeLists.txt index 95361b17aa..080e7f7d5e 100644 --- a/paddle/fluid/operators/jit/CMakeLists.txt +++ b/paddle/fluid/operators/jit/CMakeLists.txt @@ -26,6 +26,6 @@ cc_test(jit_kernel_test SRCS test.cc DEPS jit_kernel_helper) if(NOT WIN32) cc_binary(jit_kernel_benchmark SRCS benchmark.cc DEPS jit_kernel_helper device_tracer tensor) endif() -if(WITH_TESTING) -set_tests_properties(jit_kernel_test PROPERTIES TIMEOUT 120) +if(WITH_TESTING AND TEST jit_kernel_test) + set_tests_properties(jit_kernel_test PROPERTIES TIMEOUT 120) endif() diff --git a/paddle/fluid/operators/math/CMakeLists.txt b/paddle/fluid/operators/math/CMakeLists.txt index c8831013d7..a6c908421a 100644 --- a/paddle/fluid/operators/math/CMakeLists.txt +++ b/paddle/fluid/operators/math/CMakeLists.txt @@ -91,6 +91,6 @@ if(WITH_GPU) endif() cc_test(concat_test SRCS concat_test.cc DEPS concat_and_split) cc_test(cpu_vec_test SRCS cpu_vec_test.cc DEPS blas cpu_info) -if(WITH_TESTING) -set_tests_properties(im2col_test PROPERTIES TIMEOUT 120) +if(WITH_TESTING AND TEST im2col_test) + set_tests_properties(im2col_test PROPERTIES TIMEOUT 120) endif() diff --git a/paddle/fluid/train/CMakeLists.txt b/paddle/fluid/train/CMakeLists.txt index a1f75adf87..8f360d7796 100644 --- a/paddle/fluid/train/CMakeLists.txt +++ b/paddle/fluid/train/CMakeLists.txt @@ -15,11 +15,13 @@ function(train_test TARGET_NAME) DEPS paddle_fluid_api ARGS --dirname=${PYTHON_TESTS_DIR}/book/) endif() - set_tests_properties(test_train_${TARGET_NAME} - PROPERTIES FIXTURES_REQUIRED test_${TARGET_NAME}_infer_model) - if(NOT WIN32 AND NOT APPLE) + if(TEST test_train_${TARGET_NAME}) set_tests_properties(test_train_${TARGET_NAME} - PROPERTIES TIMEOUT 150) + PROPERTIES FIXTURES_REQUIRED test_${TARGET_NAME}_infer_model) + if(NOT WIN32 AND NOT APPLE) + set_tests_properties(test_train_${TARGET_NAME} + PROPERTIES TIMEOUT 150) + endif() endif() endfunction(train_test) diff --git a/paddle/scripts/paddle_build.bat b/paddle/scripts/paddle_build.bat index 7fd4a5aee1..5ad48734ad 100644 --- a/paddle/scripts/paddle_build.bat +++ b/paddle/scripts/paddle_build.bat @@ -74,6 +74,9 @@ if %ERRORLEVEL% EQU 0 ( git branch last_pr ) +:: set CI_SKIP_CPP_TEST if only *.py changed +git diff --name-only %BRANCH% | findstr /V "\.py" || set CI_SKIP_CPP_TEST=ON + :: for /F %%# in ('wmic os get localdatetime^|findstr 20') do set datetime=%%# :: set day_now=%datetime:~6,2% :: set day_before=-1 diff --git a/paddle/scripts/paddle_build.sh b/paddle/scripts/paddle_build.sh index 6eabaa1d15..21eedc6066 100755 --- a/paddle/scripts/paddle_build.sh +++ b/paddle/scripts/paddle_build.sh @@ -60,6 +60,13 @@ function init() { # NOTE(chenweihang): For easy debugging, CI displays the C++ error stacktrace by default export FLAGS_call_stack_level=2 + + # set CI_SKIP_CPP_TEST if only *.py changed + # In order to avoid using in some CI(such as daily performance), the current + # branch must not be `${BRANCH}` which is usually develop. + if [ "$(git branch | grep "^\*" | awk '{print $2}')" != "${BRANCH}" ]; then + git diff --name-only ${BRANCH} | grep -v "\.py$" || export CI_SKIP_CPP_TEST=ON + fi } function cmake_base() {