Commit 414e576f authored by Jakub Kicinski's avatar Jakub Kicinski

Merge branch 'selftests-move-bpf-offload-test-from-bpf-to-net'

Jakub Kicinski says:

====================
selftests: move bpf-offload test from bpf to net

The test_offload.py test fits in networking and bpf equally
well. We started adding more Python tests in networking
and some of the code in test_offload.py can be reused,
so move it to networking. Looks like it bit rotted over
time and some fixes are needed.

Admittedly more code could be extracted but I only had
the time for a minor cleanup :(
====================

Link: https://lore.kernel.org/r/20240409031549.3531084-1-kuba@kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents 2ecd487b 6ce2b689
...@@ -102,7 +102,6 @@ TEST_PROGS := test_kmod.sh \ ...@@ -102,7 +102,6 @@ TEST_PROGS := test_kmod.sh \
test_xdp_redirect_multi.sh \ test_xdp_redirect_multi.sh \
test_xdp_meta.sh \ test_xdp_meta.sh \
test_xdp_veth.sh \ test_xdp_veth.sh \
test_offload.py \
test_sock_addr.sh \ test_sock_addr.sh \
test_tunnel.sh \ test_tunnel.sh \
test_lwt_seg6local.sh \ test_lwt_seg6local.sh \
......
...@@ -84,6 +84,8 @@ TEST_GEN_FILES += sctp_hello ...@@ -84,6 +84,8 @@ TEST_GEN_FILES += sctp_hello
TEST_GEN_FILES += csum TEST_GEN_FILES += csum
TEST_GEN_FILES += nat6to4.o TEST_GEN_FILES += nat6to4.o
TEST_GEN_FILES += xdp_dummy.o TEST_GEN_FILES += xdp_dummy.o
TEST_GEN_FILES += sample_ret0.bpf.o
TEST_GEN_FILES += sample_map_ret0.bpf.o
TEST_GEN_FILES += ip_local_port_range TEST_GEN_FILES += ip_local_port_range
TEST_GEN_FILES += bind_wildcard TEST_GEN_FILES += bind_wildcard
TEST_PROGS += test_vxlan_mdb.sh TEST_PROGS += test_vxlan_mdb.sh
...@@ -93,6 +95,7 @@ TEST_PROGS += test_bridge_backup_port.sh ...@@ -93,6 +95,7 @@ TEST_PROGS += test_bridge_backup_port.sh
TEST_PROGS += fdb_flush.sh TEST_PROGS += fdb_flush.sh
TEST_PROGS += fq_band_pktlimit.sh TEST_PROGS += fq_band_pktlimit.sh
TEST_PROGS += vlan_hw_filter.sh TEST_PROGS += vlan_hw_filter.sh
TEST_PROGS += bpf_offload.py
TEST_FILES := settings TEST_FILES := settings
TEST_FILES += in_netns.sh lib.sh net_helper.sh setup_loopback.sh setup_veth.sh TEST_FILES += in_netns.sh lib.sh net_helper.sh setup_loopback.sh setup_veth.sh
...@@ -142,8 +145,12 @@ endif ...@@ -142,8 +145,12 @@ endif
CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH)) CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH))
$(OUTPUT)/nat6to4.o $(OUTPUT)/xdp_dummy.o: $(OUTPUT)/%.o : %.c $(BPFOBJ) | $(MAKE_DIRS) BPF_PROG_OBJS := $(OUTPUT)/nat6to4.o $(OUTPUT)/xdp_dummy.o \
$(CLANG) -O2 --target=bpf -c $< $(CCINCLUDE) $(CLANG_SYS_INCLUDES) -o $@ $(OUTPUT)/sample_map_ret0.bpf.o $(OUTPUT)/sample_ret0.bpf.o
$(BPF_PROG_OBJS): $(OUTPUT)/%.o : %.c $(BPFOBJ) | $(MAKE_DIRS)
$(CLANG) -O2 -g --target=bpf $(CCINCLUDE) $(CLANG_SYS_INCLUDES) \
-c $< -o $@
$(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile) \ $(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile) \
$(APIDIR)/linux/bpf.h \ $(APIDIR)/linux/bpf.h \
......
...@@ -21,8 +21,11 @@ class NetdevSim: ...@@ -21,8 +21,11 @@ class NetdevSim:
if match and int(match.groups()[0]) != port_index + 1: if match and int(match.groups()[0]) != port_index + 1:
raise Exception("netdevice name mismatches the expected one") raise Exception("netdevice name mismatches the expected one")
self.ifname = ifname
self.nsimdev = nsimdev self.nsimdev = nsimdev
self.port_index = port_index self.port_index = port_index
self.ns = ns
self.dfs_dir = "%s/ports/%u/" % (nsimdev.dfs_dir, port_index)
ret = ip("-j link show dev %s" % ifname, ns=ns) ret = ip("-j link show dev %s" % ifname, ns=ns)
self.dev = json.loads(ret.stdout)[0] self.dev = json.loads(ret.stdout)[0]
...@@ -79,8 +82,10 @@ class NetdevSimDev: ...@@ -79,8 +82,10 @@ class NetdevSimDev:
self.nsims = [] self.nsims = []
for port_index in range(port_count): for port_index in range(port_count):
self.nsims.append(NetdevSim(self, port_index, ifnames[port_index], self.nsims.append(self._make_port(port_index, ifnames[port_index]))
ns=ns))
def _make_port(self, port_index, ifname):
return NetdevSim(self, port_index, ifname, self.ns)
def get_ifnames(self): def get_ifnames(self):
ifnames = [] ifnames = []
......
...@@ -17,7 +17,7 @@ struct { ...@@ -17,7 +17,7 @@ struct {
} array SEC(".maps"); } array SEC(".maps");
/* Sample program which should always load for testing control paths. */ /* Sample program which should always load for testing control paths. */
SEC(".text") int func() SEC("xdp") int func()
{ {
__u64 key64 = 0; __u64 key64 = 0;
__u32 key = 0; __u32 key = 0;
......
/* SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) */ /* SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) */
#define SEC(name) __attribute__((section(name), used))
/* Sample program which should always load for testing control paths. */ /* Sample program which should always load for testing control paths. */
SEC("xdp")
int func() int func()
{ {
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment