test-definitions/blob/master/auto-test/kernel-compilation/kernel-compilation.sh

#!/bin/sh -e

# shellcheck disable=SC1091
. ../../lib/sh-test-lib
OUTPUT="$(pwd)/output"
RESULT_FILE="${OUTPUT}/result.txt"
export RESULT_FILE
LOGFILE="${OUTPUT}/kernel-compilation.txt"
VERSION='4.4.34'
NPROC=$(nproc)
#定义一个函数说明这个脚本该如何使用
usage() {
    echo "Usage: $0 [-v version] [-s true|false]" 1>&2
    exit 1
}
#parse 可选参数
while getopts "v:s:h" o; do
    case "$o" in
        v) VERSION="${OPTARG}" ;;
        s) SKIP_INSTALL="${OPTARG}" ;;
        h|*) usage ;;
    esac
done
#执行函数得到发型板的名字
dist_name
# shellcheck disable=SC2154
#目前只支持两类kernel
case "${dist}" in
    debian|ubuntu) pkgs="wget time bc xz-utils build-essential" ;;
    centos|fedora) pkgs="wget time bc xz gcc make" ;;
esac
#检查是否root 用户。非root用户的话,说出错误日志
! check_root && error_msg "You need to be root to install packages!"
# install_deps supports the above distributions.
# It will skip package installation on other distributions by default.
#安装必须的包
install_deps "${pkgs}" "${SKIP_INSTALL}"

create_out_dir "${OUTPUT}"
cd "${OUTPUT}"

# Download and extract Kernel tarball.
#从kernel 官网下载用户指定版本的kernel
major_version=$(echo "${VERSION}" | awk -F'.' '{print $1}')
wget "https://cdn.kernel.org/pub/linux/kernel/v${major_version}.x/linux-${VERSION}.tar.xz"
#解压tar 包,并cd到其目录下面
tar xf "linux-${VERSION}.tar.xz"
cd "linux-${VERSION}"

# Compile Kernel with defconfig.
# It is native not cross compiling.
# It will not work on x86.
#检查当前平台是arm64 还是x86
detect_abi
# shellcheck disable=SC2154
case "${abi}" in
    arm64|armeabi)
		#生成.config
        make defconfig
		#开始build kernel.前面加time 表示会统计build kernel 用了多久的时间
        { time -p make -j"${NPROC}" Image; } 2>&1 | tee "${LOGFILE}"
        ;;
    *)
        error_msg "Unsupported architecture!"
        ;;
esac
#从time -p输出的log中得到real的时间
measurement="$(grep "^real" "${LOGFILE}" | awk '{print $2}')"
#在特定目录下查找Image,如果可以查到说明kernel 编译通过
if egrep "arch/.*/boot/Image" "${LOGFILE}"; then
    report_pass "kernel-compilation"
    add_metric "kernel-compilation-time" "pass" "${measurement}" "seconds"
else
    report_fail "kernel-compilation"
    add_metric "kernel-compilation-time" "fail" "${measurement}" "seconds"
fi

# Cleanup.
#删除kernel 目录
cd ../
rm -rf "linux-${VERSION}"*

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值