在 8/31/26 7:48 PM, [email protected] 写道:
diff --git a/tools/testing/selftests/bpf/prog_tests/btf_map_keyless.c
b/tools/testing/selftests/bpf/prog_tests/btf_map_keyless.c
new file mode 100644
index 0000000000000..a7d037f57a7ef
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/btf_map_keyless.c
@@ -0,0 +1,82 @@
[ ... ]
+ /*
+ * Positive control: the same map with a real key type must be accepted,
+ * so the -EINVAL below is about the key-less BTF and not some unrelated
+ * rejection (e.g. an unknown map type).
+ */
+ opts.btf_key_type_id = val_id;
+ map_fd = bpf_map_create(map_type, "keyed_map", 4, 4, 8, &opts);
+ if (!ASSERT_GE(map_fd, 0, "keyed create is accepted"))
+ return;
+ close(map_fd);
A subsystem pattern flags this as potentially concerning: the positive
control turns "this kernel does not implement the map type" into a hard test
failure instead of a skip.
BPF_MAP_TYPE_RHASH (used by the rhash subtest) is new; on any kernel that
lacks it, map_create() rejects the unknown map type and this ASSERT_GE fails,
reporting a red btf_map_keyless/rhash that has nothing to do with the
behaviour under test.
Selftests run against the matching kernel, where the map type exists, so
this doesn't happen.