1#!/usr/bin/env bash 2# SPDX-License-Identifier: BSD-3-Clause 3# Copyright (C) 2022 Intel Corporation. 4# All rights reserved. 5 6spdk_conf=${spdk_conf:-"$1"} 7 8if [[ ! -f $spdk_conf ]]; then 9 echo "ERROR: SPDK test configuration not specified" 10 return 1 11fi 12 13source "$spdk_conf" 14source "$rootdir/test/common/autotest_common.sh" 15source "$rootdir/scripts/common.sh" 16 17_ocf_precompile() { 18 # We compile OCF sources ourselves 19 # They don't need to be checked with scanbuild and code coverage is not applicable 20 # So we precompile OCF now for further use as standalone static library 21 "$rootdir/configure" $(echo $config_params | sed 's/--enable-coverage//g') 22 $MAKE $MAKEFLAGS include/spdk/config.h 23 CC=gcc CCAR=ar $MAKE $MAKEFLAGS -C "$rootdir/lib/env_ocf" exportlib O="$rootdir/ocf.a" 24 # Set config to use precompiled library 25 config_params="$config_params --with-ocf=/$rootdir/ocf.a" 26 # need to reconfigure to avoid clearing ocf related files on future make clean. 27 "$rootdir/configure" $config_params 28} 29 30# Find matching llvm fuzzer library and clang compiler version 31_llvm_precompile() { 32 [[ $(clang --version) =~ "version "(([0-9]+).([0-9]+).([0-9]+)) ]] 33 clang_num=${BASH_REMATCH[2]} 34 35 export CC=clang-$clang_num 36 export CXX=clang++-$clang_num 37 38 fuzzer_libs=(/usr/lib*/clang/"$clang_num"/lib/linux/libclang_rt.fuzzer_no_main-x86_64.a) 39 fuzzer_lib=${fuzzer_libs[0]} 40 [[ -e $fuzzer_lib ]] 41 42 config_params="$config_params --with-fuzzer=$fuzzer_lib" 43 # need to reconfigure to avoid clearing llvm related files on future make clean. 44 "$rootdir/configure" $config_params 45} 46 47_build_native_dpdk() { 48 local external_dpdk_dir 49 local external_dpdk_base_dir 50 local compiler_version 51 local compiler 52 local dpdk_kmods 53 local repo='dpdk' 54 55 compiler=${CC:-gcc} 56 57 # Export CC to be absolutely sure it's set. 58 # If CC was not set and we defaulted to "gcc" then we need to do the export 59 # so that "meson build" command a few lines below is aware of which compiler 60 # to use. 61 export CC="$compiler" 62 63 if [[ $compiler != *clang* && $compiler != *gcc* ]]; then 64 echo "Unsupported compiler detected ($compiler), failing the test" >&2 65 return 1 66 fi 67 68 compiler_version=$("$compiler" -dumpversion) 69 compiler_version=${compiler_version%%.*} 70 external_dpdk_dir="$SPDK_RUN_EXTERNAL_DPDK" 71 external_dpdk_base_dir="$(dirname $external_dpdk_dir)" 72 73 if [[ ! -d "$external_dpdk_base_dir" ]]; then 74 if [[ $SPDK_TEST_NATIVE_DPDK != 'main' ]]; then 75 repo='dpdk-stable' 76 fi 77 echo "DPDK directory does not exist at the provided location." 78 sudo mkdir -p "$external_dpdk_base_dir" 79 sudo chown -R $(whoami) "$external_dpdk_base_dir"/.. 80 git clone --branch "$SPDK_TEST_NATIVE_DPDK" --depth 1 http://dpdk.org/git/${repo} "$external_dpdk_base_dir" 81 fi 82 orgdir=$PWD 83 git -C "$external_dpdk_base_dir" log --oneline -n 5 84 85 dpdk_cflags="-fPIC -g -fcommon" 86 dpdk_ldflags="" 87 dpdk_ver=$(< "$external_dpdk_base_dir/VERSION") 88 89 if [[ $compiler == *gcc* && $compiler_version -ge 5 ]]; then 90 dpdk_cflags+=" -Werror" 91 fi 92 93 if [[ $compiler == *gcc* && $compiler_version -ge 10 ]]; then 94 dpdk_cflags+=" -Wno-stringop-overflow" 95 fi 96 97 # the drivers we use 98 # net/i40e driver is not really needed by us, but it's built as a workaround 99 # for DPDK issue: https://bugs.dpdk.org/show_bug.cgi?id=576 100 DPDK_DRIVERS=("bus" "bus/pci" "bus/vdev" "mempool/ring" "net/i40e" "net/i40e/base") 101 102 local mlx5_libs_added="n" 103 if [[ "$SPDK_TEST_CRYPTO" -eq 1 || "$SPDK_TEST_SMA" -eq 1 ]]; then 104 intel_ipsec_mb_ver=v0.54 105 intel_ipsec_mb_drv=crypto/aesni_mb 106 intel_ipsec_lib="" 107 if ge "$dpdk_ver" 21.11.0; then 108 # Minimum supported version of intel-ipsec-mb, for DPDK >= 21.11, is 1.0. 109 # Source of the aesni_mb driver was moved to ipsec_mb. .{h,so,a} were moved 110 # to ./lib. 111 # https://github.com/dpdk/dpdk/commit/918fd2f1466b0e3b21a033df7012a77a83665582. 112 intel_ipsec_mb_ver=v1.0 113 intel_ipsec_mb_drv=crypto/ipsec_mb 114 intel_ipsec_lib=lib 115 fi 116 git clone --branch "$intel_ipsec_mb_ver" --depth 1 https://github.com/intel/intel-ipsec-mb.git "$external_dpdk_base_dir/intel-ipsec-mb" 117 cd "$external_dpdk_base_dir/intel-ipsec-mb" 118 $MAKE $MAKEFLAGS all SHARED=y EXTRA_CFLAGS=-fPIC 119 DPDK_DRIVERS+=("crypto") 120 DPDK_DRIVERS+=("$intel_ipsec_mb_drv") 121 DPDK_DRIVERS+=("crypto/qat") 122 DPDK_DRIVERS+=("compress/qat") 123 DPDK_DRIVERS+=("common/qat") 124 # 21.11.0 is version of DPDK with stable support for mlx5 crypto. 125 if ge "$dpdk_ver" 21.11.0; then 126 # SPDK enables CRYPTO_MLX in case supported version of DPDK is detected 127 # so make sure proper libs are built. 128 DPDK_DRIVERS+=("bus/auxiliary") 129 DPDK_DRIVERS+=("common/mlx5") 130 DPDK_DRIVERS+=("common/mlx5/linux") 131 DPDK_DRIVERS+=("crypto/mlx5") 132 mlx5_libs_added="y" 133 fi 134 dpdk_cflags+=" -I$external_dpdk_base_dir/intel-ipsec-mb/$intel_ipsec_lib" 135 dpdk_ldflags+=" -L$external_dpdk_base_dir/intel-ipsec-mb/$intel_ipsec_lib" 136 export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$external_dpdk_base_dir/intel-ipsec-mb/$intel_ipsec_lib" 137 fi 138 139 if [[ "$SPDK_TEST_VBDEV_COMPRESS" -eq 1 ]]; then 140 isal_dir="$external_dpdk_base_dir/isa-l" 141 git clone --branch v2.29.0 --depth 1 https://github.com/intel/isa-l.git "$isal_dir" 142 143 cd $isal_dir 144 ./autogen.sh 145 ./configure CFLAGS="-fPIC -g -O2" --enable-shared=yes --prefix="$isal_dir/build" 146 ln -s $PWD/include $PWD/isa-l 147 $MAKE $MAKEFLAGS all 148 $MAKE install 149 DPDK_DRIVERS+=("compress") 150 DPDK_DRIVERS+=("compress/isal") 151 DPDK_DRIVERS+=("compress/qat") 152 DPDK_DRIVERS+=("common/qat") 153 if ge "$dpdk_ver" 21.02.0; then 154 # SPDK enables REDUCE_MLX in case supported version of DPDK is detected 155 # so make sure proper libs are built. 156 if test $mlx5_libs_added = "n"; then 157 DPDK_DRIVERS+=("bus/auxiliary") 158 DPDK_DRIVERS+=("common/mlx5") 159 DPDK_DRIVERS+=("common/mlx5/linux") 160 fi 161 DPDK_DRIVERS+=("compress/mlx5") 162 fi 163 export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$isal_dir/build/lib/pkgconfig" 164 export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$isal_dir/build/lib" 165 fi 166 167 cd $external_dpdk_base_dir 168 if [ "$(uname -s)" = "Linux" ]; then 169 if lt $dpdk_ver 21.11.0; then 170 patch -p1 < "$rootdir/test/common/config/pkgdep/patches/dpdk/20.11/dpdk_pci.patch" 171 patch -p1 < "$rootdir/test/common/config/pkgdep/patches/dpdk/20.11/dpdk_qat.patch" 172 else 173 patch -p1 < "$rootdir/test/common/config/pkgdep/patches/dpdk/21.11+/dpdk_qat.patch" 174 175 if lt $dpdk_ver 23.03.0; then 176 # Commit https://review.spdk.io/gerrit/c/spdk/dpdk/+/16828 is required for DPDK <23.03.0 177 patch -p1 < "$rootdir/test/common/config/pkgdep/patches/dpdk/21.11+/dpdk_rte_thash_gfni.patch" 178 fi 179 180 # Commit https://review.spdk.io/gerrit/c/spdk/dpdk/+/16134 is required for DPDK 22.11+ 181 if ge $dpdk_ver 22.11.0 && lt $dpdk_ver 23.03.0; then 182 patch -p1 < "$rootdir/test/common/config/pkgdep/patches/dpdk/22.11+/dpdk_ipsec_mb.patch" 183 fi 184 fi 185 fi 186 187 dpdk_kmods="false" 188 if [ "$(uname -s)" = "FreeBSD" ]; then 189 dpdk_kmods="true" 190 fi 191 192 meson build-tmp --prefix="$external_dpdk_dir" --libdir lib \ 193 -Denable_docs=false -Denable_kmods="$dpdk_kmods" -Dtests=false \ 194 -Dc_link_args="$dpdk_ldflags" -Dc_args="$dpdk_cflags" \ 195 -Dmachine=native -Denable_drivers=$(printf "%s," "${DPDK_DRIVERS[@]}") 196 ninja -C "$external_dpdk_base_dir/build-tmp" $MAKEFLAGS 197 ninja -C "$external_dpdk_base_dir/build-tmp" $MAKEFLAGS install 198 199 if [[ $(uname -s) == "FreeBSD" ]]; then 200 # Make sure kernel modules are available for freebsd_update_contigmem_mod() to fetch 201 mapfile -t drivers < <(find "$external_dpdk_base_dir/build-tmp" -name '*.ko') 202 if ((${#drivers[@]} > 0)); then 203 mkdir -p "$external_dpdk_dir/kmod" 204 cp -f "${drivers[@]}" "$external_dpdk_dir/kmod/" 205 fi 206 fi 207 208 # Save this path. In tests are run using autorun.sh then autotest.sh 209 # script will be unaware of LD_LIBRARY_PATH and will fail tests. 210 cat <<- LD_PATH > /tmp/spdk-ld-path 211 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH 212 export PKG_CONFIG_PATH=$PKG_CONFIG_PATH 213 LD_PATH 214 215 cd "$orgdir" 216} 217 218check_dpdk_pci_api() { 219 local dpdk_dir 220 221 if [[ -n "$SPDK_TEST_NATIVE_DPDK" ]]; then 222 dpdk_dir=$(dirname "$SPDK_RUN_EXTERNAL_DPDK") 223 fi 224 225 "$rootdir/scripts/env_dpdk/check_dpdk_pci_api.sh" check "$dpdk_dir" 226} 227 228make_fail_cleanup() { 229 if [ -d $out/scan-build-tmp ]; then 230 scanoutput=$(ls -1 $out/scan-build-tmp/) 231 mv $out/scan-build-tmp/$scanoutput $out/scan-build 232 rm -rf $out/scan-build-tmp 233 chmod -R a+rX $out/scan-build 234 fi 235 false 236} 237 238_scanbuild_make() { 239 pass=true 240 "$rootdir/configure" $config_params --without-shared 241 $scanbuild $MAKE $MAKEFLAGS > $out/build_output.txt && rm -rf $out/scan-build-tmp || make_fail_cleanup 242 xtrace_disable 243 244 rm -f $out/*files.txt 245 for ent in $(find app examples lib module test -type f | grep -vF ".h"); do 246 if [[ $ent == lib/env_ocf* ]]; then continue; fi 247 if file -bi $ent | grep -q 'text/x-c'; then 248 echo $ent | sed 's/\.cp\{0,2\}$//g' >> $out/all_c_files.txt 249 fi 250 done 251 xtrace_restore 252 253 grep -E "CC|CXX" $out/build_output.txt | sed 's/\s\s\(CC\|CXX\)\s//g' | sed 's/\.o//g' > $out/built_c_files.txt 254 cat $rootdir/test/common/skipped_build_files.txt >> $out/built_c_files.txt 255 256 sort -o $out/all_c_files.txt $out/all_c_files.txt 257 sort -o $out/built_c_files.txt $out/built_c_files.txt 258 # from comm manual: 259 # -2 suppress column 2 (lines unique to FILE2) 260 # -3 suppress column 3 (lines that appear in both files) 261 # comm may exit 1 if no lines were printed (undocumented, unreliable) 262 comm -2 -3 $out/all_c_files.txt $out/built_c_files.txt > $out/unbuilt_c_files.txt || true 263 264 if [ $(wc -l < $out/unbuilt_c_files.txt) -ge 1 ]; then 265 echo "missing files" 266 cat <<- ERROR 267 The following C files were not built. Either scanbuild CI job needs to 268 be updated with proper flags to build these files, or exceptions need 269 to be added to test/common/skipped_build_files.txt 270 271 $(<"$out/unbuilt_c_files.txt") 272 ERROR 273 pass=false 274 fi 275 276 $pass 277} 278 279porcelain_check() { 280 if [ $(git status --porcelain --ignore-submodules | wc -l) -ne 0 ]; then 281 echo "Generated files missing from .gitignore:" 282 git status --porcelain --ignore-submodules 283 exit 1 284 fi 285} 286 287# Check that header file dependencies are working correctly by 288# capturing a binary's stat data before and after touching a 289# header file and re-making. 290header_dependency_check() { 291 STAT1=$(stat $SPDK_BIN_DIR/spdk_tgt) 292 sleep 1 293 touch "$rootdir/lib/nvme/nvme_internal.h" 294 $MAKE $MAKEFLAGS 295 STAT2=$(stat $SPDK_BIN_DIR/spdk_tgt) 296 297 if [ "$STAT1" == "$STAT2" ]; then 298 echo "Header dependency check failed" 299 false 300 fi 301} 302 303test_make_install() { 304 $MAKE $MAKEFLAGS install DESTDIR="$SPDK_WORKSPACE" prefix=/usr 305} 306 307test_make_uninstall() { 308 # Create empty file to check if it is not deleted by target uninstall 309 touch "$SPDK_WORKSPACE/usr/lib/sample_xyz.a" 310 $MAKE $MAKEFLAGS uninstall DESTDIR="$SPDK_WORKSPACE" prefix=/usr 311 if [[ $(find "$SPDK_WORKSPACE/usr" -maxdepth 1 -mindepth 1 | wc -l) -ne 2 ]] || [[ $(find "$SPDK_WORKSPACE/usr/lib/" -maxdepth 1 -mindepth 1 | wc -l) -ne 1 ]]; then 312 ls -lR "$SPDK_WORKSPACE" 313 echo "Make uninstall failed" 314 exit 1 315 fi 316} 317 318_build_doc() { 319 local doxygenv 320 doxygenv=$(doxygen --version) 321 322 $MAKE -C "$rootdir"/doc --no-print-directory $MAKEFLAGS Q=@ &> "$out"/doxygen.log 323 if [ -s "$out"/doxygen.log ]; then 324 if [[ "$doxygenv" == "1.8.20" ]]; then 325 # Doxygen 1.8.20 produces false positives, see: 326 # https://github.com/doxygen/doxygen/issues/7948 327 grep -vE '\\ilinebr' 328 elif [[ "$doxygenv" == "1.9.5" ]]; then 329 # Doxygen 1.9.5 produces false positives, see: 330 # https://github.com/doxygen/doxygen/issues/9552 and 331 # https://github.com/doxygen/doxygen/issues/9678 332 grep -vE '\\ifile|@param' 333 fi < "$out/doxygen.log" && echo "Doxygen errors found!" && return 1 334 335 echo "Doxygen $doxygenv detected. No warnings except false positives, continuing the test" 336 fi 337 if hash pdflatex 2> /dev/null; then 338 $MAKE -C "$rootdir"/doc/output/latex --no-print-directory $MAKEFLAGS &>> "$out"/doxygen.log 339 fi 340 mkdir -p "$out"/doc 341 # Copy and remove files to avoid mv: failed to preserve ownership error 342 cp -r --preserve=mode "$rootdir"/doc/output/html "$out"/doc 343 rm -rf "$rootdir"/doc/output/html 344 if [ -f "$rootdir"/doc/output/latex/refman.pdf ]; then 345 mv "$rootdir"/doc/output/latex/refman.pdf "$out"/doc/spdk.pdf 346 fi 347 $MAKE -C "$rootdir"/doc --no-print-directory $MAKEFLAGS clean &>> "$out"/doxygen.log 348 if [ -s "$out"/doxygen.log ]; then 349 # Save the log as an artifact in case we are working with potentially broken version 350 eq "$doxygenv" 1.8.20 || rm "$out"/doxygen.log 351 fi 352 rm -rf "$rootdir"/doc/output 353} 354 355check_format() { 356 run_test "autobuild_check_format" "$rootdir/scripts/check_format.sh" 357} 358 359check_so_deps() { 360 run_test "autobuild_check_so_deps" "$rootdir/test/make/check_so_deps.sh" -c "$spdk_conf" -a "$SPDK_ABI_DIR" 361} 362 363external_code() { 364 run_test "autobuild_external_code" "$rootdir/test/external_code/test_make.sh" "$rootdir" 365} 366 367dpdk_pci_api() { 368 run_test "autobuild_check_dpdk_pci_api" check_dpdk_pci_api 369} 370 371build_files() { 372 "$rootdir/configure" $config_params --without-shared 373 $MAKE $MAKEFLAGS 374 run_test "autobuild_generated_files_check" porcelain_check 375 run_test "autobuild_header_dependency_check" header_dependency_check 376 run_test "autobuild_make_install" test_make_install 377 run_test "autobuild_make_uninstall" test_make_uninstall 378} 379 380build_doc() { 381 run_test "autobuild_build_doc" _build_doc 382} 383 384autobuild_test_suite_tiny() { 385 check_format 386 check_so_deps 387 dpdk_pci_api 388} 389 390autobuild_test_suite_ext() { 391 external_code 392} 393 394autobuild_test_suite_full() { 395 autobuild_test_suite_tiny 396 autobuild_test_suite_ext 397 build_files 398 build_doc 399} 400 401_autobuild_test_suite() { 402 case "$SPDK_TEST_AUTOBUILD" in 403 tiny) autobuild_test_suite_tiny ;; 404 ext) autobuild_test_suite_ext ;; 405 full) autobuild_test_suite_full ;; 406 esac 407} 408 409_unittest_build() { 410 "$rootdir/configure" $config_params --without-shared 411 $MAKE $MAKEFLAGS 412} 413 414autobuild_test_suite() { 415 run_test "autobuild" _autobuild_test_suite 416} 417 418unittest_build() { 419 run_test "unittest_build" _unittest_build 420} 421 422scanbuild_make() { 423 run_test "scanbuild_make" _scanbuild_make 424} 425 426ocf_precompile() { 427 run_test "autobuild_ocf_precompile" _ocf_precompile 428} 429 430llvm_precompile() { 431 run_test "autobuild_llvm_precompile" _llvm_precompile 432} 433 434build_native_dpdk() { 435 run_test "build_native_dpdk" _build_native_dpdk 436} 437 438build_packaging() { 439 run_test "packaging" "$rootdir/test/packaging/packaging.sh" 440} 441 442out=$output_dir 443SPDK_WORKSPACE=$(mktemp -dt "spdk_$(date +%s).XXXXXX") 444 445if [[ -n $EXTERNAL_MAKE_HUGEMEM ]]; then 446 export EXTERNAL_MAKE_HUGEMEM 447fi 448 449if [ -n "$SPDK_TEST_NATIVE_DPDK" ]; then 450 scanbuild_exclude=" --exclude $(dirname $SPDK_RUN_EXTERNAL_DPDK)" 451else 452 scanbuild_exclude="--exclude $rootdir/dpdk/" 453fi 454# We exclude /tmp as it's used by xnvme's liburing subproject for storing 455# temporary .c files which are picked up as buggy by the scanbuild. 456scanbuild_exclude+=" --exclude $rootdir/xnvme --exclude /tmp" 457 458scanbuild="scan-build -o $output_dir/scan-build-tmp $scanbuild_exclude --status-bugs" 459config_params=$(get_config_params) 460