提交 46b2296c 编写于 作者: A Alexei Starovoitov 提交者: Zheng Zengkai

selftests/bpf: Improve inner_map test coverage.

mainline inclusion
from mainline-5.17-rc1
commit d82fa9b7
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5EUVD
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d82fa9b708d7d8a9c275d86c4388d24ecc63206c

-------------------------------------------------

Check that hash and array inner maps are properly initialized.
Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
Acked-by: NAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20211201181040.23337-14-alexei.starovoitov@gmail.com
(cherry picked from commit d82fa9b7)
Signed-off-by: NWang Yufen <wangyufen@huawei.com>
上级 5f2faae1
......@@ -341,9 +341,11 @@ static inline int check_lpm_trie(void)
return 1;
}
#define INNER_MAX_ENTRIES 1234
struct inner_map {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, 1);
__uint(max_entries, INNER_MAX_ENTRIES);
__type(key, __u32);
__type(value, __u32);
} inner_map SEC(".maps");
......@@ -355,7 +357,7 @@ struct {
__type(value, __u32);
__array(values, struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, 1);
__uint(max_entries, INNER_MAX_ENTRIES);
__type(key, __u32);
__type(value, __u32);
});
......@@ -367,8 +369,13 @@ static inline int check_array_of_maps(void)
{
struct bpf_array *array_of_maps = (struct bpf_array *)&m_array_of_maps;
struct bpf_map *map = (struct bpf_map *)&m_array_of_maps;
struct bpf_array *inner_map;
int key = 0;
VERIFY(check_default(&array_of_maps->map, map));
inner_map = bpf_map_lookup_elem(array_of_maps, &key);
VERIFY(inner_map != 0);
VERIFY(inner_map->map.max_entries == INNER_MAX_ENTRIES);
return 1;
}
......@@ -389,8 +396,13 @@ static inline int check_hash_of_maps(void)
{
struct bpf_htab *hash_of_maps = (struct bpf_htab *)&m_hash_of_maps;
struct bpf_map *map = (struct bpf_map *)&m_hash_of_maps;
struct bpf_htab *inner_map;
int key = 2;
VERIFY(check_default(&hash_of_maps->map, map));
inner_map = bpf_map_lookup_elem(hash_of_maps, &key);
VERIFY(inner_map != 0);
VERIFY(inner_map->map.max_entries == INNER_MAX_ENTRIES);
return 1;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册