You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

runtest.sh 2.7 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/bin/bash
  2. # Copyright 2020 Huawei Technologies Co., Ltd.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. set -e
  16. SCRIPT_BASEDIR=$(realpath "$(dirname "$0")")
  17. PROJECT_DIR=$(realpath "$SCRIPT_BASEDIR/../../")
  18. CRC32_SCRIPT_PATH="$PROJECT_DIR/build/scripts/crc32.sh"
  19. CRC32_OUTPUT_DIR="$PROJECT_DIR/mindinsight/datavisual/utils/"
  20. ST_PATH="$PROJECT_DIR/tests/st"
  21. IS_BUILD_CRC=""
  22. PYTEST_MARK=""
  23. show_usage() {
  24. echo "Run test cases for st."
  25. echo ""
  26. echo "usage: runtest.sh [-h] [-m <PYTEST MARK>]"
  27. echo ""
  28. echo "options:"
  29. echo " -h show usage info"
  30. echo " -m <PYTEST MARK> mark of pytest."
  31. }
  32. check_opts() {
  33. while getopts ":hm:" opt; do
  34. case $opt in
  35. h)
  36. show_usage
  37. exit 0
  38. ;;
  39. m)
  40. PYTEST_MARK="$OPTARG"
  41. ;;
  42. \?)
  43. show_usage
  44. exit 1
  45. ;;
  46. esac
  47. done
  48. }
  49. build_crc32() {
  50. echo "Start to check crc32."
  51. if [ -d "$CRC32_OUTPUT_DIR" ]; then
  52. cd "$CRC32_OUTPUT_DIR" || exit
  53. result=$(find . -maxdepth 1 -name "crc32*.so")
  54. if [ -z "$result" ]; then
  55. echo "Start to build crc32."
  56. IS_BUILD_CRC="true"
  57. bash "$CRC32_SCRIPT_PATH"
  58. fi
  59. fi
  60. }
  61. clean_crc32() {
  62. echo "Start to clean crc32."
  63. if [ -n "$IS_BUILD_CRC" ]; then
  64. rm -f "$CRC32_OUTPUT_DIR"/crc32*.so
  65. fi
  66. }
  67. before_run_test() {
  68. echo "Before run tests."
  69. export PYTHONPATH=$PROJECT_DIR:$PYTHONPATH
  70. build_crc32
  71. }
  72. after_run_test() {
  73. echo "After run tests."
  74. clean_crc32
  75. echo "End to run tests."
  76. }
  77. run_test() {
  78. echo "Start to run test."
  79. cd "$PROJECT_DIR" || exit
  80. for dir in "$ST_PATH"/*; do
  81. if [ ! -d "$dir" ] || [ "$dir" = "$ST_PATH/__pycache__" ]; then
  82. continue
  83. fi
  84. for sub_dir in "$dir"/*; do
  85. if [ ! -d "$sub_dir" ] || [ "$sub_dir" = "$dir/__pycache__" ]; then
  86. continue
  87. fi
  88. echo "Run test for path: $sub_dir"
  89. pytest "$sub_dir" --disable-pytest-warnings -m "$PYTEST_MARK"
  90. done
  91. done
  92. echo "Test all use cases success."
  93. }
  94. check_opts "$@"
  95. before_run_test
  96. run_test
  97. after_run_test