diff mbox series

[bpf-next,v2] selftests/bpf: Enable cross platform testing for local vmtest

Message ID 20240326155736.3480081-1-pulehui@huaweicloud.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series [bpf-next,v2] selftests/bpf: Enable cross platform testing for local vmtest | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for bpf-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 3 maintainers not CCed: yonghong.song@linux.dev linux-kselftest@vger.kernel.org shuah@kernel.org
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest fail Script vmtest.sh not found in tools/testing/selftests/bpf/Makefile
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch warning WARNING: line length of 82 exceeds 80 columns WARNING: line length of 91 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-26 success Logs for x86_64-gcc / test (test_verifier, false, 360) / test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-41 success Logs for x86_64-llvm-18 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-33 success Logs for x86_64-llvm-17 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-21 success Logs for x86_64-gcc / test (test_maps, false, 360) / test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-30 success Logs for x86_64-llvm-17 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-23 success Logs for x86_64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-27 success Logs for x86_64-gcc / veristat / veristat on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-32 success Logs for x86_64-llvm-17 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-24 success Logs for x86_64-gcc / test (test_progs_no_alu32_parallel, true, 30) / test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-16 success Logs for s390x-gcc / test (test_verifier, false, 360) / test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-13 success Logs for s390x-gcc / test (test_maps, false, 360) / test_maps on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-38 success Logs for x86_64-llvm-18 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-39 success Logs for x86_64-llvm-18 / test (test_progs_cpuv4, false, 360) / test_progs_cpuv4 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-31 success Logs for x86_64-llvm-17 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-25 success Logs for x86_64-gcc / test (test_progs_parallel, true, 30) / test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-40 success Logs for x86_64-llvm-18 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-37 success Logs for x86_64-llvm-18 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-15 success Logs for s390x-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-14 success Logs for s390x-gcc / test (test_progs, false, 360) / test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-next-VM_Test-18 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-22 success Logs for x86_64-llvm-17 / build-release / build for x86_64 with llvm-17 and -O2 optimization
bpf/vmtest-bpf-next-VM_Test-11 success Logs for s390x-gcc / build / build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-5 success Logs for aarch64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-4 success Logs for aarch64-gcc / build / build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-12 success Logs for s390x-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-10 success Logs for aarch64-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-3 success Logs for Validate matrix.py
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Unittests
bpf/vmtest-bpf-next-VM_Test-20 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-17 success Logs for s390x-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-9 success Logs for aarch64-gcc / test (test_verifier, false, 360) / test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-19 success Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-36 success Logs for x86_64-llvm-18 / build-release / build for x86_64 with llvm-18 and -O2 optimization
bpf/vmtest-bpf-next-VM_Test-7 success Logs for aarch64-gcc / test (test_progs, false, 360) / test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-6 success Logs for aarch64-gcc / test (test_maps, false, 360) / test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-29 success Logs for x86_64-llvm-17 / build-release / build for x86_64 with llvm-17 and -O2 optimization
bpf/vmtest-bpf-next-VM_Test-28 success Logs for x86_64-llvm-17 / build / build for x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-34 success Logs for x86_64-llvm-17 / veristat
bpf/vmtest-bpf-next-VM_Test-35 success Logs for x86_64-llvm-18 / build / build for x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-8 success Logs for aarch64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-42 success Logs for x86_64-llvm-18 / veristat

Commit Message

Pu Lehui March 26, 2024, 3:57 p.m. UTC
From: Pu Lehui <pulehui@huawei.com>

The variable $ARCH in the current script is platform semantics, not
kernel semantics. Rename it to $PLATFORM so that we can easily use $ARCH
in cross-compilation. For now, Using PLATFORM= and CROSS_COMPILE=
options will enable cross platform testing:

  PLATFORM=<platform> CROSS_COMPILE=<toolchain> vmtest.sh -- ./test_progs

Meanwhile, some descriptions have been corrected.

Signed-off-by: Pu Lehui <pulehui@huawei.com>
---
v2:
- Specifies the -cpu for the ARM64.
- Completely renamed ARCH to PLATFORM.

 tools/testing/selftests/bpf/vmtest.sh | 40 +++++++++++++++++++--------
 1 file changed, 28 insertions(+), 12 deletions(-)

Comments

Pu Lehui March 28, 2024, 12:51 p.m. UTC | #1
Gather this to riscv64 patchset [0] for better regression:

Link: 
https://lore.kernel.org/bpf/20240328124916.293173-1-pulehui@huaweicloud.com/ 
[0]

On 2024/3/26 23:57, Pu Lehui wrote:
> From: Pu Lehui <pulehui@huawei.com>
> 
> The variable $ARCH in the current script is platform semantics, not
> kernel semantics. Rename it to $PLATFORM so that we can easily use $ARCH
> in cross-compilation. For now, Using PLATFORM= and CROSS_COMPILE=
> options will enable cross platform testing:
> 
>    PLATFORM=<platform> CROSS_COMPILE=<toolchain> vmtest.sh -- ./test_progs
> 
> Meanwhile, some descriptions have been corrected.
> 
> Signed-off-by: Pu Lehui <pulehui@huawei.com>
> ---
> v2:
> - Specifies the -cpu for the ARM64.
> - Completely renamed ARCH to PLATFORM.
> 
>   tools/testing/selftests/bpf/vmtest.sh | 40 +++++++++++++++++++--------
>   1 file changed, 28 insertions(+), 12 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/vmtest.sh b/tools/testing/selftests/bpf/vmtest.sh
> index 65d14f3bbe30..825149a905e5 100755
> --- a/tools/testing/selftests/bpf/vmtest.sh
> +++ b/tools/testing/selftests/bpf/vmtest.sh
> @@ -4,28 +4,34 @@
>   set -u
>   set -e
>   
> -# This script currently only works for x86_64 and s390x, as
> -# it is based on the VM image used by the BPF CI, which is
> +# This script currently only works for the following platforms,
> +# as it is based on the VM image used by the BPF CI, which is
>   # available only for these architectures.
> -ARCH="$(uname -m)"
> -case "${ARCH}" in
> +PLATFORM="${PLATFORM:-$(uname -m)}"
> +case "${PLATFORM}" in
>   s390x)
>   	QEMU_BINARY=qemu-system-s390x
>   	QEMU_CONSOLE="ttyS1"
> -	QEMU_FLAGS=(-smp 2)
> +	HOST_FLAGS=(-smp 2 -enable-kvm)
> +	CROSS_FLAGS=(-smp 2)
>   	BZIMAGE="arch/s390/boot/vmlinux"
> +	ARCH="s390"
>   	;;
>   x86_64)
>   	QEMU_BINARY=qemu-system-x86_64
>   	QEMU_CONSOLE="ttyS0,115200"
> -	QEMU_FLAGS=(-cpu host -smp 8)
> +	HOST_FLAGS=(-cpu host -enable-kvm -smp 8)
> +	CROSS_FLAGS=(-smp 8)
>   	BZIMAGE="arch/x86/boot/bzImage"
> +	ARCH="x86"
>   	;;
>   aarch64)
>   	QEMU_BINARY=qemu-system-aarch64
>   	QEMU_CONSOLE="ttyAMA0,115200"
> -	QEMU_FLAGS=(-M virt,gic-version=3 -cpu host -smp 8)
> +	HOST_FLAGS=(-M virt,gic-version=3 -cpu host -enable-kvm -smp 8)
> +	CROSS_FLAGS=(-M virt,gic-version=3 -cpu cortex-a76 -smp 8)
>   	BZIMAGE="arch/arm64/boot/Image"
> +	ARCH="arm64"
>   	;;
>   *)
>   	echo "Unsupported architecture"
> @@ -38,7 +44,7 @@ ROOTFS_IMAGE="root.img"
>   OUTPUT_DIR="$HOME/.bpf_selftests"
>   KCONFIG_REL_PATHS=("tools/testing/selftests/bpf/config"
>   	"tools/testing/selftests/bpf/config.vm"
> -	"tools/testing/selftests/bpf/config.${ARCH}")
> +	"tools/testing/selftests/bpf/config.${PLATFORM}")
>   INDEX_URL="https://raw.githubusercontent.com/libbpf/ci/master/INDEX"
>   NUM_COMPILE_JOBS="$(nproc)"
>   LOG_FILE_BASE="$(date +"bpf_selftests.%Y-%m-%d_%H-%M-%S")"
> @@ -58,6 +64,10 @@ tools/testing/selftests/bpf. e.g:
>   If no command is specified and a debug shell (-s) is not requested,
>   "${DEFAULT_COMMAND}" will be run by default.
>   
> +Using PLATFORM= and CROSS_COMPILE= options will enable cross platform testing:
> +
> +  PLATFORM=<platform> CROSS_COMPILE=<toolchain> $0 -- ./test_progs -t test_lsm
> +
>   If you build your kernel using KBUILD_OUTPUT= or O= options, these
>   can be passed as environment variables to the script:
>   
> @@ -109,7 +119,7 @@ newest_rootfs_version()
>   {
>   	{
>   	for file in "${!URLS[@]}"; do
> -		if [[ $file =~ ^"${ARCH}"/libbpf-vmtest-rootfs-(.*)\.tar\.zst$ ]]; then
> +		if [[ $file =~ ^"${PLATFORM}"/libbpf-vmtest-rootfs-(.*)\.tar\.zst$ ]]; then
>   			echo "${BASH_REMATCH[1]}"
>   		fi
>   	done
> @@ -126,7 +136,7 @@ download_rootfs()
>   		exit 1
>   	fi
>   
> -	download "${ARCH}/libbpf-vmtest-rootfs-$rootfsversion.tar.zst" |
> +	download "${PLATFORM}/libbpf-vmtest-rootfs-$rootfsversion.tar.zst" |
>   		zstd -d | sudo tar -C "$dir" -x
>   }
>   
> @@ -244,12 +254,17 @@ EOF
>   		exit 1
>   	fi
>   
> +	if [[ "${CROSS_COMPILE}" != "" ]]; then
> +		QEMU_FLAGS=("${CROSS_FLAGS[@]}")
> +	else
> +		QEMU_FLAGS=("${HOST_FLAGS[@]}")
> +	fi
> +
>   	${QEMU_BINARY} \
>   		-nodefaults \
>   		-display none \
>   		-serial mon:stdio \
>   		"${QEMU_FLAGS[@]}" \
> -		-enable-kvm \
>   		-m 4G \
>   		-drive file="${rootfs_img}",format=raw,index=1,media=disk,if=virtio,cache=none \
>   		-kernel "${kernel_bzimage}" \
> @@ -384,7 +399,8 @@ main()
>   	fi
>   
>   	local kconfig_file="${OUTPUT_DIR}/latest.config"
> -	local make_command="make -j ${NUM_COMPILE_JOBS} KCONFIG_CONFIG=${kconfig_file}"
> +	local make_command="make ARCH=${ARCH} CROSS_COMPILE=${CROSS_COMPILE} \
> +			    -j ${NUM_COMPILE_JOBS} KCONFIG_CONFIG=${kconfig_file}"
>   
>   	# Figure out where the kernel is being built.
>   	# O takes precedence over KBUILD_OUTPUT.
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/vmtest.sh b/tools/testing/selftests/bpf/vmtest.sh
index 65d14f3bbe30..825149a905e5 100755
--- a/tools/testing/selftests/bpf/vmtest.sh
+++ b/tools/testing/selftests/bpf/vmtest.sh
@@ -4,28 +4,34 @@ 
 set -u
 set -e
 
-# This script currently only works for x86_64 and s390x, as
-# it is based on the VM image used by the BPF CI, which is
+# This script currently only works for the following platforms,
+# as it is based on the VM image used by the BPF CI, which is
 # available only for these architectures.
-ARCH="$(uname -m)"
-case "${ARCH}" in
+PLATFORM="${PLATFORM:-$(uname -m)}"
+case "${PLATFORM}" in
 s390x)
 	QEMU_BINARY=qemu-system-s390x
 	QEMU_CONSOLE="ttyS1"
-	QEMU_FLAGS=(-smp 2)
+	HOST_FLAGS=(-smp 2 -enable-kvm)
+	CROSS_FLAGS=(-smp 2)
 	BZIMAGE="arch/s390/boot/vmlinux"
+	ARCH="s390"
 	;;
 x86_64)
 	QEMU_BINARY=qemu-system-x86_64
 	QEMU_CONSOLE="ttyS0,115200"
-	QEMU_FLAGS=(-cpu host -smp 8)
+	HOST_FLAGS=(-cpu host -enable-kvm -smp 8)
+	CROSS_FLAGS=(-smp 8)
 	BZIMAGE="arch/x86/boot/bzImage"
+	ARCH="x86"
 	;;
 aarch64)
 	QEMU_BINARY=qemu-system-aarch64
 	QEMU_CONSOLE="ttyAMA0,115200"
-	QEMU_FLAGS=(-M virt,gic-version=3 -cpu host -smp 8)
+	HOST_FLAGS=(-M virt,gic-version=3 -cpu host -enable-kvm -smp 8)
+	CROSS_FLAGS=(-M virt,gic-version=3 -cpu cortex-a76 -smp 8)
 	BZIMAGE="arch/arm64/boot/Image"
+	ARCH="arm64"
 	;;
 *)
 	echo "Unsupported architecture"
@@ -38,7 +44,7 @@  ROOTFS_IMAGE="root.img"
 OUTPUT_DIR="$HOME/.bpf_selftests"
 KCONFIG_REL_PATHS=("tools/testing/selftests/bpf/config"
 	"tools/testing/selftests/bpf/config.vm"
-	"tools/testing/selftests/bpf/config.${ARCH}")
+	"tools/testing/selftests/bpf/config.${PLATFORM}")
 INDEX_URL="https://raw.githubusercontent.com/libbpf/ci/master/INDEX"
 NUM_COMPILE_JOBS="$(nproc)"
 LOG_FILE_BASE="$(date +"bpf_selftests.%Y-%m-%d_%H-%M-%S")"
@@ -58,6 +64,10 @@  tools/testing/selftests/bpf. e.g:
 If no command is specified and a debug shell (-s) is not requested,
 "${DEFAULT_COMMAND}" will be run by default.
 
+Using PLATFORM= and CROSS_COMPILE= options will enable cross platform testing:
+
+  PLATFORM=<platform> CROSS_COMPILE=<toolchain> $0 -- ./test_progs -t test_lsm
+
 If you build your kernel using KBUILD_OUTPUT= or O= options, these
 can be passed as environment variables to the script:
 
@@ -109,7 +119,7 @@  newest_rootfs_version()
 {
 	{
 	for file in "${!URLS[@]}"; do
-		if [[ $file =~ ^"${ARCH}"/libbpf-vmtest-rootfs-(.*)\.tar\.zst$ ]]; then
+		if [[ $file =~ ^"${PLATFORM}"/libbpf-vmtest-rootfs-(.*)\.tar\.zst$ ]]; then
 			echo "${BASH_REMATCH[1]}"
 		fi
 	done
@@ -126,7 +136,7 @@  download_rootfs()
 		exit 1
 	fi
 
-	download "${ARCH}/libbpf-vmtest-rootfs-$rootfsversion.tar.zst" |
+	download "${PLATFORM}/libbpf-vmtest-rootfs-$rootfsversion.tar.zst" |
 		zstd -d | sudo tar -C "$dir" -x
 }
 
@@ -244,12 +254,17 @@  EOF
 		exit 1
 	fi
 
+	if [[ "${CROSS_COMPILE}" != "" ]]; then
+		QEMU_FLAGS=("${CROSS_FLAGS[@]}")
+	else
+		QEMU_FLAGS=("${HOST_FLAGS[@]}")
+	fi
+
 	${QEMU_BINARY} \
 		-nodefaults \
 		-display none \
 		-serial mon:stdio \
 		"${QEMU_FLAGS[@]}" \
-		-enable-kvm \
 		-m 4G \
 		-drive file="${rootfs_img}",format=raw,index=1,media=disk,if=virtio,cache=none \
 		-kernel "${kernel_bzimage}" \
@@ -384,7 +399,8 @@  main()
 	fi
 
 	local kconfig_file="${OUTPUT_DIR}/latest.config"
-	local make_command="make -j ${NUM_COMPILE_JOBS} KCONFIG_CONFIG=${kconfig_file}"
+	local make_command="make ARCH=${ARCH} CROSS_COMPILE=${CROSS_COMPILE} \
+			    -j ${NUM_COMPILE_JOBS} KCONFIG_CONFIG=${kconfig_file}"
 
 	# Figure out where the kernel is being built.
 	# O takes precedence over KBUILD_OUTPUT.