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
|
|
|
|
MICRO_OSD_PATH="/micro-osd.sh"
|
|
|
|
|
2019-12-20 15:59:57 +00:00
|
|
|
CLI="$(getopt -o h --long test-run:,test-pkg:,pause,micro-osd:,help -n "$0" -- "$@")"
|
2019-11-07 19:10:37 +00:00
|
|
|
eval set -- "${CLI}"
|
|
|
|
while true ; do
|
|
|
|
case "$1" in
|
2019-12-20 15:59:57 +00:00
|
|
|
--test-pkg)
|
|
|
|
TEST_PKG="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
2019-11-07 19:10:37 +00:00
|
|
|
--test-run)
|
|
|
|
TEST_RUN="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--pause)
|
|
|
|
PAUSE=yes
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--micro-osd)
|
|
|
|
MICRO_OSD_PATH="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-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"
|
|
|
|
echo " -h|--help Display help text"
|
|
|
|
echo ""
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
--)
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "unknown option" >&2
|
|
|
|
exit 2
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2020-02-03 19:32:48 +00:00
|
|
|
test_failed() {
|
|
|
|
local pkg="$1"
|
|
|
|
echo "*** ERROR: ${pkg} tests failed"
|
|
|
|
pause_if_needed
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2020-02-03 18:55:03 +00:00
|
|
|
test_pkg() {
|
|
|
|
local pkg="$1"
|
|
|
|
if [[ "$TEST_PKG" && "$TEST_PKG" != "$pkg" ]]; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
testargs=(\
|
|
|
|
"-covermode=count" \
|
|
|
|
"-coverprofile=$pkg.cover.out" \
|
|
|
|
"-coverpkg=$P/$pkg")
|
|
|
|
# disable caching of tests results
|
|
|
|
testargs+=("-count=1")
|
|
|
|
if [[ ${TEST_RUN} != ALL ]]; then
|
|
|
|
testargs+=("-run" "${TEST_RUN}")
|
|
|
|
fi
|
|
|
|
|
|
|
|
go test -v "${testargs[@]}" "./$pkg"
|
2020-02-03 19:32:48 +00:00
|
|
|
ret=$?
|
2020-02-03 18:55:03 +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
|
|
|
|
go get -t -v ./...
|
|
|
|
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() {
|
|
|
|
mkdir -p /results/coverage
|
|
|
|
go tool cover -html=cover.out -o /results/coverage/go-ceph.html
|
|
|
|
}
|
|
|
|
|
2020-02-03 18:47:12 +00:00
|
|
|
test_go_ceph() {
|
|
|
|
mkdir -p /tmp/ceph
|
|
|
|
"${MICRO_OSD_PATH}" /tmp/ceph
|
|
|
|
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-03 19:32:48 +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
|