#!/bin/sh -e
# This test script run docker storage driver benchmarks and tests.
# Test suite source https://github.com/dmcgowan/dsdbench
# shellcheck disable=SC1091
#cd到相对路径下执行脚本
. ../../lib/sh-test-lib
#变量赋初值
OUTPUT="$(pwd)/output"
TEST_SUITE="BENCHMARKS"
RESULT_FILE="${OUTPUT}/result.txt"
LOG_FILE="${OUTPUT}/dsbench.txt"
#定义函数说明这个脚本的用法
usage() {
echo "Usage: $0 [-t <benchmarks|tests>] [-s <true|false>]" 1>&2
exit 1
}
#parse 可选参数
while getopts "t:s:h" o; do
case "$o" in
t) TEST_SUITE="${OPTARG}" ;;
s) SKIP_INSTALL="${OPTARG}" && export SKIP_INSTALL ;;
h|*) usage ;;
esac
done
#执行函数得到发型板的名字
dist_name
# shellcheck disable=SC2154
case "${dist}" in
debian|ubuntu)
dist_info
#根据发行版的名字安装不同的包
# shellcheck disable=SC2154
if [ "${Codename}" = "jessie" ]; then
install_deps "git libdevmapper-dev"
install_deps "-t jessie-backports golang"
else
install_deps "git golang libdevmapper-dev"
fi
;;
fedora|centos)
install_deps "git golang device-mapper-devel"
;;
opensuse)
install_deps "git go device-mapper-devel"
;;
esac
#检查是否是root,不是root用户的话,则输出错误日志
! check_root && error_msg "You need to be root to run this script."
create_out_dir "${OUTPUT}"
mkdir -p "${OUTPUT}/golang"
cd "${OUTPUT}"
export GOPATH="${OUTPUT}/golang"
#clone 源码
git clone https://github.com/dmcgowan/dsdbench
cd dsdbench
#cp 目录
cp -r vendor/ "${GOPATH}/src"
#如果是测试benchmark
if [ "${TEST_SUITE}" = "BENCHMARKS" ]; then
# Run benchmarks.
#执行命令测试benchmark,并将log输出到文件中,parse文件中的log来得到测试benchmark的值
DOCKER_GRAPHDRIVER=overlay2 go test -run=NONE -v -bench . \
| tee "${LOG_FILE}"
# Parse log file.
egrep "^Benchmark.*op$" "${LOG_FILE}" \
| awk '{printf("%s pass %s %s\n", $1,$3,$4)}' \
| tee -a "${RESULT_FILE}"
elif [ "${TEST_SUITE}" = "TESTS" ]; then
# Run tests.
#测试
DOCKER_GRAPHDRIVER=overlay2 go test -v . \
| tee "${LOG_FILE}"
# Parse log file.
for result in PASS FAIL SKIP; do
grep "\-\-\- ${result}" "${LOG_FILE}" \
| awk -v result="${result}" '{printf("%s %s\n", $3,result)}' \
| tee -a "${RESULT_FILE}"
done
fi
test-definitions/blob/master/auto-test/dsdbench/dsdbench.sh
最新推荐文章于 2023-07-01 17:29:53 发布