:p
atchew
Login
This patch builds bpf tests after building other mptcp selftests in btf mode: cd tools/testing/selftests/bpf && make And add run_bpftest_all to run bpftests: ./test_progs -t mptcp ./test_progs-no_alu32 -t mptcp Now mptcp bpf selftests can be tested in this way: docker run ... auto-btf run_loop run_bpftest_all in .virtme-exec-run Disable IA32_EMULATION config to fix this error: ./include/linux/if.h:28:10: fatal error: sys/socket.h: no such file or directory Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/406 Signed-off-by: Geliang Tang <geliang@kernel.org> --- v2: - drop links for 'test_progs, bpf_testmod.ko'. - rename bpf_selftest.sh to mptcp_progs.sh. - fix bugs in run_loop. --- Dockerfile | 1 + entrypoint.sh | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/Dockerfile b/Dockerfile index XXXXXXX..XXXXXXX 100644 --- a/Dockerfile +++ b/Dockerfile @@ -XXX,XX +XXX,XX @@ RUN apt-get update && \ wget xz-utils lftp cpio u-boot-tools \ cscope \ bpftrace \ + python3-docutils \ && \ apt-get clean diff --git a/entrypoint.sh b/entrypoint.sh index XXXXXXX..XXXXXXX 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -XXX,XX +XXX,XX @@ VIRTME_RUN_EXPECT="${VIRTME_SCRIPTS_DIR}/virtme.expect" SELFTESTS_DIR="${INPUT_SELFTESTS_DIR:-tools/testing/selftests/net/mptcp}" SELFTESTS_CONFIG="${SELFTESTS_DIR}/config" +BPFTESTS_DIR="${INPUT_BPFTESTS_DIR:-tools/testing/selftests/bpf}" +BPFTESTS_CONFIG="${BPFTESTS_DIR}/config" export CCACHE_MAXSIZE="${INPUT_CCACHE_MAXSIZE}" export CCACHE_DIR="${VIRTME_WORKDIR}/ccache" @@ -XXX,XX +XXX,XX @@ gen_kconfig() { local mode kconfig=() # Extra options are needed for kselftests ./scripts/kconfig/merge_config.sh -m "${VIRTME_KCONFIG}" "${SELFTESTS_CONFIG}" + if [ "${mode}" = "btf" ]; then + # Extra options are needed for bpftests + ./scripts/kconfig/merge_config.sh -m "${VIRTME_KCONFIG}" "${BPFTESTS_CONFIG}" + kconfig+=(-e DEBUG_INFO_BTF_MODULES -e MODULE_ALLOW_BTF_MISMATCH) + kconfig+=(-d IA32_EMULATION) + fi + ./scripts/config --file "${VIRTME_KCONFIG}" "${kconfig[@]}" _make_o olddefconfig @@ -XXX,XX +XXX,XX @@ build_selftests() { _make_o KHDR_INCLUDES="-I${VIRTME_BUILD_DIR}/include" -C "${SELFTESTS_DIR}" } +build_bpftests() { + if [ "${INPUT_BUILD_SKIP_BPFTESTS}" = 1 ]; then + printinfo "Skip bpftests build" + return 0 + fi + + _make KHDR_INCLUDES="-I${VIRTME_BUILD_DIR}/include" -C "${BPFTESTS_DIR}" + + printf "#!/bin/sh\n\n./test_progs -t mptcp\n./test_progs-no_alu32 -t mptcp" \ + > ${BPFTESTS_DIR}/mptcp_progs.sh + chmod +x ${BPFTESTS_DIR}/mptcp_progs.sh +} + build_packetdrill() { local old_pwd kversion kver_maj kver_min branch if [ "${INPUT_BUILD_SKIP_PACKETDRILL}" = 1 ]; then printinfo "Skip Packetdrill build" @@ -XXX,XX +XXX,XX @@ prepare() { local mode no_tap=1 printinfo "Prepare the environment" build_selftests + if [ "${mode}" = "btf" ]; then + build_bpftests + fi build_packetdrill prepare_hosts_file @@ -XXX,XX +XXX,XX @@ run_packetdrill_all() { local pktd_dir rc=0 return \${rc} } +# \$1: output tap file; rest: command to launch +_run_bpftest_one_tap() { + cd "${KERNEL_SRC}/${BPFTESTS_DIR}" + _tap "\${@}" +} + +# \$1: script file; rest: command to launch +run_bpftest_one() { local sf tap + sf=\$(basename \${1}) + tap=bpftest_\${sf:0:-3} + shift + + _can_run "\${tap}" || return 0 + + _run_bpftest_one_tap "${RESULTS_DIR}/\${tap}" "./\${sf}" "\${@}" +} + +run_bpftest_all() { local sf rc=0 + sf=${KERNEL_SRC}/${BPFTESTS_DIR}/mptcp_progs.sh + if [ -e "\${sf}" ]; then + run_bpftest_one "\${sf}" || rc=\${?} + fi + + return \${rc} +} + run_all() { run_kunit_all run_selftest_all run_mptcp_connect_mmap run_packetdrill_all + run_bpftest_all } has_call_trace() { @@ -XXX,XX +XXX,XX @@ if [ -f "${VIRTME_EXEC_POST}" ]; then # e.g.: cat /sys/kernel/tracing/trace fi +# Cleanup +if [ -e "${KERNEL_SRC}/${BPFTESTS_DIR}/mptcp_progs.sh" ]; then + rm -rf "${KERNEL_SRC}/${BPFTESTS_DIR}/mptcp_progs.sh" +fi + # end echo "${VIRTME_SCRIPT_END}" EOF -- 2.40.1
From: Geliang Tang <tanggeliang@kylinos.cn> This patch builds bpf tests after building other mptcp selftests in btf mode: cd tools/testing/selftests/bpf && make And add run_bpftest_all to run bpftests: ./test_progs -t mptcp ./test_progs-no_alu32 -t mptcp Now mptcp bpf selftests can be tested in this way: docker run ... auto-btf run_loop run_bpftest_all in .virtme-exec-run Disable IA32_EMULATION config to fix this error: ./include/linux/if.h:28:10: fatal error: sys/socket.h: no such file or directory Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/406 Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn> --- v3: - depends on "bpf, btf: Add DEBUG_INFO_BTF checks for __register_bpf_struct_ops", which I sent to BPF ML. - cleanup. v2: - drop links for 'test_progs, bpf_testmod.ko'. - rename bpf_selftest.sh to mptcp_progs.sh. - fix bugs in run_loop. --- entrypoint.sh | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index XXXXXXX..XXXXXXX 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -XXX,XX +XXX,XX @@ VIRTME_RUN_EXPECT="${VIRTME_SCRIPTS_DIR}/virtme.expect" SELFTESTS_DIR="${INPUT_SELFTESTS_DIR:-tools/testing/selftests/net/mptcp}" SELFTESTS_CONFIG="${SELFTESTS_DIR}/config" +BPFTESTS_DIR="${INPUT_BPFTESTS_DIR:-tools/testing/selftests/bpf}" +BPFTESTS_CONFIG="${BPFTESTS_DIR}/config" export CCACHE_MAXSIZE="${INPUT_CCACHE_MAXSIZE}" export CCACHE_DIR="${VIRTME_WORKDIR}/ccache" @@ -XXX,XX +XXX,XX @@ gen_kconfig() { local mode kconfig=() # We need more debug info but it is slow to generate if [ "${mode}" = "btf" ]; then kconfig+=(-e DEBUG_INFO_BTF) + # Extra options are needed for bpftests + ./scripts/kconfig/merge_config.sh -m "${VIRTME_KCONFIG}" "${BPFTESTS_CONFIG}" + kconfig+=(-e DEBUG_INFO_BTF_MODULES -e MODULE_ALLOW_BTF_MISMATCH) + # Fix ./include/linux/if.h:28:10: fatal error: + # sys/socket.h: no such file or directory + kconfig+=(-d IA32_EMULATION) elif is_ci || [ "${mode}" != "debsym" ]; then kconfig+=(-e DEBUG_INFO_REDUCED -e DEBUG_INFO_SPLIT) fi @@ -XXX,XX +XXX,XX @@ build_selftests() { _make_o KHDR_INCLUDES="-I${VIRTME_BUILD_DIR}/include" -C "${SELFTESTS_DIR}" } +build_bpftests() { + if [ "${INPUT_BUILD_SKIP_BPFTESTS}" = 1 ]; then + printinfo "Skip bpftests build" + return 0 + fi + + _make KHDR_INCLUDES="-I${VIRTME_BUILD_DIR}/include" -C "${BPFTESTS_DIR}" + + printf "#!/bin/sh\n\n./test_progs -t mptcp\n./test_progs-no_alu32 -t mptcp" \ + > ${BPFTESTS_DIR}/mptcp_progs.sh + chmod +x ${BPFTESTS_DIR}/mptcp_progs.sh +} + build_packetdrill() { local old_pwd kversion kver_maj kver_min branch if [ "${INPUT_BUILD_SKIP_PACKETDRILL}" = 1 ]; then printinfo "Skip Packetdrill build" @@ -XXX,XX +XXX,XX @@ prepare() { local mode no_tap=1 printinfo "Prepare the environment" build_selftests + if [ "${mode}" = "btf" ]; then + build_bpftests + fi build_packetdrill prepare_hosts_file @@ -XXX,XX +XXX,XX @@ run_packetdrill_all() { local pktd_dir rc=0 return \${rc} } +# \$1: output tap file; rest: command to launch +_run_bpftest_one_tap() { + cd "${KERNEL_SRC}/${BPFTESTS_DIR}" + _tap "\${@}" +} + +# \$1: script file; rest: command to launch +run_bpftest_one() { local sf tap + sf=\$(basename \${1}) + tap=bpftest_\${sf:0:-3} + shift + + _can_run "\${tap}" || return 0 + + _run_bpftest_one_tap "${RESULTS_DIR}/\${tap}" "./\${sf}" "\${@}" +} + +run_bpftest_all() { local sf rc=0 + sf=${KERNEL_SRC}/${BPFTESTS_DIR}/mptcp_progs.sh + if [ -e "\${sf}" ]; then + run_bpftest_one "\${sf}" || rc=\${?} + fi + + return \${rc} +} + run_all() { run_kunit_all run_selftest_all run_mptcp_connect_mmap run_packetdrill_all + run_bpftest_all } has_call_trace() { @@ -XXX,XX +XXX,XX @@ if [ -f "${VIRTME_EXEC_POST}" ]; then # e.g.: cat /sys/kernel/tracing/trace fi +# Cleanup +if [ -e "${KERNEL_SRC}/${BPFTESTS_DIR}/mptcp_progs.sh" ]; then + rm -rf "${KERNEL_SRC}/${BPFTESTS_DIR}/mptcp_progs.sh" +fi + # end echo "${VIRTME_SCRIPT_END}" EOF -- 2.40.1