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