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

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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
    if [[ "$tests_dir" == *"$IN_TDINTERNAL"* ]] && [[ $1 == 1 ]]; then
      cd ../../../
      tar -zcPf $corepath'taos_'`date "+%Y_%m_%d_%H_%M_%S"`.tar.gz debug/build/bin/taosd debug/build/bin/tsim debug/build/lib/libtaos*so*
      if [[ $2 == 1 ]];then
        cp -r sim ~/sim_`date "+%Y_%m_%d_%H:%M:%S"`
        rm -rf sim/case.log
      else
        cd community
        cp -r sim ~/sim_`date "+%Y_%m_%d_%H:%M:%S" `
        rm -rf sim/case.log
      fi
    else 
      cd ../../
      if [[ $1 == 1 ]];then 
        tar -zcPf $corepath'taos_'`date "+%Y_%m_%d_%H_%M_%S"`.tar.gz debug/build/bin/taosd debug/build/bin/tsim debug/build/lib/libtaos*so*
        cp -r sim ~/sim_`date "+%Y_%m_%d_%H:%M:%S" `
        rm -rf sim/case.log
      fi
    fi
51
    if [[ $1 == 1 ]];then
L
liuyq-617 已提交
52
      echo '\n'|gdb /usr/local/taos/bin/$proc $core_file -ex "bt 10" -ex quit
53 54
      exit 8
    fi
L
liuyq-617 已提交
55
  fi
56
}
L
liuyq-617 已提交
57

58 59
function runSimCaseOneByOne {
  while read -r line; do
P
Ping Xiao 已提交
60
    if [[ $line =~ ^./test.sh* ]] || [[ $line =~ ^run* ]]; then
61
			case=`echo $line | grep sim$ |awk '{print $NF}'`    
P
Ping Xiao 已提交
62
      start_time=`date +%s`      
P
Ping Xiao 已提交
63
      date +%F\ %T | tee -a out.log
L
liuyq-617 已提交
64 65 66
      if [[ "$tests_dir" == *"$IN_TDINTERNAL"* ]]; then
        echo -n $case
        ./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 70 71 72
        ( 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 已提交
73
        ( 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 已提交
74 75 76
        ( 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 已提交
77
      out_log=`tail -1 out.log  `
L
liuyq-617 已提交
78 79 80
      # if [[ $out_log =~ 'failed' ]];then
      #   exit 8
      # fi
S
Shuduo Sang 已提交
81 82
      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 0
84 85 86
    fi
  done < $1
}
L
liuyq-617 已提交
87
function runSimCaseOneByOnefq {
L
liuyq-617 已提交
88 89 90 91 92

  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 已提交
93 94 95
    if [[ $line =~ ^./test.sh* ]] || [[ $line =~ ^run* ]]; then
			case=`echo $line | grep sim$ |awk '{print $NF}'`

96
      start_time=`date +%s`    
P
Ping Xiao 已提交
97
      date +%F\ %T | tee -a out.log
98
      if [[ "$tests_dir" == *"$IN_TDINTERNAL"* ]]; then
L
liuyq-617 已提交
99
        echo -n $case
100
        ./test.sh -f $case > ../../../sim/case.log 2>&1 && \
L
liuyq-617 已提交
101
        ( 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 已提交
102
        ( grep -q 'script.*success.*m$' ../../../sim/tsim/log/taoslog0.0 && echo -e "${GREEN} success${NC}" | tee -a out.log )  || \
103
        ( echo -e "${RED} failed${NC}" | tee -a out.log && echo '=====================log=====================' && cat ../../../sim/case.log )
104
      else
L
liuyq-617 已提交
105
        echo -n $case
106
        ./test.sh -f $case > ../../sim/case.log 2>&1 && \
L
liuyq-617 已提交
107
        ( 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 已提交
108
        ( grep -q 'script.*success.*m$' ../../sim/tsim/log/taoslog0.0 && echo -e "${GREEN} success${NC}" | tee -a out.log )  || \
109
        ( echo -e "${RED} failed${NC}" | tee -a out.log && echo '=====================log=====================' &&  cat ../../sim/case.log )
110 111
      fi
      
L
liuyq-617 已提交
112 113
      out_log=`tail -1 out.log  `
      if [[ $out_log =~ 'failed' ]];then
114
        if [[ "$tests_dir" == *"$IN_TDINTERNAL"* ]]; then
L
liuyq-617 已提交
115
          cp -r ../../../sim ~/sim_`date "+%Y_%m_%d_%H:%M:%S"`
116
          rm -rf ../../../sim/case.log
117
        else 
L
liuyq-617 已提交
118
          cp -r ../../sim ~/sim_`date "+%Y_%m_%d_%H:%M:%S" `
119
          rm -rf ../../sim/case.log
120
        fi
L
liuyq-617 已提交
121
        dohavecore $2 1
L
fix  
liuyq-617 已提交
122 123 124
        if [[ $2 == 1 ]];then
          exit 8
        fi
L
liuyq-617 已提交
125 126 127
      fi
      end_time=`date +%s`
      echo execution time of $case was `expr $end_time - $start_time`s. | tee -a out.log
L
liuyq-617 已提交
128
      dohavecore $2 1
L
liuyq-617 已提交
129
    fi
L
liuyq-617 已提交
130
  done 
131 132
  rm -rf ../../../sim/case.log
  rm -rf ../../sim/case.log
L
liuyq-617 已提交
133
}
134 135 136 137

function runPyCaseOneByOne {
  while read -r line; do
    if [[ $line =~ ^python.* ]]; then
138
      if [[ $line != *sleep* ]]; then
L
liuyq-617 已提交
139 140 141 142 143 144
        
        if [[ $line =~ '-r' ]];then
          case=`echo $line|awk '{print $4}'`
        else
          case=`echo $line|awk '{print $NF}'`
        fi
S
Shuduo Sang 已提交
145
        start_time=`date +%s`
P
Ping Xiao 已提交
146
        date +%F\ %T | tee -a pytest-out.log
L
liuyq-617 已提交
147
        echo -n $case
148
        $line > /dev/null 2>&1 && \
L
liuyq-617 已提交
149 150
          echo -e "${GREEN} success${NC}" | tee -a pytest-out.log || \
          echo -e "${RED} failed${NC}" | tee -a pytest-out.log
S
Shuduo Sang 已提交
151
        end_time=`date +%s`
L
liuyq-617 已提交
152
        out_log=`tail -1 pytest-out.log  `
L
liuyq-617 已提交
153 154 155
        # if [[ $out_log =~ 'failed' ]];then
        #   exit 8
        # fi
S
Shuduo Sang 已提交
156
        echo execution time of $case was `expr $end_time - $start_time`s. | tee -a pytest-out.log
157 158 159
      else
        $line > /dev/null 2>&1
      fi
L
liuyq-617 已提交
160
      dohavecore 0
161 162 163
    fi
  done < $1
}
L
liuyq-617 已提交
164 165 166 167 168 169 170 171 172 173 174
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 已提交
175 176 177 178 179 180 181 182 183
    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 已提交
184
        date +%F\ %T | tee -a pytest-out.log
L
liuyq-617 已提交
185
        echo -n $case
186
        $line > ../../sim/case.log 2>&1 && \
L
liuyq-617 已提交
187
          echo -e "${GREEN} success${NC}" | tee -a pytest-out.log || \
188
          echo -e "${RED} failed${NC}" | tee -a pytest-out.log 
L
liuyq-617 已提交
189 190 191
        end_time=`date +%s`
        out_log=`tail -1 pytest-out.log  `
        if [[ $out_log =~ 'failed' ]];then
L
liuyq-617 已提交
192
          cp -r ../../sim ~/sim_`date "+%Y_%m_%d_%H:%M:%S" `
L
fix  
liuyq-617 已提交
193
          echo '=====================log===================== '
194 195
          cat ../../sim/case.log
          rm -rf ../../sim/case.log
L
liuyq-617 已提交
196
          dohavecore $2 2
L
fix  
liuyq-617 已提交
197 198 199
          if [[ $2 == 1 ]];then
            exit 8
          fi
L
liuyq-617 已提交
200 201 202 203 204
        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 已提交
205
      dohavecore $2 2
L
liuyq-617 已提交
206
    fi
L
liuyq-617 已提交
207
  done 
208
  rm -rf ../../sim/case.log
L
liuyq-617 已提交
209
}
210

211 212
totalFailed=0
totalPyFailed=0
213
totalJDBCFailed=0
P
Ping Xiao 已提交
214
totalUnitFailed=0
215
totalExampleFailed=0
sangshuduo's avatar
sangshuduo 已提交
216

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

222 223 224 225 226 227
  [ -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 已提交
228
    runSimCaseOneByOne jenkins/basic.txt
L
liuyq-617 已提交
229 230
  elif [ "$1" == "b1" ]; then
    echo "### run TSIM b1 test ###"
L
liuyq-617 已提交
231 232 233
    runSimCaseOneByOnefq b1 0
    runSimCaseOneByOnefq b4 0
    runSimCaseOneByOnefq b7 0
L
liuyq-617 已提交
234 235
  elif [ "$1" == "b2" ]; then
    echo "### run TSIM b2 test ###"
L
liuyq-617 已提交
236
    runSimCaseOneByOnefq b2 0
L
balance  
liuyq-617 已提交
237
    runSimCaseOneByOnefq b5 0
L
liuyq-617 已提交
238 239
  elif [ "$1" == "b3" ]; then
    echo "### run TSIM b3 test ###"
L
liuyq-617 已提交
240
    runSimCaseOneByOnefq b3 0
L
balance  
liuyq-617 已提交
241
    runSimCaseOneByOnefq b6 0
L
liuyq-617 已提交
242 243
  elif [ "$1" == "b1fq" ]; then
    echo "### run TSIM b1 test ###"
L
liuyq-617 已提交
244
    runSimCaseOneByOnefq b1 1
L
liuyq-617 已提交
245 246
  elif [ "$1" == "b2fq" ]; then
    echo "### run TSIM b2 test ###"
L
liuyq-617 已提交
247
    runSimCaseOneByOnefq b2 1
L
liuyq-617 已提交
248 249
  elif [ "$1" == "b3fq" ]; then
    echo "### run TSIM b3 test ###"
L
liuyq-617 已提交
250
    runSimCaseOneByOnefq b3 1
L
liuyq-617 已提交
251 252
  elif [ "$1" == "b4fq" ]; then
    echo "### run TSIM b4 test ###"
L
liuyq-617 已提交
253
    runSimCaseOneByOnefq b4 1
L
liuyq-617 已提交
254 255
  elif [ "$1" == "b5fq" ]; then
    echo "### run TSIM b5 test ###"
L
liuyq-617 已提交
256
    runSimCaseOneByOnefq b5 1
L
liuyq-617 已提交
257 258
  elif [ "$1" == "b6fq" ]; then
    echo "### run TSIM b6 test ###"
L
liuyq-617 已提交
259
    runSimCaseOneByOnefq b6 1
L
liuyq-617 已提交
260 261
  elif [ "$1" == "b7fq" ]; then
    echo "### run TSIM b7 test ###"
L
liuyq-617 已提交
262
    runSimCaseOneByOnefq b7 1
S
Shuduo Sang 已提交
263
  elif [ "$1" == "smoke" ] || [ -z "$1" ]; then
264 265 266
    echo "### run TSIM smoke test ###"
    runSimCaseOneByOne basicSuite.sim
  fi
267

268 269
  totalSuccess=`grep 'success' out.log | wc -l`
  totalBasic=`grep success out.log | grep Suite | wc -l`
270

271 272 273
  if [ "$totalSuccess" -gt "0" ]; then
    totalSuccess=`expr $totalSuccess - $totalBasic`
  fi
sangshuduo's avatar
sangshuduo 已提交
274

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

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

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

283 284
#  exit $totalFailed
  fi
sangshuduo's avatar
sangshuduo 已提交
285 286
fi

287
if [ "$2" != "sim" ] && [ "$2" != "jdbc" ] && [ "$2" != "unit" ]  && [ "$2" != "example" ]; then
288
  echo "### run Python test case ###"
289

S
Shuduo Sang 已提交
290
  cd $tests_dir
291

S
Shuduo Sang 已提交
292
  if [[ "$tests_dir" == *"$IN_TDINTERNAL"* ]]; then
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
    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 已提交
308
  cd $tests_dir/pytest
309 310 311 312 313 314 315 316 317

  [ -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 已提交
318
  elif [ "$1" == "pytest" ]; then
L
liuyq-617 已提交
319 320
    echo "### run Python full test ###"
    runPyCaseOneByOne fulltest.sh
L
liuyq-617 已提交
321 322
  elif [ "$1" == "pytestfq" ]; then
    echo "### run Python full test ###"
L
liuyq-617 已提交
323
    runPyCaseOneByOnefq full 0
324 325
  elif [ "$1" == "p1" ]; then
    echo "### run Python_1 test ###"
L
liuyq-617 已提交
326
    runPyCaseOneByOnefq p1 1
327 328
  elif [ "$1" == "p2" ]; then
    echo "### run Python_2 test ###"
L
liuyq-617 已提交
329
    runPyCaseOneByOnefq p2 1
L
liuyq-617 已提交
330 331
  elif [ "$1" == "p3" ]; then
    echo "### run Python_3 test ###"
L
liuyq-617 已提交
332
    runPyCaseOneByOnefq p3 1 
L
liuyq-617 已提交
333 334
  elif [ "$1" == "p4" ]; then
    echo "### run Python_4 test ###"
L
liuyq-617 已提交
335
    runPyCaseOneByOnefq p4 1
L
liuyq-617 已提交
336 337
  elif [ "$1" == "b2" ] || [ "$1" == "b3" ]; then
    exit $(($totalFailed + $totalPyFailed))
S
Shuduo Sang 已提交
338
  elif [ "$1" == "smoke" ] || [ -z "$1" ]; then
339 340 341
    echo "### run Python smoke test ###"
    runPyCaseOneByOne smoketest.sh
  fi
342
  totalPySuccess=`grep 'success' pytest-out.log | wc -l`
343 344

  if [ "$totalPySuccess" -gt "0" ]; then
S
Shuduo Sang 已提交
345
    echo -e "\n${GREEN} ### Total $totalPySuccess python case(s) succeed! ### ${NC}"
346 347 348 349
  fi

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

355

356
if [ "$2" != "sim" ] && [ "$2" != "python" ] && [ "$2" != "unit" ]  && [ "$2" != "example" ] && [ "$1" == "full" ]; then
357
  echo "### run JDBC test cases ###"
358

P
Ping Xiao 已提交
359
  cd $tests_dir
360 361 362 363 364 365 366

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

P
Ping Xiao 已提交
367
  pwd
368
  cd debug/
P
change  
Ping Xiao 已提交
369
  
P
Ping Xiao 已提交
370
  stopTaosd
371
  rm -rf /var/lib/taos/*
372 373
  nohup build/bin/taosd -c /etc/taos/ > /dev/null 2>&1 &
  sleep 30
P
change  
Ping Xiao 已提交
374
  
375
  cd $tests_dir/../src/connector/jdbc  
P
Ping Xiao 已提交
376
  
P
change  
Ping Xiao 已提交
377
  mvn test > jdbc-out.log 2>&1
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399
  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

400
if [ "$2" != "sim" ] && [ "$2" != "python" ] && [ "$2" != "jdbc" ]  && [ "$2" != "example" ]  && [ "$1" == "full" ]; then
401 402 403 404 405 406 407 408 409 410 411 412 413
  echo "### run Unit tests ###"  

  stopTaosd
  cd $tests_dir

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

  pwd
  cd debug/build/bin
414
  rm -rf /var/lib/taos/*
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
  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

436 437
if [ "$2" != "sim" ] && [ "$2" != "python" ] && [ "$2" != "jdbc" ] && [ "$2" != "unit" ] && [ "$1" == "full" ]; then
  echo "### run Example tests ###"  
438

439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
  stopTaosd
  cd $tests_dir

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

  pwd
  cd debug/build/bin
  rm -rf /var/lib/taos/*
  nohup ./taosd -c /etc/taos/ > /dev/null 2>&1 &
  echo "sleeping for 30 seconds"
  #sleep 30
  
  cd $tests_dir
  echo "current dir: "
  pwd
  cd examples/c
  echo "building applications"
  make > /dev/null
  totalExamplePass=0

  echo "Running tests"
  ./apitest > /dev/null 2>&1
  if [ $? != "0" ]; then
P
Ping Xiao 已提交
466
    echo "apitest failed"
467 468
    totalExampleFailed=`expr $totalExampleFailed + 1`    
  else
P
Ping Xiao 已提交
469
    echo "apitest pass"
470 471 472 473 474 475 476 477 478 479 480 481 482 483
    totalExamplePass=`expr $totalExamplePass + 1`
  fi 

  ./prepare 127.0.0.1 > /dev/null 2>&1
  if [ $? != "0" ]; then
    echo "prepare failed"
    totalExampleFailed=`expr $totalExampleFailed + 1`    
  else
    echo "prepare pass"
    totalExamplePass=`expr $totalExamplePass + 1`
  fi

  ./subscribe -test > /dev/null 2>&1
  if [ $? != "0" ]; then
P
Ping Xiao 已提交
484
    echo "subscribe failed"
485 486
    totalExampleFailed=`expr $totalExampleFailed + 1`    
  else
P
Ping Xiao 已提交
487
    echo "subscribe pass"
488 489 490 491 492
    totalExamplePass=`expr $totalExamplePass + 1`
  fi

  yes |./asyncdemo 127.0.0.1 test 1000 10 > /dev/null 2>&1
  if [ $? != "0" ]; then
P
Ping Xiao 已提交
493
    echo "asyncdemo failed"
494 495
    totalExampleFailed=`expr $totalExampleFailed + 1`    
  else
P
Ping Xiao 已提交
496
    echo "asyncdemo pass"
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512
    totalExamplePass=`expr $totalExamplePass + 1`
  fi
  
  if [ "$totalExamplePass" -gt "0" ]; then
    echo -e "\n${GREEN} ### Total $totalExamplePass examples succeed! ### ${NC}"
  fi
  
  if [ "$totalExampleFailed" -ne "0" ]; then
    echo -e "\n${RED} ### Total $totalExampleFailed examples failed! ### ${NC}"
  fi

  dohavecore 1
fi


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