On Mon, Jul 27, 2020 at 1:53 PM Song Liu <song@xxxxxxxxxx> wrote: > > On Thu, Jul 23, 2020 at 6:17 PM Andrii Nakryiko <andriin@xxxxxx> wrote: > > > > Add test validating that all inner maps are released properly after skeleton > > is destroyed. To ensure determinism, trigger kernel-size synchronize_rcu() > > before checking map existence by their IDs. > > > > Signed-off-by: Andrii Nakryiko <andriin@xxxxxx> > > --- > > .../selftests/bpf/prog_tests/btf_map_in_map.c | 104 +++++++++++++++--- > > 1 file changed, 91 insertions(+), 13 deletions(-) > > > > diff --git a/tools/testing/selftests/bpf/prog_tests/btf_map_in_map.c b/tools/testing/selftests/bpf/prog_tests/btf_map_in_map.c > > index f7ee8fa377ad..043e8ffe03d1 100644 > > --- a/tools/testing/selftests/bpf/prog_tests/btf_map_in_map.c > > +++ b/tools/testing/selftests/bpf/prog_tests/btf_map_in_map.c > > @@ -5,10 +5,50 @@ > > > > #include "test_btf_map_in_map.skel.h" > > > > +static int duration; > > + > > +int bpf_map_id(struct bpf_map *map) > Should this return __u32? yeah, probably, will change > > > +{ > > + struct bpf_map_info info; > > + __u32 info_len = sizeof(info); > > + int err; > > + > > + memset(&info, 0, info_len); > > + err = bpf_obj_get_info_by_fd(bpf_map__fd(map), &info, &info_len); > > + if (err) > > + return 0; > > + return info.id; > > +} > > + > > +int kern_sync_rcu() { > > int kern_sync_rcu(void) > { > ... > > A comment for this function would be nice too. Sure. > > > + int inner_map_fd, outer_map_fd, err, zero = 0; > > + > > + inner_map_fd = bpf_create_map(BPF_MAP_TYPE_ARRAY, 4, 4, 1, 0); > > + if (CHECK(inner_map_fd < 0, "inner_map_create", "failed %d\n", -errno)) > > + return -1; > > + > > + outer_map_fd = bpf_create_map_in_map(BPF_MAP_TYPE_ARRAY_OF_MAPS, NULL, > > + sizeof(int), inner_map_fd, 1, 0); > > + if (CHECK(outer_map_fd < 0, "outer_map_create", "failed %d\n", -errno)) { > > + close(inner_map_fd); > > + return -1; > > + } > > + > > + err = bpf_map_update_elem(outer_map_fd, &zero, &inner_map_fd, 0); > > + if (err) > > + err = -errno; > > + CHECK(err, "outer_map_update", "failed %d\n", err); > > + close(inner_map_fd); > > + close(outer_map_fd); > > + return err; > > +} > > + > > void test_btf_map_in_map(void) > > { > > - int duration = 0, err, key = 0, val; > > + int err, key = 0, val, i; > > struct test_btf_map_in_map* skel; > > + int outer_arr_fd, outer_hash_fd; > > + int fd, map1_fd, map2_fd, map1_id, map2_id; > nit: reverse Christmas tree. We don't enforce that and it hasn't been a requirement for a long time. It's better to minimize a code churn rather than preserving pretty line ordering. > > > > > skel = test_btf_map_in_map__open_and_load(); > > if (CHECK(!skel, "skel_open", "failed to open&load skeleton\n")) > > @@ -18,32 +58,70 @@ void test_btf_map_in_map(void) > > if (CHECK(err, "skel_attach", "skeleton attach failed: %d\n", err)) > > goto cleanup; > > [...]