2018-07-07 17:34:56 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2019-11-07 19:10:37 +00:00
|
|
|
TEST_RUN=ALL
|
|
|
|
PAUSE=no
|
2020-02-03 22:01:40 +00:00
|
|
|
COVERAGE=yes
|
2020-02-03 20:55:59 +00:00
|
|
|
CPUPROFILE=no
|
|
|
|
MEMPROFILE=no
|
2019-11-07 19:10:37 +00:00
|
|
|
MICRO_OSD_PATH="/micro-osd.sh"
|
2019-12-17 15:50:58 +00:00
|
|
|
BUILD_TAGS=""
|
2019-11-07 19:10:37 +00:00
|
|
|
|
2020-02-10 19:16:43 +00:00
|
|
|
CLI="$(getopt -o h --long test-run:,test-pkg:,pause,cpuprofile,memprofile,no-cover,micro-osd:,help -n "${0}" -- "$@")"
|
2019-11-07 19:10:37 +00:00
|
|
|
eval set -- "${CLI}"
|
|
|
|
while true ; do
|
2020-02-10 19:16:43 +00:00
|
|
|
case "${1}" in
|
2019-12-20 15:59:57 +00:00
|
|
|
--test-pkg)
|
2020-02-10 19:16:43 +00:00
|
|
|
TEST_PKG="${2}"
|
2019-12-20 15:59:57 +00:00
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
2019-11-07 19:10:37 +00:00
|
|
|
--test-run)
|
2020-02-10 19:16:43 +00:00
|
|
|
TEST_RUN="${2}"
|
2019-11-07 19:10:37 +00:00
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--pause)
|
|
|
|
PAUSE=yes
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--micro-osd)
|
2020-02-10 19:16:43 +00:00
|
|
|
MICRO_OSD_PATH="${2}"
|
2019-11-07 19:10:37 +00:00
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
2020-02-03 20:55:59 +00:00
|
|
|
--cpuprofile)
|
|
|
|
CPUPROFILE=yes
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--memprofile)
|
|
|
|
MEMPROFILE=yes
|
|
|
|
shift
|
|
|
|
;;
|
2020-02-03 22:01:40 +00:00
|
|
|
--no-cover)
|
|
|
|
COVERAGE=no
|
|
|
|
shift
|
|
|
|
;;
|
2019-11-07 19:10:37 +00:00
|
|
|
-h|--help)
|
|
|
|
echo "Options:"
|
|
|
|
echo " --test-run=VALUE Run selected test or ALL, NONE"
|
|
|
|
echo " ALL is the default"
|
2019-12-20 15:59:57 +00:00
|
|
|
echo " --test-pkg=PKG Run only tests from PKG"
|
2019-11-07 19:10:37 +00:00
|
|
|
echo " --pause Sleep forever after tests execute"
|
|
|
|
echo " --micro-osd Specify path to micro-osd script"
|
2020-02-03 20:55:59 +00:00
|
|
|
echo " --cpuprofile Run tests with cpu profiling"
|
|
|
|
echo " --memprofile Run tests with mem profiling"
|
2020-02-03 22:01:40 +00:00
|
|
|
echo " --no-cover Disable code coverage profiling"
|
2019-11-07 19:10:37 +00:00
|
|
|
echo " -h|--help Display help text"
|
|
|
|
echo ""
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
--)
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "unknown option" >&2
|
|
|
|
exit 2
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2019-12-17 15:50:58 +00:00
|
|
|
if [ -n "${CEPH_VERSION}" ]; then
|
|
|
|
BUILD_TAGS="-tags ${CEPH_VERSION}"
|
|
|
|
fi
|
|
|
|
|
2020-02-03 20:00:23 +00:00
|
|
|
show() {
|
|
|
|
echo "*** running:" "$@"
|
|
|
|
"$@"
|
|
|
|
}
|
|
|
|
|
2020-02-03 19:32:48 +00:00
|
|
|
test_failed() {
|
2020-02-10 19:16:43 +00:00
|
|
|
local pkg="${1}"
|
2020-02-03 19:32:48 +00:00
|
|
|
echo "*** ERROR: ${pkg} tests failed"
|
|
|
|
pause_if_needed
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2020-02-03 18:55:03 +00:00
|
|
|
test_pkg() {
|
2020-02-10 19:16:43 +00:00
|
|
|
local pkg="${1}"
|
|
|
|
if [[ "${TEST_PKG}" && "${TEST_PKG}" != "${pkg}" ]]; then
|
2020-02-03 18:55:03 +00:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
# disable caching of tests results
|
2019-12-17 15:50:58 +00:00
|
|
|
testargs=("-count=1"\
|
|
|
|
${BUILD_TAGS})
|
2020-02-03 18:55:03 +00:00
|
|
|
if [[ ${TEST_RUN} != ALL ]]; then
|
|
|
|
testargs+=("-run" "${TEST_RUN}")
|
|
|
|
fi
|
2020-02-03 22:01:40 +00:00
|
|
|
if [[ ${COVERAGE} = yes ]]; then
|
|
|
|
testargs+=(\
|
|
|
|
"-covermode=count" \
|
2020-02-10 19:16:43 +00:00
|
|
|
"-coverprofile=${pkg}.cover.out" \
|
|
|
|
"-coverpkg=${P}/${pkg}")
|
2020-02-03 22:01:40 +00:00
|
|
|
fi
|
2020-02-03 20:55:59 +00:00
|
|
|
if [[ ${CPUPROFILE} = yes ]]; then
|
|
|
|
testargs+=("-cpuprofile" "${pkg}.cpu.out")
|
|
|
|
fi
|
|
|
|
if [[ ${MEMPROFILE} = yes ]]; then
|
|
|
|
testargs+=("-memprofile" "${pkg}.mem.out")
|
|
|
|
fi
|
2020-02-03 18:55:03 +00:00
|
|
|
|
2020-02-10 19:16:43 +00:00
|
|
|
show go test -v "${testargs[@]}" "./${pkg}"
|
2020-02-03 19:32:48 +00:00
|
|
|
ret=$?
|
2020-02-10 19:16:43 +00:00
|
|
|
grep -v "^mode: count" "${pkg}.cover.out" >> "cover.out"
|
2020-02-03 19:32:48 +00:00
|
|
|
return ${ret}
|
2020-02-03 18:55:03 +00:00
|
|
|
}
|
|
|
|
|
2020-02-03 19:14:17 +00:00
|
|
|
pre_all_tests() {
|
|
|
|
# Prepare Go code
|
2019-12-17 15:50:58 +00:00
|
|
|
go get -t -v ${BUILD_TAGS} ./...
|
2020-02-03 19:14:17 +00:00
|
|
|
diff -u <(echo -n) <(gofmt -d -s .)
|
|
|
|
|
|
|
|
# TODO: Consider enabling go vet but it currently fails
|
|
|
|
|
|
|
|
# Reset whole-module coverage file
|
|
|
|
echo "mode: count" > "cover.out"
|
|
|
|
}
|
|
|
|
|
|
|
|
post_all_tests() {
|
2020-02-03 22:01:40 +00:00
|
|
|
if [[ ${COVERAGE} = yes ]]; then
|
|
|
|
mkdir -p /results/coverage
|
|
|
|
show go tool cover -html=cover.out -o /results/coverage/go-ceph.html
|
|
|
|
fi
|
2020-02-03 19:14:17 +00:00
|
|
|
}
|
|
|
|
|
2020-02-03 18:47:12 +00:00
|
|
|
test_go_ceph() {
|
|
|
|
mkdir -p /tmp/ceph
|
2020-02-03 20:00:23 +00:00
|
|
|
show "${MICRO_OSD_PATH}" /tmp/ceph
|
2020-02-03 18:47:12 +00:00
|
|
|
export CEPH_CONF=/tmp/ceph/ceph.conf
|
2018-07-07 17:34:56 +00:00
|
|
|
|
2020-02-03 18:47:12 +00:00
|
|
|
if [[ ${TEST_RUN} == NONE ]]; then
|
|
|
|
echo "skipping test execution"
|
2020-02-03 18:55:03 +00:00
|
|
|
return 0
|
2020-02-03 18:47:12 +00:00
|
|
|
fi
|
2020-02-03 18:55:03 +00:00
|
|
|
|
|
|
|
P=github.com/ceph/go-ceph
|
|
|
|
pkgs=(\
|
|
|
|
"cephfs" \
|
|
|
|
"errutil" \
|
|
|
|
"rados" \
|
|
|
|
"rbd" \
|
|
|
|
)
|
2020-02-03 19:14:17 +00:00
|
|
|
pre_all_tests
|
2020-02-03 18:55:03 +00:00
|
|
|
for pkg in "${pkgs[@]}"; do
|
2020-02-10 19:16:43 +00:00
|
|
|
test_pkg "${pkg}" || test_failed "${pkg}"
|
2020-02-03 18:55:03 +00:00
|
|
|
done
|
2020-02-03 19:14:17 +00:00
|
|
|
post_all_tests
|
2020-02-03 18:47:12 +00:00
|
|
|
}
|
2019-11-07 19:10:37 +00:00
|
|
|
|
2020-02-03 18:47:12 +00:00
|
|
|
pause_if_needed() {
|
|
|
|
if [[ ${PAUSE} = yes ]]; then
|
2020-02-03 19:32:48 +00:00
|
|
|
echo "*** pausing execution"
|
2020-02-03 18:47:12 +00:00
|
|
|
sleep infinity
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
test_go_ceph
|
|
|
|
pause_if_needed
|