forked from matrixorigin/matrixone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_ut.sh
executable file
·176 lines (146 loc) · 5.13 KB
/
run_ut.sh
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
#!/bin/bash
# Copyright 2021 Matrix Origin
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -o nounset
if (( $# == 0 )); then
echo "Usage: $0 TestType SkipTest"
echo " TestType: UT|SCA"
echo " SkipTest: race"
exit 1
fi
TEST_TYPE=$1
if [[ $# == 2 ]]; then
SKIP_TESTS=$2;
else
SKIP_TESTS="";
fi
shopt -s expand_aliases
source ./utilities.sh
go version
BUILD_WKSP=$(dirname "$PWD") && cd $BUILD_WKSP
LOG="$G_TS-$TEST_TYPE.log"
UT_TIMEOUT=${UT_TIMEOUT:-"30"}
UT_PARALLEL=${UT_PARALLEL:-"1"}
SCA_REPORT="$G_WKSP/$G_TS-SCA-Report.out"
UT_REPORT="$G_WKSP/$G_TS-UT-Report.out"
UT_FILTER="$G_WKSP/$G_TS-UT-Filter.out"
UT_COUNT="$G_WKSP/$G_TS-UT-Count.out"
CODE_COVERAGE="$G_WKSP/$G_TS-UT-Coverage.html"
RAW_COVERAGE="coverage.out"
IS_BUILD_FAIL=""
if [[ -f $SCA_REPORT ]]; then rm $SCA_REPORT; fi
if [[ -f $UT_REPORT ]]; then rm $UT_REPORT; fi
if [[ -f $UT_FILTER ]]; then rm $UT_FILTER; fi
if [[ -f $UT_COUNT ]]; then rm $UT_COUNT; fi
function logger(){
local level=$1
local msg=$2
local log=$LOG
logger_base "$level" "$msg" "$log"
}
function run_vet(){
cd $BUILD_WKSP
horiz_rule
echo "# BUILD WORKSPACE: $BUILD_WKSP"
echo "# SCA REPORT: $SCA_REPORT"
horiz_rule
if [[ -f $SCA_REPORT ]]; then rm $SCA_REPORT; fi
logger "INF" "Test is in progress... "
go vet -tags matrixone_test -unsafeptr=false ./pkg/... 2>&1 | tee $SCA_REPORT
logger "INF" "Refer to $SCA_REPORT for details"
}
function run_tests(){
cd $BUILD_WKSP
horiz_rule
echo "# BUILD WORKSPACE: $BUILD_WKSP"
echo "# SKIPPED TEST: $SKIP_TESTS"
echo "# UT REPORT: $UT_REPORT"
echo "# COVERAGE REPORT: $CODE_COVERAGE"
echo "# UT TIMEOUT: $UT_TIMEOUT"
echo "# UT PARALLEL: $UT_PARALLEL"
horiz_rule
logger "INF" "Clean go test cache"
go clean -testcache
local test_scope=$(go list ./... | grep -v 'driver/aoe' | grep -v 'engine/aoe' | grep -v 'pkg/catalog')
local leave_out=$(egrep -lr --include="*.go" 'Code generated by protoc-gen-gogo. DO NOT EDIT.' ./pkg/* | sort -u | xargs basename -a)
logger "INF" "Ingore code coverage $(echo ${leave_out[@]}|tr " " "|")"
local cover_profile='profile.raw'
make cgo
if [[ $SKIP_TESTS == 'race' ]]; then
logger "INF" "Run UT without race check"
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
else
logger "INF" "Run UT with race check"
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
fi
IS_BUILD_FAIL=$(egrep "^FAIL.*\ \[build\ failed\]$" $UT_REPORT)
egrep -a '^=== RUN *Test[^\/]*$|^\-\-\- PASS: *Test|^\-\-\- FAIL: *Test|^\-\-\- SKIP: *Test' $UT_REPORT > $UT_FILTER
logger "INF" "Refer to $UT_REPORT for details"
}
function ut_summary(){
cd $BUILD_WKSP
local total=$(cat "$UT_FILTER" | egrep '^=== RUN *Test' | wc -l | xargs)
local pass=$(cat "$UT_FILTER" | egrep "^\-\-\- PASS: *Test" | wc -l | xargs)
local skip=$(cat "$UT_FILTER" | egrep "^\-\-\- SKIP: *Test" | wc -l | xargs)
local fail=$(cat "$UT_FILTER" | egrep "^\-\-\- FAIL: *Test" | wc -l | xargs)
local unknown=$(cat "$UT_FILTER" | sed '/^=== RUN/{x;p;x;}' | sed -n '/=== RUN/N;/--- /!p' | grep -v '^$' | wc -l | xargs)
cat << EOF > $UT_COUNT
# Total: $total; Passed: $pass; Skipped: $skip; Failed: $fail; Unknown: $unknown
#
# SKIPPED CASES:
$(cat "$UT_FILTER" | egrep "^\-\-\- SKIP: *Test")
# FAILED CASES:
$(cat "$UT_FILTER" | egrep "^\-\-\- FAIL: *Test")
# UNKNOWN CASES:
$(cat "$UT_FILTER" | sed '/^=== RUN/{x;p;x;}' | sed -n '/=== RUN/N;/--- /!p' | grep -v '^$')
# BUILD FAILED in UT:
echo "${IS_BUILD_FAIL[@]}"
EOF
horiz_rule
cat "$UT_COUNT"
horiz_rule
if (( $fail > 0 )) || (( $unknown > 0 )) || [[ -n "$IS_BUILD_FAIL" ]]; then
logger "INF" "UNIT TESTING FAILED !!!"
exit 1
else
logger "INF" "UNIT TESTING SUCCEEDED !!!"
fi
}
function post_test(){
local aoe_test=$(find pkg/vm/engine/aoe/test/* -type d -maxdepth 0)
for dir in ${aoe_test[@]}; do
logger "WRN" "Remove $dir"
rm -rf $dir
done
}
if [[ 'SCA' == $TEST_TYPE ]]; then
horiz_rule
echo "# Examining source code"
horiz_rule
run_vet
elif [[ 'UT' == $TEST_TYPE ]]; then
horiz_rule
echo "# Running UT"
horiz_rule
run_tests
horiz_rule
echo "# Post testing"
horiz_rule
post_test
ut_summary
else
logger "ERR" "Wrong test type"
exit 1
fi
exit 0