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