c6dfaf0a850dc46d8b482e7990cb1fd4e435bb73
[deb_dpdk.git] / devtools / test-build.sh
1 #! /bin/sh -e
2
3 # BSD LICENSE
4 #
5 # Copyright 2015 6WIND S.A.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 #
11 #   * Redistributions of source code must retain the above copyright
12 #     notice, this list of conditions and the following disclaimer.
13 #   * Redistributions in binary form must reproduce the above copyright
14 #     notice, this list of conditions and the following disclaimer in
15 #     the documentation and/or other materials provided with the
16 #     distribution.
17 #   * Neither the name of 6WIND S.A. nor the names of its
18 #     contributors may be used to endorse or promote products derived
19 #     from this software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33 default_path=$PATH
34
35 # Load config options:
36 # - AESNI_MULTI_BUFFER_LIB_PATH
37 # - ARMV8_CRYPTO_LIB_PATH
38 # - DPDK_BUILD_TEST_CONFIGS (defconfig1+option1+option2 defconfig2)
39 # - DPDK_DEP_ARCHIVE
40 # - DPDK_DEP_CFLAGS
41 # - DPDK_DEP_LDFLAGS
42 # - DPDK_DEP_MOFED (y/[n])
43 # - DPDK_DEP_NUMA ([y]/n)
44 # - DPDK_DEP_PCAP (y/[n])
45 # - DPDK_DEP_SSL (y/[n])
46 # - DPDK_DEP_SZE (y/[n])
47 # - DPDK_DEP_ZLIB (y/[n])
48 # - DPDK_MAKE_JOBS (int)
49 # - DPDK_NOTIFY (notify-send)
50 # - LIBSSO_SNOW3G_PATH
51 # - LIBSSO_KASUMI_PATH
52 # - LIBSSO_ZUC_PATH
53 . $(dirname $(readlink -e $0))/load-devel-config
54
55 print_usage () {
56         echo "usage: $(basename $0) [-h] [-jX] [-s] [config1 [config2] ...]]"
57 }
58
59 print_help () {
60         echo 'Test building several targets with different options'
61         echo
62         print_usage
63         cat <<- END_OF_HELP
64
65         options:
66                 -h    this help
67                 -jX   use X parallel jobs in "make"
68                 -s    short test only first config without tests|examples|doc
69                 -v    verbose build
70
71         config: defconfig[[~][+]option1[[~][+]option2...]]
72                 Example: x86_64-native-linuxapp-gcc+debug~RXTX_CALLBACKS
73                 The lowercase options are defined inside $(basename $0).
74                 The uppercase options can be the end of a defconfig option
75                 to enable if prefixed with '+' or to disable if prefixed with '~'.
76                 Default is to automatically enable most of the options.
77                 The external dependencies are setup with DPDK_DEP_* variables.
78                 If no config on command line, DPDK_BUILD_TEST_CONFIGS is used.
79         END_OF_HELP
80 }
81
82 J=$DPDK_MAKE_JOBS
83 short=false
84 unset verbose
85 maxerr=-Wfatal-errors
86 while getopts hj:sv ARG ; do
87         case $ARG in
88                 j ) J=$OPTARG ;;
89                 s ) short=true ;;
90                 v ) verbose='V=1' ;;
91                 h ) print_help ; exit 0 ;;
92                 ? ) print_usage ; exit 1 ;;
93         esac
94 done
95 shift $(($OPTIND - 1))
96 configs=${*:-$DPDK_BUILD_TEST_CONFIGS}
97
98 success=false
99 on_exit ()
100 {
101         if $success ; then
102                 [ "$DPDK_NOTIFY" != notify-send ] || \
103                         notify-send -u low --icon=dialog-information 'DPDK build' 'finished'
104         elif [ -z "$signal" ] ; then
105                 [ -z "$dir" ] || echo "failed to build $dir" >&2
106                 [ "$DPDK_NOTIFY" != notify-send ] || \
107                         notify-send -u low --icon=dialog-error 'DPDK build' 'failed'
108         fi
109 }
110 # catch manual interrupt to ignore notification
111 trap "signal=INT ; trap - INT ; kill -INT $$" INT
112 # notify result on exit
113 trap on_exit EXIT
114
115 cd $(dirname $(readlink -m $0))/..
116
117 reset_env ()
118 {
119         export PATH=$default_path
120         unset CROSS
121         unset DPDK_DEP_ARCHIVE
122         unset DPDK_DEP_CFLAGS
123         unset DPDK_DEP_LDFLAGS
124         unset DPDK_DEP_MOFED
125         unset DPDK_DEP_NUMA
126         unset DPDK_DEP_PCAP
127         unset DPDK_DEP_SSL
128         unset DPDK_DEP_SZE
129         unset DPDK_DEP_ZLIB
130         unset AESNI_MULTI_BUFFER_LIB_PATH
131         unset ARMV8_CRYPTO_LIB_PATH
132         unset LIBSSO_SNOW3G_PATH
133         unset LIBSSO_KASUMI_PATH
134         unset LIBSSO_ZUC_PATH
135         unset PQOS_INSTALL_PATH
136 }
137
138 config () # <directory> <target> <options>
139 {
140         reconfig=false
141         if git rev-parse 2>&- && [ -n "$(git diff HEAD~ -- config)" ] ; then
142                 echo 'Default config may have changed'
143                 reconfig=true
144         fi
145         if [ ! -e $1/.config ] || $reconfig ; then
146                 echo "================== Configure $1"
147                 make T=$2 O=$1 config
148
149                 echo 'Customize configuration'
150                 # Built-in options (lowercase)
151                 ! echo $3 | grep -q '+default' || \
152                 sed -ri 's,(RTE_MACHINE=")native,\1default,' $1/.config
153                 echo $3 | grep -q '+next' || \
154                 sed -ri           's,(NEXT_ABI=)y,\1n,' $1/.config
155                 ! echo $3 | grep -q '+shared' || \
156                 sed -ri         's,(SHARED_LIB=)n,\1y,' $1/.config
157                 ! echo $3 | grep -q '+debug' || ( \
158                 sed -ri     's,(RTE_LOG_LEVEL=).*,\1RTE_LOG_DEBUG,' $1/.config
159                 sed -ri           's,(_DEBUG.*=)n,\1y,' $1/.config
160                 sed -ri            's,(_STAT.*=)n,\1y,' $1/.config
161                 sed -ri 's,(TEST_PMD_RECORD_.*=)n,\1y,' $1/.config )
162
163                 # Automatic configuration
164                 test "$DPDK_DEP_NUMA" != n || \
165                 sed -ri             's,(NUMA.*=)y,\1n,' $1/.config
166                 sed -ri    's,(LIBRTE_IEEE1588=)n,\1y,' $1/.config
167                 sed -ri             's,(BYPASS=)n,\1y,' $1/.config
168                 test "$DPDK_DEP_ARCHIVE" != y || \
169                 sed -ri       's,(RESOURCE_TAR=)n,\1y,' $1/.config
170                 test "$DPDK_DEP_MOFED" != y || \
171                 sed -ri           's,(MLX._PMD=)n,\1y,' $1/.config
172                 test "$DPDK_DEP_SZE" != y || \
173                 sed -ri       's,(PMD_SZEDATA2=)n,\1y,' $1/.config
174                 test "$DPDK_DEP_ZLIB" != y || \
175                 sed -ri          's,(BNX2X_PMD=)n,\1y,' $1/.config
176                 sed -ri            's,(NFP_PMD=)n,\1y,' $1/.config
177                 test "$DPDK_DEP_PCAP" != y || \
178                 sed -ri               's,(PCAP=)n,\1y,' $1/.config
179                 test -z "$ARMV8_CRYPTO_LIB_PATH" || \
180                 sed -ri   's,(PMD_ARMV8_CRYPTO=)n,\1y,' $1/.config
181                 test -z "$AESNI_MULTI_BUFFER_LIB_PATH" || \
182                 sed -ri       's,(PMD_AESNI_MB=)n,\1y,' $1/.config
183                 test -z "$AESNI_MULTI_BUFFER_LIB_PATH" || \
184                 sed -ri      's,(PMD_AESNI_GCM=)n,\1y,' $1/.config
185                 test -z "$LIBSSO_SNOW3G_PATH" || \
186                 sed -ri         's,(PMD_SNOW3G=)n,\1y,' $1/.config
187                 test -z "$LIBSSO_KASUMI_PATH" || \
188                 sed -ri         's,(PMD_KASUMI=)n,\1y,' $1/.config
189                 test -z "$LIBSSO_ZUC_PATH" || \
190                 sed -ri            's,(PMD_ZUC=)n,\1y,' $1/.config
191                 test "$DPDK_DEP_SSL" != y || \
192                 sed -ri        's,(PMD_OPENSSL=)n,\1y,' $1/.config
193                 test "$DPDK_DEP_SSL" != y || \
194                 sed -ri            's,(PMD_QAT=)n,\1y,' $1/.config
195                 sed -ri           's,(SCHED_.*=)n,\1y,' $1/.config
196                 build_config_hook $1 $2 $3
197
198                 # Explicit enabler/disabler (uppercase)
199                 for option in $(echo $3 | sed 's,[~+], &,g') ; do
200                         pattern=$(echo $option | cut -c2-)
201                         if echo $option | grep -q '^~' ; then
202                                 sed -ri "s,($pattern=)y,\1n," $1/.config
203                         elif echo $option | grep -q '^+' ; then
204                                 sed -ri "s,($pattern=)n,\1y," $1/.config
205                         fi
206                 done
207         fi
208 }
209
210 # default empty hook to override in devel config
211 build_config_hook () # <directory> <target> <options>
212 {
213         :
214 }
215
216 for conf in $configs ; do
217         target=$(echo $conf | sed 's,[~+].*,,')
218         # reload config with DPDK_TARGET set
219         DPDK_TARGET=$target
220         reset_env
221         . $(dirname $(readlink -e $0))/load-devel-config
222
223         options=$(echo $conf | sed 's,[^~+]*,,')
224         dir=$conf
225         config $dir $target $options
226
227         echo "================== Build $dir"
228         make -j$J EXTRA_CFLAGS="$maxerr $DPDK_DEP_CFLAGS" \
229                 EXTRA_LDFLAGS="$DPDK_DEP_LDFLAGS" $verbose O=$dir
230         ! $short || break
231         echo "================== Build tests for $dir"
232         make test-build -j$J EXTRA_CFLAGS="$maxerr $DPDK_DEP_CFLAGS" \
233                 EXTRA_LDFLAGS="$DPDK_DEP_LDFLAGS" $verbose O=$dir
234         echo "================== Build examples for $dir"
235         export RTE_SDK=$(pwd)
236         export RTE_TARGET=$dir
237         make -j$J -sC examples \
238                 EXTRA_LDFLAGS="$DPDK_DEP_LDFLAGS" $verbose \
239                 O=$(readlink -m $dir/examples)
240         unset RTE_TARGET
241         echo "################## $dir done."
242         unset dir
243 done
244
245 if ! $short ; then
246         mkdir -p .check
247         echo "================== Build doxygen HTML API"
248         make doc-api-html >/dev/null 2>.check/doc.txt
249         echo "================== Build sphinx HTML guides"
250         make doc-guides-html >/dev/null 2>>.check/doc.txt
251         echo "================== Check docs"
252         diff -u /dev/null .check/doc.txt
253 fi
254
255 success=true