New upstream version 18.08
[deb_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_BUILD_TEST_CONFIGS (defconfig1+option1+option2 defconfig2)
10 # - DPDK_DEP_ARCHIVE
11 # - DPDK_DEP_CFLAGS
12 # - DPDK_DEP_ISAL (y/[n])
13 # - DPDK_DEP_LDFLAGS
14 # - DPDK_DEP_MLX (y/[n])
15 # - DPDK_DEP_NUMA ([y]/n)
16 # - DPDK_DEP_PCAP (y/[n])
17 # - DPDK_DEP_SSL (y/[n])
18 # - DPDK_DEP_IPSEC_MB (y/[n])
19 # - DPDK_DEP_SZE (y/[n])
20 # - DPDK_DEP_ZLIB (y/[n])
21 # - DPDK_MAKE_JOBS (int)
22 # - DPDK_NOTIFY (notify-send)
23 # - FLEXRAN_SDK
24 # - LIBMUSDK_PATH
25 # - LIBSSO_SNOW3G_PATH
26 # - LIBSSO_KASUMI_PATH
27 # - LIBSSO_ZUC_PATH
28 . $(dirname $(readlink -e $0))/load-devel-config
29
30 print_usage () {
31         echo "usage: $(basename $0) [-h] [-jX] [-s] [config1 [config2] ...]]"
32 }
33
34 print_help () {
35         echo 'Test building several targets with different options'
36         echo
37         print_usage
38         cat <<- END_OF_HELP
39
40         options:
41                 -h    this help
42                 -jX   use X parallel jobs in "make"
43                 -s    short test only first config without tests|examples|doc
44                 -v    verbose build
45
46         config: defconfig[[~][+]option1[[~][+]option2...]]
47                 Example: x86_64-native-linuxapp-gcc+debug~RXTX_CALLBACKS
48                 The lowercase options are defined inside $(basename $0).
49                 The uppercase options can be the end of a defconfig option
50                 to enable if prefixed with '+' or to disable if prefixed with '~'.
51                 Default is to automatically enable most of the options.
52                 The external dependencies are setup with DPDK_DEP_* variables.
53                 If no config on command line, DPDK_BUILD_TEST_CONFIGS is used.
54         END_OF_HELP
55 }
56
57 J=$DPDK_MAKE_JOBS
58 short=false
59 unset verbose
60 maxerr=-Wfatal-errors
61 while getopts hj:sv ARG ; do
62         case $ARG in
63                 j ) J=$OPTARG ;;
64                 s ) short=true ;;
65                 v ) verbose='V=1' ;;
66                 h ) print_help ; exit 0 ;;
67                 ? ) print_usage ; exit 1 ;;
68         esac
69 done
70 shift $(($OPTIND - 1))
71 configs=${*:-$DPDK_BUILD_TEST_CONFIGS}
72
73 success=false
74 on_exit ()
75 {
76         if $success ; then
77                 [ "$DPDK_NOTIFY" != notify-send ] || \
78                         notify-send -u low --icon=dialog-information 'DPDK build' 'finished'
79         elif [ -z "$signal" ] ; then
80                 [ -z "$dir" ] || echo "failed to build $dir" >&2
81                 [ "$DPDK_NOTIFY" != notify-send ] || \
82                         notify-send -u low --icon=dialog-error 'DPDK build' 'failed'
83         fi
84 }
85 # catch manual interrupt to ignore notification
86 trap "signal=INT ; trap - INT ; kill -INT $$" INT
87 # notify result on exit
88 trap on_exit EXIT
89
90 cd $(dirname $(readlink -m $0))/..
91
92 reset_env ()
93 {
94         export PATH=$default_path
95         unset CROSS
96         unset DPDK_DEP_ARCHIVE
97         unset DPDK_DEP_CFLAGS
98         unset DPDK_DEP_ISAL
99         unset DPDK_DEP_LDFLAGS
100         unset DPDK_DEP_MLX
101         unset DPDK_DEP_NUMA
102         unset DPDK_DEP_PCAP
103         unset DPDK_DEP_SSL
104         unset DPDK_DEP_IPSEC_MB
105         unset DPDK_DEP_SZE
106         unset DPDK_DEP_ZLIB
107         unset ARMV8_CRYPTO_LIB_PATH
108         unset FLEXRAN_SDK
109         unset LIBMUSDK_PATH
110         unset LIBSSO_SNOW3G_PATH
111         unset LIBSSO_KASUMI_PATH
112         unset LIBSSO_ZUC_PATH
113         unset PQOS_INSTALL_PATH
114 }
115
116 config () # <directory> <target> <options>
117 {
118         reconfig=false
119         if git rev-parse 2>&- && [ -n "$(git diff HEAD~ -- config)" ] ; then
120                 echo 'Default config may have changed'
121                 reconfig=true
122         fi
123         if [ ! -e $1/.config ] || $reconfig ; then
124                 echo "================== Configure $1"
125                 make T=$2 O=$1 config
126
127                 echo 'Customize configuration'
128                 # Built-in options (lowercase)
129                 ! echo $3 | grep -q '+default' || \
130                 sed -ri 's,(RTE_MACHINE=")native,\1default,' $1/.config
131                 echo $3 | grep -q '+next' || \
132                 sed -ri           's,(NEXT_ABI=)y,\1n,' $1/.config
133                 ! echo $3 | grep -q '+shared' || \
134                 sed -ri         's,(SHARED_LIB=)n,\1y,' $1/.config
135                 ! echo $3 | grep -q '+debug' || ( \
136                 sed -ri  's,(RTE_LOG_DP_LEVEL=).*,\1RTE_LOG_DEBUG,' $1/.config
137                 sed -ri           's,(_DEBUG.*=)n,\1y,' $1/.config
138                 sed -ri            's,(_STAT.*=)n,\1y,' $1/.config
139                 sed -ri 's,(TEST_PMD_RECORD_.*=)n,\1y,' $1/.config )
140
141                 # Automatic configuration
142                 test "$DPDK_DEP_NUMA" != n || \
143                 sed -ri             's,(NUMA.*=)y,\1n,' $1/.config
144                 sed -ri    's,(LIBRTE_IEEE1588=)n,\1y,' $1/.config
145                 sed -ri             's,(BYPASS=)n,\1y,' $1/.config
146                 test "$DPDK_DEP_ARCHIVE" != y || \
147                 sed -ri       's,(RESOURCE_TAR=)n,\1y,' $1/.config
148                 test "$DPDK_DEP_ISAL" != y || \
149                 sed -ri           's,(ISAL_PMD=)n,\1y,' $1/.config
150                 test "$DPDK_DEP_MLX" != y || \
151                 sed -ri           's,(MLX._PMD=)n,\1y,' $1/.config
152                 test "$DPDK_DEP_SZE" != y || \
153                 sed -ri       's,(PMD_SZEDATA2=)n,\1y,' $1/.config
154                 test "$DPDK_DEP_ZLIB" != y || \
155                 sed -ri          's,(BNX2X_PMD=)n,\1y,' $1/.config
156                 test "$DPDK_DEP_ZLIB" != y || \
157                 sed -ri   's,(COMPRESSDEV_TEST=)n,\1y,' $1/.config
158                 test "$DPDK_DEP_PCAP" != y || \
159                 sed -ri               's,(PCAP=)n,\1y,' $1/.config
160                 test -z "$ARMV8_CRYPTO_LIB_PATH" || \
161                 sed -ri   's,(PMD_ARMV8_CRYPTO=)n,\1y,' $1/.config
162                 test "$DPDK_DEP_IPSEC_MB" != y || \
163                 sed -ri       's,(PMD_AESNI_MB=)n,\1y,' $1/.config
164                 test "$DPDK_DEP_IPSEC_MB" != y || \
165                 sed -ri      's,(PMD_AESNI_GCM=)n,\1y,' $1/.config
166                 test -z "$LIBSSO_SNOW3G_PATH" || \
167                 sed -ri         's,(PMD_SNOW3G=)n,\1y,' $1/.config
168                 test -z "$LIBSSO_KASUMI_PATH" || \
169                 sed -ri         's,(PMD_KASUMI=)n,\1y,' $1/.config
170                 test -z "$LIBSSO_ZUC_PATH" || \
171                 sed -ri            's,(PMD_ZUC=)n,\1y,' $1/.config
172                 test "$DPDK_DEP_SSL" != y || \
173                 sed -ri            's,(PMD_CCP=)n,\1y,' $1/.config
174                 test "$DPDK_DEP_SSL" != y || \
175                 sed -ri        's,(PMD_OPENSSL=)n,\1y,' $1/.config
176                 test "$DPDK_DEP_SSL" != y || \
177                 sed -ri            's,(PMD_QAT=)n,\1y,' $1/.config
178                 test -z "$FLEXRAN_SDK" || \
179                 sed -ri     's,(BBDEV_TURBO_SW=)n,\1y,' $1/.config
180                 sed -ri           's,(SCHED_.*=)n,\1y,' $1/.config
181                 test -z "$LIBMUSDK_PATH" || \
182                 sed -ri    's,(PMD_MVSAM_CRYPTO=)n,\1y,' $1/.config
183                 test -z "$LIBMUSDK_PATH" || \
184                 sed -ri          's,(MVPP2_PMD=)n,\1y,' $1/.config
185                 build_config_hook $1 $2 $3
186
187                 # Explicit enabler/disabler (uppercase)
188                 for option in $(echo $3 | sed 's,[~+], &,g') ; do
189                         pattern=$(echo $option | cut -c2-)
190                         if echo $option | grep -q '^~' ; then
191                                 sed -ri "s,($pattern=)y,\1n," $1/.config
192                         elif echo $option | grep -q '^+' ; then
193                                 sed -ri "s,($pattern=)n,\1y," $1/.config
194                         fi
195                 done
196         fi
197 }
198
199 # default empty hook to override in devel config
200 build_config_hook () # <directory> <target> <options>
201 {
202         :
203 }
204
205 for conf in $configs ; do
206         target=$(echo $conf | sed 's,[~+].*,,')
207         # reload config with DPDK_TARGET set
208         DPDK_TARGET=$target
209         reset_env
210         . $(dirname $(readlink -e $0))/load-devel-config
211
212         options=$(echo $conf | sed 's,[^~+]*,,')
213         dir=$conf
214         config $dir $target $options
215
216         echo "================== Build $dir"
217         make -j$J EXTRA_CFLAGS="$maxerr $DPDK_DEP_CFLAGS" \
218                 EXTRA_LDFLAGS="$DPDK_DEP_LDFLAGS" $verbose O=$dir
219         ! $short || break
220         echo "================== Build tests for $dir"
221         make test-build -j$J EXTRA_CFLAGS="$maxerr $DPDK_DEP_CFLAGS" \
222                 EXTRA_LDFLAGS="$DPDK_DEP_LDFLAGS" $verbose O=$dir
223         echo "================== Build examples for $dir"
224         export RTE_SDK=$(pwd)
225         export RTE_TARGET=$dir
226         make -j$J -sC examples \
227                 EXTRA_LDFLAGS="$DPDK_DEP_LDFLAGS" $verbose \
228                 O=$(readlink -m $dir/examples)
229         unset RTE_TARGET
230         echo "################## $dir done."
231         unset dir
232 done
233
234 if ! $short ; then
235         mkdir -p .check
236         echo "================== Build doxygen HTML API"
237         make doc-api-html >/dev/null 2>.check/doc.txt
238         echo "================== Build sphinx HTML guides"
239         make doc-guides-html >/dev/null 2>>.check/doc.txt
240         echo "================== Check docs"
241         diff -u /dev/null .check/doc.txt
242 fi
243
244 success=true