#!/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}"*
test-definitions/blob/master/auto-test/kernel-compilation/kernel-compilation.sh
最新推荐文章于 2023-08-15 13:16:23 发布