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
|
|
|
# env vars consumed by go code directly.
|
|
|
|
# set defaults if they are currently unset in the environment
|
|
|
|
: "${GO_CEPH_TEST_REQUIRE_MOUNT:=yes}"
|
|
|
|
|
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_MOUNT_DIR
|
|
|
|
# GO_CEPH_TEST_MDS_NAME
|
|
|
|
|
2020-03-19 19:04:13 +00:00
|
|
|
CLI="$(getopt -o h --long test-run:,test-pkg:,pause,cpuprofile,memprofile,no-cover,micro-osd:,results:,ceph-conf:,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-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
|
|
|
|
;;
|
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-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"
|
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
|
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
|
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-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
|
2020-02-03 20:00:23 +00:00
|
|
|
show "${MICRO_OSD_PATH}" /tmp/ceph
|
2020-03-23 18:08:16 +00:00
|
|
|
export CEPH_CONF GO_CEPH_TEST_REQUIRE_MOUNT
|
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" \
|
2020-02-05 16:49:48 +00:00
|
|
|
"internal/callbacks" \
|
2020-04-13 15:22:39 +00:00
|
|
|
"internal/cutil" \
|
2020-03-09 15:12:44 +00:00
|
|
|
"internal/errutil" \
|
2020-04-10 17:12:35 +00:00
|
|
|
"internal/retry" \
|
2020-02-03 18:55:03 +00:00
|
|
|
"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
|