test-all.sh 4.5 KB
Newer Older
sangshuduo's avatar
sangshuduo 已提交
1 2
#!/bin/bash

3 4 5 6 7 8 9
# Color setting
RED='\033[0;31m'
GREEN='\033[1;32m'
GREEN_DARK='\033[0;32m'
GREEN_UNDERLINE='\033[4;32m'
NC='\033[0m'

10 11
function runSimCaseOneByOne {
  while read -r line; do
P
Ping Xiao 已提交
12
    if [[ $line =~ ^./test.sh* ]] || [[ $line =~ ^run* ]]; then
P
Ping Xiao 已提交
13 14
			case=`echo $line | grep sim$ |awk '{print $NF}'`

S
Shuduo Sang 已提交
15
      start_time=`date +%s`
16
      ./test.sh -f $case > /dev/null 2>&1 && \
S
Shuduo Sang 已提交
17
        echo -e "${GREEN}$case success${NC}" | tee -a out.log || \
18
        echo -e "${RED}$case failed${NC}" | tee -a out.log
L
liuyq-617 已提交
19
      out_log=`tail -1 out.log  `
L
liuyq-617 已提交
20 21 22
      # if [[ $out_log =~ 'failed' ]];then
      #   exit 8
      # fi
S
Shuduo Sang 已提交
23 24
      end_time=`date +%s`
      echo execution time of $case was `expr $end_time - $start_time`s. | tee -a out.log
25 26 27 28 29 30 31
    fi
  done < $1
}

function runPyCaseOneByOne {
  while read -r line; do
    if [[ $line =~ ^python.* ]]; then
32
      if [[ $line != *sleep* ]]; then
L
liuyq-617 已提交
33 34 35 36 37 38
        
        if [[ $line =~ '-r' ]];then
          case=`echo $line|awk '{print $4}'`
        else
          case=`echo $line|awk '{print $NF}'`
        fi
S
Shuduo Sang 已提交
39
        start_time=`date +%s`
40
        $line > /dev/null 2>&1 && \
S
Shuduo Sang 已提交
41
          echo -e "${GREEN}$case success${NC}" | tee -a pytest-out.log || \
42
          echo -e "${RED}$case failed${NC}" | tee -a pytest-out.log
S
Shuduo Sang 已提交
43
        end_time=`date +%s`
L
liuyq-617 已提交
44
        out_log=`tail -1 pytest-out.log  `
L
liuyq-617 已提交
45 46 47
        # if [[ $out_log =~ 'failed' ]];then
        #   exit 8
        # fi
S
Shuduo Sang 已提交
48
        echo execution time of $case was `expr $end_time - $start_time`s. | tee -a pytest-out.log
49 50 51
      else
        $line > /dev/null 2>&1
      fi
52 53 54 55
    fi
  done < $1
}

56 57
totalFailed=0
totalPyFailed=0
sangshuduo's avatar
sangshuduo 已提交
58

S
Shuduo Sang 已提交
59
tests_dir=`pwd`
sangshuduo's avatar
sangshuduo 已提交
60

61 62
if [ "$2" != "python" ]; then
  echo "### run TSIM test case ###"
S
Shuduo Sang 已提交
63
  cd $tests_dir/script
64

65 66 67 68 69 70
  [ -f out.log ] && rm -f out.log
  if [ "$1" == "cron" ]; then
    echo "### run TSIM regression test ###"
    runSimCaseOneByOne regressionSuite.sim
  elif [ "$1" == "full" ]; then
    echo "### run TSIM full test ###"
P
Ping Xiao 已提交
71
    runSimCaseOneByOne jenkins/basic.txt
L
liuyq-617 已提交
72 73 74 75 76 77 78 79 80
  elif [ "$1" == "b1" ]; then
    echo "### run TSIM b1 test ###"
    runSimCaseOneByOne jenkins/basic_1.txt
  elif [ "$1" == "b2" ]; then
    echo "### run TSIM b2 test ###"
    runSimCaseOneByOne jenkins/basic_2.txt
  elif [ "$1" == "b3" ]; then
    echo "### run TSIM b3 test ###"
    runSimCaseOneByOne jenkins/basic_3.txt
S
Shuduo Sang 已提交
81
  elif [ "$1" == "smoke" ] || [ -z "$1" ]; then
82 83 84
    echo "### run TSIM smoke test ###"
    runSimCaseOneByOne basicSuite.sim
  fi
85

86 87
  totalSuccess=`grep 'success' out.log | wc -l`
  totalBasic=`grep success out.log | grep Suite | wc -l`
88

89 90 91
  if [ "$totalSuccess" -gt "0" ]; then
    totalSuccess=`expr $totalSuccess - $totalBasic`
  fi
sangshuduo's avatar
sangshuduo 已提交
92

S
Shuduo Sang 已提交
93
  echo -e "\n${GREEN} ### Total $totalSuccess TSIM case(s) succeed! ### ${NC}"
94

95 96
  totalFailed=`grep 'failed\|fault' out.log | wc -l`
# echo -e "${RED} ### Total $totalFailed TSIM case(s) failed! ### ${NC}"
97

98
  if [ "$totalFailed" -ne "0" ]; then
S
Shuduo Sang 已提交
99
    echo -e "\n${RED} ### Total $totalFailed TSIM case(s) failed! ### ${NC}"
sangshuduo's avatar
sangshuduo 已提交
100

101 102
#  exit $totalFailed
  fi
sangshuduo's avatar
sangshuduo 已提交
103 104
fi

105 106
if [ "$2" != "sim" ]; then
  echo "### run Python test case ###"
107

S
Shuduo Sang 已提交
108
  cd $tests_dir
109 110
  IN_TDINTERNAL="community"

S
Shuduo Sang 已提交
111
  if [[ "$tests_dir" == *"$IN_TDINTERNAL"* ]]; then
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
    cd ../..
  else
    cd ../
  fi

  TOP_DIR=`pwd`
  TAOSLIB_DIR=`find . -name "libtaos.so"|grep -w lib|head -n1`
  if [[ "$TAOSLIB_DIR" == *"$IN_TDINTERNAL"* ]]; then
    LIB_DIR=`find . -name "libtaos.so"|grep -w lib|head -n1|cut -d '/' --fields=2,3,4,5`
  else
    LIB_DIR=`find . -name "libtaos.so"|grep -w lib|head -n1|cut -d '/' --fields=2,3,4`
  fi

  export LD_LIBRARY_PATH=$TOP_DIR/$LIB_DIR:$LD_LIBRARY_PATH

S
Shuduo Sang 已提交
127
  cd $tests_dir/pytest
128 129 130 131 132 133 134 135 136

  [ -f pytest-out.log ] && rm -f pytest-out.log

  if [ "$1" == "cron" ]; then
    echo "### run Python regression test ###"
    runPyCaseOneByOne regressiontest.sh
  elif [ "$1" == "full" ]; then
    echo "### run Python full test ###"
    runPyCaseOneByOne fulltest.sh
L
liuyq-617 已提交
137
  elif [ "$1" == "pytest" ]; then
L
liuyq-617 已提交
138 139 140 141
    echo "### run Python full test ###"
    runPyCaseOneByOne fulltest.sh
  elif [ "$1" == "b2" ] || [ "$1" == "b3" ]; then
    exit $(($totalFailed + $totalPyFailed))
S
Shuduo Sang 已提交
142
  elif [ "$1" == "smoke" ] || [ -z "$1" ]; then
143 144 145
    echo "### run Python smoke test ###"
    runPyCaseOneByOne smoketest.sh
  fi
146
  totalPySuccess=`grep 'success' pytest-out.log | wc -l`
147 148

  if [ "$totalPySuccess" -gt "0" ]; then
S
Shuduo Sang 已提交
149
    echo -e "\n${GREEN} ### Total $totalPySuccess python case(s) succeed! ### ${NC}"
150 151 152 153
  fi

  totalPyFailed=`grep 'failed\|fault' pytest-out.log | wc -l`
  if [ "$totalPyFailed" -ne "0" ]; then
S
Shuduo Sang 已提交
154
    echo -e "\n${RED} ### Total $totalPyFailed python case(s) failed! ### ${NC}"
155
#  exit $totalPyFailed
156
  fi
sangshuduo's avatar
sangshuduo 已提交
157 158
fi

159
exit $(($totalFailed + $totalPyFailed))