[PATCH 1/3] selftests/bpf: make test_doc_build.sh work from script directory
Subsystems:
bpf [general] (safe dynamic programs and tools) , bpf [selftests] (test runners & infrastructure) , kernel selftest framework , the rest
STALE1813d
7 messages,
3 authors,
2021-08-20 · open the first message on its own page
Previously, it fails as below:
-------------
root@lkp-skl-d01 /opt/rootfs/v5.14-rc4/tools/testing/selftests/bpf# ./test_doc_build.sh
++ realpath --relative-to=/opt/rootfs/v5.14-rc4/tools/testing/selftests/bpf ./test_doc_build.sh
+ SCRIPT_REL_PATH=test_doc_build.sh
++ dirname test_doc_build.sh
+ SCRIPT_REL_DIR=.
++ realpath /opt/rootfs/v5.14-rc4/tools/testing/selftests/bpf/./../../../../
+ KDIR_ROOT_DIR=/opt/rootfs/v5.14-rc4
+ cd /opt/rootfs/v5.14-rc4
+ for tgt in docs docs-clean
+ make -s -C /opt/rootfs/v5.14-rc4/. docs
make: *** No rule to make target 'docs'. Stop.
+ for tgt in docs docs-clean
+ make -s -C /opt/rootfs/v5.14-rc4/. docs-clean
make: *** No rule to make target 'docs-clean'. Stop.
-----------
Reported-by: kernel test robot <redacted>
Signed-off-by: Li Zhijian <redacted>
---
tools/testing/selftests/bpf/test_doc_build.sh | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/bpf/test_doc_build.sh b/tools/testing/selftests/bpf/test_doc_build.sh
index ed12111cd2f0..d67ced95a6cf 100755
--- a/tools/testing/selftests/bpf/test_doc_build.sh
+++ b/tools/testing/selftests/bpf/test_doc_build.sh @@ -4,9 +4,10 @@ set -e
# Assume script is located under tools/testing/selftests/bpf/. We want to start
# build attempts from the top of kernel repository.
- SCRIPT_REL_PATH = $( realpath --relative-to= $PWD $0 )
+ SCRIPT_REL_PATH = $( realpath $0 )
SCRIPT_REL_DIR = $( dirname $SCRIPT_REL_PATH )
- KDIR_ROOT_DIR = $( realpath $PWD /$SCRIPT_REL_DIR /../../../../)
+ KDIR_ROOT_DIR = $( realpath $SCRIPT_REL_DIR /../../../../)
+ SCRIPT_REL_DIR = $( dirname $( realpath --relative-to= $KDIR_ROOT_DIR $SCRIPT_REL_PATH ))
cd $KDIR_ROOT_DIR
for tgt in docs docs-clean; do --
2.32.0
For 'make run_tests':
selftests will build bpftool into tools/testing/selftests/bpf/tools/sbin/bpftool
by default.
==================
root@lkp-skl-d01 /opt/rootfs/v5.14-rc4# make -C tools/testing/selftests/bpf run_tests
make: Entering directory '/opt/rootfs/v5.14-rc4/tools/testing/selftests/bpf'
MKDIR include
MKDIR libbpf
MKDIR bpftool
[...]
GEN /opt/rootfs/v5.14-rc4/tools/testing/selftests/bpf/tools/build/bpftool/profiler.skel.h
CC /opt/rootfs/v5.14-rc4/tools/testing/selftests/bpf/tools/build/bpftool/prog.o
GEN /opt/rootfs/v5.14-rc4/tools/testing/selftests/bpf/tools/build/bpftool/pid_iter.skel.h
CC /opt/rootfs/v5.14-rc4/tools/testing/selftests/bpf/tools/build/bpftool/pids.o
LINK /opt/rootfs/v5.14-rc4/tools/testing/selftests/bpf/tools/build/bpftool/bpftool
INSTALL bpftool
GEN vmlinux.h
[...]
# test_feature_dev_json (test_bpftool.TestBpftool) ... ERROR
# test_feature_kernel (test_bpftool.TestBpftool) ... ERROR
# test_feature_kernel_full (test_bpftool.TestBpftool) ... ERROR
# test_feature_kernel_full_vs_not_full (test_bpftool.TestBpftool) ... ERROR
# test_feature_macros (test_bpftool.TestBpftool) ... Error: bug: failed to retrieve CAP_BPF status: Invalid argument
# ERROR
#
# ======================================================================
# ERROR: test_feature_dev_json (test_bpftool.TestBpftool)
# ----------------------------------------------------------------------
# Traceback (most recent call last):
# File "/opt/rootfs/v5.14-rc4/tools/testing/selftests/bpf/test_bpftool.py", line 57, in wrapper
# return f(*args, iface, **kwargs)
# File "/opt/rootfs/v5.14-rc4/tools/testing/selftests/bpf/test_bpftool.py", line 82, in test_feature_dev_json
# res = bpftool_json(["feature", "probe", "dev", iface])
# File "/opt/rootfs/v5.14-rc4/tools/testing/selftests/bpf/test_bpftool.py", line 42, in bpftool_json
# res = _bpftool(args)
# File "/opt/rootfs/v5.14-rc4/tools/testing/selftests/bpf/test_bpftool.py", line 34, in _bpftool
# return subprocess.check_output(_args)
# File "/usr/lib/python3.7/subprocess.py", line 395, in check_output
# **kwargs).stdout
# File "/usr/lib/python3.7/subprocess.py", line 487, in run
# output=stdout, stderr=stderr)
# subprocess.CalledProcessError: Command '['bpftool', '-j', 'feature', 'probe', 'dev', 'dummy0']' returned non-zero exit status 255.
#
==================
Signed-off-by: Li Zhijian <redacted>
---
tools/testing/selftests/bpf/test_bpftool.sh | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/tools/testing/selftests/bpf/test_bpftool.sh b/tools/testing/selftests/bpf/test_bpftool.sh
index 66690778e36d..6b7ba19be1d0 100755
--- a/tools/testing/selftests/bpf/test_bpftool.sh
+++ b/tools/testing/selftests/bpf/test_bpftool.sh @@ -2,4 +2,9 @@
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2020 SUSE LLC.
+ SCRIPT_DIR = $( dirname $( realpath $0 ))
+
+ # 'make -C tools/testing/selftests/bpf' will install to BPFTOOL_INSTALL_PATH
+ BPFTOOL_INSTALL_PATH = " $SCRIPT_DIR " /tools/sbin
+ export PATH = $BPFTOOL_INSTALL_PATH :$PATH
python3 -m unittest -v test_bpftool.TestBpftool --
2.32.0
- 'make install' will install bpftool to INSTALL_PATH/bpf/bpftool
- add INSTALL_PATH/bpf to PATH
Signed-off-by: Li Zhijian <redacted>
---
tools/testing/selftests/bpf/Makefile | 4 +++-
tools/testing/selftests/bpf/test_bpftool.sh | 3 ++-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index f405b20c1e6c..c6ca1b8e33d5 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile @@ -85,7 +85,7 @@ TEST_PROGS_EXTENDED := with_addr.sh \
TEST_GEN_PROGS_EXTENDED = test_sock_addr test_skb_cgroup_id_user \
flow_dissector_load test_flow_dissector test_tcp_check_syncookie_user \
test_lirc_mode2_user xdping test_cpp runqslower bench bpf_testmod.ko \
- xdpxceiver xdp_redirect_multi
+ xdpxceiver xdp_redirect_multi test_bpftool.py
TEST_CUSTOM_PROGS = $( OUTPUT) /urandom_read
@@ -187,6 +187,8 @@ $(OUTPUT)/runqslower: $(BPFOBJ) | $(DEFAULT_BPFTOOL)
BPFOBJ = $( BPFOBJ) BPF_INCLUDE = $( INCLUDE_DIR) && \
cp $( SCRATCH_DIR) /runqslower $@
+ TEST_GEN_PROGS_EXTENDED += $( DEFAULT_BPFTOOL)
+
$(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) : $( OUTPUT ) /test_stub .o $( BPFOBJ )
$(OUTPUT)/test_dev_cgroup : cgroup_helpers .c diff --git a/tools/testing/selftests/bpf/test_bpftool.sh b/tools/testing/selftests/bpf/test_bpftool.sh
index 6b7ba19be1d0..50cf9d3645d2 100755
--- a/tools/testing/selftests/bpf/test_bpftool.sh
+++ b/tools/testing/selftests/bpf/test_bpftool.sh @@ -2,9 +2,10 @@
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2020 SUSE LLC.
+ # 'make -C tools/testing/selftests/bpf install' will install to SCRIPT_PATH
SCRIPT_DIR = $( dirname $( realpath $0 ))
# 'make -C tools/testing/selftests/bpf' will install to BPFTOOL_INSTALL_PATH
BPFTOOL_INSTALL_PATH = " $SCRIPT_DIR " /tools/sbin
- export PATH = $BPFTOOL_INSTALL_PATH :$PATH
+ export PATH = $SCRIPT_DIR :$BPFTOOL_INSTALL_PATH :$PATH
python3 -m unittest -v test_bpftool.TestBpftool --
2.32.0
On Thu, Aug 19, 2021 at 12:27 AM Li Zhijian [off-list ref] wrote:
Previously, it fails as below:
-------------
root@lkp-skl-d01 /opt/rootfs/v5.14-rc4/tools/testing/selftests/bpf# ./test_doc_build.sh
++ realpath --relative-to=/opt/rootfs/v5.14-rc4/tools/testing/selftests/bpf ./test_doc_build.sh
+ SCRIPT_REL_PATH=test_doc_build.sh
++ dirname test_doc_build.sh
+ SCRIPT_REL_DIR=.
++ realpath /opt/rootfs/v5.14-rc4/tools/testing/selftests/bpf/./../../../../
+ KDIR_ROOT_DIR=/opt/rootfs/v5.14-rc4
+ cd /opt/rootfs/v5.14-rc4
+ for tgt in docs docs-clean
+ make -s -C /opt/rootfs/v5.14-rc4/. docs
make: *** No rule to make target 'docs'. Stop.
+ for tgt in docs docs-clean
+ make -s -C /opt/rootfs/v5.14-rc4/. docs-clean
make: *** No rule to make target 'docs-clean'. Stop.
-----------
Reported-by: kernel test robot <redacted>
Signed-off-by: Li Zhijian <redacted>
Acked-by: Song Liu <redacted>
quoted hunk ---
tools/testing/selftests/bpf/test_doc_build.sh | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/bpf/test_doc_build.sh b/tools/testing/selftests/bpf/test_doc_build.sh
index ed12111cd2f0..d67ced95a6cf 100755
--- a/tools/testing/selftests/bpf/test_doc_build.sh
+++ b/tools/testing/selftests/bpf/test_doc_build.sh @@ -4,9 +4,10 @@ set -e
# Assume script is located under tools/testing/selftests/bpf/. We want to start
# build attempts from the top of kernel repository.
- SCRIPT_REL_PATH = $( realpath --relative-to= $PWD $0 )
+ SCRIPT_REL_PATH = $( realpath $0 )
SCRIPT_REL_DIR = $( dirname $SCRIPT_REL_PATH )
- KDIR_ROOT_DIR = $( realpath $PWD /$SCRIPT_REL_DIR /../../../../)
+ KDIR_ROOT_DIR = $( realpath $SCRIPT_REL_DIR /../../../../)
+ SCRIPT_REL_DIR = $( dirname $( realpath --relative-to= $KDIR_ROOT_DIR $SCRIPT_REL_PATH ))
cd $KDIR_ROOT_DIR
for tgt in docs docs-clean; do
- -2.32.0
On Thu, Aug 19, 2021 at 12:27 AM Li Zhijian [off-list ref] wrote:
For 'make run_tests':
selftests will build bpftool into tools/testing/selftests/bpf/tools/sbin/bpftool
by default.
==================
root@lkp-skl-d01 /opt/rootfs/v5.14-rc4# make -C tools/testing/selftests/bpf run_tests
make: Entering directory '/opt/rootfs/v5.14-rc4/tools/testing/selftests/bpf'
MKDIR include
MKDIR libbpf
MKDIR bpftool
[...]
GEN /opt/rootfs/v5.14-rc4/tools/testing/selftests/bpf/tools/build/bpftool/profiler.skel.h
CC /opt/rootfs/v5.14-rc4/tools/testing/selftests/bpf/tools/build/bpftool/prog.o
GEN /opt/rootfs/v5.14-rc4/tools/testing/selftests/bpf/tools/build/bpftool/pid_iter.skel.h
CC /opt/rootfs/v5.14-rc4/tools/testing/selftests/bpf/tools/build/bpftool/pids.o
LINK /opt/rootfs/v5.14-rc4/tools/testing/selftests/bpf/tools/build/bpftool/bpftool
INSTALL bpftool
GEN vmlinux.h
[...]
# test_feature_dev_json (test_bpftool.TestBpftool) ... ERROR
# test_feature_kernel (test_bpftool.TestBpftool) ... ERROR
# test_feature_kernel_full (test_bpftool.TestBpftool) ... ERROR
# test_feature_kernel_full_vs_not_full (test_bpftool.TestBpftool) ... ERROR
# test_feature_macros (test_bpftool.TestBpftool) ... Error: bug: failed to retrieve CAP_BPF status: Invalid argument
# ERROR
#
# ======================================================================
# ERROR: test_feature_dev_json (test_bpftool.TestBpftool)
# ----------------------------------------------------------------------
# Traceback (most recent call last):
# File "/opt/rootfs/v5.14-rc4/tools/testing/selftests/bpf/test_bpftool.py", line 57, in wrapper
# return f(*args, iface, **kwargs)
# File "/opt/rootfs/v5.14-rc4/tools/testing/selftests/bpf/test_bpftool.py", line 82, in test_feature_dev_json
# res = bpftool_json(["feature", "probe", "dev", iface])
# File "/opt/rootfs/v5.14-rc4/tools/testing/selftests/bpf/test_bpftool.py", line 42, in bpftool_json
# res = _bpftool(args)
# File "/opt/rootfs/v5.14-rc4/tools/testing/selftests/bpf/test_bpftool.py", line 34, in _bpftool
# return subprocess.check_output(_args)
# File "/usr/lib/python3.7/subprocess.py", line 395, in check_output
# **kwargs).stdout
# File "/usr/lib/python3.7/subprocess.py", line 487, in run
# output=stdout, stderr=stderr)
# subprocess.CalledProcessError: Command '['bpftool', '-j', 'feature', 'probe', 'dev', 'dummy0']' returned non-zero exit status 255.
#
==================
Signed-off-by: Li Zhijian <redacted>
Acked-by: Song Liu <redacted>
quoted hunk ---
tools/testing/selftests/bpf/test_bpftool.sh | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/tools/testing/selftests/bpf/test_bpftool.sh b/tools/testing/selftests/bpf/test_bpftool.sh
index 66690778e36d..6b7ba19be1d0 100755
--- a/tools/testing/selftests/bpf/test_bpftool.sh
+++ b/tools/testing/selftests/bpf/test_bpftool.sh @@ -2,4 +2,9 @@
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2020 SUSE LLC.
+ SCRIPT_DIR = $( dirname $( realpath $0 ))
+
+ # 'make -C tools/testing/selftests/bpf' will install to BPFTOOL_INSTALL_PATH
+ BPFTOOL_INSTALL_PATH = " $SCRIPT_DIR " /tools/sbin
+ export PATH = $BPFTOOL_INSTALL_PATH :$PATH
python3 -m unittest -v test_bpftool.TestBpftool
- -2.32.0
On Thu, Aug 19, 2021 at 12:28 AM Li Zhijian [off-list ref] wrote:
- 'make install' will install bpftool to INSTALL_PATH/bpf/bpftool
- add INSTALL_PATH/bpf to PATH
Signed-off-by: Li Zhijian <redacted>
Acked-by: Song Liu <redacted>
With one nit below:
quoted hunk ---
tools/testing/selftests/bpf/Makefile | 4 +++-
tools/testing/selftests/bpf/test_bpftool.sh | 3 ++-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index f405b20c1e6c..c6ca1b8e33d5 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile @@ -85,7 +85,7 @@ TEST_PROGS_EXTENDED := with_addr.sh \
TEST_GEN_PROGS_EXTENDED = test_sock_addr test_skb_cgroup_id_user \
flow_dissector_load test_flow_dissector test_tcp_check_syncookie_user \
test_lirc_mode2_user xdping test_cpp runqslower bench bpf_testmod.ko \
- xdpxceiver xdp_redirect_multi
+ xdpxceiver xdp_redirect_multi test_bpftool.py
TEST_CUSTOM_PROGS = $( OUTPUT) /urandom_read
@@ -187,6 +187,8 @@ $(OUTPUT)/runqslower: $(BPFOBJ) | $(DEFAULT_BPFTOOL)
BPFOBJ = $( BPFOBJ) BPF_INCLUDE = $( INCLUDE_DIR) && \
cp $( SCRATCH_DIR) /runqslower $@
+ TEST_GEN_PROGS_EXTENDED += $( DEFAULT_BPFTOOL)
+
$(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) : $( OUTPUT ) /test_stub .o $( BPFOBJ )
$(OUTPUT)/test_dev_cgroup : cgroup_helpers .c diff --git a/tools/testing/selftests/bpf/test_bpftool.sh b/tools/testing/selftests/bpf/test_bpftool.sh
index 6b7ba19be1d0..50cf9d3645d2 100755
--- a/tools/testing/selftests/bpf/test_bpftool.sh
+++ b/tools/testing/selftests/bpf/test_bpftool.sh @@ -2,9 +2,10 @@
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2020 SUSE LLC.
+ # 'make -C tools/testing/selftests/bpf install' will install to SCRIPT_PATH
nit: Should be SCRIPT_DIR. ^^^^^
SCRIPT_DIR=$(dirname $(realpath $0))
# 'make -C tools/testing/selftests/bpf' will install to BPFTOOL_INSTALL_PATH
BPFTOOL_INSTALL_PATH="$SCRIPT_DIR"/tools/sbin
-export PATH=$BPFTOOL_INSTALL_PATH:$PATH
+export PATH=$SCRIPT_DIR:$BPFTOOL_INSTALL_PATH:$PATH
python3 -m unittest -v test_bpftool.TestBpftool
--
2.32.0
On 20/08/2021 06:16, Song Liu wrote: On Thu, Aug 19, 2021 at 12:28 AM Li Zhijian [off-list ref] wrote: quoted - 'make install' will install bpftool to INSTALL_PATH/bpf/bpftool
- add INSTALL_PATH/bpf to PATH
Signed-off-by: Li Zhijian <redacted> Acked-by: Song Liu <redacted>
With one nit below: thanks for your review, i just submit a V2 to fix it and
Change-log:
V2:
- folded previous similar standalone patch to [1/5], and add acked tag from Song Liu
- add acked tag to [2/5], [3/5] from Song Liu
- [4/5]: move test_bpftool.py to TEST_PROGS_EXTENDED, files in TEST_GEN_PROGS_EXTENDED
are generated by make. Otherwise, it will break out-of-tree install:
'make O=/kselftest-build SKIP_TARGETS= V=1 -C tools/testing/selftests install INSTALL_PATH=/kselftest-install'
- [5/5]: new patch
Please take a look.
Thanks
Zhijian
quoted ---
tools/testing/selftests/bpf/Makefile | 4 +++-
tools/testing/selftests/bpf/test_bpftool.sh | 3 ++-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index f405b20c1e6c..c6ca1b8e33d5 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile @@ -85,7 +85,7 @@ TEST_PROGS_EXTENDED := with_addr.sh \
TEST_GEN_PROGS_EXTENDED = test_sock_addr test_skb_cgroup_id_user \
flow_dissector_load test_flow_dissector test_tcp_check_syncookie_user \
test_lirc_mode2_user xdping test_cpp runqslower bench bpf_testmod.ko \
- xdpxceiver xdp_redirect_multi
+ xdpxceiver xdp_redirect_multi test_bpftool.py
TEST_CUSTOM_PROGS = $( OUTPUT) /urandom_read
@@ -187,6 +187,8 @@ $(OUTPUT)/runqslower: $(BPFOBJ) | $(DEFAULT_BPFTOOL)
BPFOBJ = $( BPFOBJ) BPF_INCLUDE = $( INCLUDE_DIR) && \
cp $( SCRATCH_DIR) /runqslower $@
+ TEST_GEN_PROGS_EXTENDED += $( DEFAULT_BPFTOOL)
+
$( TEST_GEN_PROGS) $( TEST_GEN_PROGS_EXTENDED) : $( OUTPUT) /test_stub.o $( BPFOBJ)
$( OUTPUT) /test_dev_cgroup: cgroup_helpers.c diff --git a/tools/testing/selftests/bpf/test_bpftool.sh b/tools/testing/selftests/bpf/test_bpftool.sh
index 6b7ba19be1d0..50cf9d3645d2 100755
--- a/tools/testing/selftests/bpf/test_bpftool.sh
+++ b/tools/testing/selftests/bpf/test_bpftool.sh @@ -2,9 +2,10 @@
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2020 SUSE LLC.
+ # 'make -C tools/testing/selftests/bpf install' will install to SCRIPT_PATH nit: Should be SCRIPT_DIR. ^^^^^
quoted SCRIPT_DIR=$(dirname $(realpath $0))
# 'make -C tools/testing/selftests/bpf' will install to BPFTOOL_INSTALL_PATH
BPFTOOL_INSTALL_PATH="$SCRIPT_DIR"/tools/sbin
-export PATH=$BPFTOOL_INSTALL_PATH:$PATH
+export PATH=$SCRIPT_DIR:$BPFTOOL_INSTALL_PATH:$PATH
python3 -m unittest -v test_bpftool.TestBpftool
--
2.32.0