bpf: selftests: Add test for different inner map size

This patch tests the inner map size can be different
for reuseport_sockarray but has to be the same for
arraymap.  A new subtest "diff_size" is added for this.

The existing test is moved to a subtest "lookup_update".

Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20200828011819.1970825-1-kafai@fb.com
This commit is contained in:
Martin KaFai Lau 2020-08-27 18:18:19 -07:00 коммит произвёл Daniel Borkmann
Родитель 134fede4ee
Коммит d557ea39a5
2 изменённых файлов: 65 добавлений и 1 удалений

Просмотреть файл

@ -53,7 +53,7 @@ static int kern_sync_rcu(void)
return err;
}
void test_btf_map_in_map(void)
static void test_lookup_update(void)
{
int err, key = 0, val, i;
struct test_btf_map_in_map *skel;
@ -143,3 +143,36 @@ void test_btf_map_in_map(void)
cleanup:
test_btf_map_in_map__destroy(skel);
}
static void test_diff_size(void)
{
struct test_btf_map_in_map *skel;
int err, inner_map_fd, zero = 0;
skel = test_btf_map_in_map__open_and_load();
if (CHECK(!skel, "skel_open", "failed to open&load skeleton\n"))
return;
inner_map_fd = bpf_map__fd(skel->maps.sockarr_sz2);
err = bpf_map_update_elem(bpf_map__fd(skel->maps.outer_sockarr), &zero,
&inner_map_fd, 0);
CHECK(err, "outer_sockarr inner map size check",
"cannot use a different size inner_map\n");
inner_map_fd = bpf_map__fd(skel->maps.inner_map_sz2);
err = bpf_map_update_elem(bpf_map__fd(skel->maps.outer_arr), &zero,
&inner_map_fd, 0);
CHECK(!err, "outer_arr inner map size check",
"incorrectly updated with a different size inner_map\n");
test_btf_map_in_map__destroy(skel);
}
void test_btf_map_in_map(void)
{
if (test__start_subtest("lookup_update"))
test_lookup_update();
if (test__start_subtest("diff_size"))
test_diff_size();
}

Просмотреть файл

@ -11,6 +11,13 @@ struct inner_map {
} inner_map1 SEC(".maps"),
inner_map2 SEC(".maps");
struct inner_map_sz2 {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, 2);
__type(key, int);
__type(value, int);
} inner_map_sz2 SEC(".maps");
struct outer_arr {
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
__uint(max_entries, 3);
@ -50,6 +57,30 @@ struct outer_hash {
},
};
struct sockarr_sz1 {
__uint(type, BPF_MAP_TYPE_REUSEPORT_SOCKARRAY);
__uint(max_entries, 1);
__type(key, int);
__type(value, int);
} sockarr_sz1 SEC(".maps");
struct sockarr_sz2 {
__uint(type, BPF_MAP_TYPE_REUSEPORT_SOCKARRAY);
__uint(max_entries, 2);
__type(key, int);
__type(value, int);
} sockarr_sz2 SEC(".maps");
struct outer_sockarr_sz1 {
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
__uint(max_entries, 1);
__uint(key_size, sizeof(int));
__uint(value_size, sizeof(int));
__array(values, struct sockarr_sz1);
} outer_sockarr SEC(".maps") = {
.values = { (void *)&sockarr_sz1 },
};
int input = 0;
SEC("raw_tp/sys_enter")