]> git.proxmox.com Git - ovs.git/blob - .travis/linux-build.sh
travis: Test build with afxdp.
[ovs.git] / .travis / linux-build.sh
1 #!/bin/bash
2
3 set -o errexit
4 set -x
5
6 CFLAGS_FOR_OVS="-g -O2"
7 SPARSE_FLAGS=""
8 EXTRA_OPTS="--enable-Werror"
9 TARGET="x86_64-native-linuxapp-gcc"
10
11 function install_kernel()
12 {
13 if [[ "$1" =~ ^5.* ]]; then
14 PREFIX="v5.x"
15 elif [[ "$1" =~ ^4.* ]]; then
16 PREFIX="v4.x"
17 elif [[ "$1" =~ ^3.* ]]; then
18 PREFIX="v3.x"
19 else
20 PREFIX="v2.6/longterm/v2.6.32"
21 fi
22
23 base_url="https://cdn.kernel.org/pub/linux/kernel/${PREFIX}"
24 # Download page with list of all available kernel versions.
25 wget ${base_url}/
26 # Uncompress in case server returned gzipped page.
27 (file index* | grep ASCII) || (mv index* index.new.gz && gunzip index*)
28 # Get version of the latest stable release.
29 hi_ver=$(echo ${1} | sed 's/\./\\\./')
30 lo_ver=$(cat ./index* | grep -P -o "${hi_ver}\.[0-9]+" | \
31 sed 's/.*\..*\.\(.*\)/\1/' | sort -h | tail -1)
32 version="${1}.${lo_ver}"
33
34 rm -rf index* linux-*
35
36 url="${base_url}/linux-${version}.tar.xz"
37 # Download kernel sources. Try direct link on CDN failure.
38 wget ${url} || wget ${url} || wget ${url/cdn/www}
39
40 tar xvf linux-${version}.tar.xz > /dev/null
41 pushd linux-${version}
42 make allmodconfig
43
44 # Cannot use CONFIG_KCOV: -fsanitize-coverage=trace-pc is not supported by compiler
45 sed -i 's/CONFIG_KCOV=y/CONFIG_KCOV=n/' .config
46
47 # stack validation depends on tools/objtool, but objtool does not compile on travis.
48 # It is giving following error.
49 # >>> GEN arch/x86/insn/inat-tables.c
50 # >>> Semantic error at 40: Unknown imm opnd: AL
51 # So for now disable stack-validation for the build.
52
53 sed -i 's/CONFIG_STACK_VALIDATION=y/CONFIG_STACK_VALIDATION=n/' .config
54 make oldconfig
55
56 # Older kernels do not include openvswitch
57 if [ -d "net/openvswitch" ]; then
58 make net/openvswitch/
59 else
60 make net/bridge/
61 fi
62
63 if [ "$AFXDP" ]; then
64 sudo make headers_install INSTALL_HDR_PATH=/usr
65 pushd tools/lib/bpf/
66 # Bulding with gcc because there are some issues in make files
67 # that breaks building libbpf with clang on Travis.
68 CC=gcc sudo make install
69 CC=gcc sudo make install_headers
70 sudo ldconfig
71 popd
72 # The Linux kernel defines __always_inline in stddef.h (283d7573), and
73 # sys/cdefs.h tries to re-define it. Older libc-dev package in xenial
74 # doesn't have a fix for this issue. Applying it manually.
75 sudo sed -i '/^# define __always_inline .*/i # undef __always_inline' \
76 /usr/include/x86_64-linux-gnu/sys/cdefs.h || true
77 EXTRA_OPTS="${EXTRA_OPTS} --enable-afxdp"
78 else
79 EXTRA_OPTS="${EXTRA_OPTS} --with-linux=$(pwd)"
80 echo "Installed kernel source in $(pwd)"
81 fi
82 popd
83 }
84
85 function install_dpdk()
86 {
87 local DPDK_VER=$1
88 local VERSION_FILE="dpdk-dir/travis-dpdk-cache-version"
89
90 if [ "${DPDK_VER##refs/*/}" != "${DPDK_VER}" ]; then
91 # Avoid using cache for git tree build.
92 rm -rf dpdk-dir
93
94 DPDK_GIT=${DPDK_GIT:-https://dpdk.org/git/dpdk}
95 git clone --single-branch $DPDK_GIT dpdk-dir -b "${DPDK_VER##refs/*/}"
96 pushd dpdk-dir
97 git log -1 --oneline
98 else
99 if [ -f "${VERSION_FILE}" ]; then
100 VER=$(cat ${VERSION_FILE})
101 if [ "${VER}" = "${DPDK_VER}" ]; then
102 EXTRA_OPTS="${EXTRA_OPTS} --with-dpdk=$(pwd)/dpdk-dir/build"
103 echo "Found cached DPDK ${VER} build in $(pwd)/dpdk-dir"
104 return
105 fi
106 fi
107 # No cache or version mismatch.
108 rm -rf dpdk-dir
109 wget https://fast.dpdk.org/rel/dpdk-$1.tar.xz
110 tar xvf dpdk-$1.tar.xz > /dev/null
111 DIR_NAME=$(tar -tf dpdk-$1.tar.xz | head -1 | cut -f1 -d"/")
112 mv ${DIR_NAME} dpdk-dir
113 pushd dpdk-dir
114 fi
115
116 make config CC=gcc T=$TARGET
117
118 if [ "$DPDK_SHARED" ]; then
119 sed -i '/CONFIG_RTE_BUILD_SHARED_LIB=n/s/=n/=y/' build/.config
120 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(pwd)/$TARGET/lib
121 fi
122
123 # Disable building DPDK kernel modules. Not needed for OVS build or tests.
124 sed -i '/CONFIG_RTE_EAL_IGB_UIO=y/s/=y/=n/' build/.config
125 sed -i '/CONFIG_RTE_KNI_KMOD=y/s/=y/=n/' build/.config
126
127 make -j4 CC=gcc EXTRA_CFLAGS='-fPIC'
128 EXTRA_OPTS="$EXTRA_OPTS --with-dpdk=$(pwd)/build"
129 echo "Installed DPDK source in $(pwd)"
130 popd
131 echo "${DPDK_VER}" > ${VERSION_FILE}
132 }
133
134 function configure_ovs()
135 {
136 ./boot.sh
137 ./configure CFLAGS="${CFLAGS_FOR_OVS}" $* || { cat config.log; exit 1; }
138 }
139
140 function build_ovs()
141 {
142 local KERNEL=$1
143
144 configure_ovs $OPTS
145 make selinux-policy
146
147 # Only build datapath if we are testing kernel w/o running testsuite and
148 # AF_XDP support.
149 if [ "${KERNEL}" ] && ! [ "$AFXDP" ]; then
150 pushd datapath
151 make -j4
152 popd
153 else
154 make -j4 || { cat config.log; exit 1; }
155 fi
156 }
157
158 if [ "$KERNEL" ]; then
159 install_kernel $KERNEL
160 fi
161
162 if [ "$DPDK" ] || [ "$DPDK_SHARED" ]; then
163 if [ -z "$DPDK_VER" ]; then
164 DPDK_VER="18.11.2"
165 fi
166 install_dpdk $DPDK_VER
167 if [ "$CC" = "clang" ]; then
168 # Disregard cast alignment errors until DPDK is fixed
169 CFLAGS_FOR_OVS="${CFLAGS_FOR_OVS} -Wno-cast-align"
170 fi
171 fi
172
173 if [ "$CC" = "clang" ]; then
174 CFLAGS_FOR_OVS="${CFLAGS_FOR_OVS} -Wno-error=unused-command-line-argument"
175 elif [ "$M32" ]; then
176 # Not using sparse for 32bit builds on 64bit machine.
177 # Adding m32 flag directly to CC to avoid any posiible issues with API/ABI
178 # difference on 'configure' and 'make' stages.
179 export CC="$CC -m32"
180 else
181 OPTS="--enable-sparse"
182 if [ "$AFXDP" ]; then
183 # netdev-afxdp uses memset for 64M for umem initialization.
184 SPARSE_FLAGS="${SPARSE_FLAGS} -Wno-memcpy-max-count"
185 fi
186 CFLAGS_FOR_OVS="${CFLAGS_FOR_OVS} ${SPARSE_FLAGS}"
187 fi
188
189 save_OPTS="${OPTS} $*"
190 OPTS="${EXTRA_OPTS} ${save_OPTS}"
191
192 if [ "$TESTSUITE" ]; then
193 # 'distcheck' will reconfigure with required options.
194 # Now we only need to prepare the Makefile without sparse-wrapped CC.
195 configure_ovs
196
197 export DISTCHECK_CONFIGURE_FLAGS="$OPTS"
198 if ! make distcheck CFLAGS="${CFLAGS_FOR_OVS}" \
199 TESTSUITEFLAGS=-j4 RECHECK=yes; then
200 # testsuite.log is necessary for debugging.
201 cat */_build/sub/tests/testsuite.log
202 exit 1
203 fi
204 else
205 if [ -z "${KERNEL_LIST}" ]; then build_ovs ${KERNEL};
206 else
207 save_EXTRA_OPTS="${EXTRA_OPTS}"
208 for KERNEL in ${KERNEL_LIST}; do
209 echo "=============================="
210 echo "Building with kernel ${KERNEL}"
211 echo "=============================="
212 EXTRA_OPTS="${save_EXTRA_OPTS}"
213 install_kernel ${KERNEL}
214 OPTS="${EXTRA_OPTS} ${save_OPTS}"
215 build_ovs ${KERNEL}
216 make distclean
217 done
218 fi
219 fi
220
221 exit 0