github.com/matrixorigin/matrixone@v1.2.0/optools/run_ut.sh (about) 1 #!/bin/bash 2 3 # Copyright 2021 Matrix Origin 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 set -o nounset 18 19 if (( $# == 0 )); then 20 echo "Usage: $0 TestType SkipTest" 21 echo " TestType: UT|SCA" 22 echo " SkipTest: race" 23 exit 1 24 fi 25 26 TEST_TYPE=$1 27 if [[ $# == 2 ]]; then 28 SKIP_TESTS=$2; 29 else 30 SKIP_TESTS=""; 31 fi 32 33 shopt -s expand_aliases 34 source ./utilities.sh 35 go version 36 37 BUILD_WKSP=$(dirname "$PWD") && cd $BUILD_WKSP 38 39 40 LOG="$G_TS-$TEST_TYPE.log" 41 UT_TIMEOUT=${UT_TIMEOUT:-"30"} 42 UT_PARALLEL=${UT_PARALLEL:-"1"} 43 SCA_REPORT="$G_WKSP/$G_TS-SCA-Report.out" 44 UT_REPORT="$G_WKSP/$G_TS-UT-Report.out" 45 UT_FILTER="$G_WKSP/$G_TS-UT-Filter.out" 46 UT_COUNT="$G_WKSP/$G_TS-UT-Count.out" 47 CODE_COVERAGE="$G_WKSP/$G_TS-UT-Coverage.html" 48 RAW_COVERAGE="coverage.out" 49 IS_BUILD_FAIL="" 50 51 if [[ -f $SCA_REPORT ]]; then rm $SCA_REPORT; fi 52 if [[ -f $UT_REPORT ]]; then rm $UT_REPORT; fi 53 if [[ -f $UT_FILTER ]]; then rm $UT_FILTER; fi 54 if [[ -f $UT_COUNT ]]; then rm $UT_COUNT; fi 55 56 57 function logger(){ 58 local level=$1 59 local msg=$2 60 local log=$LOG 61 logger_base "$level" "$msg" "$log" 62 } 63 64 function run_vet(){ 65 cd $BUILD_WKSP 66 horiz_rule 67 echo "# BUILD WORKSPACE: $BUILD_WKSP" 68 echo "# SCA REPORT: $SCA_REPORT" 69 horiz_rule 70 71 if [[ -f $SCA_REPORT ]]; then rm $SCA_REPORT; fi 72 logger "INF" "Test is in progress... " 73 go vet -tags matrixone_test -unsafeptr=false ./pkg/... 2>&1 | tee $SCA_REPORT 74 logger "INF" "Refer to $SCA_REPORT for details" 75 76 } 77 78 function run_tests(){ 79 cd $BUILD_WKSP 80 horiz_rule 81 echo "# BUILD WORKSPACE: $BUILD_WKSP" 82 echo "# SKIPPED TEST: $SKIP_TESTS" 83 echo "# UT REPORT: $UT_REPORT" 84 echo "# COVERAGE REPORT: $CODE_COVERAGE" 85 echo "# UT TIMEOUT: $UT_TIMEOUT" 86 echo "# UT PARALLEL: $UT_PARALLEL" 87 horiz_rule 88 89 logger "INF" "Clean go test cache" 90 go clean -testcache 91 92 local test_scope=$(go list ./... | grep -v 'driver/aoe' | grep -v 'engine/aoe' | grep -v 'pkg/catalog') 93 local leave_out=$(egrep -lr --include="*.go" 'Code generated by protoc-gen-gogo. DO NOT EDIT.' ./pkg/* | sort -u | xargs basename -a) 94 logger "INF" "Ingore code coverage $(echo ${leave_out[@]}|tr " " "|")" 95 local cover_profile='profile.raw' 96 make cgo 97 if [[ $SKIP_TESTS == 'race' ]]; then 98 logger "INF" "Run UT without race check" 99 CGO_CFLAGS="-I${BUILD_WKSP}/cgo" CGO_LDFLAGS="-L${BUILD_WKSP}/cgo -lmo" go test -short -v -tags matrixone_test -p ${UT_PARALLEL} -timeout "${UT_TIMEOUT}m" $test_scope | tee $UT_REPORT 100 101 else 102 logger "INF" "Run UT with race check" 103 CGO_CFLAGS="-I${BUILD_WKSP}/cgo" CGO_LDFLAGS="-L${BUILD_WKSP}/cgo -lmo" go test -short -v -tags matrixone_test -p ${UT_PARALLEL} -timeout "${UT_TIMEOUT}m" -race $test_scope | tee $UT_REPORT 104 fi 105 IS_BUILD_FAIL=$(egrep "^FAIL.*\ \[build\ failed\]$" $UT_REPORT) 106 egrep -a '^=== RUN *Test[^\/]*$|^\-\-\- PASS: *Test|^\-\-\- FAIL: *Test|^\-\-\- SKIP: *Test' $UT_REPORT > $UT_FILTER 107 logger "INF" "Refer to $UT_REPORT for details" 108 109 } 110 111 function ut_summary(){ 112 cd $BUILD_WKSP 113 local total=$(cat "$UT_FILTER" | egrep '^=== RUN *Test' | wc -l | xargs) 114 local pass=$(cat "$UT_FILTER" | egrep "^\-\-\- PASS: *Test" | wc -l | xargs) 115 local skip=$(cat "$UT_FILTER" | egrep "^\-\-\- SKIP: *Test" | wc -l | xargs) 116 local fail=$(cat "$UT_FILTER" | egrep "^\-\-\- FAIL: *Test" | wc -l | xargs) 117 local unknown=$(cat "$UT_FILTER" | sed '/^=== RUN/{x;p;x;}' | sed -n '/=== RUN/N;/--- /!p' | grep -v '^$' | wc -l | xargs) 118 cat << EOF > $UT_COUNT 119 # Total: $total; Passed: $pass; Skipped: $skip; Failed: $fail; Unknown: $unknown 120 # 121 # SKIPPED CASES: 122 $(cat "$UT_FILTER" | egrep "^\-\-\- SKIP: *Test") 123 124 # FAILED CASES: 125 $(cat "$UT_FILTER" | egrep "^\-\-\- FAIL: *Test") 126 127 # UNKNOWN CASES: 128 $(cat "$UT_FILTER" | sed '/^=== RUN/{x;p;x;}' | sed -n '/=== RUN/N;/--- /!p' | grep -v '^$') 129 130 # BUILD FAILED in UT: 131 echo "${IS_BUILD_FAIL[@]}" 132 133 134 EOF 135 horiz_rule 136 cat "$UT_COUNT" 137 horiz_rule 138 if (( $fail > 0 )) || (( $unknown > 0 )) || [[ -n "$IS_BUILD_FAIL" ]]; then 139 logger "INF" "UNIT TESTING FAILED !!!" 140 exit 1 141 else 142 logger "INF" "UNIT TESTING SUCCEEDED !!!" 143 fi 144 } 145 146 function post_test(){ 147 local aoe_test=$(find pkg/vm/engine/aoe/test/* -type d -maxdepth 0) 148 for dir in ${aoe_test[@]}; do 149 logger "WRN" "Remove $dir" 150 rm -rf $dir 151 done 152 } 153 154 if [[ 'SCA' == $TEST_TYPE ]]; then 155 horiz_rule 156 echo "# Examining source code" 157 horiz_rule 158 run_vet 159 elif [[ 'UT' == $TEST_TYPE ]]; then 160 horiz_rule 161 echo "# Running UT" 162 horiz_rule 163 run_tests 164 165 horiz_rule 166 echo "# Post testing" 167 horiz_rule 168 post_test 169 170 ut_summary 171 else 172 logger "ERR" "Wrong test type" 173 exit 1 174 fi 175 176 exit 0