devtools: add ABI checks
[dpdk.git] / devtools / test-build.sh
1 #! /bin/sh -e
2 # SPDX-License-Identifier: BSD-3-Clause
3 # Copyright 2015 6WIND S.A.
4
5 default_path=$PATH
6
7 # Load config options:
8 # - ARMV8_CRYPTO_LIB_PATH
9 # - DPDK_ABI_REF_DIR
10 # - DPDK_ABI_REF_VERSION
11 # - DPDK_BUILD_TEST_CONFIGS (defconfig1+option1+option2 defconfig2)
12 # - DPDK_BUILD_TEST_DIR
13 # - DPDK_DEP_ARCHIVE
14 # - DPDK_DEP_BPF (y/[n])
15 # - DPDK_DEP_CFLAGS
16 # - DPDK_DEP_ELF (y/[n])
17 # - DPDK_DEP_ISAL (y/[n])
18 # - DPDK_DEP_JSON (y/[n])
19 # - DPDK_DEP_LDFLAGS
20 # - DPDK_DEP_MLX (y/[n])
21 # - DPDK_DEP_NFB (y/[n])
22 # - DPDK_DEP_NUMA ([y]/n)
23 # - DPDK_DEP_PCAP (y/[n])
24 # - DPDK_DEP_SSL (y/[n])
25 # - DPDK_DEP_IPSEC_MB (y/[n])
26 # - DPDK_DEP_SZE (y/[n])
27 # - DPDK_DEP_ZLIB (y/[n])
28 # - DPDK_MAKE_JOBS (int)
29 # - DPDK_NOTIFY (notify-send)
30 # - FLEXRAN_SDK
31 # - LIBMUSDK_PATH
32 # - LIBSSO_SNOW3G_PATH
33 # - LIBSSO_KASUMI_PATH
34 # - LIBSSO_ZUC_PATH
35 devtools_dir=$(dirname $(readlink -f $0))
36 . $devtools_dir/load-devel-config
37
38 print_usage () {
39         echo "usage: $(basename $0) [-h] [-jX] [-s] [config1 [config2] ...]]"
40 }
41
42 print_help () {
43         echo 'Test building several targets with different options'
44         echo
45         print_usage
46         cat <<- END_OF_HELP
47
48         options:
49                 -h    this help
50                 -jX   use X parallel jobs in "make"
51                 -s    short test only first config without tests|examples|doc
52                 -v    verbose build
53
54         config: defconfig[[~][+]option1[[~][+]option2...]]
55                 Example: x86_64-native-linux-gcc+debug~RXTX_CALLBACKS
56                 The lowercase options are defined inside $(basename $0).
57                 The uppercase options can be the end of a defconfig option
58                 to enable if prefixed with '+' or to disable if prefixed with '~'.
59                 Default is to automatically enable most of the options.
60                 The external dependencies are setup with DPDK_DEP_* variables.
61                 If no config on command line, DPDK_BUILD_TEST_CONFIGS is used.
62         END_OF_HELP
63 }
64
65 [ -z $MAKE ] && command -v gmake > /dev/null && MAKE=gmake
66 [ -z $MAKE ] && command -v make > /dev/null && MAKE=make
67 [ -z $MAKE ] && echo "Cannot find make or gmake" && exit 1
68
69 J=$DPDK_MAKE_JOBS
70 builds_dir=${DPDK_BUILD_TEST_DIR:-.}
71 short=false
72 unset verbose
73 # for ABI checks, we need debuginfo
74 test_cflags="-Wfatal-errors -g"
75 while getopts hj:sv ARG ; do
76         case $ARG in
77                 j ) J=$OPTARG ;;
78                 s ) short=true ;;
79                 v ) verbose='V=1' ;;
80                 h ) print_help ; exit 0 ;;
81                 ? ) print_usage ; exit 1 ;;
82         esac
83 done
84 shift $(($OPTIND - 1))
85 configs=${*:-$DPDK_BUILD_TEST_CONFIGS}
86
87 success=false
88 on_exit ()
89 {
90         if $success ; then
91                 [ "$DPDK_NOTIFY" != notify-send ] || \
92                         notify-send -u low --icon=dialog-information 'DPDK build' 'finished'
93         elif [ -z "$signal" ] ; then
94                 [ -z "$dir" ] || echo "failed to build $dir" >&2
95                 [ "$DPDK_NOTIFY" != notify-send ] || \
96                         notify-send -u low --icon=dialog-error 'DPDK build' 'failed'
97         fi
98 }
99 # catch manual interrupt to ignore notification
100 trap "signal=INT ; trap - INT ; kill -INT $$" INT
101 # notify result on exit
102 trap on_exit EXIT
103
104 cd $devtools_dir/..
105
106 reset_env ()
107 {
108         export PATH=$default_path
109         unset CROSS
110         unset DPDK_DEP_ARCHIVE
111         unset DPDK_DEP_BPF
112         unset DPDK_DEP_CFLAGS
113         unset DPDK_DEP_ELF
114         unset DPDK_DEP_ISAL
115         unset DPDK_DEP_JSON
116         unset DPDK_DEP_LDFLAGS
117         unset DPDK_DEP_MLX
118         unset DPDK_DEP_NFB
119         unset DPDK_DEP_NUMA
120         unset DPDK_DEP_PCAP
121         unset DPDK_DEP_SSL
122         unset DPDK_DEP_IPSEC_MB
123         unset DPDK_DEP_SZE
124         unset DPDK_DEP_ZLIB
125         unset ARMV8_CRYPTO_LIB_PATH
126         unset FLEXRAN_SDK
127         unset LIBMUSDK_PATH
128         unset LIBSSO_SNOW3G_PATH
129         unset LIBSSO_KASUMI_PATH
130         unset LIBSSO_ZUC_PATH
131         unset PQOS_INSTALL_PATH
132 }
133
134 config () # <directory> <target> <options>
135 {
136         reconfig=false
137         if git rev-parse 2>&- && [ -n "$(git diff HEAD~ -- config)" ] ; then
138                 echo 'Default config may have changed'
139                 reconfig=true
140         fi
141         if [ ! -e $1/.config ] || $reconfig ; then
142                 echo "================== Configure $1"
143                 ${MAKE} T=$2 O=$1 config
144
145                 echo 'Customize configuration'
146                 # Built-in options (lowercase)
147                 ! echo $3 | grep -q '+default' || \
148                 sed -ri="" 's,(RTE_MACHINE=")native,\1default,' $1/.config
149                 echo $3 | grep -q '+next' || \
150                 sed -ri=""           's,(NEXT_ABI=)y,\1n,' $1/.config
151                 ! echo $3 | grep -q '+shared' || \
152                 sed -ri=""         's,(SHARED_LIB=)n,\1y,' $1/.config
153                 ! echo $3 | grep -q '+debug' || ( \
154                 sed -ri=""  's,(RTE_LOG_DP_LEVEL=).*,\1RTE_LOG_DEBUG,' $1/.config
155                 sed -ri=""           's,(_DEBUG.*=)n,\1y,' $1/.config
156                 sed -ri=""  's,(_STAT)([S_].*=|=)n,\1\2y,' $1/.config
157                 sed -ri="" 's,(TEST_PMD_RECORD_.*=)n,\1y,' $1/.config )
158
159                 # Automatic configuration
160                 test "$DPDK_DEP_NUMA" != n || \
161                 sed -ri=""             's,(NUMA.*=)y,\1n,' $1/.config
162                 sed -ri=""    's,(LIBRTE_IEEE1588=)n,\1y,' $1/.config
163                 sed -ri=""             's,(BYPASS=)n,\1y,' $1/.config
164                 test "$DPDK_DEP_ARCHIVE" != y || \
165                 sed -ri=""       's,(RESOURCE_TAR=)n,\1y,' $1/.config
166                 test "$DPDK_DEP_BPF" != y || \
167                 sed -ri=""         's,(PMD_AF_XDP=)n,\1y,' $1/.config
168                 test "$DPDK_DEP_ISAL" != y || \
169                 sed -ri=""           's,(PMD_ISAL=)n,\1y,' $1/.config
170                 test "$DPDK_DEP_MLX" != y || \
171                 sed -ri=""           's,(MLX._PMD=)n,\1y,' $1/.config
172                 test "$DPDK_DEP_NFB" != y || \
173                 sed -ri=""            's,(NFB_PMD=)n,\1y,' $1/.config
174                 test "$DPDK_DEP_SZE" != y || \
175                 sed -ri=""       's,(PMD_SZEDATA2=)n,\1y,' $1/.config
176                 test "$DPDK_DEP_ZLIB" != y || \
177                 sed -ri=""          's,(BNX2X_PMD=)n,\1y,' $1/.config
178                 test "$DPDK_DEP_ZLIB" != y || \
179                 sed -ri=""           's,(PMD_ZLIB=)n,\1y,' $1/.config
180                 test "$DPDK_DEP_ZLIB" != y || \
181                 sed -ri=""   's,(COMPRESSDEV_TEST=)n,\1y,' $1/.config
182                 test "$DPDK_DEP_PCAP" != y || \
183                 sed -ri=""               's,(PCAP=)n,\1y,' $1/.config
184                 test -z "$ARMV8_CRYPTO_LIB_PATH" || \
185                 sed -ri=""   's,(PMD_ARMV8_CRYPTO=)n,\1y,' $1/.config
186                 test "$DPDK_DEP_IPSEC_MB" != y || \
187                 sed -ri=""       's,(PMD_AESNI_MB=)n,\1y,' $1/.config
188                 test "$DPDK_DEP_IPSEC_MB" != y || \
189                 sed -ri=""      's,(PMD_AESNI_GCM=)n,\1y,' $1/.config
190                 test -z "$LIBSSO_SNOW3G_PATH" || \
191                 sed -ri=""         's,(PMD_SNOW3G=)n,\1y,' $1/.config
192                 test -z "$LIBSSO_KASUMI_PATH" || \
193                 sed -ri=""         's,(PMD_KASUMI=)n,\1y,' $1/.config
194                 test -z "$LIBSSO_ZUC_PATH" || \
195                 sed -ri=""            's,(PMD_ZUC=)n,\1y,' $1/.config
196                 test "$DPDK_DEP_SSL" != y || \
197                 sed -ri=""            's,(PMD_CCP=)n,\1y,' $1/.config
198                 test "$DPDK_DEP_SSL" != y || \
199                 sed -ri=""        's,(PMD_OPENSSL=)n,\1y,' $1/.config
200                 test "$DPDK_DEP_SSL" != y || \
201                 sed -ri=""            's,(QAT_SYM=)n,\1y,' $1/.config
202                 test -z "$FLEXRAN_SDK" || \
203                 sed -ri=""     's,(BBDEV_TURBO_SW=)n,\1y,' $1/.config
204                 sed -ri=""           's,(SCHED_.*=)n,\1y,' $1/.config
205                 test -z "$LIBMUSDK_PATH" || \
206                 sed -ri=""   's,(PMD_MVSAM_CRYPTO=)n,\1y,' $1/.config
207                 test -z "$LIBMUSDK_PATH" || \
208                 sed -ri=""          's,(MVPP2_PMD=)n,\1y,' $1/.config
209                 test -z "$LIBMUSDK_PATH" || \
210                 sed -ri=""         's,(MVNETA_PMD=)n,\1y,' $1/.config
211                 test "$DPDK_DEP_ELF" != y || \
212                 sed -ri=""            's,(BPF_ELF=)n,\1y,' $1/.config
213                 test "$DPDK_DEP_JSON" != y || \
214                 sed -ri=""          's,(TELEMETRY=)n,\1y,' $1/.config
215                 build_config_hook $1 $2 $3
216
217                 # Explicit enabler/disabler (uppercase)
218                 for option in $(echo $3 | sed 's,[~+], &,g') ; do
219                         pattern=$(echo $option | cut -c2-)
220                         if echo $option | grep -q '^~' ; then
221                                 sed -ri="" "s,($pattern=)y,\1n," $1/.config
222                         elif echo $option | grep -q '^+' ; then
223                                 sed -ri="" "s,($pattern=)n,\1y," $1/.config
224                         fi
225                 done
226         fi
227 }
228
229 # default empty hook to override in devel config
230 build_config_hook () # <directory> <target> <options>
231 {
232         :
233 }
234
235 for conf in $configs ; do
236         target=$(echo $conf | sed 's,[~+].*,,')
237         # reload config with DPDK_TARGET set
238         DPDK_TARGET=$target
239         reset_env
240         . $devtools_dir/load-devel-config
241
242         options=$(echo $conf | sed 's,[^~+]*,,')
243         dir=$builds_dir/$conf
244         config $dir $target $options
245
246         echo "================== Build $conf"
247         ${MAKE} -j$J EXTRA_CFLAGS="$test_cflags $DPDK_DEP_CFLAGS" \
248                 EXTRA_LDFLAGS="$DPDK_DEP_LDFLAGS" $verbose O=$dir
249         ! $short || break
250         export RTE_TARGET=$target
251         rm -rf $dir/install
252         ${MAKE} install O=$dir DESTDIR=$dir/install prefix=
253         echo "================== Build examples for $conf"
254         export RTE_SDK=$(readlink -f $dir)/install/share/dpdk
255         ln -sTf $(pwd)/lib $RTE_SDK/lib # workaround for vm_power_manager
256         ${MAKE} -j$J -sC examples \
257                 EXTRA_LDFLAGS="$DPDK_DEP_LDFLAGS" $verbose \
258                 O=$(readlink -f $dir)/examples
259         unset RTE_TARGET
260         if [ -n "$DPDK_ABI_REF_VERSION" ]; then
261                 abirefdir=${DPDK_ABI_REF_DIR:-reference}/$DPDK_ABI_REF_VERSION
262                 if [ ! -d $abirefdir/$conf ]; then
263                         # clone current sources
264                         if [ ! -d $abirefdir/src ]; then
265                                 git clone --local --no-hardlinks \
266                                         --single-branch \
267                                         -b $DPDK_ABI_REF_VERSION \
268                                         $(pwd) $abirefdir/src
269                         fi
270
271                         cd $abirefdir/src
272
273                         rm -rf $abirefdir/build
274                         config $abirefdir/build $target $options
275
276                         echo -n "================== Build $conf "
277                         echo "($DPDK_ABI_REF_VERSION)"
278                         ${MAKE} -j$J \
279                                 EXTRA_CFLAGS="$test_cflags $DPDK_DEP_CFLAGS" \
280                                 EXTRA_LDFLAGS="$DPDK_DEP_LDFLAGS" $verbose \
281                                 O=$abirefdir/build
282                         export RTE_TARGET=$target
283                         ${MAKE} install O=$abirefdir/build \
284                                 DESTDIR=$abirefdir/$conf \
285                                 prefix=
286                         unset RTE_TARGET
287                         $devtools_dir/gen-abi.sh $abirefdir/$conf
288
289                         # back to current workdir
290                         cd $devtools_dir/..
291                 fi
292
293                 echo "================== Check ABI $conf"
294                 $devtools_dir/gen-abi.sh $dir/install
295                 $devtools_dir/check-abi.sh $abirefdir/$conf $dir/install
296         fi
297         echo "################## $conf done."
298         unset dir
299 done
300
301 if ! $short ; then
302         mkdir -p .check
303         echo "================== Build doxygen HTML API"
304         ${MAKE} doc-api-html >/dev/null 2>.check/doc.txt
305         echo "================== Build sphinx HTML guides"
306         ${MAKE} doc-guides-html >/dev/null 2>>.check/doc.txt
307         echo "================== Check docs"
308         diff -u /dev/null .check/doc.txt
309 fi
310
311 success=true