Test-definitions/blob/master/auto-test/kernel-compilation/kernel-compilation.sh,
Test-definitions/blob/master/auto-test/kernel-compilation/kernel-compilation.sh
#! /Bin/sh-e # shellcheck disable = SC1091... /.. /lib/sh-test-libOUTPUT = "$ (pwd) /output "RESULT_FILE =" $ {OUTPUT}/result.txt "export RESULT_FILELOGFILE =" $ {OUTPUT}/kernel-compilation.txt "VERSION = '4. 4.34 'nproc =$ (NPROC) # define a function to describe how this script uses usage () {echo "Usage: $0 [-v version] [-s true | false] "1> & 2 exit 1} # parse optional parameter while getopts" v: s: h "o; do case "$ o" in v) VERSION = "$ {OPTARG}"; s) SKIP_INSTALL = "$ {OPTARG }";; H | *) usage; esacdone # Run the function to obtain the hairstyle board name dist_name # shellcheck disable = SC2154 # currently only two types of kernelcase "$ {dist}" in debian | ubuntu) pkgs = "wget time bc xz-utils build-essential"; centos | fedora) pkgs = "wget time bc xz gcc make"; esac # Check whether the user is a root user. If the user is not the root user, the error log is displayed! 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 the required package install_deps "$ {pkgs}" $ {SKIP_INSTALL} "create_out_dir" $ {OUTPUT} "cd" $ {OUTPUT} "# Download and extract Kernel tarball. # download kernelmajor_version of the specified VERSION from the kernel official website =$ (echo "$ {VERSION}" | awk-F '. ''{print $1} ') wget" https://cdn.kernel.org/pub/linux/kernel/v $ {Major_version }. x/linux-00000000version0000.tar. xz "# decompress the tar package and cd it to tar xf under its directory" linux-20.version=.tar. xz "cd" linux-$ {VERSION} "# Compile Kernel with defconfig. # It is native not cross compiling. # It will not work on x86. # Check whether the current platform is arm64 or x86detect_abi # shellcheck disable = SC2154case "$ {abi}" in arm64 | armeabi) # generate. config make defconfig # Start building kernel. the preceding time indicates how long the build kernel has been used. {time-p make-j "$ {NPROC}" Imag E;} 2> & 1 | tee "$ {LOGFILE}"; *) error_msg "Unsupported architecture! ";; Esac # obtain the real time measurement = "$ (grep" ^ real "" $ {LOGFILE} "| awk '{print $2}' from the log output by time-p }') "# search for the Image in a specific directory. if you can find the Image, it indicates that the kernel is compiled through 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. # Delete the kernel directory cd .. /rm-rf "linux-$ {VERSION }"*