test-all.sh 12.4 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"

P
Ping Xiao 已提交
13 14
function stopTaosd {
	echo "Stop taosd"
P
Ping Xiao 已提交
15
  sudo systemctl stop taosd
P
Ping Xiao 已提交
16 17 18 19 20 21 22 23 24
  PID=`ps -ef|grep -w taosd | grep -v grep | awk '{print $2}'`
	while [ -n "$PID" ]
	do
    pkill -TERM -x taosd
    sleep 1
  	PID=`ps -ef|grep -w taosd | grep -v grep | awk '{print $2}'`
	done
}

L
liuyq-617 已提交
25 26
function dohavecore(){
  corefile=`find $corepath -mmin 1`  
27
  proc=`echo $corefile|cut -d "_" -f2`
L
liuyq-617 已提交
28
  if [ -n "$corefile" ];then
29 30 31 32 33 34
    echo 'taosd or taos has generated core'
    echo '\n'|gdb /usr/local/taos/bin/$proc $corepath/$corefile -ex "bt 10" -ex quit
    tar zcvf $corepath/taos_`date "+%Y_%m_%d_%H:%M:%S"`.tar.gz /usr/local/taos
    if [[ $1 == 1 ]];then
      exit 8
    fi
L
liuyq-617 已提交
35
  fi
36
}
37 38
function runSimCaseOneByOne {
  while read -r line; do
P
Ping Xiao 已提交
39
    if [[ $line =~ ^./test.sh* ]] || [[ $line =~ ^run* ]]; then
40
			case=`echo $line | grep sim$ |awk '{print $NF}'`    
P
Ping Xiao 已提交
41
      start_time=`date +%s`      
P
Ping Xiao 已提交
42
      date +%F\ %T | tee -a out.log
L
liuyq-617 已提交
43 44 45
      if [[ "$tests_dir" == *"$IN_TDINTERNAL"* ]]; then
        echo -n $case
        ./test.sh -f $case > /dev/null 2>&1 && \
L
liuyq-617 已提交
46
        ( 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 已提交
47 48 49 50 51
        ( 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 已提交
52
        ( 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 已提交
53 54 55
        ( 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 已提交
56
      out_log=`tail -1 out.log  `
L
liuyq-617 已提交
57 58 59
      # if [[ $out_log =~ 'failed' ]];then
      #   exit 8
      # fi
S
Shuduo Sang 已提交
60 61
      end_time=`date +%s`
      echo execution time of $case was `expr $end_time - $start_time`s. | tee -a out.log
L
liuyq-617 已提交
62
      dohavecore 0
63 64 65
    fi
  done < $1
}
L
liuyq-617 已提交
66 67 68 69 70
function runSimCaseOneByOnefq {
  while read -r line; do
    if [[ $line =~ ^./test.sh* ]] || [[ $line =~ ^run* ]]; then
			case=`echo $line | grep sim$ |awk '{print $NF}'`

71
      start_time=`date +%s`    
P
Ping Xiao 已提交
72
      date +%F\ %T | tee -a out.log
73
      if [[ "$tests_dir" == *"$IN_TDINTERNAL"* ]]; then
L
liuyq-617 已提交
74
        echo -n $case
75
        ./test.sh -f $case > /dev/null 2>&1 && \
L
liuyq-617 已提交
76
        ( 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 已提交
77 78
        ( 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
79
      else
L
liuyq-617 已提交
80
        echo -n $case
81
        ./test.sh -f $case > /dev/null 2>&1 && \
L
liuyq-617 已提交
82
        ( 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 已提交
83 84
        ( 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
85 86
      fi
      
L
liuyq-617 已提交
87 88
      out_log=`tail -1 out.log  `
      if [[ $out_log =~ 'failed' ]];then
89
        if [[ "$tests_dir" == *"$IN_TDINTERNAL"* ]]; then
L
liuyq-617 已提交
90
          cp -r ../../../sim ~/sim_`date "+%Y_%m_%d_%H:%M:%S"`
91
        else 
L
liuyq-617 已提交
92
          cp -r ../../sim ~/sim_`date "+%Y_%m_%d_%H:%M:%S" `
93
        fi
L
liuyq-617 已提交
94 95 96 97
        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 已提交
98
      dohavecore 1
L
liuyq-617 已提交
99 100 101
    fi
  done < $1
}
102 103 104 105

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

163 164
totalFailed=0
totalPyFailed=0
165
totalJDBCFailed=0
P
Ping Xiao 已提交
166
totalUnitFailed=0
sangshuduo's avatar
sangshuduo 已提交
167

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

173 174 175 176 177 178
  [ -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 已提交
179
    runSimCaseOneByOne jenkins/basic.txt
L
liuyq-617 已提交
180 181 182
  elif [ "$1" == "b1" ]; then
    echo "### run TSIM b1 test ###"
    runSimCaseOneByOne jenkins/basic_1.txt
L
liuyq-617 已提交
183 184 185 186
    runSimCaseOneByOne jenkins/basic_4.txt
    runSimCaseOneByOne jenkins/basic_5.txt
    runSimCaseOneByOne jenkins/basic_6.txt
    runSimCaseOneByOne jenkins/basic_7.txt
L
liuyq-617 已提交
187 188 189 190 191 192
  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 已提交
193 194 195 196 197 198 199 200 201
  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 已提交
202 203 204
  elif [ "$1" == "b4fq" ]; then
    echo "### run TSIM b4 test ###"
    runSimCaseOneByOnefq jenkins/basic_4.txt
L
liuyq-617 已提交
205 206 207 208 209 210 211 212 213
  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 已提交
214
  elif [ "$1" == "smoke" ] || [ -z "$1" ]; then
215 216 217
    echo "### run TSIM smoke test ###"
    runSimCaseOneByOne basicSuite.sim
  fi
218

219 220
  totalSuccess=`grep 'success' out.log | wc -l`
  totalBasic=`grep success out.log | grep Suite | wc -l`
221

222 223 224
  if [ "$totalSuccess" -gt "0" ]; then
    totalSuccess=`expr $totalSuccess - $totalBasic`
  fi
sangshuduo's avatar
sangshuduo 已提交
225

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

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

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

234 235
#  exit $totalFailed
  fi
sangshuduo's avatar
sangshuduo 已提交
236 237
fi

238
if [ "$2" != "sim" ] && [ "$2" != "jdbc" ] && [ "$2" != "unit" ]; then
239
  echo "### run Python test case ###"
240

S
Shuduo Sang 已提交
241
  cd $tests_dir
242

S
Shuduo Sang 已提交
243
  if [[ "$tests_dir" == *"$IN_TDINTERNAL"* ]]; then
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
    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 已提交
259
  cd $tests_dir/pytest
260 261 262 263 264 265 266 267 268

  [ -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 已提交
269
  elif [ "$1" == "pytest" ]; then
L
liuyq-617 已提交
270 271
    echo "### run Python full test ###"
    runPyCaseOneByOne fulltest.sh
L
liuyq-617 已提交
272 273 274
  elif [ "$1" == "pytestfq" ]; then
    echo "### run Python full test ###"
    runPyCaseOneByOnefq fulltest.sh
275 276
  elif [ "$1" == "p1" ]; then
    echo "### run Python_1 test ###"
L
liuyq-617 已提交
277
    runPyCaseOneByOnefq pytest_1.sh
278 279
  elif [ "$1" == "p2" ]; then
    echo "### run Python_2 test ###"
L
liuyq-617 已提交
280
    runPyCaseOneByOnefq pytest_2.sh
L
liuyq-617 已提交
281 282 283
  elif [ "$1" == "p3" ]; then
    echo "### run Python_3 test ###"
    runPyCaseOneByOnefq pytest_3.sh
L
liuyq-617 已提交
284 285 286
  elif [ "$1" == "p4" ]; then
    echo "### run Python_4 test ###"
    runPyCaseOneByOnefq pytest_4.sh
L
liuyq-617 已提交
287 288
  elif [ "$1" == "b2" ] || [ "$1" == "b3" ]; then
    exit $(($totalFailed + $totalPyFailed))
S
Shuduo Sang 已提交
289
  elif [ "$1" == "smoke" ] || [ -z "$1" ]; then
290 291 292
    echo "### run Python smoke test ###"
    runPyCaseOneByOne smoketest.sh
  fi
293
  totalPySuccess=`grep 'success' pytest-out.log | wc -l`
294 295

  if [ "$totalPySuccess" -gt "0" ]; then
S
Shuduo Sang 已提交
296
    echo -e "\n${GREEN} ### Total $totalPySuccess python case(s) succeed! ### ${NC}"
297 298 299 300
  fi

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

306

307 308
if [ "$2" != "sim" ] && [ "$2" != "python" ] && [ "$2" != "unit" ] && [ "$1" == "full" ]; then
  echo "### run JDBC test cases ###"
309

P
Ping Xiao 已提交
310
  cd $tests_dir
311 312 313 314 315 316 317

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

P
Ping Xiao 已提交
318
  pwd
319
  cd debug/
P
change  
Ping Xiao 已提交
320
  
P
Ping Xiao 已提交
321
  stopTaosd
322
  rm -rf /var/lib/taos/*
323 324
  nohup build/bin/taosd -c /etc/taos/ > /dev/null 2>&1 &
  sleep 30
P
change  
Ping Xiao 已提交
325
  
326
  cd $tests_dir/../src/connector/jdbc  
P
Ping Xiao 已提交
327
  
P
change  
Ping Xiao 已提交
328
  mvn test > jdbc-out.log 2>&1
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
  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

351 352 353 354 355 356 357 358 359 360 361 362 363 364
if [ "$2" != "sim" ] && [ "$2" != "python" ] && [ "$2" != "jdbc" ] && [ "$1" == "full" ]; then
  echo "### run Unit tests ###"  

  stopTaosd
  cd $tests_dir

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

  pwd
  cd debug/build/bin
365
  rm -rf /var/lib/taos/*
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
  nohup ./taosd -c /etc/taos/ > /dev/null 2>&1 &
  sleep 30
  
  pwd
  ./queryTest > unittest-out.log 2>&1
  tail -n 20 unittest-out.log

  totalUnitTests=`grep "Running" unittest-out.log | awk '{print $3}'`  
  totalUnitSuccess=`grep 'PASSED' unittest-out.log | awk '{print $4}'`
  totalUnitFailed=`expr $totalUnitTests - $totalUnitSuccess`

  if [ "$totalUnitSuccess" -gt "0" ]; then
    echo -e "\n${GREEN} ### Total $totalUnitSuccess Unit test succeed! ### ${NC}"
  fi
  
  if [ "$totalUnitFailed" -ne "0" ]; then
    echo -e "\n${RED} ### Total $totalUnitFailed Unit test failed! ### ${NC}"
  fi
  dohavecore 1
fi


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