test-all.sh 7.7 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'
9 10 11 12 13 14 15 16 17 18
function git_branch {
   branch="`git branch 2>/dev/null | grep "^\*" | sed -e "s/^\*\ //"`"
   if [ "${branch}" != "" ];then
       if [ "${branch}" = "(no branch)" ];then
           branch="(`git rev-parse --short HEAD`...)"
       fi  
       branch=(${branch////_})
       echo "$branch"
   fi  
}
19 20
function runSimCaseOneByOne {
  while read -r line; do
P
Ping Xiao 已提交
21
    if [[ $line =~ ^./test.sh* ]] || [[ $line =~ ^run* ]]; then
P
Ping Xiao 已提交
22 23
			case=`echo $line | grep sim$ |awk '{print $NF}'`

S
Shuduo Sang 已提交
24
      start_time=`date +%s`
25
      ./test.sh -f $case > /dev/null 2>&1 && \
S
Shuduo Sang 已提交
26
        echo -e "${GREEN}$case success${NC}" | tee -a out.log || \
27
        echo -e "${RED}$case failed${NC}" | tee -a out.log
L
liuyq-617 已提交
28
      out_log=`tail -1 out.log  `
L
liuyq-617 已提交
29 30 31
      # if [[ $out_log =~ 'failed' ]];then
      #   exit 8
      # fi
S
Shuduo Sang 已提交
32 33
      end_time=`date +%s`
      echo execution time of $case was `expr $end_time - $start_time`s. | tee -a out.log
34 35 36
    fi
  done < $1
}
L
liuyq-617 已提交
37 38 39 40 41 42
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`
43 44 45
      IN_TDINTERNAL="community"
      if [[ "$tests_dir" == *"$IN_TDINTERNAL"* ]]; then
        ./test.sh -f $case > /dev/null 2>&1 && \
L
liuyq-617 已提交
46
        echo -e "${GREEN}$case success${NC}" | tee -a out.log || \
L
liuyq-617 已提交
47
        ( grep 'script.*success.*m$' ../../../sim/tsim/log/taoslog0.0 && echo -e "${GREEN}$case success${NC}" | tee -a out.log ) || echo -e "${RED}$case failed${NC}" | tee -a out.log
48 49 50 51 52 53
      else
        ./test.sh -f $case > /dev/null 2>&1 && \
        echo -e "${GREEN}$case success${NC}" | tee -a out.log || \
        ( grep 'script.*success.*m$' ../../sim/tsim/log/taoslog0.0 && echo -e "${GREEN}$case success${NC}" | tee -a out.log ) || echo -e "${RED}$case failed${NC}" | tee -a out.log
      fi
      
L
liuyq-617 已提交
54 55
      out_log=`tail -1 out.log  `
      if [[ $out_log =~ 'failed' ]];then
56 57 58 59 60
        if [[ "$tests_dir" == *"$IN_TDINTERNAL"* ]]; then
          cp -r ../../../sim ~/sim_$(git_branch)_`date "+%Y_%m_%d_%H:%M:%S"`
        else 
          cp -r ../../sim ~/sim_$(git_branch)_`date "+%Y_%m_%d_%H:%M:%S" `
        fi
L
liuyq-617 已提交
61 62 63 64 65 66 67
        exit 8
      fi
      end_time=`date +%s`
      echo execution time of $case was `expr $end_time - $start_time`s. | tee -a out.log
    fi
  done < $1
}
68 69 70 71

function runPyCaseOneByOne {
  while read -r line; do
    if [[ $line =~ ^python.* ]]; then
72
      if [[ $line != *sleep* ]]; then
L
liuyq-617 已提交
73 74 75 76 77 78
        
        if [[ $line =~ '-r' ]];then
          case=`echo $line|awk '{print $4}'`
        else
          case=`echo $line|awk '{print $NF}'`
        fi
S
Shuduo Sang 已提交
79
        start_time=`date +%s`
80
        $line > /dev/null 2>&1 && \
S
Shuduo Sang 已提交
81
          echo -e "${GREEN}$case success${NC}" | tee -a pytest-out.log || \
82
          echo -e "${RED}$case failed${NC}" | tee -a pytest-out.log
S
Shuduo Sang 已提交
83
        end_time=`date +%s`
L
liuyq-617 已提交
84
        out_log=`tail -1 pytest-out.log  `
L
liuyq-617 已提交
85 86 87
        # if [[ $out_log =~ 'failed' ]];then
        #   exit 8
        # fi
S
Shuduo Sang 已提交
88
        echo execution time of $case was `expr $end_time - $start_time`s. | tee -a pytest-out.log
89 90 91
      else
        $line > /dev/null 2>&1
      fi
92 93 94
    fi
  done < $1
}
L
liuyq-617 已提交
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
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`
        $line > /dev/null 2>&1 && \
          echo -e "${GREEN}$case success${NC}" | tee -a pytest-out.log || \
          echo -e "${RED}$case failed${NC}" | tee -a pytest-out.log
        end_time=`date +%s`
        out_log=`tail -1 pytest-out.log  `
        if [[ $out_log =~ 'failed' ]];then
112
          cp -r ../../sim ~/sim_$(git_branch)_`date "+%Y_%m_%d_%H:%M:%S" `
L
liuyq-617 已提交
113 114 115 116 117 118 119 120 121
          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
    fi
  done < $1
}
122 123
totalFailed=0
totalPyFailed=0
sangshuduo's avatar
sangshuduo 已提交
124

S
Shuduo Sang 已提交
125
tests_dir=`pwd`
sangshuduo's avatar
sangshuduo 已提交
126

127 128
if [ "$2" != "python" ]; then
  echo "### run TSIM test case ###"
S
Shuduo Sang 已提交
129
  cd $tests_dir/script
130

131 132 133 134 135 136
  [ -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 已提交
137
    runSimCaseOneByOne jenkins/basic.txt
L
liuyq-617 已提交
138 139 140 141 142 143 144 145 146
  elif [ "$1" == "b1" ]; then
    echo "### run TSIM b1 test ###"
    runSimCaseOneByOne jenkins/basic_1.txt
  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 已提交
147 148 149 150 151 152 153 154 155
  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
S
Shuduo Sang 已提交
156
  elif [ "$1" == "smoke" ] || [ -z "$1" ]; then
157 158 159
    echo "### run TSIM smoke test ###"
    runSimCaseOneByOne basicSuite.sim
  fi
160

161 162
  totalSuccess=`grep 'success' out.log | wc -l`
  totalBasic=`grep success out.log | grep Suite | wc -l`
163

164 165 166
  if [ "$totalSuccess" -gt "0" ]; then
    totalSuccess=`expr $totalSuccess - $totalBasic`
  fi
sangshuduo's avatar
sangshuduo 已提交
167

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

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

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

176 177
#  exit $totalFailed
  fi
sangshuduo's avatar
sangshuduo 已提交
178 179
fi

180 181
if [ "$2" != "sim" ]; then
  echo "### run Python test case ###"
182

S
Shuduo Sang 已提交
183
  cd $tests_dir
184 185
  IN_TDINTERNAL="community"

S
Shuduo Sang 已提交
186
  if [[ "$tests_dir" == *"$IN_TDINTERNAL"* ]]; then
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
    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 已提交
202
  cd $tests_dir/pytest
203 204 205 206 207 208 209 210 211

  [ -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 已提交
212
  elif [ "$1" == "pytest" ]; then
L
liuyq-617 已提交
213 214
    echo "### run Python full test ###"
    runPyCaseOneByOne fulltest.sh
L
liuyq-617 已提交
215 216 217
  elif [ "$1" == "pytestfq" ]; then
    echo "### run Python full test ###"
    runPyCaseOneByOnefq fulltest.sh
218 219
  elif [ "$1" == "p1" ]; then
    echo "### run Python_1 test ###"
L
liuyq-617 已提交
220
    runPyCaseOneByOnefq pytest_1.sh
221 222
  elif [ "$1" == "p2" ]; then
    echo "### run Python_2 test ###"
L
liuyq-617 已提交
223
    runPyCaseOneByOnefq pytest_2.sh
L
liuyq-617 已提交
224 225
  elif [ "$1" == "b2" ] || [ "$1" == "b3" ]; then
    exit $(($totalFailed + $totalPyFailed))
S
Shuduo Sang 已提交
226
  elif [ "$1" == "smoke" ] || [ -z "$1" ]; then
227 228 229
    echo "### run Python smoke test ###"
    runPyCaseOneByOne smoketest.sh
  fi
230
  totalPySuccess=`grep 'success' pytest-out.log | wc -l`
231 232

  if [ "$totalPySuccess" -gt "0" ]; then
S
Shuduo Sang 已提交
233
    echo -e "\n${GREEN} ### Total $totalPySuccess python case(s) succeed! ### ${NC}"
234 235 236 237
  fi

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

243
exit $(($totalFailed + $totalPyFailed))