From f6c3b77d20e5bde165f8415977122c3ad978bccb Mon Sep 17 00:00:00 2001 From: Huihuang Zheng Date: Tue, 17 Aug 2021 19:50:09 +0800 Subject: [PATCH] Add CI Test (#30) 1. Add piano_ci_test.sh, which runs the ctests that has corresponding files under `paddle/fluid/compiler` folder. 2. Add `libtinfo-dev` to Dockerfile 3. Change `piano_layout_test` and `piano_shape_test` to `layout_test` and `shape_test` 4. Add `-DWITH_COMPILER` into `paddle_build.sh` --- paddle/fluid/compiler/piano/CMakeLists.txt | 4 +- .../fluid/compiler/scripts/piano_ci_test.sh | 131 ++++++++++++++++++ paddle/scripts/paddle_build.sh | 2 + tools/dockerfile/Dockerfile.ubuntu | 2 +- 4 files changed, 136 insertions(+), 3 deletions(-) create mode 100644 paddle/fluid/compiler/scripts/piano_ci_test.sh diff --git a/paddle/fluid/compiler/piano/CMakeLists.txt b/paddle/fluid/compiler/piano/CMakeLists.txt index 9c7a66648bd01..241df83e6bfb8 100644 --- a/paddle/fluid/compiler/piano/CMakeLists.txt +++ b/paddle/fluid/compiler/piano/CMakeLists.txt @@ -2,5 +2,5 @@ add_subdirectory(backends) add_subdirectory(note) cc_library(piano_data_description SRCS layout.cc shape.cc DEPS string_helper note_proto) -cc_test(piano_layout_test SRCS layout_test.cc DEPS piano_data_description) -cc_test(piano_shape_test SRCS shape_test.cc DEPS piano_data_description) +cc_test(layout_test SRCS layout_test.cc DEPS piano_data_description) +cc_test(shape_test SRCS shape_test.cc DEPS piano_data_description) diff --git a/paddle/fluid/compiler/scripts/piano_ci_test.sh b/paddle/fluid/compiler/scripts/piano_ci_test.sh new file mode 100644 index 0000000000000..a1a533d10f3d3 --- /dev/null +++ b/paddle/fluid/compiler/scripts/piano_ci_test.sh @@ -0,0 +1,131 @@ +#!/usr/bin/env bash + +# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -ex + +if [ -z ${BRANCH} ]; then + BRANCH="paddle_compiler" +fi + +function init() { + RED='\033[0;31m' + BLUE='\033[0;34m' + BOLD='\033[1m' + NONE='\033[0m' + + PADDLE_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}")/../../../../" && pwd )" + export PADDLE_ROOT + if [ -z "${SCRIPT_NAME}" ]; then + SCRIPT_NAME=$0 + fi + + ENABLE_MAKE_CLEAN=${ENABLE_MAKE_CLEAN:-ON} + + # 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 [ ${CI_SKIP_CPP_TEST:-ON} == "OFF" ];then + echo "CI_SKIP_CPP_TEST=OFF" + else + if [ "$(git branch | grep "^\*" | awk '{print $2}')" != "${BRANCH}" ]; then + git diff --name-only ${BRANCH} | grep -v "\.py$" || export CI_SKIP_CPP_TEST=ON + fi + fi +} + +function parallel_test() { + mkdir -p ${PADDLE_ROOT}/build + cd ${PADDLE_ROOT}/build + pip install ${PADDLE_ROOT}/build/python/dist/*whl + cp ${PADDLE_ROOT}/build/python/paddle/fluid/tests/unittests/op_test.py ${PADDLE_ROOT}/build/python + ut_total_startTime_s=`date +%s` + + EXIT_CODE=0 + + all_ctests=$(ctest -N | awk -F ': ' '{print $2}' | sed '/^$/d' | sed '$d') + compiler_files_contains_test=$(find ${PADDLE_ROOT}/paddle/fluid/compiler -iname "*test*" -type f) + + # Temporary directory to save failed Piano test + tmp_dir=`mktemp -d` + echo "Created temporary directory to store test result:" $tmp_dir + + piano_test_list='' + for test_case in $all_ctests; do + is_piano_test=0 + for test_file in $compiler_files_contains_test; do + if [[ $test_file =~ $test_case ]]; then + is_piano_test=1 + break + fi + done + + if [ $is_piano_test = 1 ]; then + tmp_file_rand=`date +%s%N` + tmp_file=$tmp_dir/$tmp_file_rand + ctest -R $test_case --output-on-failure | tee $tmp_file + piano_test_list="${piano_test_list} + ${test_case}" + fi + done + + failed_test_lists='' + set +e + for file in `ls $tmp_dir`; do + grep -q 'The following tests FAILED:' $tmp_dir/$file + grep_exit_code=$? + if [ $grep_exit_code -ne 0 ]; then + failed_test='' + else + EXIT_CODE=8 + failed_test=`grep -A 10000 'The following tests FAILED:' $tmp_dir/$file | sed 's/The following tests FAILED://g'|sed '/^$/d'` + failed_test_lists="${failed_test_lists} + ${failed_test}" + fi + done + set -e + + rm -rf $tmp_dir + echo "Removed temporary directory which stores test result:" $tmp_dir + + if [ $EXIT_CODE != 0 ]; then + echo "=========================================" + echo "The following tests FAILED:" + echo "=========================================" + echo "${failed_test_lists}" + exit 8; + fi + + ut_total_endTime_s=`date +%s` + echo "=========================================" + echo "The following tests SUCCESSED:" + echo "=========================================" + echo "${piano_test_list}" + echo "" + echo "TestCases Total Time: $[ $ut_total_endTime_s - $ut_total_startTime_s ]s" + echo "ipipe_log_param_TestCases_Total_Time: $[ $ut_total_endTime_s - $ut_total_startTime_s ]s" +} + +function main() { + init + parallel_test + + echo "piano_ci_test script finished as expected" +} + +main $@ diff --git a/paddle/scripts/paddle_build.sh b/paddle/scripts/paddle_build.sh index 1eee270c8dc46..334055a9921ec 100755 --- a/paddle/scripts/paddle_build.sh +++ b/paddle/scripts/paddle_build.sh @@ -202,6 +202,7 @@ function cmake_base() { -DWITH_GPU=${WITH_GPU:-OFF} -DWITH_TENSORRT=${WITH_TENSORRT:-ON} -DWITH_ROCM=${WITH_ROCM:-OFF} + -DWITH_COMPILER=${WITH_COMPILER:-OFF} -DWITH_DISTRIBUTE=${distibuted_flag} -DWITH_MKL=${WITH_MKL:-ON} -DWITH_AVX=${WITH_AVX:-OFF} @@ -242,6 +243,7 @@ EOF -DWITH_GPU=${WITH_GPU:-OFF} \ -DWITH_TENSORRT=${WITH_TENSORRT:-ON} \ -DWITH_ROCM=${WITH_ROCM:-OFF} \ + -DWITH_COMPILER=${WITH_COMPILER:-OFF} \ -DWITH_DISTRIBUTE=${distibuted_flag} \ -DWITH_MKL=${WITH_MKL:-ON} \ -DWITH_AVX=${WITH_AVX:-OFF} \ diff --git a/tools/dockerfile/Dockerfile.ubuntu b/tools/dockerfile/Dockerfile.ubuntu index df863cd893c19..03d310f99cd1e 100644 --- a/tools/dockerfile/Dockerfile.ubuntu +++ b/tools/dockerfile/Dockerfile.ubuntu @@ -19,7 +19,7 @@ COPY paddle/scripts/docker/root/ /root/ RUN apt-get update && \ apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \ libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \ - xz-utils tk-dev libffi-dev liblzma-dev + xz-utils tk-dev libffi-dev liblzma-dev libtinfo-dev RUN apt-get update && \ apt-get install -y --allow-downgrades --allow-change-held-packages \