test-definitions/blob/master/auto-test/dsdbench/dsdbench.sh

#!/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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值