blob: b9b8d2abf3ea64206f1ac90a1369f0c3c0f176d8 [file] [log] [blame]
Chase Qifed78722016-11-24 12:27:59 +08001#!/bin/sh -e
2
3# shellcheck disable=SC1091
4. ../../lib/sh-test-lib
5OUTPUT="$(pwd)/output"
6RESULT_FILE="${OUTPUT}/result.txt"
7export RESULT_FILE
8LOGFILE="${OUTPUT}/kernel-compilation.txt"
9VERSION='4.4.34'
10NPROC=$(nproc)
11
12usage() {
13 echo "Usage: $0 [-v version] [-s true|false]" 1>&2
14 exit 1
15}
16
17while getopts "v:s:h" o; do
18 case "$o" in
19 v) VERSION="${OPTARG}" ;;
20 s) SKIP_INSTALL="${OPTARG}" ;;
21 h|*) usage ;;
22 esac
23done
24
25dist_name
26# shellcheck disable=SC2154
27case "${dist}" in
Nicolas Dechesneb7e38762017-01-25 12:07:08 +010028 debian|ubuntu) pkgs="wget time bc xz-utils build-essential" ;;
29 centos|fedora) pkgs="wget time bc xz gcc make" ;;
Chase Qifed78722016-11-24 12:27:59 +080030esac
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.
34install_deps "${pkgs}" "${SKIP_INSTALL}"
35
36[ -d "${OUTPUT}" ] && mv "${OUTPUT}" "${OUTPUT}_$(date +%Y%m%d%H%M%S)"
37mkdir -p "${OUTPUT}"
38cd "${OUTPUT}"
39
40# Download and extract Kernel tarball.
41major_version=$(echo "${VERSION}" | awk -F'.' '{print $1}')
42wget "https://cdn.kernel.org/pub/linux/kernel/v${major_version}.x/linux-${VERSION}.tar.xz"
43tar xf "linux-${VERSION}.tar.xz"
44cd "linux-${VERSION}"
45
46# Compile Kernel with defconfig.
47# It is native not cross compiling.
48# It will not work on x86.
49detect_abi
50# shellcheck disable=SC2154
51case "${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 ;;
59esac
60
61measurement="$(grep "^real" "${LOGFILE}" | awk '{print $2}')"
62if egrep "arch/.*/boot/Image" "${LOGFILE}"; then
63 report_pass "kernel-compilation"
64 add_metric "kernel-compilation-time" "pass" "${measurement}" "seconds"
65else
66 report_fail "kernel-compilation"
67 add_metric "kernel-compilation-time" "fail" "${measurement}" "seconds"
68fi
69
70# Cleanup.
71cd ../
72rm -rf "linux-${VERSION}"*