-
Notifications
You must be signed in to change notification settings - Fork 247
Expand file tree
/
Copy pathrun_unit_tests.sh
More file actions
executable file
·120 lines (107 loc) · 4.39 KB
/
run_unit_tests.sh
File metadata and controls
executable file
·120 lines (107 loc) · 4.39 KB
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
#!/bin/bash -x
# Copyright (c) 2023 Intel Corporation
#
# 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.
#
# This script should be used inside build image to run unit tests
JOBS=${JOBS:-"$(nproc)"}
RUN_TESTS=${RUN_TESTS:-"1"}
RUN_GPU_TESTS=${RUN_GPU_TESTS:-"0"}
CHECK_COVERAGE=${CHECK_COVERAGE:-"0"}
TEST_LOG=${TEST_LOG:-"test.log"}
FAIL_LOG=${FAIL_LOG:-"fail.log"}
if [ -f /etc/redhat-release ] ; then dist="--//:distro=redhat" ; fi
debug_bazel_flags=${debug_bazel_flags:-"--config=mp_on_py_on $dist"}
TEST_FILTER="--test_filter=*"
SHARED_OPTIONS=" \
--jobs=$JOBS \
${debug_bazel_flags} \
--test_timeout=1800 \
--test_summary=detailed \
--test_output=streamed"
LD_LIBRARY_PATH=/opt/opencv/lib/:/opt/intel/openvino/runtime/lib/intel64/:/opt/intel/openvino/runtime/3rdparty/tbb/lib/
PYTHONPATH=/opt/intel/openvino/python:/ovms/bazel-bin/src/python/binding
# if https proxy is set in the environment and file .user.bazelrc doesn't exist yet, add proxy env for bazel test
if [ -n "${HTTPS_PROXY}" ] && [ ! -f .user.bazelrc ] ; then
echo test:linux --test_env https_proxy=${HTTPS_PROXY} >> .user.bazelrc
echo test:linux --test_env http_proxy=${HTTP_PROXY} >> .user.bazelrc
fi
# Check if RUN_GPU_TESTS is set and add it to SHARED_OPTIONS
if [ "$RUN_GPU_TESTS" == "1" ]; then
if grep -q "ID=ubuntu" /etc/os-release; then
sh ./install_va.sh # It is required for VA API unit tests on Ubuntu
fi
SHARED_OPTIONS+=" --test_env RUN_GPU_TESTS=1"
fi
compress_logs() {
tar -czf test_logs.tar.gz ${TEST_LOG}
rm -rf ${TEST_LOG}
rm -rf tmp.log
}
generate_coverage_report() {
local coverage_dat="$(bazel info output_path)/_coverage/_coverage_report.dat"
# lcov 2.x supports --ignore-errors negative,unused; lcov 1.x does not
local lcov_ver
lcov_ver=$(lcov --version | grep -oP '\d+' | head -1)
local lcov_ignore=""
local genhtml_ignore=""
if [ "$lcov_ver" -ge 2 ] 2>/dev/null; then
lcov_ignore="--ignore-errors negative,unused"
genhtml_ignore="--ignore-errors negative"
fi
# Required filtering fixes below, because for some reason "bazel coverage --instrumentation_filter="-src/test""
# is not enough to list just ovms source files.
if ! lcov --extract "$coverage_dat" 'src/*' --output-file filtered_coverage.dat $lcov_ignore; then
echo "Error: lcov extraction failed" >&2
return 1
fi
if ! lcov --remove filtered_coverage.dat 'src/test/*' 'external/*' --output-file filtered_coverage.dat $lcov_ignore; then
echo "Error: lcov filtering failed" >&2
return 1
fi
if ! genhtml $genhtml_ignore --output genhtml filtered_coverage.dat; then
echo "Error: genhtml report generation failed" >&2
return 1
fi
}
echo "Run test: ${RUN_TESTS}"
echo "Run GPU test: ${RUN_GPU_TESTS}"
echo "Run coverage: ${CHECK_COVERAGE}"
if [ "$RUN_TESTS" == "1" ] ; then
if [ "$CHECK_COVERAGE" == "1" ] ; then
if bazel coverage --instrumentation_filter="-src/test" --combined_report=lcov \
${SHARED_OPTIONS} ${TEST_FILTER} \
//src:ovms_test ${SHARED_OPTIONS} > ${TEST_LOG} 2>&1 ; then
if ! generate_coverage_report ; then
compress_logs
exit 1
fi
else
compress_logs
exit 1
fi
fi
bazel test ${SHARED_OPTIONS} "${TEST_FILTER}" //src/python/binding:test_python_binding || exit 1
bazel build ${SHARED_OPTIONS} //src:ovms_test || exit 1
echo "Executing unit tests"
failed=0
# For RH UBI and Ubuntu
if ! bazel test --jobs=$JOBS ${debug_bazel_flags} ${SHARED_OPTIONS} --test_summary=detailed --test_output=streamed --test_filter="*" //src:ovms_test > ${TEST_LOG} 2>&1 ; then
failed=1
fi
cat ${TEST_LOG} | tail -500
grep -a " ms \| ms)" ${TEST_LOG} > linux_tests_summary.log
echo "Tests completed:" `grep -a " ms \| ms)" ${TEST_LOG} | grep " OK " | wc -l`
compress_logs
exit $failed
fi