4 # lustre/lustre/tests/kbuild
6 # Copyright (C) 2005 Cluster File Systems, Inc.
8 # Author: Nikita Danilov <nikita@clusterfs.com>
10 # This file is part of Lustre, http://www.lustre.org.
12 # Lustre is free software; you can redistribute it and/or modify it
13 # under the terms of version 2 of the GNU General Public License as
14 # published by the Free Software Foundation.
16 # Lustre is distributed in the hope that it will be useful, but
17 # WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 # General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with Lustre; if not, write to the Free Software Foundation,
23 # Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 # kbuild is a swiss-army linux kernel build script. Its purpose is to run
27 # automated kernel builds on given target file system (presumably Lustre) to
28 # measure file system performance and, occasionally, correctness.
30 # Usual kernel build doesn't not stress file system, because the bottleneck
31 # is CPU consumption by the user level (compiler). To work around this,
32 # kbuild uses ccache(1) that eliminates most of CPU load by the compiler,
33 # once the cache is primed.
40 $pname --- builds a kernel.
42 Usage: $pname [-s <source>] \\
44 [-m <make-options>] \\
47 [-c <config-target>] \\
51 -s <source> source of kernel to build. This can be:
55 . tar.gz, .tgz, or .tar.bz2 archive;
57 . ftp or http URL to the source archive;
61 -t <target> target directory, where build process takes place.
64 -m <make-options> additional options supplied to each make invocation.
67 -c <config-target> kernel makefile target to invoke to configure kernel
68 (defconfig, allyesconfig, allmodconfig, etc.). This
69 option conflicts with -C <config-file>. Defaults to
72 -C <config-file> use given .config file as kernel configuration. Not
75 -S skip kernel copying: kernel source is already unpacked
76 in $target. Defaults to false.
78 -v increase verbosity level.
82 $pname -s /usr/src/linux-2.6.10-base.tar.gz -t /mnt/lustre2 \\
83 -m -j4 -C /usr/src/.config.fc3
85 $pname -s ftp://ftp.clusterfs.com/pub/kernels/fc3-2.6/linux-2.6.10-base.tgz \\
86 -m -j4 -c defconfig -vvv
95 # The output of kbuild are times as reported by time. First line is for build
96 # that fills the ccache cache (that is also located on the target file
97 # system). Consecutive times are repeated builds that reuse ccache
98 # cache. Number of iteration is set through -i option. Example output:
100 # R 783.757 S 319.615 U 281.720
101 # R 540.823 S 277.387 U 54.168
102 # R 557.762 S 263.566 U 53.222
103 # R 543.877 S 278.569 U 54.412
104 # R 544.455 S 279.096 U 53.697
105 # R 545.445 S 280.546 U 53.943
109 # Kernel builds can be quite slow as example output above shows. Create your
110 # own .config file to build smaller kernel.
114 OPTVAL=`getopt -o s:m:i:t:vc:SC:h -n 'kbuild' -- "$@"` || usage
116 # Note the quotes around `$OPTVAL': they are essential!
117 eval set -- "$OPTVAL"
137 lfile=/tmp/$pname-tmp-log.$$
172 verbose=$(($verbose + 1))
183 echo "Internal error!"
189 [ $verbose -ge $LOG_ALL ] && set -x
194 echo WARNING $pname: $*
203 warning $* ... failing.
213 if [ $verbose -ge $level ] ;then
224 echo ---- start: $(date +"%Y-%m-%d %H:%M:%S") ---- >> $lfile
226 echo "ARG: $i" >> $lfile
228 log $LOG_PROGRESS "Running '$cmd'..."
229 $cmd >>$lfile 2>&1 || \
230 fail 1 "Errors while running '$cmd'. See $lfile for transcript"
231 log $LOG_PROGRESS "Finished '$cmd'."
232 echo ---- done: $(date +"%Y-%m-%d %H:%M:%S") ---- >> $lfile
240 export TIMEFORMAT="R %3R S %3S U %3U"
244 ccache_dir=$tgt/ccache_dir
245 cc_script=$tgt/cc_script
247 which ccache >/dev/null || fail 2 "No ccache found"
248 mkdir -p $ccache_dir || fail 3 "Cannot create $ccache_dir"
250 export CCACHE_DIR=$ccache_dir
254 cd $tgt || fail 4 "Cannot cd into $tgt"
256 echo '#! /bin/sh' > $cc_script || fail 5 "Cannot write into $cc_script"
257 echo 'ccache cc $*' >> $cc_script || fail 6 "Cannot append to $cc_script"
258 chmod u+rx $cc_script || fail 7 "Cannot chmod u+rx $cc_script"
260 cc_opt="CC=$cc_script"
262 [ $verbose -ge $LOG_TRACE ] && vopt=-v
264 if [ $skip_copy -eq 0 ] ;then
274 log $LOG_PROGRESS "Copying directory $src into $tgt"
289 cd linux-* || fail 20 "Cannot change to linux-* from $PWD"
293 doquiet make $mopt mrproper
294 if [ x$conf_file = x ] ;then
295 doquiet make $mopt $mconfig
297 cp $conf_file .config || fail 8 "Cannot copy $conf_file"
299 doquiet make $mopt oldconfig
302 dotime doquiet make $mopt $cc_opt bzImage modules
305 log $LOG_PROGRESS Fill the cache...
309 for i in $(seq 1 $it) ;do
310 log $LOG_PROGRESS Iteration $i...