run_cpp_codecov.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/usr/bin/env bash
  2. # Licensed to the LF AI & Data foundation under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. The ASF licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. # Exit immediately for non zero status
  18. set -e
  19. SOURCE="${BASH_SOURCE[0]}"
  20. while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
  21. DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
  22. SOURCE="$(readlink "$SOURCE")"
  23. [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
  24. done
  25. ROOT_DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"
  26. source ${ROOT_DIR}/scripts/setenv.sh
  27. MILVUS_CORE_DIR="${ROOT_DIR}/internal/core"
  28. MILVUS_CORE_UNITTEST_DIR="${MILVUS_CORE_DIR}/output/unittest"
  29. echo "ROOT_DIR = ${ROOT_DIR}"
  30. echo "MILVUS_CORE_DIR = ${MILVUS_CORE_DIR}"
  31. echo "MILVUS_CORE_UNITTEST_DIR = ${MILVUS_CORE_UNITTEST_DIR}"
  32. LCOV_CMD="lcov"
  33. LCOV_GEN_CMD="genhtml"
  34. FILE_INFO_BASE="${ROOT_DIR}/lcov_base.info"
  35. FILE_INFO_UT="${ROOT_DIR}/lcov_ut.info"
  36. FILE_INFO_COMBINE="${ROOT_DIR}/lcov_combine.info"
  37. FILE_INFO_OUTPUT="${ROOT_DIR}/lcov_output.info"
  38. DIR_LCOV_OUTPUT="${ROOT_DIR}/cpp_coverage"
  39. DIR_GCNO="${ROOT_DIR}/cmake_build/"
  40. # delete old code coverage info files
  41. rm -f ${FILE_INFO_BASE}
  42. rm -f ${FILE_INFO_UT}
  43. rm -f ${FILE_INFO_COMBINE}
  44. rm -f ${FILE_INFO_OUTPUT}
  45. rm -rf ${DIR_LCOV_OUTPUT}
  46. # generate baseline
  47. ${LCOV_CMD} -c -i -d ${DIR_GCNO} -o ${FILE_INFO_BASE}
  48. if [ $? -ne 0 ]; then
  49. echo "Failed to generate coverage baseline"
  50. exit -1
  51. fi
  52. # starting the timer
  53. beginTime=`date +%s`
  54. # run unittest
  55. for test in `ls ${MILVUS_CORE_UNITTEST_DIR}`; do
  56. echo "Running cpp unittest: ${MILVUS_CORE_UNITTEST_DIR}/$test"
  57. # run unittest
  58. ${MILVUS_CORE_UNITTEST_DIR}/${test}
  59. if [ $? -ne 0 ]; then
  60. echo ${args}
  61. echo "${MILVUS_CORE_UNITTEST_DIR}/${test} run failed"
  62. exit -1
  63. fi
  64. done
  65. # generate ut file
  66. ${LCOV_CMD} -c -d ${DIR_GCNO} -o ${FILE_INFO_UT}
  67. # merge baseline and ut file
  68. ${LCOV_CMD} -a ${FILE_INFO_BASE} -a ${FILE_INFO_UT} -o ${FILE_INFO_COMBINE}
  69. # remove unnecessary info
  70. ${LCOV_CMD} -r "${FILE_INFO_COMBINE}" -o "${FILE_INFO_OUTPUT}" \
  71. "/usr/*" \
  72. "*/llvm/*" \
  73. "*/src/pb/*" \
  74. "*/src/core/bench/*" \
  75. "*/unittest/*" \
  76. "*/thirdparty/*" \
  77. "*/3rdparty_download/*" \
  78. "*/.conan/data/*"
  79. # generate html report
  80. ${LCOV_GEN_CMD} ${FILE_INFO_OUTPUT} --output-directory ${DIR_LCOV_OUTPUT}/
  81. echo "Generate cpp code coverage report to ${DIR_LCOV_OUTPUT}"
  82. endTime=`date +%s`
  83. echo "Total time for cpp unittest:" $(($endTime-$beginTime)) "s"