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

3 4 5 6 7 8
# Color setting
RED='\033[0;31m'
GREEN='\033[1;32m'
GREEN_DARK='\033[0;32m'
GREEN_UNDERLINE='\033[4;32m'
NC='\033[0m'
L
liuyq-617 已提交
9 10 11 12 13 14 15 16 17

function dohavecore(){
  corefile=`find $corepath -mmin 1`  
  if [ -n "$corefile" ];then
  echo 'taosd or taos has generated core'
  if [[ $1 == 1 ]];then
    exit 8
  fi
  fi
18
}
19 20
function runSimCaseOneByOne {
  while read -r line; do
P
Ping Xiao 已提交
21
    if [[ $line =~ ^./test.sh* ]] || [[ $line =~ ^run* ]]; then
P
Ping Xiao 已提交
22
			case=`echo $line | grep sim$ |awk '{print $NF}'`
L
liuyq-617 已提交
23
      IN_TDINTERNAL="community"
S
Shuduo Sang 已提交
24
      start_time=`date +%s`
L
liuyq-617 已提交
25 26 27 28
       IN_TDINTERNAL="community"
      if [[ "$tests_dir" == *"$IN_TDINTERNAL"* ]]; then
        echo -n $case
        ./test.sh -f $case > /dev/null 2>&1 && \
L
liuyq-617 已提交
29
        ( grep -q 'script.*'$case'.*failed.*, err.*lineNum' ../../../sim/tsim/log/taoslog0.0 && echo -e "${RED} failed${NC}" | tee -a out.log  ||  echo -e "${GREEN} success${NC}" | tee -a out.log )|| \
L
liuyq-617 已提交
30 31 32 33 34
        ( grep -q 'script.*success.*m$' ../../../sim/tsim/log/taoslog0.0 && echo -e "${GREEN} success${NC}" | tee -a out.log )  || \
        echo -e "${RED} failed${NC}" | tee -a out.log
      else
        echo -n $case
        ./test.sh -f $case > /dev/null 2>&1 && \
L
liuyq-617 已提交
35
        ( grep -q 'script.*'$case'.*failed.*, err.*lineNum' ../../sim/tsim/log/taoslog0.0 && echo -e "${RED} failed${NC}" | tee -a out.log  ||  echo -e "${GREEN} success${NC}" | tee -a out.log )|| \
L
liuyq-617 已提交
36 37 38
        ( grep -q 'script.*success.*m$' ../../sim/tsim/log/taoslog0.0 && echo -e "${GREEN} success${NC}" | tee -a out.log )  || \
        echo -e "${RED} failed${NC}" | tee -a out.log
      fi
L
liuyq-617 已提交
39
      out_log=`tail -1 out.log  `
L
liuyq-617 已提交
40 41 42
      # if [[ $out_log =~ 'failed' ]];then
      #   exit 8
      # fi
S
Shuduo Sang 已提交
43 44
      end_time=`date +%s`
      echo execution time of $case was `expr $end_time - $start_time`s. | tee -a out.log
L
liuyq-617 已提交
45
      dohavecore 0
46 47 48
    fi
  done < $1
}
L
liuyq-617 已提交
49 50 51 52 53 54
function runSimCaseOneByOnefq {
  while read -r line; do
    if [[ $line =~ ^./test.sh* ]] || [[ $line =~ ^run* ]]; then
			case=`echo $line | grep sim$ |awk '{print $NF}'`

      start_time=`date +%s`
55 56
      IN_TDINTERNAL="community"
      if [[ "$tests_dir" == *"$IN_TDINTERNAL"* ]]; then
L
liuyq-617 已提交
57
        echo -n $case
58
        ./test.sh -f $case > /dev/null 2>&1 && \
L
liuyq-617 已提交
59
        ( grep -q 'script.*'$case'.*failed.*, err.*lineNum' ../../../sim/tsim/log/taoslog0.0 && echo -e "${RED} failed${NC}" | tee -a out.log  ||  echo -e "${GREEN} success${NC}" | tee -a out.log )|| \
L
liuyq-617 已提交
60 61
        ( grep -q 'script.*success.*m$' ../../../sim/tsim/log/taoslog0.0 && echo -e "${GREEN} success${NC}" | tee -a out.log )  || \
        echo -e "${RED} failed${NC}" | tee -a out.log
62
      else
L
liuyq-617 已提交
63
        echo -n $case
64
        ./test.sh -f $case > /dev/null 2>&1 && \
L
liuyq-617 已提交
65
        ( grep -q 'script.*'$case'.*failed.*, err.*lineNum' ../../sim/tsim/log/taoslog0.0 && echo -e "${RED} failed${NC}" | tee -a out.log  ||  echo -e "${GREEN} success${NC}" | tee -a out.log )|| \
L
liuyq-617 已提交
66 67
        ( grep -q 'script.*success.*m$' ../../sim/tsim/log/taoslog0.0 && echo -e "${GREEN} success${NC}" | tee -a out.log )  || \
        echo -e "${RED} failed${NC}" | tee -a out.log
68 69
      fi
      
L
liuyq-617 已提交
70 71
      out_log=`tail -1 out.log  `
      if [[ $out_log =~ 'failed' ]];then
72
        if [[ "$tests_dir" == *"$IN_TDINTERNAL"* ]]; then
L
liuyq-617 已提交
73
          cp -r ../../../sim ~/sim_`date "+%Y_%m_%d_%H:%M:%S"`
74
        else 
L
liuyq-617 已提交
75
          cp -r ../../sim ~/sim_`date "+%Y_%m_%d_%H:%M:%S" `
76
        fi
L
liuyq-617 已提交
77 78 79 80
        exit 8
      fi
      end_time=`date +%s`
      echo execution time of $case was `expr $end_time - $start_time`s. | tee -a out.log
L
liuyq-617 已提交
81
      dohavecore 1
L
liuyq-617 已提交
82 83 84
    fi
  done < $1
}
85 86 87 88

function runPyCaseOneByOne {
  while read -r line; do
    if [[ $line =~ ^python.* ]]; then
89
      if [[ $line != *sleep* ]]; then
L
liuyq-617 已提交
90 91 92 93 94 95
        
        if [[ $line =~ '-r' ]];then
          case=`echo $line|awk '{print $4}'`
        else
          case=`echo $line|awk '{print $NF}'`
        fi
S
Shuduo Sang 已提交
96
        start_time=`date +%s`
L
liuyq-617 已提交
97
        echo -n $case
98
        $line > /dev/null 2>&1 && \
L
liuyq-617 已提交
99 100
          echo -e "${GREEN} success${NC}" | tee -a pytest-out.log || \
          echo -e "${RED} failed${NC}" | tee -a pytest-out.log
S
Shuduo Sang 已提交
101
        end_time=`date +%s`
L
liuyq-617 已提交
102
        out_log=`tail -1 pytest-out.log  `
L
liuyq-617 已提交
103 104 105
        # if [[ $out_log =~ 'failed' ]];then
        #   exit 8
        # fi
S
Shuduo Sang 已提交
106
        echo execution time of $case was `expr $end_time - $start_time`s. | tee -a pytest-out.log
107 108 109
      else
        $line > /dev/null 2>&1
      fi
L
liuyq-617 已提交
110
      dohavecore 0
111 112 113
    fi
  done < $1
}
L
liuyq-617 已提交
114 115 116 117 118 119 120 121 122 123 124
function runPyCaseOneByOnefq {
  while read -r line; do
    if [[ $line =~ ^python.* ]]; then
      if [[ $line != *sleep* ]]; then
        
        if [[ $line =~ '-r' ]];then
          case=`echo $line|awk '{print $4}'`
        else
          case=`echo $line|awk '{print $NF}'`
        fi
        start_time=`date +%s`
L
liuyq-617 已提交
125
        echo -n $case
L
liuyq-617 已提交
126
        $line > /dev/null 2>&1 && \
L
liuyq-617 已提交
127 128
          echo -e "${GREEN} success${NC}" | tee -a pytest-out.log || \
          echo -e "${RED} failed${NC}" | tee -a pytest-out.log
L
liuyq-617 已提交
129 130 131
        end_time=`date +%s`
        out_log=`tail -1 pytest-out.log  `
        if [[ $out_log =~ 'failed' ]];then
L
liuyq-617 已提交
132
          cp -r ../../sim ~/sim_`date "+%Y_%m_%d_%H:%M:%S" `
L
liuyq-617 已提交
133 134 135 136 137 138
          exit 8
        fi
        echo execution time of $case was `expr $end_time - $start_time`s. | tee -a pytest-out.log
      else
        $line > /dev/null 2>&1
      fi
L
liuyq-617 已提交
139
      dohavecore 1
L
liuyq-617 已提交
140 141 142
    fi
  done < $1
}
143 144
totalFailed=0
totalPyFailed=0
sangshuduo's avatar
sangshuduo 已提交
145

S
Shuduo Sang 已提交
146
tests_dir=`pwd`
L
liuyq-617 已提交
147
corepath=`grep -oP '.*(?=core_)' /proc/sys/kernel/core_pattern||grep -oP '.*(?=core-)' /proc/sys/kernel/core_pattern`
148 149
if [ "$2" != "python" ]; then
  echo "### run TSIM test case ###"
S
Shuduo Sang 已提交
150
  cd $tests_dir/script
151

152 153 154 155 156 157
  [ -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 已提交
158
    runSimCaseOneByOne jenkins/basic.txt
L
liuyq-617 已提交
159 160 161
  elif [ "$1" == "b1" ]; then
    echo "### run TSIM b1 test ###"
    runSimCaseOneByOne jenkins/basic_1.txt
L
liuyq-617 已提交
162 163 164 165
    runSimCaseOneByOne jenkins/basic_4.txt
    runSimCaseOneByOne jenkins/basic_5.txt
    runSimCaseOneByOne jenkins/basic_6.txt
    runSimCaseOneByOne jenkins/basic_7.txt
L
liuyq-617 已提交
166 167 168 169 170 171
  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
L
liuyq-617 已提交
172 173 174 175 176 177 178 179 180
  elif [ "$1" == "b1fq" ]; then
    echo "### run TSIM b1 test ###"
    runSimCaseOneByOnefq jenkins/basic_1.txt
  elif [ "$1" == "b2fq" ]; then
    echo "### run TSIM b2 test ###"
    runSimCaseOneByOnefq jenkins/basic_2.txt
  elif [ "$1" == "b3fq" ]; then
    echo "### run TSIM b3 test ###"
    runSimCaseOneByOnefq jenkins/basic_3.txt
L
liuyq-617 已提交
181 182 183
  elif [ "$1" == "b4fq" ]; then
    echo "### run TSIM b4 test ###"
    runSimCaseOneByOnefq jenkins/basic_4.txt
L
liuyq-617 已提交
184 185 186 187 188 189 190 191 192
  elif [ "$1" == "b5fq" ]; then
    echo "### run TSIM b5 test ###"
    runSimCaseOneByOnefq jenkins/basic_5.txt
  elif [ "$1" == "b6fq" ]; then
    echo "### run TSIM b6 test ###"
    runSimCaseOneByOnefq jenkins/basic_6.txt
  elif [ "$1" == "b7fq" ]; then
    echo "### run TSIM b7 test ###"
    runSimCaseOneByOnefq jenkins/basic_7.txt
S
Shuduo Sang 已提交
193
  elif [ "$1" == "smoke" ] || [ -z "$1" ]; then
194 195 196
    echo "### run TSIM smoke test ###"
    runSimCaseOneByOne basicSuite.sim
  fi
197

198 199
  totalSuccess=`grep 'success' out.log | wc -l`
  totalBasic=`grep success out.log | grep Suite | wc -l`
200

201 202 203
  if [ "$totalSuccess" -gt "0" ]; then
    totalSuccess=`expr $totalSuccess - $totalBasic`
  fi
sangshuduo's avatar
sangshuduo 已提交
204

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

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

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

213 214
#  exit $totalFailed
  fi
sangshuduo's avatar
sangshuduo 已提交
215 216
fi

217 218
if [ "$2" != "sim" ]; then
  echo "### run Python test case ###"
219

S
Shuduo Sang 已提交
220
  cd $tests_dir
221 222
  IN_TDINTERNAL="community"

S
Shuduo Sang 已提交
223
  if [[ "$tests_dir" == *"$IN_TDINTERNAL"* ]]; then
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
    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 已提交
239
  cd $tests_dir/pytest
240 241 242 243 244 245 246 247 248

  [ -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 已提交
249
  elif [ "$1" == "pytest" ]; then
L
liuyq-617 已提交
250 251
    echo "### run Python full test ###"
    runPyCaseOneByOne fulltest.sh
L
liuyq-617 已提交
252 253 254
  elif [ "$1" == "pytestfq" ]; then
    echo "### run Python full test ###"
    runPyCaseOneByOnefq fulltest.sh
255 256
  elif [ "$1" == "p1" ]; then
    echo "### run Python_1 test ###"
L
liuyq-617 已提交
257
    runPyCaseOneByOnefq pytest_1.sh
258 259
  elif [ "$1" == "p2" ]; then
    echo "### run Python_2 test ###"
L
liuyq-617 已提交
260
    runPyCaseOneByOnefq pytest_2.sh
L
liuyq-617 已提交
261 262 263
  elif [ "$1" == "p3" ]; then
    echo "### run Python_3 test ###"
    runPyCaseOneByOnefq pytest_3.sh
L
liuyq-617 已提交
264 265
  elif [ "$1" == "b2" ] || [ "$1" == "b3" ]; then
    exit $(($totalFailed + $totalPyFailed))
S
Shuduo Sang 已提交
266
  elif [ "$1" == "smoke" ] || [ -z "$1" ]; then
267 268 269
    echo "### run Python smoke test ###"
    runPyCaseOneByOne smoketest.sh
  fi
270
  totalPySuccess=`grep 'success' pytest-out.log | wc -l`
271 272

  if [ "$totalPySuccess" -gt "0" ]; then
S
Shuduo Sang 已提交
273
    echo -e "\n${GREEN} ### Total $totalPySuccess python case(s) succeed! ### ${NC}"
274 275 276 277
  fi

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

283
exit $(($totalFailed + $totalPyFailed))