Skip to content

Commit 902196a

Browse files
committed
Merge branch 'bpf-misc-fixes'
Jakub Kicinski says: ==================== This small series allows test_offload.py selftest to run on modern distributions which may create BPF programs for cgroups at boot, like Ubuntu 18.04. We still expect the program list to not be altered by any other agent while the test is running, but no longer depend on there being no BPF programs at all at the start. Fixing the test revealed a small problem with bpftool, which doesn't report the program load time very accurately. Because nanoseconds were not taken into account reported load time would fluctuate by 1 second. First patch of the series takes care of fixing that. ==================== Signed-off-by: Daniel Borkmann <[email protected]>
2 parents 3bce593 + 47cf52a commit 902196a

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

tools/bpf/bpftool/prog.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ static void print_boot_time(__u64 nsecs, char *buf, unsigned int size)
9090
}
9191

9292
wallclock_secs = (real_time_ts.tv_sec - boot_time_ts.tv_sec) +
93-
nsecs / 1000000000;
93+
(real_time_ts.tv_nsec - boot_time_ts.tv_nsec + nsecs) /
94+
1000000000;
95+
9496

9597
if (!localtime_r(&wallclock_secs, &load_tm)) {
9698
snprintf(buf, size, "%llu", nsecs / 1000000000);

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)