-
Notifications
You must be signed in to change notification settings - Fork 10
/
manage.sh
executable file
·160 lines (135 loc) · 4.43 KB
/
manage.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
#! /bin/bash
CurDir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd)"
######## envs ########
DOCKER_REGISTRY=registry.cn-hangzhou.aliyuncs.com/leosocy
# docker images used in ci
OPENCV_CI_IMAGE=${DOCKER_REGISTRY}/opencv:ci
CPPCHECK_CI_IMAGE=${DOCKER_REGISTRY}/cppcheck:1.83
CACHED_IMAGES=(${OPENCV_CI_IMAGE} ${CPPCHECK_CI_IMAGE})
APP_TEST_NAME=test-robust-palm-roi
######## functions ########
check_exec_success() {
if [ "$1" != "0" ]; then
echo "[ERROR] $2 failed!"
exit 1
else
echo "[INFO] $2 success!"
fi
}
test() {
load_images ${OPENCV_CI_IMAGE}
image_exist ${OPENCV_CI_IMAGE}
if [ $? -ne 0 ]; then
docker pull ${OPENCV_CI_IMAGE} > /dev/null
fi
check_exec_success "$?" "pulling ${OPENCV_CI_IMAGE} image"
docker run -it --rm -v ${CurDir}:/app -w /app ${OPENCV_CI_IMAGE} /bin/sh -ec """
mkdir -p build_test; cd build_test;
cmake .. -DROBUST_PALM_ROI_BUILD_TESTS=ON; make -j2 build_and_test;
lcov -b . -d . -c -o cov.info > /dev/null;
lcov -r cov.info \"/usr/*\" \"*/thirdparty/*\" \"*/test/*\" \"*/build_test/*\" \"/**/b64.*\" -o cov.info -q;
lcov -l cov.info;
genhtml -o cov_result cov.info > /dev/null; rm -rf ../cov_result; mv cov_result ..;
echo ""
echo ""
echo \"==========Generated code coverage report under ./cov_result directory.==========\"
"""
check_exec_success "$?" "run test"
}
gdbtest() {
load_images ${OPENCV_CI_IMAGE}
image_exist ${OPENCV_CI_IMAGE}
if [ $? -ne 0 ]; then
docker pull ${OPENCV_CI_IMAGE} > /dev/null
fi
check_exec_success "$?" "pulling ${OPENCV_CI_IMAGE} image"
docker run -it --rm -v ${CurDir}:/app -w /app \
--cap-add=SYS_PTRACE --security-opt seccomp=unconfined \
${OPENCV_CI_IMAGE} /bin/sh -ec """
mkdir -p build_test; cd build_test;
cmake .. -DROBUST_PALM_ROI_BUILD_TESTS=ON; make -j2; gdb ${APP_TEST_NAME}
"""
check_exec_success "$?" "gdb test"
}
lint() {
load_images ${CPPCHECK_CI_IMAGE}
if [ $? -ne 0 ]; then
docker pull ${CPPCHECK_CI_IMAGE} > /dev/null
fi
check_exec_success "$?" "pulling ${CPPCHECK_CI_IMAGE} image"
docker run -it --rm -v ${CurDir}:/app -w /app ${CPPCHECK_CI_IMAGE} /bin/sh -ec """
cppcheck --enable=warning,performance --error-exitcode=1 include src
"""
check_exec_success "$?" "run lint"
}
test_and_lint() {
test
lint
}
runenv() {
load_images ${OPENCV_CI_IMAGE}
image_exist ${OPENCV_CI_IMAGE}
if [ $? -ne 0 ]; then
docker pull ${OPENCV_CI_IMAGE} > /dev/null
fi
check_exec_success "$?" "pulling ${OPENCV_CI_IMAGE} image"
docker run -it --rm -v ${CurDir}:/app -w /app ${OPENCV_CI_IMAGE} /bin/sh -ec """
mkdir -p build_install; cd build_install;
cmake ..; make install;
bash
"""
}
######## below functions are used for travis-ci ########
upload_codecov() {
if [ -z ${CODECOV_TOKEN} ]; then
echo "Please set CODECOV_TOKEN value"
exit 1
fi
docker run -it --rm -v ${CurDir}:/app -w /app/build_test \
-e CODECOV_TOKEN=${CODECOV_TOKEN} \
${OPENCV_CI_IMAGE} /bin/bash -ec "$(curl -s https://codecov.io/bash)"
check_exec_success "$?" "upload codecov"
}
image_exist() {
docker images -a --filter='dangling=false' --format '{{.Repository}}:{{.Tag}} {{.ID}}' | grep $1 &> /dev/null
return $?
}
save_images() {
for image in "${CACHED_IMAGES[@]}"; do
image_exist ${image}
if [ $? -eq 0 ]; then
mkdir -p ${HOME}/docker && docker images -a \
--filter='dangling=false' --format '{{.Repository}}:{{.Tag}} {{.ID}}' | grep ${image} \
| xargs -n 2 -t sh -c 'test -e $HOME/docker/$1.tar.gz || docker save $0 | gzip -2 > ${HOME}/docker/$1.tar.gz'
fi
done
}
load_images() {
image_exist $1
if [ $? -eq 0 ]; then
return 0
fi
if [[ -d ${HOME}/docker ]]; then
ls ${HOME}/docker/*.tar.gz | xargs -I {file} sh -c "zcat {file} | docker load";
fi
}
######## script start ########
case "$1" in
test) test ;;
gdbtest) gdbtest ;;
lint) lint ;;
test_and_lint) test_and_lint ;;
env) runenv ;;
upload_codecov) upload_codecov ;;
save_images) save_images ;;
load_images) load_images $2 ;;
*)
echo "Usage:"
echo "./manage.sh test | gdbtest"
echo "./manage.sh lint"
echo "./manage.sh test_and_lint"
echo "./manage.sh env"
exit 1
;;
esac
exit 0