full_test.sh 5.5 KB
Newer Older
S
Shuduo Sang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
#!/bin/bash

today=`date +"%Y%m%d"`
TDENGINE_DIR=/home/shuduo/work/taosdata/TDengine.orig
TDENGINE_FULLTEST_REPORT=$TDENGINE_DIR/tests/full-report-$today.log

# Color setting
RED='\033[0;31m'
GREEN='\033[1;32m'
GREEN_DARK='\033[0;32m'
GREEN_UNDERLINE='\033[4;32m'
NC='\033[0m'

function buildTDengine {
  echo "check if TDengine need build"

  need_rebuild=false

  if [ ! -d $TDENGINE_DIR ]; then
    echo "No TDengine source code found!"
    git clone https://github.com/taosdata/TDengine $TDENGINE_DIR
    need_rebuild=true
  fi

  cd $TDENGINE_DIR
  git remote prune origin > /dev/null
  git remote update > /dev/null
  REMOTE_COMMIT=`git rev-parse --short remotes/origin/develop`
  LOCAL_COMMIT=`git rev-parse --short @`
  echo " LOCAL: $LOCAL_COMMIT"
  echo "REMOTE: $REMOTE_COMMIT"

  if [ "$LOCAL_COMMIT" == "$REMOTE_COMMIT" ]; then
    echo "repo up-to-date"
  else
    echo "repo need to pull"
    git pull
    need_rebuild=true
  fi

  [ -d $TDENGINE_DIR/debug ] || mkdir $TDENGINE_DIR/debug
  cd $TDENGINE_DIR/debug
  [ -f $TDENGINE_DIR/debug/build/bin/taosd ] || need_rebuild=true

  if $need_rebuild ; then
    echo "rebuild.."

    LOCAL_COMMIT=`git rev-parse --short @`
    rm -rf *
    cmake .. > /dev/null
    make > /dev/null
  fi

  make install > /dev/null
}

function runGeneralCaseOneByOne {
  while read -r line; do
    if [[ $line =~ ^./test.sh* ]]; then
      general_case=`echo $line | grep -w general`

      if [ -n "$general_case" ]; then
        case=`echo $line | awk '{print $NF}'`

        start_time=`date +%s`
        ./test.sh -f $case > /dev/null 2>&1 && ret=0 || ret = 1
        end_time=`date +%s`

        if [[ ret -eq 0 ]]; then
          echo -e "${GREEN}$case success${NC}" | tee -a $TDENGINE_FULLTEST_REPORT
        else
          casename=`echo $case|sed 's/\//\-/g'`
          find $TDENGINE_DIR/sim -name "*log" -exec tar czf $TDENGINE_DIR/fulltest-$today-$casename.log.tar.gz {} +
          echo -e "${RED}$case failed and log saved${NC}" | tee -a $TDENGINE_FULLTEST_REPORT
        fi
        echo execution time of $case was `expr $end_time - $start_time`s. | tee -a $TDENGINE_FULLTEST_REPORT
      fi
    fi
  done < $1
}

function runPyCaseOneByOne {
  while read -r line; do
    if [[ $line =~ ^python.* ]]; then
      if [[ $line != *sleep* ]]; then
        case=`echo $line|awk '{print $NF}'`
        start_time=`date +%s`
        $line > /dev/null 2>&1 && ret=0 || ret=1
        end_time=`date +%s`

        if [[ ret -eq 0 ]]; then
          echo -e "${GREEN}$case success${NC}" | tee -a pytest-out.log
        else
          casename=`echo $case|sed 's/\//\-/g'`
          find $TDENGINE_DIR/sim -name "*log" -exec tar czf $TDENGINE_DIR/fulltest-$today-$casename.log.tar.gz {} +
          echo -e "${RED}$case failed and log saved${NC}" | tee -a pytest-out.log
        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
}

function runTest {
  echo "Run Test"
  cd $TDENGINE_DIR/tests/script

  [ -d $TDENGINE_DIR/sim ] && rm -rf $TDENGINE_DIR/sim
  [ -f $TDENGINE_FULLTEST_REPORT ] && rm $TDENGINE_FULLTEST_REPORT

  runGeneralCaseOneByOne jenkins/basic.txt

  totalSuccess=`grep 'success' $TDENGINE_FULLTEST_REPORT | wc -l`

  if [ "$totalSuccess" -gt "0" ]; then
    echo -e "\n${GREEN} ### Total $totalSuccess SIM case(s) succeed! ### ${NC}" \
      | tee -a $TDENGINE_FULLTEST_REPORT
  fi

  totalFailed=`grep 'failed\|fault' $TDENGINE_FULLTEST_REPORT | wc -l`
  if [ "$totalFailed" -ne "0" ]; then
    echo -e "${RED} ### Total $totalFailed SIM case(s) failed! ### ${NC}\n" \
    | tee -a $TDENGINE_FULLTEST_REPORT
  fi

  cd $TDENGINE_DIR/tests/pytest
  [ -d $TDENGINE_DIR/sim ] && rm -rf $TDENGINE_DIR/sim
  [ -f pytest-out.log ] && rm -f pytest-out.log
  runPyCaseOneByOne fulltest.sh

  totalPySuccess=`grep 'success' pytest-out.log | wc -l`
  totalPyFailed=`grep 'failed\|fault' pytest-out.log | wc -l`

  cat pytest-out.log >> $TDENGINE_FULLTEST_REPORT
  if [ "$totalPySuccess" -gt "0" ]; then
    echo -e "\n${GREEN} ### Total $totalPySuccess python case(s) succeed! ### ${NC}" \
      | tee -a $TDENGINE_FULLTEST_REPORT
  fi

  if [ "$totalPyFailed" -ne "0" ]; then
    echo -e "\n${RED} ### Total $totalPyFailed python case(s) failed! ### ${NC}" \
      | tee -a $TDENGINE_FULLTEST_REPORT
  fi
}

function sendReport {
  echo "Send Report"
  receiver="sdsang@taosdata.com, sangshuduo@gmail.com, pxiao@taosdata.com"
  mimebody="MIME-Version: 1.0\nContent-Type: text/html; charset=utf-8\n"

  cd $TDENGINE_DIR/tests

  sed -i 's/\x1b\[[0-9;]*m//g' $TDENGINE_FULLTEST_REPORT
  BODY_CONTENT=`cat $TDENGINE_FULLTEST_REPORT`

  cd $TDENGINE_DIR
  tar czf fulltest-$today.tar.gz fulltest-$today-*.log.tar.gz

  echo -e "to: ${receiver}\nsubject: Full test report ${today}, commit ID: ${LOCAL_COMMIT}\n\n${today}:\n${BODY_CONTENT}" | \
  (cat - && uuencode $TDENGINE_FULLTEST_REPORT fulltest-report-$today.log) | \
  (cat - && uuencode $TDENGINE_DIR/fulltest-$today.tar.gz fulltest-$today.tar.gz) | \
  ssmtp "${receiver}" && echo "Report Sent!"
}

function stopTaosd {
  echo "Stop taosd"
  systemctl stop taosd
  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
}

WORK_DIR=/home/shuduo/work/taosdata

date >> $WORK_DIR/cron.log
echo "Run Full Test" | tee -a $WORK_DIR/cron.log

stopTaosd
buildTDengine
runTest
sendReport
stopTaosd

date >> $WORK_DIR/cron.log
echo "End of Full Test" | tee -a $WORK_DIR/cron.log