forked from ceph/go-ceph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·197 lines (177 loc) · 4.67 KB
/
entrypoint.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/bin/bash
set -e
TEST_RUN=ALL
PAUSE=no
COVERAGE=yes
CPUPROFILE=no
MEMPROFILE=no
MICRO_OSD_PATH="/micro-osd.sh"
BUILD_TAGS=""
RESULTS_DIR=/results
CEPH_CONF=/tmp/ceph/ceph.conf
# env vars consumed by go code directly.
# set defaults if they are currently unset in the environment
: "${GO_CEPH_TEST_REQUIRE_MOUNT:=yes}"
# Default env vars that are not currently changed by this script
# but can be used to change the test behavior:
# GO_CEPH_TEST_MOUNT_DIR
# GO_CEPH_TEST_MDS_NAME
CLI="$(getopt -o h --long test-run:,test-pkg:,pause,cpuprofile,memprofile,no-cover,micro-osd:,results:,ceph-conf:,help -n "${0}" -- "$@")"
eval set -- "${CLI}"
while true ; do
case "${1}" in
--test-pkg)
TEST_PKG="${2}"
shift
shift
;;
--test-run)
TEST_RUN="${2}"
shift
shift
;;
--pause)
PAUSE=yes
shift
;;
--micro-osd)
MICRO_OSD_PATH="${2}"
shift
shift
;;
--results)
RESULTS_DIR="${2}"
shift
shift
;;
--ceph-conf)
CEPH_CONF="${2}"
shift
shift
;;
--cpuprofile)
CPUPROFILE=yes
shift
;;
--memprofile)
MEMPROFILE=yes
shift
;;
--no-cover)
COVERAGE=no
shift
;;
-h|--help)
echo "Options:"
echo " --test-run=VALUE Run selected test or ALL, NONE"
echo " ALL is the default"
echo " --test-pkg=PKG Run only tests from PKG"
echo " --pause Sleep forever after tests execute"
echo " --micro-osd Specify path to micro-osd script"
echo " --results=PATH Specify path to store test results"
echo " --ceph-conf=PATH Specify path to ceph configuration"
echo " --cpuprofile Run tests with cpu profiling"
echo " --memprofile Run tests with mem profiling"
echo " --no-cover Disable code coverage profiling"
echo " -h|--help Display help text"
echo ""
exit 0
;;
--)
shift
break
;;
*)
echo "unknown option" >&2
exit 2
;;
esac
done
if [ -n "${CEPH_VERSION}" ]; then
BUILD_TAGS="-tags ${CEPH_VERSION}"
fi
show() {
echo "*** running:" "$@"
"$@"
}
test_failed() {
local pkg="${1}"
echo "*** ERROR: ${pkg} tests failed"
pause_if_needed
return 1
}
test_pkg() {
local pkg="${1}"
if [[ "${TEST_PKG}" && "${TEST_PKG}" != "${pkg}" ]]; then
return 0
fi
# run go vet and capture the result for the package, but still execute the
# test suite anyway
show go vet ${BUILD_TAGS} "./${pkg}"
ret=$?
# disable caching of tests results
testargs=("-count=1"\
${BUILD_TAGS})
if [[ ${TEST_RUN} != ALL ]]; then
testargs+=("-run" "${TEST_RUN}")
fi
if [[ ${COVERAGE} = yes ]]; then
testargs+=(\
"-covermode=count" \
"-coverprofile=${pkg}.cover.out" \
"-coverpkg=${P}/${pkg}")
fi
if [[ ${CPUPROFILE} = yes ]]; then
testargs+=("-cpuprofile" "${pkg}.cpu.out")
fi
if [[ ${MEMPROFILE} = yes ]]; then
testargs+=("-memprofile" "${pkg}.mem.out")
fi
show go test -v "${testargs[@]}" "./${pkg}"
ret=$(($?+${ret}))
grep -v "^mode: count" "${pkg}.cover.out" >> "cover.out"
return ${ret}
}
pre_all_tests() {
# Prepare Go code
go get -t -v ${BUILD_TAGS} ./...
diff -u <(echo -n) <(gofmt -d -s .)
# Reset whole-module coverage file
echo "mode: count" > "cover.out"
}
post_all_tests() {
if [[ ${COVERAGE} = yes ]]; then
mkdir -p "${RESULTS_DIR}/coverage"
show go tool cover -html=cover.out -o "${RESULTS_DIR}/coverage/go-ceph.html"
fi
}
test_go_ceph() {
mkdir -p /tmp/ceph
show "${MICRO_OSD_PATH}" /tmp/ceph
export CEPH_CONF GO_CEPH_TEST_REQUIRE_MOUNT
if [[ ${TEST_RUN} == NONE ]]; then
echo "skipping test execution"
return 0
fi
P=github.com/ceph/go-ceph
pkgs=(\
"cephfs" \
"internal/callbacks" \
"internal/errutil" \
"rados" \
"rbd" \
)
pre_all_tests
for pkg in "${pkgs[@]}"; do
test_pkg "${pkg}" || test_failed "${pkg}"
done
post_all_tests
}
pause_if_needed() {
if [[ ${PAUSE} = yes ]]; then
echo "*** pausing execution"
sleep infinity
fi
}
test_go_ceph
pause_if_needed