]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/bpf: Limit URLS parsing logic to actual scope in vmtest
authorPu Lehui <pulehui@huawei.com>
Thu, 5 Sep 2024 08:13:55 +0000 (08:13 +0000)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 5 Sep 2024 20:13:40 +0000 (13:13 -0700)
The URLS array is only valid in the download_rootfs function and does
not need to be parsed globally in advance. At the same time, the logic
of loading rootfs is refactored to prepare vmtest for supporting local
rootfs.

Signed-off-by: Pu Lehui <pulehui@huawei.com>
Link: https://lore.kernel.org/r/20240905081401.1894789-5-pulehui@huaweicloud.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/vmtest.sh

index 65d14f3bbe3012ca7e102179be6412d7e9e53876..87d93f29c5657a14314524712e44e59baa3a29f4 100755 (executable)
@@ -92,19 +92,6 @@ populate_url_map()
        fi
 }
 
-download()
-{
-       local file="$1"
-
-       if [[ ! -v URLS[$file] ]]; then
-               echo "$file not found" >&2
-               return 1
-       fi
-
-       echo "Downloading $file..." >&2
-       curl -Lsf "${URLS[$file]}" "${@:2}"
-}
-
 newest_rootfs_version()
 {
        {
@@ -118,16 +105,30 @@ newest_rootfs_version()
 
 download_rootfs()
 {
-       local rootfsversion="$1"
-       local dir="$2"
+       populate_url_map
+
+       local rootfsversion="$(newest_rootfs_version)"
+       local file="${ARCH}/libbpf-vmtest-rootfs-$rootfsversion.tar.zst"
+
+       if [[ ! -v URLS[$file] ]]; then
+               echo "$file not found" >&2
+               return 1
+       fi
+
+       echo "Downloading $file..." >&2
+       curl -Lsf "${URLS[$file]}" "${@:2}"
+}
+
+load_rootfs()
+{
+       local dir="$1"
 
        if ! which zstd &> /dev/null; then
                echo 'Could not find "zstd" on the system, please install zstd'
                exit 1
        fi
 
-       download "${ARCH}/libbpf-vmtest-rootfs-$rootfsversion.tar.zst" |
-               zstd -d | sudo tar -C "$dir" -x
+       download_rootfs | zstd -d | sudo tar -C "$dir" -x
 }
 
 recompile_kernel()
@@ -227,7 +228,7 @@ create_vm_image()
        mkfs.ext4 -q "${rootfs_img}"
 
        mount_image
-       download_rootfs "$(newest_rootfs_version)" "${mount_dir}"
+       load_rootfs "${mount_dir}"
        unmount_image
 }
 
@@ -402,8 +403,6 @@ main()
                make_command="${make_command} KBUILD_OUTPUT=${KBUILD_OUTPUT}"
        fi
 
-       populate_url_map
-
        local rootfs_img="${OUTPUT_DIR}/${ROOTFS_IMAGE}"
        local mount_dir="${OUTPUT_DIR}/${MOUNT_DIR}"