Skip to content

Commit 47cf52a

Browse files
Jakub Kicinskiborkmann
authored andcommitted
selftests/bpf: test offloads even with BPF programs present
Modern distroes increasingly make use of BPF programs. Default Ubuntu 18.04 installation boots with a number of cgroup_skb programs loaded. test_offloads.py tries to check if programs and maps are not leaked on error paths by confirming the list of programs on the system is empty between tests. Since we can no longer expect the system to have no BPF objects at boot try to remember the programs and maps present at the start, and skip those when scanning the system. Signed-off-by: Jakub Kicinski <[email protected]> Reviewed-by: Quentin Monnet <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent 07480cb commit 47cf52a

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

tools/testing/selftests/bpf/test_offload.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ def bpftool(args, JSON=True, ns="", fail=True):
163163

164164
def bpftool_prog_list(expected=None, ns=""):
165165
_, progs = bpftool("prog show", JSON=True, ns=ns, fail=True)
166+
# Remove the base progs
167+
for p in base_progs:
168+
if p in progs:
169+
progs.remove(p)
166170
if expected is not None:
167171
if len(progs) != expected:
168172
fail(True, "%d BPF programs loaded, expected %d" %
@@ -171,6 +175,10 @@ def bpftool_prog_list(expected=None, ns=""):
171175

172176
def bpftool_map_list(expected=None, ns=""):
173177
_, maps = bpftool("map show", JSON=True, ns=ns, fail=True)
178+
# Remove the base maps
179+
for m in base_maps:
180+
if m in maps:
181+
maps.remove(m)
174182
if expected is not None:
175183
if len(maps) != expected:
176184
fail(True, "%d BPF maps loaded, expected %d" %
@@ -585,8 +593,8 @@ def test_spurios_extack(sim, obj, skip_hw, needle):
585593
# Check tools
586594
ret, progs = bpftool("prog", fail=False)
587595
skip(ret != 0, "bpftool not installed")
588-
# Check no BPF programs are loaded
589-
skip(len(progs) != 0, "BPF programs already loaded on the system")
596+
base_progs = progs
597+
_, base_maps = bpftool("map")
590598

591599
# Check netdevsim
592600
ret, out = cmd("modprobe netdevsim", fail=False)

0 commit comments

Comments
 (0)