bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
To: bpf@vger.kernel.org
Cc: andrii@kernel.org, jolsa@redhat.com,
	Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Subject: [PATCH bpf-next v4 9/9] selftests/bpf: ringbuf_multi: test bpf_map__set_inner_map_fd
Date: Thu,  8 Apr 2021 09:13:10 +0300	[thread overview]
Message-ID: <20210408061310.95877-9-yauheni.kaliuta@redhat.com> (raw)
In-Reply-To: <20210408061310.95877-1-yauheni.kaliuta@redhat.com>

Test map__set_inner_map_fd() interaction with map-in-map
initialization. Use hashmap of maps just to make it different to
existing array of maps.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
---
 .../testing/selftests/bpf/prog_tests/ringbuf_multi.c  | 11 +++++++++++
 .../testing/selftests/bpf/progs/test_ringbuf_multi.c  | 11 +++++++++++
 2 files changed, 22 insertions(+)

diff --git a/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c b/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c
index 159de99621c7..0e79a7d28361 100644
--- a/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c
+++ b/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c
@@ -44,6 +44,7 @@ void test_ringbuf_multi(void)
 	struct ring_buffer *ringbuf = NULL;
 	int err;
 	int page_size = getpagesize();
+	int proto_fd;
 
 	skel = test_ringbuf_multi__open();
 	if (CHECK(!skel, "skel_open", "skeleton open failed\n"))
@@ -61,10 +62,20 @@ void test_ringbuf_multi(void)
 	if (CHECK(err != 0, "bpf_map__set_max_entries", "bpf_map__set_max_entries failed\n"))
 		goto cleanup;
 
+	proto_fd = bpf_create_map(BPF_MAP_TYPE_RINGBUF, 0, 0, page_size, 0);
+	if (CHECK(proto_fd == -1, "bpf_create_map", "bpf_create_map failed\n"))
+		goto cleanup;
+
+	err = bpf_map__set_inner_map_fd(skel->maps.ringbuf_hash, proto_fd);
+	if (CHECK(err != 0, "bpf_map__set_inner_map_fd", "bpf_map__set_inner_map_fd failed\n"))
+		goto cleanup;
+
 	err = test_ringbuf_multi__load(skel);
 	if (CHECK(err != 0, "skel_load", "skeleton load failed\n"))
 		goto cleanup;
 
+	close(proto_fd);
+
 	/* only trigger BPF program for current process */
 	skel->bss->pid = getpid();
 
diff --git a/tools/testing/selftests/bpf/progs/test_ringbuf_multi.c b/tools/testing/selftests/bpf/progs/test_ringbuf_multi.c
index 055c10b2ff80..197b86546dca 100644
--- a/tools/testing/selftests/bpf/progs/test_ringbuf_multi.c
+++ b/tools/testing/selftests/bpf/progs/test_ringbuf_multi.c
@@ -30,6 +30,17 @@ struct {
 	},
 };
 
+struct {
+	__uint(type, BPF_MAP_TYPE_HASH_OF_MAPS);
+	__uint(max_entries, 1);
+	__type(key, int);
+	__array(values, struct ringbuf_map);
+} ringbuf_hash SEC(".maps") = {
+	.values = {
+		[0] = &ringbuf1,
+	},
+};
+
 /* inputs */
 int pid = 0;
 int target_ring = 0;
-- 
2.31.1


  parent reply	other threads:[~2021-04-08  6:14 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-08  6:12 [PATCH bpf-next v4 0/9] bpf/selftests: page size fixes Yauheni Kaliuta
2021-04-08  6:13 ` [PATCH bpf-next v4 1/9] selftests/bpf: test_progs/sockopt_sk: remove version Yauheni Kaliuta
2021-04-08  6:13   ` [PATCH bpf-next v4 2/9] selftests/bpf: test_progs/sockopt_sk: Convert to use BPF skeleton Yauheni Kaliuta
2021-04-08  6:13   ` [PATCH bpf-next v4 3/9] selftests/bpf: pass page size from userspace in sockopt_sk Yauheni Kaliuta
2021-04-08  6:13   ` [PATCH bpf-next v4 4/9] selftests/bpf: pass page size from userspace in map_ptr Yauheni Kaliuta
2021-04-08  6:13   ` [PATCH bpf-next v4 5/9] selftests/bpf: mmap: use runtime page size Yauheni Kaliuta
2021-04-08  6:13   ` [PATCH bpf-next v4 6/9] selftests/bpf: ringbuf: " Yauheni Kaliuta
2021-04-08  6:13   ` [PATCH bpf-next v4 7/9] libbpf: add bpf_map__inner_map API Yauheni Kaliuta
2021-04-09  6:57     ` Andrii Nakryiko
2021-04-08  6:13   ` [PATCH bpf-next v4 8/9] selftests/bpf: ringbuf_multi: use runtime page size Yauheni Kaliuta
2021-04-08  6:13   ` Yauheni Kaliuta [this message]
2021-04-09  6:56     ` [PATCH bpf-next v4 9/9] selftests/bpf: ringbuf_multi: test bpf_map__set_inner_map_fd Andrii Nakryiko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210408061310.95877-9-yauheni.kaliuta@redhat.com \
    --to=yauheni.kaliuta@redhat.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=jolsa@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).