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

#!/bin/sh -e
# cyclictest measures event latency in Linux kernel by measuring the amount of
# time that passes between when a timer expires and when the thread which set
# the timer actually runs.

# shellcheck disable=SC1091
#cd 到相对目录下执行脚本文件
. ../../lib/sh-test-lib

#定义变量并赋值
OUTPUT="$(pwd)/output"
LOGFILE="${OUTPUT}/cyclictest.txt"
RESULT_FILE="${OUTPUT}/result.txt"
#可选参数赋初值,如果用户不指定的话。
PRIORITY="99"
INTERVAL="10000"
THREADS="1"
LOOPS="10000"

usage() {
    echo "Usage: $0 [-p priority] [-i interval] [-t threads] [-l loops]" 1>&2
    exit 1
}
#使用while循环来parse 可选参数
while getopts ":p:i:t:l:" opt; do
    case "${opt}" in
        p) PRIORITY="${OPTARG}" ;;
        i) INTERVAL="${OPTARG}" ;;
        t) THREADS="${OPTARG}" ;;
        l) LOOPS="${OPTARG}" ;;
        *) usage ;;
    esac
done
#检查是否是root
! check_root && error_msg "Please run this script as root."
#调用函数新建文件夹
create_out_dir "${OUTPUT}"

# Run cyclictest.
#调用函数检查是arm还是x86
detect_abi
# shellcheck disable=SC2154
#根据abi的不同执行命令
./bin/"${abi}"/cyclictest -p "${PRIORITY}" -i "${INTERVAL}" -t "${THREADS}" \
    -l "${LOOPS}" | tee "${LOGFILE}"

# Parse test log.
#parse test的log
tail -n "${THREADS}" "${LOGFILE}" \
    | sed 's/T:/T: /' \
    | awk '{printf("t%s-min-latency pass %s us\n", $2, $(NF-6))};
           {printf("t%s-avg-latency pass %s us\n", $2, $(NF-2))};
           {printf("t%s-max-latency pass %s us\n", $2, $NF)};'  \
    | tee -a "${RESULT_FILE}"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值