Chase Qi | fed7872 | 2016-11-24 12:27:59 +0800 | [diff] [blame] | 1 | #!/bin/sh -e |
| 2 | |
| 3 | # shellcheck disable=SC1091 |
| 4 | . ../../lib/sh-test-lib |
| 5 | OUTPUT="$(pwd)/output" |
| 6 | RESULT_FILE="${OUTPUT}/result.txt" |
| 7 | export RESULT_FILE |
| 8 | LOGFILE="${OUTPUT}/kernel-compilation.txt" |
| 9 | VERSION='4.4.34' |
| 10 | NPROC=$(nproc) |
| 11 | |
| 12 | usage() { |
| 13 | echo "Usage: $0 [-v version] [-s true|false]" 1>&2 |
| 14 | exit 1 |
| 15 | } |
| 16 | |
| 17 | while getopts "v:s:h" o; do |
| 18 | case "$o" in |
| 19 | v) VERSION="${OPTARG}" ;; |
| 20 | s) SKIP_INSTALL="${OPTARG}" ;; |
| 21 | h|*) usage ;; |
| 22 | esac |
| 23 | done |
| 24 | |
| 25 | dist_name |
| 26 | # shellcheck disable=SC2154 |
| 27 | case "${dist}" in |
Nicolas Dechesne | b7e3876 | 2017-01-25 12:07:08 +0100 | [diff] [blame^] | 28 | debian|ubuntu) pkgs="wget time bc xz-utils build-essential" ;; |
| 29 | centos|fedora) pkgs="wget time bc xz gcc make" ;; |
Chase Qi | fed7872 | 2016-11-24 12:27:59 +0800 | [diff] [blame] | 30 | esac |
| 31 | ! check_root && error_msg "You need to be root to install packages!" |
| 32 | # install_deps supports the above distributions. |
| 33 | # It will skip package installation on other distributions by default. |
| 34 | install_deps "${pkgs}" "${SKIP_INSTALL}" |
| 35 | |
| 36 | [ -d "${OUTPUT}" ] && mv "${OUTPUT}" "${OUTPUT}_$(date +%Y%m%d%H%M%S)" |
| 37 | mkdir -p "${OUTPUT}" |
| 38 | cd "${OUTPUT}" |
| 39 | |
| 40 | # Download and extract Kernel tarball. |
| 41 | major_version=$(echo "${VERSION}" | awk -F'.' '{print $1}') |
| 42 | wget "https://cdn.kernel.org/pub/linux/kernel/v${major_version}.x/linux-${VERSION}.tar.xz" |
| 43 | tar xf "linux-${VERSION}.tar.xz" |
| 44 | cd "linux-${VERSION}" |
| 45 | |
| 46 | # Compile Kernel with defconfig. |
| 47 | # It is native not cross compiling. |
| 48 | # It will not work on x86. |
| 49 | detect_abi |
| 50 | # shellcheck disable=SC2154 |
| 51 | case "${abi}" in |
| 52 | arm64|armeabi) |
| 53 | make defconfig |
| 54 | { time -p make -j"${NPROC}" Image; } 2>&1 | tee "${LOGFILE}" |
| 55 | ;; |
| 56 | *) |
| 57 | error_msg "Unsupported architecture!" |
| 58 | ;; |
| 59 | esac |
| 60 | |
| 61 | measurement="$(grep "^real" "${LOGFILE}" | awk '{print $2}')" |
| 62 | if egrep "arch/.*/boot/Image" "${LOGFILE}"; then |
| 63 | report_pass "kernel-compilation" |
| 64 | add_metric "kernel-compilation-time" "pass" "${measurement}" "seconds" |
| 65 | else |
| 66 | report_fail "kernel-compilation" |
| 67 | add_metric "kernel-compilation-time" "fail" "${measurement}" "seconds" |
| 68 | fi |
| 69 | |
| 70 | # Cleanup. |
| 71 | cd ../ |
| 72 | rm -rf "linux-${VERSION}"* |