Skip to contentSkip to conversation

failing selftests/bpf/test_offload.py

RFC In review Jiri Olsa 2 participants 3 messages Jan 30, 2022 – Feb 4, 2022

Subsystems (7)
lore
Share & tools
lore

Jiri Olsa

author
#0 lore raw

RFC 1/1 failing selftests/bpf/test_offload.py

hi,
I have failing test_offload.py with following output:

  # ./test_offload.py
  ...
  Test bpftool bound info reporting (own ns)...
  FAIL: 3 BPF maps loaded, expected 2
    File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 1177, in <module>
      check_dev_info(False, "")
    File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 645, in check_dev_info
      maps = bpftool_map_list(expected=2, ns=ns)
    File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 190, in bpftool_map_list
      fail(True, "%d BPF maps loaded, expected %d" %
    File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 86, in fail
      tb = "".join(traceback.extract_stack().format())

it fails to detect maps from bpftool's feature detection, that did not make it yet through deferred removal

with the fix below I have this subtest passed, but it fails further on:

  # ./test_offload.py
  ...
  Test bpftool bound info reporting (own ns)...
  Test bpftool bound info reporting (other ns)...
  Test bpftool bound info reporting (remote ns)...
  Test bpftool bound info reporting (back to own ns)...
  Test bpftool bound info reporting (removed dev)...
  Test map update (no flags)...
  Test map update (exists)...
  Test map update (noexist)...
  Test map dump...
  Test map dump...
  Traceback (most recent call last):
    File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 1251, in <module>
      _, entries = bpftool("map dump id %d" % (m["id"]))
    File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 169, in bpftool
      return tool("bpftool", args, {"json":"-p"}, JSON=JSON, ns=ns,
    File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 155, in tool
      ret, stdout = cmd(ns + name + " " + params + args,
    File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 109, in cmd
      return cmd_result(proc, include_stderr=include_stderr, fail=fail)
    File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 131, in cmd_result
      raise Exception("Command failed: %s\n%s" % (proc.args, stderr))
  Exception: Command failed: bpftool -p map dump id 4325

the test seems to expect maps having BTF loaded, which for some reason did not happen, so the test fails with bpftool pretty dump fail

the test loads the object with 'ip link ...', which I never touched, so I wanted ask first before I dive in, perhaps I miss some setup

thoughts? ;-)

thanks,
jirka

---
 tools/lib/bpf/libbpf.c                      | 6 +++---
 tools/testing/selftests/bpf/test_offload.py | 6 +++++-
 2 files changed, 8 insertions(+), 4 deletions(-)
tools/lib/bpf/libbpf.c +3 -3
index 4ce94f4ed34a..881c88eceed0 100644
@@ -4407,7 +4407,7 @@ static int probe_kern_global_data(void)
 	};
 	int ret, map, insn_cnt = ARRAY_SIZE(insns);
 
-	map = bpf_map_create(BPF_MAP_TYPE_ARRAY, NULL, sizeof(int), 32, 1, NULL);
+	map = bpf_map_create(BPF_MAP_TYPE_ARRAY, "global_data", sizeof(int), 32, 1, NULL);
 	if (map < 0) {
 		ret = -errno;
 		cp = libbpf_strerror_r(ret, errmsg, sizeof(errmsg));
@@ -4540,7 +4540,7 @@ static int probe_kern_array_mmap(void)
 	LIBBPF_OPTS(bpf_map_create_opts, opts, .map_flags = BPF_F_MMAPABLE);
 	int fd;
 
-	fd = bpf_map_create(BPF_MAP_TYPE_ARRAY, NULL, sizeof(int), sizeof(int), 1, &opts);
+	fd = bpf_map_create(BPF_MAP_TYPE_ARRAY, "array_mmap", sizeof(int), sizeof(int), 1, &opts);
 	return probe_fd(fd);
 }
 
@@ -4587,7 +4587,7 @@ static int probe_prog_bind_map(void)
 	};
 	int ret, map, prog, insn_cnt = ARRAY_SIZE(insns);
 
-	map = bpf_map_create(BPF_MAP_TYPE_ARRAY, NULL, sizeof(int), 32, 1, NULL);
+	map = bpf_map_create(BPF_MAP_TYPE_ARRAY, "bind_map_detect", sizeof(int), 32, 1, NULL);
 	if (map < 0) {
 		ret = -errno;
 		cp = libbpf_strerror_r(ret, errmsg, sizeof(errmsg));
tools/testing/selftests/bpf/test_offload.py +5 -1
index edaffd43da83..0cf93d246804 100755
@@ -769,7 +769,11 @@ skip(ret != 0, "bpftool not installed")
 base_progs = progs
 _, base_maps = bpftool("map")
 base_map_names = [
-    'pid_iter.rodata' # created on each bpftool invocation
+    # created on each bpftool invocation
+    'pid_iter.rodata',
+    'bind_map_detect',
+    'global_data',
+    'array_mmap',
 ]
 
 # Check netdevsim
Signature · 1 line
2.31.1
#1 lore raw
Quoted 47 lines · Jiri Olsa

hi,
I have failing test_offload.py with following output:

  # ./test_offload.py
  ...
  Test bpftool bound info reporting (own ns)...
  FAIL: 3 BPF maps loaded, expected 2
    File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 1177, in <module>
      check_dev_info(False, "")
    File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 645, in check_dev_info
      maps = bpftool_map_list(expected=2, ns=ns)
    File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 190, in bpftool_map_list
      fail(True, "%d BPF maps loaded, expected %d" %
    File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 86, in fail
      tb = "".join(traceback.extract_stack().format())

it fails to detect maps from bpftool's feature detection, that did not make it yet through deferred removal

with the fix below I have this subtest passed, but it fails further on:

  # ./test_offload.py
  ...
  Test bpftool bound info reporting (own ns)...
  Test bpftool bound info reporting (other ns)...
  Test bpftool bound info reporting (remote ns)...
  Test bpftool bound info reporting (back to own ns)...
  Test bpftool bound info reporting (removed dev)...
  Test map update (no flags)...
  Test map update (exists)...
  Test map update (noexist)...
  Test map dump...
  Test map dump...
  Traceback (most recent call last):
    File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 1251, in <module>
      _, entries = bpftool("map dump id %d" % (m["id"]))
    File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 169, in bpftool
      return tool("bpftool", args, {"json":"-p"}, JSON=JSON, ns=ns,
    File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 155, in tool
      ret, stdout = cmd(ns + name + " " + params + args,
    File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 109, in cmd
      return cmd_result(proc, include_stderr=include_stderr, fail=fail)
    File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 131, in cmd_result
      raise Exception("Command failed: %s\n%s" % (proc.args, stderr))
  Exception: Command failed: bpftool -p map dump id 4325
Quoted 7 lines

the test seems to expect maps having BTF loaded, which for some reason did not happen, so the test fails with bpftool pretty dump fail

the test loads the object with 'ip link ...', which I never touched, so I wanted ask first before I dive in, perhaps I miss some setup

thoughts? ;-)

It looks like the test_offload.py has been using 'bpftool -p' since its inception (in commit: 417ec26477a5 ("selftests/bpf: add offload test based on netdevsim") introduced in December 2017), so this sounds like a regression in bpftool?

-Toke

author
#2 lore raw
Quoted 55 lines · Toke Høiland-Jørgensen
Quoted 53 lines · Jiri Olsa

hi,
I have failing test_offload.py with following output:

  # ./test_offload.py
  ...
  Test bpftool bound info reporting (own ns)...
  FAIL: 3 BPF maps loaded, expected 2
    File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 1177, in <module>
      check_dev_info(False, "")
    File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 645, in check_dev_info
      maps = bpftool_map_list(expected=2, ns=ns)
    File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 190, in bpftool_map_list
      fail(True, "%d BPF maps loaded, expected %d" %
    File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 86, in fail
      tb = "".join(traceback.extract_stack().format())

it fails to detect maps from bpftool's feature detection, that did not make it yet through deferred removal

with the fix below I have this subtest passed, but it fails further on:

  # ./test_offload.py
  ...
  Test bpftool bound info reporting (own ns)...
  Test bpftool bound info reporting (other ns)...
  Test bpftool bound info reporting (remote ns)...
  Test bpftool bound info reporting (back to own ns)...
  Test bpftool bound info reporting (removed dev)...
  Test map update (no flags)...
  Test map update (exists)...
  Test map update (noexist)...
  Test map dump...
  Test map dump...
  Traceback (most recent call last):
    File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 1251, in <module>
      _, entries = bpftool("map dump id %d" % (m["id"]))
    File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 169, in bpftool
      return tool("bpftool", args, {"json":"-p"}, JSON=JSON, ns=ns,
    File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 155, in tool
      ret, stdout = cmd(ns + name + " " + params + args,
    File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 109, in cmd
      return cmd_result(proc, include_stderr=include_stderr, fail=fail)
    File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 131, in cmd_result
      raise Exception("Command failed: %s\n%s" % (proc.args, stderr))
  Exception: Command failed: bpftool -p map dump id 4325

the test seems to expect maps having BTF loaded, which for some reason did not happen, so the test fails with bpftool pretty dump fail

the test loads the object with 'ip link ...', which I never touched, so I wanted ask first before I dive in, perhaps I miss some setup

Quoted 9 lines
Quoted 1 line

thoughts? ;-)

It looks like the test_offload.py has been using 'bpftool -p' since its inception (in commit: 417ec26477a5 ("selftests/bpf: add offload test based on netdevsim") introduced in December 2017), so this sounds like a regression in bpftool?

-Toke

right, looks like this commit:
e5043894b21f ("bpftool: Use libbpf_get_error() to check error")

forced btf for pretty map dump.. change below fixes the test for me, I'll send full patchset for this later

thanks,
jirka

---
 tools/bpf/bpftool/map.c | 1 +
 1 file changed, 1 insertion(+)
tools/bpf/bpftool/map.c +1 -0
index c66a3c979b7a..2ccf85042e75 100644
@@ -862,6 +862,7 @@ map_dump(int fd, struct bpf_map_info *info, json_writer_t *wtr,
 	prev_key = NULL;
 
 	if (wtr) {
+		errno = 0;
 		btf = get_map_kv_btf(info);
 		err = libbpf_get_error(btf);
 		if (err) {
Signature · 1 line
2.34.1