Skip to content

Commit 0c3fc33

Browse files
Pu LehuiAlexei Starovoitov
authored andcommitted
selftests/bpf: Limit URLS parsing logic to actual scope in vmtest
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 67ab80a commit 0c3fc33

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

tools/testing/selftests/bpf/vmtest.sh

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,6 @@ populate_url_map()
9292
fi
9393
}
9494

95-
download()
96-
{
97-
local file="$1"
98-
99-
if [[ ! -v URLS[$file] ]]; then
100-
echo "$file not found" >&2
101-
return 1
102-
fi
103-
104-
echo "Downloading $file..." >&2
105-
curl -Lsf "${URLS[$file]}" "${@:2}"
106-
}
107-
10895
newest_rootfs_version()
10996
{
11097
{
@@ -118,16 +105,30 @@ newest_rootfs_version()
118105

119106
download_rootfs()
120107
{
121-
local rootfsversion="$1"
122-
local dir="$2"
108+
populate_url_map
109+
110+
local rootfsversion="$(newest_rootfs_version)"
111+
local file="${ARCH}/libbpf-vmtest-rootfs-$rootfsversion.tar.zst"
112+
113+
if [[ ! -v URLS[$file] ]]; then
114+
echo "$file not found" >&2
115+
return 1
116+
fi
117+
118+
echo "Downloading $file..." >&2
119+
curl -Lsf "${URLS[$file]}" "${@:2}"
120+
}
121+
122+
load_rootfs()
123+
{
124+
local dir="$1"
123125

124126
if ! which zstd &> /dev/null; then
125127
echo 'Could not find "zstd" on the system, please install zstd'
126128
exit 1
127129
fi
128130

129-
download "${ARCH}/libbpf-vmtest-rootfs-$rootfsversion.tar.zst" |
130-
zstd -d | sudo tar -C "$dir" -x
131+
download_rootfs | zstd -d | sudo tar -C "$dir" -x
131132
}
132133

133134
recompile_kernel()
@@ -227,7 +228,7 @@ create_vm_image()
227228
mkfs.ext4 -q "${rootfs_img}"
228229

229230
mount_image
230-
download_rootfs "$(newest_rootfs_version)" "${mount_dir}"
231+
load_rootfs "${mount_dir}"
231232
unmount_image
232233
}
233234

@@ -402,8 +403,6 @@ main()
402403
make_command="${make_command} KBUILD_OUTPUT=${KBUILD_OUTPUT}"
403404
fi
404405

405-
populate_url_map
406-
407406
local rootfs_img="${OUTPUT_DIR}/${ROOTFS_IMAGE}"
408407
local mount_dir="${OUTPUT_DIR}/${MOUNT_DIR}"
409408

0 commit comments

Comments
 (0)