summaryrefslogtreecommitdiff
path: root/build-linux.sh
blob: bd39fa53f29c6d13e5d39779a5630338f609c43b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/bin/bash

# cross compile the Linux kernel with given cross toolchain
set -ex

usage()
{
    echo "Usage: $0 toolchain_dir target boot={true|false} [userconfig] [repo] [branch]"
    exit 1
}

toolchain_dir=$1
target=$2
case "$3" in
    boot=true|boot=false)
	boot=$(echo $3 | sed 's/boot=//')
	;;
    *)
	echo "boot option incorrect: $3"
	usage
	;;
esac
userconfig=$4
repo=$5
branch=$6

if [ x"$toolchain_dir" = x ]; then usage; fi
if [ x"$target" = x ]; then usage; fi

rundir="$(pwd -P)"
mydir="$(dirname $0)"
cd "${mydir}"
mydir="$(pwd)"
cd ${rundir}

rm -rf app_linux
mkdir app_linux
cd app_linux

git_reference_dir=/home/tcwg-buildslave/snapshots-ref
git_reference_opt=
if test -d "${git_reference_dir}/linux.git"; then
    git_reference_opt="--reference ${git_reference_dir}/linux.git"
fi

linux_prefix=git://git.kernel.org/pub/scm/linux/kernel/git
# Default to Linus Torvalds' tree
linux_git=${linux_prefix}/torvalds/linux.git

if [ x"${repo}" != x ]; then
    linux_git=${linux_prefix}/${repo}.git
fi

git clone ${git_reference_opt} ${linux_git} linux

case ${target} in
    arm*)
	arch=arm
	;;
    aarch64*)
	arch=arm64
	;;
    *)
	echo Unsupported target
	return 1
	;;
esac

cd linux

[ "x${branch}" = "x" ] && branch=master
git checkout ${branch}

# Show the latest commit, to help debug if needed
git show

# configs default to allmodconfig
# If the user asked for "all", and build the list of supported
# configs and build them all sequentially
case "x${userconfig}" in
    xall)
	configs="$(cd arch/${arch}/configs ; echo *defconfig)"
	;;
    x)
	configs=allmodconfig
	;;
    *)
	configs=${userconfig}_defconfig
	;;
esac

jobs=
if $boot ; then
    # To get LAVA_XXX variables
    . ${mydir}/.env

    sudo apt-get update
    sudo apt-get install -y --no-install-recommends python3-requests python3-yaml python3-jinja2
fi

lava_boot()
{
    config=$1
    job=

    # Use an external file to pass lava_job_id, to avoid having to
    # parse various possible error messages from linaro-cp.py,
    # yaml-to-json.py, lava-tool, ...
    echo > lava_job_id

    case ${config} in
	multi_v7_defconfig)
	    DEVICE_TYPE=beaglebone-black
	    DTB=arch/arm/boot/dts/am335x-boneblack.dtb
	    KERNEL=arch/arm/boot/zImage
	    ;;
	*)
	    echo "$0: Unsupported config: ${config}"
	    echo 0 > lava_job_id
	    return
	    ;;
    esac

    # lava_boot.py works only when started from its own dir
    pushd ${mydir}
    python3 ./lava-boot.py --level DEBUG --board ${DEVICE_TYPE} --linux-image app_linux/linux/$KERNEL --linux-dtb app_linux/linux/$DTB starttest > lava.stdout || true
    echo "Return code: $?"
    echo "Output:"
    cat lava.stdout
    result=$(grep "INFO job" lava.stdout)
    popd

    case "$result" in
	*"INFO job"*)
	    job=`echo $result | awk '{print $5;}'`
	    ;;
	*)
	    echo "Error submitting job: $result"
	    ;;
    esac

    echo $job > lava_job_id
}

status=0
lava_status=0
for config in ${configs}
do
    echo Building CONFIG=$config
    this_status=0
    make ARCH=${arch} CROSS_COMPILE=${toolchain_dir}/bin/${target}- mrproper
    make ARCH=${arch} CROSS_COMPILE=${toolchain_dir}/bin/${target}- ${config}
    make ARCH=${arch} CROSS_COMPILE=${toolchain_dir}/bin/${target}- all -j16 || this_status=$?
    if [ ${this_status} -ne 0 ]; then
	# Rebuild without parallelism to make errors easier to read
	make ARCH=${arch} CROSS_COMPILE=${toolchain_dir}/bin/${target}- all -j1 || true
	echo "CONFIG=$config FAILED to build."
	status=1
	break
    fi

    # Handle boot test via lava, if requested. Put the job in the lava
    # queue, we collect the results later
    if $boot ; then
	lava_boot $config
	job=$(cat lava_job_id)
	case ${job} in
	    "")
		status=1
		lava_status=1
		;;
	    0)
		# Special case where we don't support the config to
		# boot, we do not want to report an error
		;;
	    *)
		jobs="${jobs} ${job}"
		;;
	esac
    fi
done

# Gather lava jobs results, if requested.
if $boot ; then

    global_lava_result=PASS
    [ $lava_status -eq 1 ] && global_lava_result=FAILED
    failed_jobs=
    for job in $jobs
    do
	this_lava_result=0
	python3 ${mydir}/lava-boot.py --level DEBUG --job_id ${job} wait || this_lava_result=$?

	# If the job completed, check that the individual tests were successful
	if [ "$this_lava_result" = "0" ]; then
	    rm -f csv
	    wget https://${LAVA_SERVER}/results/${job}/csv
	    # linux-linaro-ubuntu-lsb_release fails because lsb_release is not
	    # in the rootfs, so ignore this failure
	    cat csv | grep -v linux-linaro-ubuntu-lsb_release | awk -F, '{print $3;}' | grep -i fail && this_lava_result=1
	fi

	if [ "$this_lava_result" = "1" ]; then
	    global_lava_result=FAILED
	    failed_jobs="${failed_jobs} $job"
	fi
    done

    echo "LAVA agregated results: $global_lava_result"

    if [ "$global_lava_result" = "FAILED" ]; then
	status=1
	echo "These jobs failed:"
	for job in ${failed_jobs}
	do
	    echo ${job} https://${LAVA_SERVER}/results/${job}
	done
    fi
fi

exit $status