aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAKASHI Takahiro <takahiro.akashi@linaro.org>2015-10-27 15:07:59 +0900
committerAKASHI Takahiro <takahiro.akashi@linaro.org>2015-10-27 15:07:59 +0900
commitafa6773301cb4c4b8276efd44836269dd094b622 (patch)
treeef0106cf98bd3b5d3426d70b72ae3f0600ad9306
parentef83659d22614296ea08838660f4bb1fa544f3fc (diff)
downloadkbuildtest-afa6773301cb4c4b8276efd44836269dd094b622.tar.gz
first workable version
-rwxr-xr-xkbuildtest.sh346
1 files changed, 346 insertions, 0 deletions
diff --git a/kbuildtest.sh b/kbuildtest.sh
index 1a24852..5b127d6 100755
--- a/kbuildtest.sh
+++ b/kbuildtest.sh
@@ -1 +1,347 @@
#!/bin/sh
+
+GETOPTARGS="a:A:b:C:e:hi:Il:no:P:v"
+ARGS=$(getopt ${GETOPTARGS} $*)
+
+function print_usage() {
+ echo "Usage: $(basename ${SELF}) [options] <commit>"
+ echo "options:"
+ echo " -a <config>...: forcedly add these configs"
+ echo " -A <ARCH>: overide ARCH"
+ echo " -b <build dir>: passed to 'make' as -o"
+ echo " -C <CROSS_COMPILE>: overide CROSS_COMPILE"
+ echo " -e <config>...: exclude these configs"
+ echo " -h : help messages"
+ echo " -i <config>...: include these configs"
+# echo " -I : inferior execution of loops"
+ echo " -l <log root dir>"
+ echo " -n : not executing, but creating environment"
+ echo " -o <flag>...: passed to 'make' as flags"
+# echo " -P <param file>: parameter file, only used with -I"
+ echo " -v : verbose messages"
+ echo "<commit>: commit object name to start from"
+}
+
+function parse_args() {
+ ECHO=true
+ set -- ${ARGS}
+ for i
+ do
+ case $i in
+ -a)
+ ADD_CONFIGS="$2"
+ ADD_CONFIGS=${ADD_CONFIGS//,/ }
+ shift 2;;
+ -A)
+ ARCH="$2"
+ shift 2;;
+ -b)
+ BUILDTMPDIR="$2"
+ shift 2;;
+ -C)
+ CROSS_COMPILE="$2"
+ shift 2;;
+ -e)
+ EXCL_CONFIGS="$2"
+ EXCL_CONFIGS=${EXCL_CONFIGS//,/ }
+ shift 2;;
+ -h)
+ print_usage
+ exit 2;;
+ -i)
+ INCL_CONFIGS="$2"
+ INCL_CONFIGS=${INCL_CONFIGS//,/ }
+ shift 2;;
+ -I)
+ iflag="y";
+ shift;;
+ -l)
+ LOGROOTDIR="$2"
+ shift 2;;
+ -n)
+ nflag="-n";
+ shift;;
+ -o)
+ OFLAGS="$2"
+ OFLAGS=${OFLAGS//,/ }
+ shift 2;;
+ -P)
+ PARAMFILE="$2"
+ shift 2;;
+ -v)
+ vflag="-v";
+ ECHO=echo
+ shift;;
+ --)
+ shift;
+ break;;
+ esac
+ done
+
+ # Infenior loop check
+ if [ ! -z ${iflag} ]
+ then
+ if [ -z ${PARAMFILE} ]
+ then
+ echo "Inferior loop, but no -P specified"
+ exit 2
+ else
+ return
+ fi
+ fi
+
+ # top level check
+ if [ $# -eq 0 ]
+ then
+ print_usage
+ exit 2
+ fi
+ COMMIT="$1"
+
+ case "${ARCH}" in
+ x86|arm64)
+ ;;
+ *)
+ echo "ARCH '${ARCH}' is invalid or NULL"
+ exit 2
+ esac
+
+ type ${CROSS_COMPILE}gcc > /dev/null 2>&1
+ if [ $? -ne 0 ]
+ then
+ echo "CC '${CROSS_COMPILE}gcc' not found"
+ exit 2
+ fi
+
+ if [ -z ${LOGROOTDIR} ]
+ then
+ LOGROOTDIR="/tmp"
+ elif [ ! -d ${LOGROOTDIR} ]
+ then
+ echo "Log dir '${LOGROOTDIR}' does not exist"
+ exit 2
+ fi
+
+ if [ -z ${BUILDTMPDIR} ]
+ then
+ BUILDTMPDIR="/tmp"
+ elif [ ! -d ${BUILDTMPDIR} ]
+ then
+ echo "Build dir '${BUILDTMPDIR}' does not exist"
+ exit 2
+ fi
+
+ if [ -z ${OFLAGS} ]
+ then
+ case "${ARCH}" in
+ x86)
+ OFLAGS=zImage;;
+ arm64)
+ OFLAGS=Image;;
+ esac
+ OFLAGS="-j$(nproc) ${OFLAGS}"
+ else
+ OFLAGS=${OFLAGS//,/ }
+ fi
+
+ ${ECHO} ARCH is ${ARCH}
+ ${ECHO} CC is ${CROSS_COMPILE}gcc
+}
+
+function setup_env {
+ DIRNAME=$(date +%y%m%d%H%M)_$$
+ LOGDIR=${LOGROOTDIR}/${DIRNAME}
+ PARAMFILE=${LOGDIR}/params
+ BUILDDIR=${BUILDTMPDIR}/${DIRNAME}_build
+
+ mkdir ${LOGDIR}
+ mkdir ${BUILDDIR}
+
+ ${ECHO} "Log directory is ${LOGDIR}"
+ ${ECHO} "Build directory is ${BUILDDIR}"
+}
+
+function save_env {
+ echo ADD_CONFIGS=\"${ADD_CONFIGS}\" >> ${PARAMFILE}
+ if [ ! -z ${ARCH} ] ; then
+ echo ARCH=${ARCH} >> ${PARAMFILE}
+ fi
+ if [ ! -z ${CROSS_COMPILE} ] ; then
+ echo CROSS_COMPILE=${CROSS_COMPILE} >> ${PARAMFILE}
+ fi
+ echo EXCL_CONFIGS=\"${EXCL_CONFIGS}\" >> ${PARAMFILE}
+ echo INCL_CONFIGS=\"${INCL_CONFIGS}\" >> ${PARAMFILE}
+ echo LOGDIR=${LOGDIR} >> ${PARAMFILE}
+ echo BUILDDIR=${BUILDDIR} >> ${PARAMFILE}
+ echo OFLAGS=\"${OFLAGS}\" >> ${PARAMFILE}
+# echo PATCHLIST="${PATCHLIST}" >> ${PARAMFILE}
+}
+
+function create_patchlist {
+# echo doing git log --format=%h ${COMMIT}..HEAD
+ PATCHLIST=$(git log --format=%h ${COMMIT}..HEAD 2> /dev/null)
+ if [ $? -ne 0 ] || [ -z "${PATCHLIST}" ]
+ then
+ echo doubious commit: ${COMMIT}
+ exit 2
+ fi
+ ${ECHO} Patches are ${PATCHLIST}
+}
+
+function do_combo {
+ if [ -z "$2" ]
+ then
+ ${ECHO} Creating config $p/$i
+ mkdir ${LOGDIR}/$p/$i
+ echo $1 | tr " " "\n" | sed 's/^\(CONFIG_[A-Za-z0-9_]*\)$/\1=y/' > ${LOGDIR}/$p/$i/kernel_config
+ i=$(expr $i + 1)
+
+ return
+ fi
+
+ local head=$(echo $2 | awk '{print $1}')
+ local tail=$(echo $2 | awk '{$1=""; print}')
+# echo 1111 - $1 2222 - $1
+# echo head - $head tail - $tail
+
+ if [ -z "${tail}" ]
+ then
+ ${ECHO} Creating config $p/$i
+ mkdir ${LOGDIR}/$p/$i
+ echo $1 $tail | tr " " "\n" | sed 's/^\(CONFIG_[A-Za-z0-9_]*\)$/\1=y/' > ${LOGDIR}/$p/$i/kernel_config
+ i=$(expr $i + 1)
+ ${ECHO} Creating config $p/$i
+ mkdir ${LOGDIR}/$p/$i
+ echo $1 $head $tail | tr " " "\n" | sed 's/^\(CONFIG_[A-Za-z0-9_]*\)$/\1=y/' > ${LOGDIR}/$p/$i/kernel_config
+ i=$(expr $i + 1)
+
+ return
+ fi
+
+# echo do_combo2 "$1" - "$tail"
+ do_combo "$1" "$tail"
+# echo do_combo1 "$1 $head" - "$tail"
+ do_combo "$1 $head" "$tail"
+}
+
+function create_configs {
+ ALLCONFIGS=${LOGDIR}/allconfigs
+ if [ ! -z "${ADD_CONFIGS}" ]
+ then
+ ADD_CONFIGS=$(echo ${ADD_CONFIGS} | tr " " "\n" | \
+ awk '{print "CONFIG_"$1}' | xargs echo)
+ fi
+ if [ ! -z "${INCL_CONFIGS}" ]
+ then
+ INCL_CONFIGS=$(echo ${INCL_CONFIGS} | tr " " "\n" | \
+ awk '{print "CONFIG_"$1}' | xargs echo)
+ fi
+
+ git diff $p^..$p | \
+ grep '^+' | grep CONFIG_ | \
+ sed -n ':again
+ s/\(.*\)CONFIG_\([A-Za-z0-9_]*\)\(.*\)/config_\2 \1/
+ t again
+ s/\(.*config_[A-Za-z0-9_]*\)\(.*\)/\1/
+ s/config_/CONFIG_/gp
+ ' - | (cat - ; echo ${INCL_CONFIGS}) | \
+ tr -s " " "\n" | sort | uniq | comm -23 - ${ALLCONFIGS} >> ${ALLCONFIGS}
+
+ for e in ${EXCL_CONFIGS}
+ do
+ sed -i -e "/CONFIG_$e/d" ${ALLCONFIGS}
+ done
+
+ i=1
+ do_combo "${ADD_CONFIGS}" "$(cat ${ALLCONFIGS})"
+}
+
+function run_build_test {
+# make O=${BUILDDIR} defconfig > ${LOGDIR}/$p/$c/config.log 2>&1
+ cat ${LOGDIR}/$p/$c/kernel_config >> ${BUILDDIR}/.config
+ make O=${BUILDDIR} olddefconfig > ${LOGDIR}/$p/$c/config.log 2>&1
+ if [ $? -ne 0 ]
+ then
+ echo $p/$c FAIL config >> ${LOGDIR}/results.log
+ return
+ fi
+ cp ${BUILDDIR}/.config ${LOGDIR}/$p/$c/kernel_config_build
+
+ if [ ! -z ${nflag} ]
+ then
+ return
+ fi
+
+ ${ECHO} Do make O=${BUILDDIR} ${OFLAGS}
+ make O=${BUILDDIR} ${OFLAGS} > ${LOGDIR}/$p/$c/build.log 2>&1
+ if [ $? -eq 0 ]
+ then
+ echo $p/$c PASS
+ else
+ echo $p/$c FAIL
+ fi >> ${LOGDIR}/results.log
+# ./baa
+ make O=${BUILDDIR} clean > ${LOGDIR}/$p/$c/clean.log 2>&1
+}
+
+function run_build_test_configs {
+ p=$(git log --format=%h -1)
+ ${ECHO} Processing patch $p
+ mkdir ${LOGDIR}/$p
+
+ create_configs
+
+ error=0
+ for c in $(seq 1 $(expr $i - 1))
+ do
+ run_build_test
+ if [ ${error} -ne 0 ]
+ then
+ return
+ fi
+ done
+}
+
+function run_build_test_loop {
+# for later git,
+# git rebase -x "${SELF}" -i ${COMMIT}
+# or
+# export GIT_EDITOR="../inscmd.sh \"exec ${SELF} ${nflag} ${vflag} -I -P ${PARAMFILE} \""
+ SED_CMD="/^pick /a exec ${SELF} ${nflag} ${vflag} -I -P ${PARAMFILE}"
+ export GIT_EDITOR="sed -i -e '${SED_CMD}'"
+# echo GIT_EIDTOR is ${GIT_EDITOR}
+ git rebase -i ${COMMIT} 2> /dev/null
+}
+
+#
+# main
+#
+SELF=$0
+parse_args
+
+# for inferior loop
+if [ ! -z ${iflag} ]
+then
+ trap "git rebase --abort" SIGINT SIGTERM
+
+ . ${PARAMFILE}
+ run_build_test_configs
+ if [ ${error} -eq 0 ]
+ then
+ exit 0
+ else
+ git rebase --abort
+ exit 1
+ fi
+fi
+
+# top level
+setup_env
+
+create_patchlist
+
+save_env
+
+run_build_test_loop
+
+exit 0