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=""
|
2020-03-04 21:46:07 +00:00
|
|
|
RESULTS_DIR=/results
|
2020-03-19 19:04:13 +00:00
|
|
|
CEPH_CONF=/tmp/ceph/ceph.conf
|
2019-11-07 19:10:37 +00:00
|
|
|
|
2020-03-23 18:08:16 +00:00
|
|
|
|
2020-03-24 17:46:08 +00:00
|
|
|
# Default env vars that are not currently changed by this script
|
|
|
|
# but can be used to change the test behavior:
|
|
|
|
# GO_CEPH_TEST_MDS_NAME
|
|
|
|
|
2021-05-05 19:46:37 +00:00
|
|
|
CLI="$(getopt -o h --long test-run:,test-bench:,test-pkg:,pause,cpuprofile,memprofile,no-cover,micro-osd:,wait-for:,results:,ceph-conf:,mirror:,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
|
|
|
|
;;
|
2021-05-05 19:46:37 +00:00
|
|
|
--test-bench)
|
|
|
|
TEST_BENCH="${2}"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
2019-11-07 19:10:37 +00:00
|
|
|
--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
|
|
|
|
;;
|
2021-03-03 17:06:18 +00:00
|
|
|
--wait-for)
|
|
|
|
WAIT_FILES="${2}"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
2020-03-04 21:46:07 +00:00
|
|
|
--results)
|
|
|
|
RESULTS_DIR="${2}"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
2020-03-19 19:04:13 +00:00
|
|
|
--ceph-conf)
|
|
|
|
CEPH_CONF="${2}"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
2021-03-03 22:31:49 +00:00
|
|
|
--mirror)
|
|
|
|
MIRROR_CONF="${2}"
|
|
|
|
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"
|
2021-05-05 19:46:37 +00:00
|
|
|
echo " --test-bench=VALUE Run selected benchmarks"
|
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"
|
2021-03-03 17:06:18 +00:00
|
|
|
echo " --wait-for=FILES Wait for files before starting tests"
|
|
|
|
echo " (colon separated, disables micro-osd)"
|
2020-03-04 21:46:07 +00:00
|
|
|
echo " --results=PATH Specify path to store test results"
|
2020-03-19 19:04:13 +00:00
|
|
|
echo " --ceph-conf=PATH Specify path to ceph configuration"
|
2021-03-03 22:31:49 +00:00
|
|
|
echo " --mirror=PATH Specify path to ceph conf of mirror"
|
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
|
2021-01-18 22:29:06 +00:00
|
|
|
BUILD_TAGS="${CEPH_VERSION}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "${USE_PTRGUARD}" ]; then
|
|
|
|
BUILD_TAGS+=",ptrguard"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "${BUILD_TAGS}" ]; then
|
|
|
|
BUILD_TAGS="-tags ${BUILD_TAGS}"
|
2019-12-17 15:50:58 +00:00
|
|
|
fi
|
|
|
|
|
2020-02-03 20:00:23 +00:00
|
|
|
show() {
|
|
|
|
echo "*** running:" "$@"
|
|
|
|
"$@"
|
|
|
|
}
|
|
|
|
|
2021-03-03 17:06:18 +00:00
|
|
|
wait_for_files() {
|
|
|
|
for file in "$@" ; do
|
|
|
|
echo -n "*** waiting for $file ..."
|
|
|
|
while ! [[ -f $file ]] ; do
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
echo "done"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-03-03 22:31:49 +00:00
|
|
|
setup_mirroring() {
|
|
|
|
echo "Setting up mirroring..."
|
|
|
|
local CONF_A=${CEPH_CONF}
|
|
|
|
local CONF_B=${MIRROR_CONF}
|
|
|
|
ceph -c $CONF_A osd pool create rbd 8
|
|
|
|
ceph -c $CONF_B osd pool create rbd 8
|
|
|
|
rbd -c $CONF_A pool init
|
|
|
|
rbd -c $CONF_B pool init
|
|
|
|
rbd -c $CONF_A mirror pool enable rbd image
|
|
|
|
rbd -c $CONF_B mirror pool enable rbd image
|
|
|
|
rbd -c $CONF_A mirror pool peer bootstrap create --site-name ceph_a rbd > token
|
|
|
|
rbd -c $CONF_B mirror pool peer bootstrap import --site-name ceph_b rbd token
|
2021-04-12 13:45:52 +00:00
|
|
|
|
|
|
|
rbd -c $CONF_A rm mirror_test 2>/dev/null || true
|
|
|
|
rbd -c $CONF_B rm mirror_test 2>/dev/null || true
|
|
|
|
(echo "Mirror Test"; dd if=/dev/zero bs=1 count=500K) | rbd -c $CONF_A import - mirror_test
|
2021-03-03 22:31:49 +00:00
|
|
|
rbd -c $CONF_A mirror image enable mirror_test snapshot
|
|
|
|
echo -n "Waiting for mirroring activation..."
|
|
|
|
while ! rbd -c $CONF_A mirror image status mirror_test \
|
|
|
|
| grep -q "state: \+up+replaying" ; do
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
echo "done"
|
|
|
|
rbd -c $CONF_A mirror image snapshot mirror_test
|
|
|
|
echo -n "Waiting for mirror sync..."
|
2021-04-12 13:45:52 +00:00
|
|
|
while ! rbd -c $CONF_B export mirror_test - 2>/dev/null | grep -q "Mirror Test" ; do
|
2021-03-03 22:31:49 +00:00
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
echo " mirroring functional!"
|
|
|
|
}
|
|
|
|
|
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
|
2020-03-09 20:13:18 +00:00
|
|
|
|
|
|
|
# run go vet and capture the result for the package, but still execute the
|
|
|
|
# test suite anyway
|
|
|
|
show go vet ${BUILD_TAGS} "./${pkg}"
|
|
|
|
ret=$?
|
|
|
|
|
2020-02-03 18:55:03 +00:00
|
|
|
# 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
|
2021-05-05 19:46:37 +00:00
|
|
|
if [[ -n ${TEST_BENCH} ]]; then
|
|
|
|
testargs+=("-bench" "${TEST_BENCH}")
|
|
|
|
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" \
|
2021-04-28 21:55:32 +00:00
|
|
|
"-coverpkg=${PKG_PREFIX}/${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-03-09 20:13:18 +00:00
|
|
|
ret=$(($?+${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 .)
|
2020-05-20 17:16:58 +00:00
|
|
|
make implements
|
2020-02-03 19:14:17 +00:00
|
|
|
|
|
|
|
# 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
|
2020-03-04 21:46:07 +00:00
|
|
|
mkdir -p "${RESULTS_DIR}/coverage"
|
|
|
|
show go tool cover -html=cover.out -o "${RESULTS_DIR}/coverage/go-ceph.html"
|
2020-02-03 22:01:40 +00:00
|
|
|
fi
|
2020-05-20 17:16:58 +00:00
|
|
|
if [[ ${COVERAGE} = yes ]] && command -v castxml ; then
|
|
|
|
mkdir -p "${RESULTS_DIR}/coverage"
|
|
|
|
show ./implements --list \
|
|
|
|
--report-json "${RESULTS_DIR}/implements.json" \
|
|
|
|
--report-text "${RESULTS_DIR}/implements.txt" \
|
|
|
|
cephfs rados rbd
|
|
|
|
# output the brief summary info onto stdout
|
|
|
|
grep '^[A-Z]' "${RESULTS_DIR}/implements.txt"
|
|
|
|
fi
|
2020-02-03 19:14:17 +00:00
|
|
|
}
|
|
|
|
|
2020-02-03 18:47:12 +00:00
|
|
|
test_go_ceph() {
|
|
|
|
mkdir -p /tmp/ceph
|
2021-03-03 17:06:18 +00:00
|
|
|
if ! [[ ${WAIT_FILES} ]]; then
|
|
|
|
show "${MICRO_OSD_PATH}" /tmp/ceph
|
|
|
|
fi
|
2021-03-12 21:07:06 +00:00
|
|
|
export 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
|
|
|
|
2021-04-28 21:55:32 +00:00
|
|
|
PKG_PREFIX=github.com/ceph/go-ceph
|
|
|
|
pkgs=$(go list ./... | sed -e "s,^${PKG_PREFIX}/\?,," | grep -v ^contrib)
|
2020-02-03 19:14:17 +00:00
|
|
|
pre_all_tests
|
2021-03-03 17:06:18 +00:00
|
|
|
if [[ ${WAIT_FILES} ]]; then
|
|
|
|
wait_for_files ${WAIT_FILES//:/ }
|
|
|
|
fi
|
2021-03-03 22:31:49 +00:00
|
|
|
if [[ ${MIRROR_CONF} && ${CEPH_VERSION} != nautilus ]]; then
|
|
|
|
setup_mirroring
|
2021-04-06 17:37:16 +00:00
|
|
|
export MIRROR_CONF
|
2021-03-03 22:31:49 +00:00
|
|
|
fi
|
2021-04-28 21:55:32 +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
|
2021-05-10 16:00:58 +00:00
|
|
|
|
|
|
|
# vim: set ts=4 sw=4 sts=4 et:
|