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