Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <jakub.kicinski@netronome.com>
Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>

authored by

Jakub Kicinski and committed by
Daniel Borkmann
47cf52a2 07480cbc

+10 -2
+10 -2
tools/testing/selftests/bpf/test_offload.py
··· 163 163 164 164 def bpftool_prog_list(expected=None, ns=""): 165 165 _, 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) 166 170 if expected is not None: 167 171 if len(progs) != expected: 168 172 fail(True, "%d BPF programs loaded, expected %d" % ··· 175 171 176 172 def bpftool_map_list(expected=None, ns=""): 177 173 _, maps = bpftool("map show", JSON=True, ns=ns, fail=True) 174 + # Remove the base maps 175 + for m in base_maps: 176 + if m in maps: 177 + maps.remove(m) 178 178 if expected is not None: 179 179 if len(maps) != expected: 180 180 fail(True, "%d BPF maps loaded, expected %d" % ··· 593 585 # Check tools 594 586 ret, progs = bpftool("prog", fail=False) 595 587 skip(ret != 0, "bpftool not installed") 596 - # Check no BPF programs are loaded 597 - skip(len(progs) != 0, "BPF programs already loaded on the system") 588 + base_progs = progs 589 + _, base_maps = bpftool("map") 598 590 599 591 # Check netdevsim 600 592 ret, out = cmd("modprobe netdevsim", fail=False)