run_cpp_unittest.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. set -e
  18. SOURCE="${BASH_SOURCE[0]}"
  19. while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
  20. DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
  21. SOURCE="$(readlink "$SOURCE")"
  22. [[ $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
  23. done
  24. SCRIPTS_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
  25. MILVUS_CORE_DIR="${SCRIPTS_DIR}/../internal/core"
  26. CORE_INSTALL_PREFIX="${MILVUS_CORE_DIR}/output"
  27. UNITTEST_DIRS=("${CORE_INSTALL_PREFIX}/unittest")
  28. # currently core will install target lib to "internal/core/output/lib"
  29. if [ -d "${CORE_INSTALL_PREFIX}/lib" ]; then
  30. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${CORE_INSTALL_PREFIX}/lib
  31. fi
  32. # run unittest
  33. arg="$1"
  34. filter_value="${arg#*=}"
  35. for UNITTEST_DIR in "${UNITTEST_DIRS[@]}"; do
  36. if [ ! -d "${UNITTEST_DIR}" ]; then
  37. echo "The unittest folder does not exist!"
  38. exit 1
  39. fi
  40. if [[ $filter_value ]]; then
  41. if [ $filter_value == "--gtest_list_tests" ]; then
  42. ${UNITTEST_DIR}/all_tests $filter_value
  43. exit 0
  44. else
  45. ${UNITTEST_DIR}/all_tests --gtest_filter=$filter_value
  46. exit 0
  47. fi
  48. fi
  49. echo "Running all unittest ..."
  50. ${UNITTEST_DIR}/all_tests
  51. if [ $? -ne 0 ]; then
  52. echo ${UNITTEST_DIR}/all_tests "run failed"
  53. exit 1
  54. fi
  55. if [ -f "${UNITTEST_DIR}/dynamic_simd_test" ]; then
  56. echo "Running dynamic simd test"
  57. ${UNITTEST_DIR}/dynamic_simd_test
  58. if [ $? -ne 0 ]; then
  59. echo ${UNITTEST_DIR}/dynamic_simd_test "run failed"
  60. exit 1
  61. fi
  62. fi
  63. done
  64. # run cwrapper unittest
  65. if [ -f ${CWRAPPER_UNITTEST} ];then
  66. echo "Running cwrapper unittest: ${CWRAPPER_UNITTEST}"
  67. ${CWRAPPER_UNITTEST}
  68. if [ $? -ne 0 ]; then
  69. echo ${CWRAPPER_UNITTEST} " run failed"
  70. exit 1
  71. fi
  72. fi