Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: Adjust vmtest.sh to use local kernel configuration

So far the vmtest.sh script, which can be used as a convenient way to
run bpf selftests, has obtained the kernel config safe to use for
testing from the libbpf/libbpf GitHub repository [0].

Given that we now have included this configuration into this very
repository, we can just consume it from here as well, eliminating the
necessity of remote accesses.

With this change we adjust the logic in the script to use the
configuration from below tools/testing/selftests/bpf/configs/ instead
of pulling it over the network.

[0] https://github.com/libbpf/libbpf

Signed-off-by: Daniel Müller <deso@posteo.net>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Acked-by: Mykola Lysenko <mykolal@fb.com>
Link: https://lore.kernel.org/bpf/20220727001156.3553701-4-deso@posteo.net

authored by

Daniel Müller and committed by
Daniel Borkmann
40b09653 cbd620fc

+34 -19
+34 -19
tools/testing/selftests/bpf/vmtest.sh
··· 30 30 MOUNT_DIR="mnt" 31 31 ROOTFS_IMAGE="root.img" 32 32 OUTPUT_DIR="$HOME/.bpf_selftests" 33 - KCONFIG_URL="https://raw.githubusercontent.com/libbpf/libbpf/master/travis-ci/vmtest/configs/config-latest.${ARCH}" 34 - KCONFIG_API_URL="https://api.github.com/repos/libbpf/libbpf/contents/travis-ci/vmtest/configs/config-latest.${ARCH}" 33 + KCONFIG_REL_PATHS=("tools/testing/selftests/bpf/config" "tools/testing/selftests/bpf/config.${ARCH}") 35 34 INDEX_URL="https://raw.githubusercontent.com/libbpf/ci/master/INDEX" 36 35 NUM_COMPILE_JOBS="$(nproc)" 37 36 LOG_FILE_BASE="$(date +"bpf_selftests.%Y-%m-%d_%H-%M-%S")" ··· 268 269 [[ ${path:0:1} != "/" ]] 269 270 } 270 271 272 + do_update_kconfig() 273 + { 274 + local kernel_checkout="$1" 275 + local kconfig_file="$2" 276 + 277 + rm -f "$kconfig_file" 2> /dev/null 278 + 279 + for config in "${KCONFIG_REL_PATHS[@]}"; do 280 + local kconfig_src="${kernel_checkout}/${config}" 281 + cat "$kconfig_src" >> "$kconfig_file" 282 + done 283 + } 284 + 271 285 update_kconfig() 272 286 { 273 - local kconfig_file="$1" 274 - local update_command="curl -sLf ${KCONFIG_URL} -o ${kconfig_file}" 275 - # Github does not return the "last-modified" header when retrieving the 276 - # raw contents of the file. Use the API call to get the last-modified 277 - # time of the kernel config and only update the config if it has been 278 - # updated after the previously cached config was created. This avoids 279 - # unnecessarily compiling the kernel and selftests. 280 - if [[ -f "${kconfig_file}" ]]; then 281 - local last_modified_date="$(curl -sL -D - "${KCONFIG_API_URL}" -o /dev/null | \ 282 - grep "last-modified" | awk -F ': ' '{print $2}')" 283 - local remote_modified_timestamp="$(date -d "${last_modified_date}" +"%s")" 284 - local local_creation_timestamp="$(stat -c %Y "${kconfig_file}")" 287 + local kernel_checkout="$1" 288 + local kconfig_file="$2" 285 289 286 - if [[ "${remote_modified_timestamp}" -gt "${local_creation_timestamp}" ]]; then 287 - ${update_command} 288 - fi 290 + if [[ -f "${kconfig_file}" ]]; then 291 + local local_modified="$(stat -c %Y "${kconfig_file}")" 292 + 293 + for config in "${KCONFIG_REL_PATHS[@]}"; do 294 + local kconfig_src="${kernel_checkout}/${config}" 295 + local src_modified="$(stat -c %Y "${kconfig_src}")" 296 + # Only update the config if it has been updated after the 297 + # previously cached config was created. This avoids 298 + # unnecessarily compiling the kernel and selftests. 299 + if [[ "${src_modified}" -gt "${local_modified}" ]]; then 300 + do_update_kconfig "$kernel_checkout" "$kconfig_file" 301 + # Once we have found one outdated configuration 302 + # there is no need to check other ones. 303 + break 304 + fi 305 + done 289 306 else 290 - ${update_command} 307 + do_update_kconfig "$kernel_checkout" "$kconfig_file" 291 308 fi 292 309 } 293 310 ··· 387 372 388 373 mkdir -p "${OUTPUT_DIR}" 389 374 mkdir -p "${mount_dir}" 390 - update_kconfig "${kconfig_file}" 375 + update_kconfig "${kernel_checkout}" "${kconfig_file}" 391 376 392 377 recompile_kernel "${kernel_checkout}" "${make_command}" 393 378