-
-
Notifications
You must be signed in to change notification settings - Fork 289
/
Copy pathruntime
executable file
·229 lines (215 loc) · 6.61 KB
/
runtime
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/bin/bash
# set -e
# set -o pipefail
PROJDIR=$(dirname "$(cd "$(dirname "${0}")"; pwd -P)")
# {{{ Colors
RED='\033[0;31m'
BOLD_RED='\033[1;31m'
GREEN='\033[0;32m'
BOLD_GREEN='\033[1;32m'
YELLOW='\033[0;33m'
BOLD_YELLOW='\033[1;33m'
RESET='\033[0m'
# }}}
# {{{ Help message
function help() {
cat >&2 << EOF
This script is a driver for "runtime tests".
The "runtime test" is to test gosseract package in specific environments,
such as OS, Go version and Tesseract version.
Options:
--driver|-d {name} Specify VM driver software, either of [docker].
--build|-b Build testable images if provided, otherwise pull images.
--no-cache|-c Build testable images without layer cache (only available with -b)
--push|-p Push local images to dockerhub (for development purpose).
--quiet|-q Don't show verbose logs of setting VMs up.
--run|-R {case} Run only cases which have specified pattern in the case names.
--exclude|-X {case} Run only cases which DON'T have specified pattern in the case names.
--rm Remove VMs which are created by this runtime test.
--list|-l Just list runtimes
--help|-h Show this message ;)
Examples:
./test/runtime -d docker -v --run CentOS --rm
EOF
}
# }}}
# {{{ Parse CLI options
function parse_options() {
DRIVER=
REMOVE=
BUILD=
NO_CACHE=
PUSH=
QUIET=
MATCH=
EXCLUDE=
LIST=
while [[ $# -gt 0 ]]; do
case "${1}" in
--driver|-d)
DRIVER="${2}"
shift && shift
;;
--rm)
REMOVE=YES
shift
;;
--build|-b)
BUILD=YES
shift
;;
--no-cache|-c)
NO_CACHE="--no-cache"
shift
;;
--push|-p)
PUSH=YES
shift
;;
--quiet|-q)
QUIET="--quiet"
shift
;;
--run|-R)
MATCH="${2}"
shift && shift
;;
--exclude|-X)
EXCLUDE="${2}"
shift && shift
;;
--list|-l)
LIST=YES
shift
;;
--help|-h)
help && exit 0
;;
*)
printf "Unkown flag: ${1}\n\n"
help
exit 1
;;
esac
done
}
# }}}
# {{{ Runner function for "--driver docker"
function test_docker_runtimes() {
if [ -n "${LIST}" ]; then
echo "Available runtimes (docker):"
for runtime in `ls ${PROJDIR}/test/runtimes/*.Dockerfile`; do
testcase=`basename ${runtime} | sed -e s/\.Dockerfile$//`
echo " ${testcase}"
done
return 0
fi
for runtime in `ls ${PROJDIR}/test/runtimes/*.Dockerfile`; do
testcase=`basename ${runtime} | sed -e s/\.Dockerfile$//`
if [ -n "${MATCH}" ]; then
if [[ "${testcase}" != *${MATCH}* ]]; then
continue
fi
fi
if [ -n "${EXCLUDE}" ]; then
if [[ "${testcase}" == *${EXCLUDE}* ]]; then
continue
fi
fi
echo "┌───────────── ${testcase}"
# q: Is following line correct?
# XXX: Since clearlinux docker image doesn't support ARM64 architecture, as of 2024-07-26a,
# we need to add `--platform linux/amd64` to the `docker build` command when we build it on macos M3 chip.
# if [ ${testcase} == "clearlinux" ]; then DOCKER_PLATFORM_ARG="--platform linux/amd64"; fi
if [ -n "${BUILD}" ]; then
echo "│ [Docker] Building image..."
docker build . ${NO_CACHE} -f ${runtime} -t gosseract/test:${testcase} ${QUIET} | sed "s/^/│ /"
else
echo "│ [Docker] Pulling image..."
docker pull gosseract/test:${testcase} ${QUIET} | sed "s/^/│ /"
fi
echo "│ [Docker] Running tests..."
docker run -i -t -e "TESTCASE=${testcase}" --rm gosseract/test:${testcase} 1>./test/runtimes/TESTRESULT.${testcase}.txt 2>&1
EXIT_CODE=$?
cat ./test/runtimes/TESTRESULT.${testcase}.txt | sed "s/^/│ [${testcase}] /"
if [ ${EXIT_CODE} -gt 0 ]; then
printf "│ ${BOLD_RED}RUNTIME TEST FAILED! ${testcase}${RESET}\n"
printf "└───────────── ${testcase} ${BOLD_RED}[NG]${RESET}\n"
exit ${EXIT_CODE}
fi
if [ -n "${PUSH}" ]; then
echo "│ [Docker] Pushing the image..."
docker push gosseract/test:${testcase} | sed "s/^/│ /"
fi
if [ -n "${REMOVE}" ]; then
echo "│ [Docker] Removing image..."
docker rmi gosseract/test:${testcase} 1>/dev/null
fi
printf "└───────────── ${testcase} ${BOLD_GREEN}[OK]${RESET}\n"
done
}
# }}}
# {{{ Runner function for "--driver vagrant"
# function test_vagrant_runtimes() {
# if [ -n "${LIST}" ]; then
# echo "Available runtimes (vagrant):"
# for runtime in `ls ${PROJDIR}/test/runtimes/*.Vagrantfile`; do
# testcase=`basename ${runtime} | sed -e s/\.Vagrantfile$//`
# echo " ${testcase}"
# done
# return 0
# fi
#
# for runtime in `ls ${PROJDIR}/test/runtimes/*.Vagrantfile`; do
# testcase=`basename ${runtime} | sed -e s/\.Vagrantfile$//`
# if [ -n "${MATCH}" ]; then
# if [[ "${testcase}" != *${MATCH}* ]]; then continue; fi
# fi
# echo "┌───────────── ${testcase}"
# echo "│ [Vagrant] Making VM up..."
# vboxname=gosseract-test-${testcase}
# VAGRANT_VAGRANTFILE=${runtime} VIRTUALBOX_NAME=${vboxname} vagrant up ${VAGRANT_DEBUG} --provision --provider virtualbox # | sed "s/^/│ /"
# TESTRESULT="${?}"
# echo "[DEBUG] VAGRANT_VAGRANTFILE: " ${runtime}
# echo "[DEBUG] VIRTUALBOX_NAME: " ${vboxname}
# VAGRANT_VAGRANTFILE=${runtime} VIRTUALBOX_NAME=${vboxname} vagrant ssh-config
# echo "[DEBUG] ssh"
# VAGRANT_VAGRANTFILE=${runtime} VIRTUALBOX_NAME=${vboxname} vagrant ssh -c "echo 'Hello, world!'"
# echo "[DEBUG] /end"
# if [ "${TESTRESULT}" != "0" ]; then
# echo "│ [Vagrant] An error detected while upping VM"
# fi
# echo "│ [Vagrant] Stopping VM..."
# VAGRANT_VAGRANTFILE=${runtime} vagrant halt # | sed "s/^/│ /"
# if [ -n "${REMOVE}" ]; then
# echo "│ [Vagrant] Removing VM..."
# VAGRANT_VAGRANTFILE=${runtime} vagrant destroy -f # | sed "s/^/│ /"
# fi
# if [ "${TESTRESULT}" != "0" ]; then
# printf "│ ${BOLD_RED}RUNTIME TEST FAILED! ${testcase}${RESET}\n"
# printf "└───────────── ${testcase} ${BOLD_RED}[NG]${RESET}\n"
# exit 1
# fi
# printf "└───────────── ${testcase} ${BOLD_GREEN}[OK]${RESET}\n"
# done
# }
# }}}
# {{{ Main procedure
function __main__() {
parse_options $@
case ${DRIVER} in
docker)
test_docker_runtimes
;;
# vagrant)
# test_vagrant_runtimes
# ;;
*)
test_docker_runtimes
# test_vagrant_runtimes
;;
esac
}
# }}}
# Entrypoint
__main__ $@