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