[PATCH bpf-next] selftests/bpf: Bring test_offload.py back to life

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Commit ccc3f56918f6 ("selftests/bpf: convert remaining legacy map
definitions") converted sample_map_ret0.c to modern BTF map format.
However, it doesn't looks like iproute2 part that attaches XDP
supports this format. Let's use bpftool to load the obj file
instead of iproute2; iproute2 will only attach a pinned program.

Some other related issues:
* bpftool has new extra libbpf_det_bind probing map we need to exclude
* skip trying to load netdevsim modules if it's already loaded (builtin)

Cc: Jakub Kicinski <kuba@xxxxxxxxxx>
Fixes: ccc3f56918f6 ("selftests/bpf: convert remaining legacy map definitions")
Signed-off-by: Stanislav Fomichev <sdf@xxxxxxxxxx>
---
 tools/testing/selftests/bpf/test_offload.py | 33 ++++++++++++++++-----
 1 file changed, 25 insertions(+), 8 deletions(-)

diff --git a/tools/testing/selftests/bpf/test_offload.py b/tools/testing/selftests/bpf/test_offload.py
index 7fc15e0d24a9..9718140c13fa 100755
--- a/tools/testing/selftests/bpf/test_offload.py
+++ b/tools/testing/selftests/bpf/test_offload.py
@@ -769,12 +769,14 @@ skip(ret != 0, "bpftool not installed")
 base_progs = progs
 _, base_maps = bpftool("map")
 base_map_names = [
-    'pid_iter.rodata' # created on each bpftool invocation
+    'pid_iter.rodata', # created on each bpftool invocation
+    'libbpf_det_bind', # created on each bpftool invocation
 ]
 
 # Check netdevsim
-ret, out = cmd("modprobe netdevsim", fail=False)
-skip(ret != 0, "netdevsim module could not be loaded")
+if not os.path.isdir("/sys/bus/netdevsim/"):
+    ret, out = cmd("modprobe netdevsim", fail=False)
+    skip(ret != 0, "netdevsim module could not be loaded")
 
 # Check debugfs
 _, out = cmd("mount")
@@ -1169,9 +1171,12 @@ netns = []
 
     simdev = NetdevSimDev()
     sim, = simdev.nsims
-    map_obj = bpf_obj("sample_map_ret0.bpf.o")
+    bpftool_prog_load("sample_map_ret0.bpf.o", "/sys/fs/bpf/offload",
+                      dev=sim['ifname'])
+    offload = bpf_pinned("/sys/fs/bpf/offload")
+
     start_test("Test loading program with maps...")
-    sim.set_xdp(map_obj, "offload", JSON=False) # map fixup msg breaks JSON
+    sim.set_xdp(offload, "offload", JSON=False) # map fixup msg breaks JSON
 
     start_test("Test bpftool bound info reporting (own ns)...")
     check_dev_info(False, "")
@@ -1191,6 +1196,7 @@ netns = []
     prog_file, _ = pin_prog("/sys/fs/bpf/tmp_prog")
     map_file, _ = pin_map("/sys/fs/bpf/tmp_map", idx=1, expected=2)
     simdev.remove()
+    rm("/sys/fs/bpf/offload")
 
     start_test("Test bpftool bound info reporting (removed dev)...")
     check_dev_info_removed(prog_file=prog_file, map_file=map_file)
@@ -1203,7 +1209,10 @@ netns = []
     sim, = simdev.nsims
 
     start_test("Test map update (no flags)...")
-    sim.set_xdp(map_obj, "offload", JSON=False) # map fixup msg breaks JSON
+    bpftool_prog_load("sample_map_ret0.bpf.o", "/sys/fs/bpf/offload",
+                      dev=sim['ifname'])
+    offload = bpf_pinned("/sys/fs/bpf/offload")
+    sim.set_xdp(offload, "offload", JSON=False) # map fixup msg breaks JSON
     maps = bpftool_map_list(expected=2)
     array = maps[0] if maps[0]["type"] == "array" else maps[1]
     htab = maps[0] if maps[0]["type"] == "hash" else maps[1]
@@ -1280,23 +1289,31 @@ netns = []
 
     start_test("Test map remove...")
     sim.unset_xdp("offload")
+    rm("/sys/fs/bpf/offload")
     bpftool_map_list_wait(expected=0)
     simdev.remove()
 
     simdev = NetdevSimDev()
     sim, = simdev.nsims
-    sim.set_xdp(map_obj, "offload", JSON=False) # map fixup msg breaks JSON
+    bpftool_prog_load("sample_map_ret0.bpf.o", "/sys/fs/bpf/offload",
+                      dev=sim['ifname'])
+    offload = bpf_pinned("/sys/fs/bpf/offload")
+    sim.set_xdp(offload, "offload", JSON=False) # map fixup msg breaks JSON
+    rm("/sys/fs/bpf/offload")
     simdev.remove()
     bpftool_map_list_wait(expected=0)
 
     start_test("Test map creation fail path...")
     simdev = NetdevSimDev()
     sim, = simdev.nsims
+    bpftool_prog_load("sample_map_ret0.bpf.o", "/sys/fs/bpf/nooffload")
+    nooffload = bpf_pinned("/sys/fs/bpf/nooffload")
     sim.dfs["bpf_map_accept"] = "N"
-    ret, _ = sim.set_xdp(map_obj, "offload", JSON=False, fail=False)
+    ret, _ = sim.set_xdp(nooffload, "offload", JSON=False, fail=False)
     fail(ret == 0,
          "netdevsim didn't refuse to create a map with offload disabled")
 
+    rm("/sys/fs/bpf/nooffload")
     simdev.remove()
 
     start_test("Test multi-dev ASIC program reuse...")
-- 
2.39.0.rc0.267.gcb52ba06e7-goog




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux