test-all.sh 12.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
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`  
L
liuyq-617 已提交
27 28
  core_file=`echo $corefile|cut -d " " -f2`
  echo $core_file
L
liuyq-617 已提交
29
  proc=`echo $corefile|cut -d "_" -f3`
L
liuyq-617 已提交
30
  if [ -n "$corefile" ];then
31
    echo 'taosd or taos has generated core'
L
liuyq-617 已提交
32
    tar -zcPf $corepath'taos_'`date "+%Y_%m_%d_%H_%M_%S"`.tar.gz 
33
    if [[ $1 == 1 ]];then
L
liuyq-617 已提交
34
      echo '\n'|gdb /usr/local/taos/bin/$proc $core_file -ex "bt 10" -ex quit
35 36
      exit 8
    fi
L
liuyq-617 已提交
37
  fi
38
}
L
liuyq-617 已提交
39

40 41
function runSimCaseOneByOne {
  while read -r line; do
P
Ping Xiao 已提交
42
    if [[ $line =~ ^./test.sh* ]] || [[ $line =~ ^run* ]]; then
43
			case=`echo $line | grep sim$ |awk '{print $NF}'`    
P
Ping Xiao 已提交
44
      start_time=`date +%s`      
P
Ping Xiao 已提交
45
      date +%F\ %T | tee -a out.log
L
liuyq-617 已提交
46 47 48
      if [[ "$tests_dir" == *"$IN_TDINTERNAL"* ]]; then
        echo -n $case
        ./test.sh -f $case > /dev/null 2>&1 && \
L
liuyq-617 已提交
49
        ( 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 已提交
50 51 52 53 54
        ( 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 已提交
55
        ( 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 已提交
56 57 58
        ( 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 已提交
59
      out_log=`tail -1 out.log  `
L
liuyq-617 已提交
60 61 62
      # if [[ $out_log =~ 'failed' ]];then
      #   exit 8
      # fi
S
Shuduo Sang 已提交
63 64
      end_time=`date +%s`
      echo execution time of $case was `expr $end_time - $start_time`s. | tee -a out.log
L
liuyq-617 已提交
65
      dohavecore 0
66 67 68
    fi
  done < $1
}
L
liuyq-617 已提交
69
function runSimCaseOneByOnefq {
L
liuyq-617 已提交
70 71 72 73 74

  start=`sed -n "/$1-start/=" jenkins/basic.txt`
  end=`sed -n "/$1-end/=" jenkins/basic.txt`  
  for ((i=$start;i<=$end;i++)) ; do
    line=`sed -n "$i"p jenkins/basic.txt`
L
liuyq-617 已提交
75 76 77
    if [[ $line =~ ^./test.sh* ]] || [[ $line =~ ^run* ]]; then
			case=`echo $line | grep sim$ |awk '{print $NF}'`

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

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

179 180
totalFailed=0
totalPyFailed=0
181
totalJDBCFailed=0
P
Ping Xiao 已提交
182
totalUnitFailed=0
sangshuduo's avatar
sangshuduo 已提交
183

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

189 190 191 192 193 194
  [ -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 已提交
195
    runSimCaseOneByOne jenkins/basic.txt
L
liuyq-617 已提交
196 197
  elif [ "$1" == "b1" ]; then
    echo "### run TSIM b1 test ###"
L
liuyq-617 已提交
198 199 200 201 202
    runSimCaseOneByOnefq b1 0
    runSimCaseOneByOnefq b4 0
    runSimCaseOneByOnefq b5 0
    runSimCaseOneByOnefq b6 0
    runSimCaseOneByOnefq b7 0
L
liuyq-617 已提交
203 204
  elif [ "$1" == "b2" ]; then
    echo "### run TSIM b2 test ###"
L
liuyq-617 已提交
205
    runSimCaseOneByOnefq b2 0
L
liuyq-617 已提交
206 207
  elif [ "$1" == "b3" ]; then
    echo "### run TSIM b3 test ###"
L
liuyq-617 已提交
208
    runSimCaseOneByOnefq b3 0
L
liuyq-617 已提交
209 210
  elif [ "$1" == "b1fq" ]; then
    echo "### run TSIM b1 test ###"
L
liuyq-617 已提交
211
    runSimCaseOneByOnefq b1 1
L
liuyq-617 已提交
212 213
  elif [ "$1" == "b2fq" ]; then
    echo "### run TSIM b2 test ###"
L
liuyq-617 已提交
214
    runSimCaseOneByOnefq b2 1
L
liuyq-617 已提交
215 216
  elif [ "$1" == "b3fq" ]; then
    echo "### run TSIM b3 test ###"
L
liuyq-617 已提交
217
    runSimCaseOneByOnefq b3 1
L
liuyq-617 已提交
218 219
  elif [ "$1" == "b4fq" ]; then
    echo "### run TSIM b4 test ###"
L
liuyq-617 已提交
220
    runSimCaseOneByOnefq b4 1
L
liuyq-617 已提交
221 222
  elif [ "$1" == "b5fq" ]; then
    echo "### run TSIM b5 test ###"
L
liuyq-617 已提交
223
    runSimCaseOneByOnefq b5 1
L
liuyq-617 已提交
224 225
  elif [ "$1" == "b6fq" ]; then
    echo "### run TSIM b6 test ###"
L
liuyq-617 已提交
226
    runSimCaseOneByOnefq b6 1
L
liuyq-617 已提交
227 228
  elif [ "$1" == "b7fq" ]; then
    echo "### run TSIM b7 test ###"
L
liuyq-617 已提交
229
    runSimCaseOneByOnefq b7 1
S
Shuduo Sang 已提交
230
  elif [ "$1" == "smoke" ] || [ -z "$1" ]; then
231 232 233
    echo "### run TSIM smoke test ###"
    runSimCaseOneByOne basicSuite.sim
  fi
234

235 236
  totalSuccess=`grep 'success' out.log | wc -l`
  totalBasic=`grep success out.log | grep Suite | wc -l`
237

238 239 240
  if [ "$totalSuccess" -gt "0" ]; then
    totalSuccess=`expr $totalSuccess - $totalBasic`
  fi
sangshuduo's avatar
sangshuduo 已提交
241

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

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

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

250 251
#  exit $totalFailed
  fi
sangshuduo's avatar
sangshuduo 已提交
252 253
fi

254
if [ "$2" != "sim" ] && [ "$2" != "jdbc" ] && [ "$2" != "unit" ]; then
255
  echo "### run Python test case ###"
256

S
Shuduo Sang 已提交
257
  cd $tests_dir
258

S
Shuduo Sang 已提交
259
  if [[ "$tests_dir" == *"$IN_TDINTERNAL"* ]]; then
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
    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 已提交
275
  cd $tests_dir/pytest
276 277 278 279 280 281 282 283 284

  [ -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 已提交
285
  elif [ "$1" == "pytest" ]; then
L
liuyq-617 已提交
286 287
    echo "### run Python full test ###"
    runPyCaseOneByOne fulltest.sh
L
liuyq-617 已提交
288 289
  elif [ "$1" == "pytestfq" ]; then
    echo "### run Python full test ###"
L
liuyq-617 已提交
290
    runPyCaseOneByOnefq full 0
291 292
  elif [ "$1" == "p1" ]; then
    echo "### run Python_1 test ###"
L
liuyq-617 已提交
293
    runPyCaseOneByOnefq p1 1
294 295
  elif [ "$1" == "p2" ]; then
    echo "### run Python_2 test ###"
L
liuyq-617 已提交
296
    runPyCaseOneByOnefq p2 1
L
liuyq-617 已提交
297 298
  elif [ "$1" == "p3" ]; then
    echo "### run Python_3 test ###"
L
liuyq-617 已提交
299
    runPyCaseOneByOnefq p3 1 
L
liuyq-617 已提交
300 301
  elif [ "$1" == "p4" ]; then
    echo "### run Python_4 test ###"
L
liuyq-617 已提交
302
    runPyCaseOneByOnefq p4 1
L
liuyq-617 已提交
303 304
  elif [ "$1" == "b2" ] || [ "$1" == "b3" ]; then
    exit $(($totalFailed + $totalPyFailed))
S
Shuduo Sang 已提交
305
  elif [ "$1" == "smoke" ] || [ -z "$1" ]; then
306 307 308
    echo "### run Python smoke test ###"
    runPyCaseOneByOne smoketest.sh
  fi
309
  totalPySuccess=`grep 'success' pytest-out.log | wc -l`
310 311

  if [ "$totalPySuccess" -gt "0" ]; then
S
Shuduo Sang 已提交
312
    echo -e "\n${GREEN} ### Total $totalPySuccess python case(s) succeed! ### ${NC}"
313 314 315 316
  fi

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

322

323 324
if [ "$2" != "sim" ] && [ "$2" != "python" ] && [ "$2" != "unit" ] && [ "$1" == "full" ]; then
  echo "### run JDBC test cases ###"
325

P
Ping Xiao 已提交
326
  cd $tests_dir
327 328 329 330 331 332 333

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

P
Ping Xiao 已提交
334
  pwd
335
  cd debug/
P
change  
Ping Xiao 已提交
336
  
P
Ping Xiao 已提交
337
  stopTaosd
338
  rm -rf /var/lib/taos/*
339 340
  nohup build/bin/taosd -c /etc/taos/ > /dev/null 2>&1 &
  sleep 30
P
change  
Ping Xiao 已提交
341
  
342
  cd $tests_dir/../src/connector/jdbc  
P
Ping Xiao 已提交
343
  
P
change  
Ping Xiao 已提交
344
  mvn test > jdbc-out.log 2>&1
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
  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

367 368 369 370 371 372 373 374 375 376 377 378 379 380
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
381
  rm -rf /var/lib/taos/*
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
  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))