test-all.sh 10.9 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
tests_dir=`pwd`
IN_TDINTERNAL="community"

L
liuyq-617 已提交
13 14 15 16 17 18 19 20
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
21
}
22 23
function runSimCaseOneByOne {
  while read -r line; do
P
Ping Xiao 已提交
24
    if [[ $line =~ ^./test.sh* ]] || [[ $line =~ ^run* ]]; then
25
			case=`echo $line | grep sim$ |awk '{print $NF}'`    
P
Ping Xiao 已提交
26
      start_time=`date +%s`      
P
Ping Xiao 已提交
27
      date +%F\ %T | tee -a out.log
L
liuyq-617 已提交
28 29 30
      if [[ "$tests_dir" == *"$IN_TDINTERNAL"* ]]; then
        echo -n $case
        ./test.sh -f $case > /dev/null 2>&1 && \
L
liuyq-617 已提交
31
        ( 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 已提交
32 33 34 35 36
        ( 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 已提交
37
        ( 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 已提交
38 39 40
        ( 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 已提交
41
      out_log=`tail -1 out.log  `
L
liuyq-617 已提交
42 43 44
      # if [[ $out_log =~ 'failed' ]];then
      #   exit 8
      # fi
S
Shuduo Sang 已提交
45 46
      end_time=`date +%s`
      echo execution time of $case was `expr $end_time - $start_time`s. | tee -a out.log
L
liuyq-617 已提交
47
      dohavecore 0
48 49 50
    fi
  done < $1
}
L
liuyq-617 已提交
51 52 53 54 55
function runSimCaseOneByOnefq {
  while read -r line; do
    if [[ $line =~ ^./test.sh* ]] || [[ $line =~ ^run* ]]; then
			case=`echo $line | grep sim$ |awk '{print $NF}'`

56
      start_time=`date +%s`    
P
Ping Xiao 已提交
57
      date +%F\ %T | tee -a out.log
58
      if [[ "$tests_dir" == *"$IN_TDINTERNAL"* ]]; then
L
liuyq-617 已提交
59
        echo -n $case
60
        ./test.sh -f $case > /dev/null 2>&1 && \
L
liuyq-617 已提交
61
        ( 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 已提交
62 63
        ( 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
64
      else
L
liuyq-617 已提交
65
        echo -n $case
66
        ./test.sh -f $case > /dev/null 2>&1 && \
L
liuyq-617 已提交
67
        ( 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 已提交
68 69
        ( 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
70 71
      fi
      
L
liuyq-617 已提交
72 73
      out_log=`tail -1 out.log  `
      if [[ $out_log =~ 'failed' ]];then
74
        if [[ "$tests_dir" == *"$IN_TDINTERNAL"* ]]; then
L
liuyq-617 已提交
75
          cp -r ../../../sim ~/sim_`date "+%Y_%m_%d_%H:%M:%S"`
76
        else 
L
liuyq-617 已提交
77
          cp -r ../../sim ~/sim_`date "+%Y_%m_%d_%H:%M:%S" `
78
        fi
L
liuyq-617 已提交
79 80 81 82
        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 已提交
83
      dohavecore 1
L
liuyq-617 已提交
84 85 86
    fi
  done < $1
}
87 88 89 90

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

148 149
totalFailed=0
totalPyFailed=0
150
totalJDBCFailed=0
sangshuduo's avatar
sangshuduo 已提交
151

L
liuyq-617 已提交
152
corepath=`grep -oP '.*(?=core_)' /proc/sys/kernel/core_pattern||grep -oP '.*(?=core-)' /proc/sys/kernel/core_pattern`
153
if [ "$2" != "jdbc" ] && [ "$2" != "python" ]; then
154
  echo "### run TSIM test case ###"
S
Shuduo Sang 已提交
155
  cd $tests_dir/script
156

157 158 159 160 161 162
  [ -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 已提交
163
    runSimCaseOneByOne jenkins/basic.txt
L
liuyq-617 已提交
164 165 166
  elif [ "$1" == "b1" ]; then
    echo "### run TSIM b1 test ###"
    runSimCaseOneByOne jenkins/basic_1.txt
L
liuyq-617 已提交
167 168 169 170
    runSimCaseOneByOne jenkins/basic_4.txt
    runSimCaseOneByOne jenkins/basic_5.txt
    runSimCaseOneByOne jenkins/basic_6.txt
    runSimCaseOneByOne jenkins/basic_7.txt
L
liuyq-617 已提交
171 172 173 174 175 176
  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 已提交
177 178 179 180 181 182 183 184 185
  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 已提交
186 187 188
  elif [ "$1" == "b4fq" ]; then
    echo "### run TSIM b4 test ###"
    runSimCaseOneByOnefq jenkins/basic_4.txt
L
liuyq-617 已提交
189 190 191 192 193 194 195 196 197
  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 已提交
198
  elif [ "$1" == "smoke" ] || [ -z "$1" ]; then
199 200 201
    echo "### run TSIM smoke test ###"
    runSimCaseOneByOne basicSuite.sim
  fi
202

203 204
  totalSuccess=`grep 'success' out.log | wc -l`
  totalBasic=`grep success out.log | grep Suite | wc -l`
205

206 207 208
  if [ "$totalSuccess" -gt "0" ]; then
    totalSuccess=`expr $totalSuccess - $totalBasic`
  fi
sangshuduo's avatar
sangshuduo 已提交
209

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

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

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

218 219
#  exit $totalFailed
  fi
sangshuduo's avatar
sangshuduo 已提交
220 221
fi

222
if [ "$2" != "sim" ] && [ "$2" != "jdbc" ] ; then
223
  echo "### run Python test case ###"
224

S
Shuduo Sang 已提交
225
  cd $tests_dir
226

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

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

  if [ "$totalPySuccess" -gt "0" ]; then
S
Shuduo Sang 已提交
280
    echo -e "\n${GREEN} ### Total $totalPySuccess python case(s) succeed! ### ${NC}"
281 282 283 284
  fi

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

290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331

if [ "$2" != "sim" ] && [ "$2" != "python" ]; then
  echo "### run JDBC test case ###"  

  echo $tests_dir

  if [[ "$tests_dir" == *"$IN_TDINTERNAL"* ]]; then
    cd ../../
  else
    cd ../
  fi

  cd debug/
  nohup build/bin/taosd -c /etc/taos/ > /dev/null 2>&1 &
  sleep 30

  cd $tests_dir/../src/connector/jdbc
    
  mvn test > jdbc-out.log 2>&1
  tail -n 20 jdbc-out.log

  cases=`grep 'Tests run' jdbc-out.log | awk 'END{print $3}'`
  totalJDBCCases=`echo ${cases/%,}`
  failed=`grep 'Tests run' jdbc-out.log | awk 'END{print $5}'`
  JDBCFailed=`echo ${failed/%,}`
  error=`grep 'Tests run' jdbc-out.log | awk 'END{print $7}'`
  JDBCError=`echo ${error/%,}`
  
  totalJDBCFailed=`expr $JDBCFailed + $JDBCError`
  totalJDBCSuccess=`expr $totalJDBCCases - $totalJDBCFailed`

  if [ "$totalJDBCSuccess" -gt "0" ]; then
    echo -e "\n${GREEN} ### Total $totalJDBCSuccess JDBC case(s) succeed! ### ${NC}"
  fi
  
  if [ "$totalJDBCFailed" -ne "0" ]; then
    echo -e "\n${RED} ### Total $totalJDBCFailed JDBC case(s) failed! ### ${NC}"
  fi
  dohavecore 1
fi

exit $(($totalFailed + $totalPyFailed + $totalJDBCFailed))