scripts: allow tuning build options per test target
[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 (target1+option1+option2 target2)
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 . $(dirname $(readlink -e $0))/load-devel-config.sh
48
49 print_usage () {
50         echo "usage: $(basename $0) [-h] [-jX] [-s] [config1 [config2] ...]]"
51 }
52
53 print_help () {
54         echo 'Test building several targets with different options'
55         echo
56         print_usage
57         cat <<- END_OF_HELP
58
59         options:
60                 -h    this help
61                 -jX   use X parallel jobs in "make"
62                 -s    short test with only first config without examples/doc
63
64         config: defconfig name followed by switches delimited with "+" sign
65                 Example: x86_64-native-linuxapp-gcc+next+shared
66                 Default is to enable most of the options.
67                 The external dependencies are setup with DPDK_DEP_* variables.
68         END_OF_HELP
69 }
70
71 J=$DPDK_MAKE_JOBS
72 short=false
73 maxerr=-Wfatal-errors
74 while getopts hj:s ARG ; do
75         case $ARG in
76                 j ) J=$OPTARG ;;
77                 s ) short=true ;;
78                 h ) print_help ; exit 0 ;;
79                 ? ) print_usage ; exit 1 ;;
80         esac
81 done
82 shift $(($OPTIND - 1))
83 configs=${*:-$DPDK_BUILD_TEST_CONFIGS}
84
85 success=false
86 on_exit ()
87 {
88         if [ "$DPDK_NOTIFY" = notify-send ] ; then
89                 if $success ; then
90                         notify-send -u low --icon=dialog-information 'DPDK build' 'finished'
91                 elif [ -z "$signal" ] ; then
92                         notify-send -u low --icon=dialog-error 'DPDK build' 'failed'
93                 fi
94         fi
95 }
96 # catch manual interrupt to ignore notification
97 trap "signal=INT ; trap - INT ; kill -INT $$" INT
98 # notify result on exit
99 trap on_exit EXIT
100
101 cd $(dirname $(readlink -m $0))/..
102
103 reset_env ()
104 {
105         export PATH=$default_path
106         unset CROSS
107         unset DPDK_DEP_CFLAGS
108         unset DPDK_DEP_LDFLAGS
109         unset DPDK_DEP_MOFED
110         unset DPDK_DEP_PCAP
111         unset DPDK_DEP_SSL
112         unset DPDK_DEP_SZE
113         unset DPDK_DEP_ZLIB
114         unset AESNI_MULTI_BUFFER_LIB_PATH
115         unset PQOS_INSTALL_PATH
116 }
117
118 config () # <directory> <target> <options>
119 {
120         if [ ! -e $1/.config ] ; then
121                 echo "================== Configure $1"
122                 make T=$2 O=$1 config
123                 echo $3 | grep -q next || \
124                 sed -ri           's,(NEXT_ABI=)y,\1n,' $1/.config
125                 ! echo $3 | grep -q shared || \
126                 sed -ri         's,(SHARED_LIB=)n,\1y,' $1/.config
127                 ! echo $2 | grep -q '^x86_64' || \
128                 sed -ri               's,(NUMA=)n,\1y,' $1/.config
129                 sed -ri         's,(PCI_CONFIG=)n,\1y,' $1/.config
130                 sed -ri    's,(LIBRTE_IEEE1588=)n,\1y,' $1/.config
131                 sed -ri             's,(BYPASS=)n,\1y,' $1/.config
132                 test "$DPDK_DEP_MOFED" != y || \
133                 sed -ri           's,(MLX._PMD=)n,\1y,' $1/.config
134                 test "$DPDK_DEP_SZE" != y || \
135                 sed -ri       's,(PMD_SZEDATA2=)n,\1y,' $1/.config
136                 test "$DPDK_DEP_ZLIB" != y || \
137                 sed -ri          's,(BNX2X_PMD=)n,\1y,' $1/.config
138                 sed -ri            's,(NFP_PMD=)n,\1y,' $1/.config
139                 test "$DPDK_DEP_PCAP" != y || \
140                 sed -ri               's,(PCAP=)n,\1y,' $1/.config
141                 test -z "$AESNI_MULTI_BUFFER_LIB_PATH" || \
142                 sed -ri       's,(PMD_AESNI_MB=)n,\1y,' $1/.config
143                 test -z "$AESNI_MULTI_BUFFER_LIB_PATH" || \
144                 sed -ri      's,(PMD_AESNI_GCM=)n,\1y,' $1/.config
145                 test "$DPDK_DEP_SSL" != y || \
146                 sed -ri            's,(PMD_QAT=)n,\1y,' $1/.config
147                 sed -ri        's,(KNI_VHOST.*=)n,\1y,' $1/.config
148                 sed -ri           's,(SCHED_.*=)n,\1y,' $1/.config
149                 sed -ri 's,(TEST_PMD_RECORD_.*=)n,\1y,' $1/.config
150                 sed -ri            's,(DEBUG.*=)n,\1y,' $1/.config
151         fi
152 }
153
154 for conf in $configs ; do
155         target=$(echo $conf | cut -d'+' -f1)
156         # reload config with DPDK_TARGET set
157         DPDK_TARGET=$target
158         reset_env
159         . $(dirname $(readlink -e $0))/load-devel-config.sh
160
161         options=$(echo $conf | cut -d'+' -sf2- --output-delimiter='-')
162         if [ -z "$options" ] ; then
163                 dir=$target
164         else
165                 dir=$target-$options
166         fi
167         config $dir $target $options
168
169         echo "================== Build $dir"
170         make -j$J EXTRA_CFLAGS="$maxerr $DPDK_DEP_CFLAGS" \
171                 EXTRA_LDFLAGS="$DPDK_DEP_LDFLAGS" O=$dir
172         ! $short || break
173         echo "================== Build examples for $dir"
174         export RTE_SDK=$(pwd)
175         export RTE_TARGET=$dir
176         make -j$J -sC examples \
177                 EXTRA_LDFLAGS="$DPDK_DEP_LDFLAGS" \
178                 O=$(readlink -m $dir/examples)
179         ! echo $target | grep -q '^x86_64' || \
180         make -j$J -sC examples/performance-thread \
181                 EXTRA_LDFLAGS="$DPDK_DEP_LDFLAGS" \
182                 O=$(readlink -m $dir/examples/performance-thread)
183         unset RTE_TARGET
184         echo "################## $dir done."
185 done
186
187 if ! $short ; then
188         mkdir -p .check
189         echo "================== Build doxygen HTML API"
190         make doc-api-html >/dev/null 2>.check/doc.txt
191         echo "================== Build sphinx HTML guides"
192         make doc-guides-html >/dev/null 2>>.check/doc.txt
193         echo "================== Check docs"
194         diff -u /dev/null .check/doc.txt
195 fi
196
197 success=true