public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Florian Lehner <dev@der-flo.net>
To: bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org,
	yonghong.song@linux.dev, john.fastabend@gmail.com,
	kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com,
	jolsa@kernel.org, aspsk@isovalent.com, kees@kernel.org,
	quic_abchauha@quicinc.com, martin.kelly@crowdstrike.com,
	mykolal@fb.com, shuah@kernel.org, yikai.lin@vivo.com,
	Florian Lehner <dev@der-flo.net>
Subject: [bpf-next 2/2] selftests/bpf: Add a test for batch operation flag
Date: Sun, 10 Nov 2024 12:29:04 +0100	[thread overview]
Message-ID: <20241110112905.64616-3-dev@der-flo.net> (raw)
In-Reply-To: <20241110112905.64616-1-dev@der-flo.net>

Add a test that verifies the batch operation continues if
BPF_F_BATCH_IGNORE_MISSING_KEY is set.

Signed-off-by: Florian Lehner <dev@der-flo.net>
---
 .../bpf/map_tests/htab_map_batch_ops.c        | 20 ++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/map_tests/htab_map_batch_ops.c b/tools/testing/selftests/bpf/map_tests/htab_map_batch_ops.c
index 5da493b94ae2..76df196f5223 100644
--- a/tools/testing/selftests/bpf/map_tests/htab_map_batch_ops.c
+++ b/tools/testing/selftests/bpf/map_tests/htab_map_batch_ops.c
@@ -136,7 +136,25 @@ void __test_map_lookup_and_delete_batch(bool is_pcpu)
 	err = bpf_map_get_next_key(map_fd, NULL, &key);
 	CHECK(!err, "bpf_map_get_next_key()", "error: %s\n", strerror(errno));
 
-	/* test 4: lookup/delete in a loop with various steps. */
+	/* test 4: batch delete with missing key */
+	map_batch_update(map_fd, max_entries, keys, values, is_pcpu);
+
+	key = 2;
+	err = bpf_map_delete_elem(map_fd, &key);
+	CHECK(err, "bpf_map_delete_elem()", "error: %s\n", strerror(errno));
+
+	DECLARE_LIBBPF_OPTS(bpf_map_batch_opts, ignore_opts,
+		.elem_flags = 0,
+		.flags = BPF_F_BATCH_IGNORE_MISSING_KEY,
+	);
+
+	err = bpf_map_delete_batch(map_fd, keys, &count,
+	       &ignore_opts);
+	CHECK(err, "batch delete with missing key", "error: %s\n", strerror(errno));
+	CHECK(count != max_entries-1, "count != max_entries-1",
+	      "count = %u, max_entries = %u\n", count, max_entries);
+
+	/* test 5: lookup/delete in a loop with various steps. */
 	total_success = 0;
 	for (step = 1; step < max_entries; step++) {
 		map_batch_update(map_fd, max_entries, keys, values, is_pcpu);
-- 
2.47.0


  parent reply	other threads:[~2024-11-10 11:37 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-10 11:29 [bpf-next 0/2] bpf: Add flag for batch operation Florian Lehner
2024-11-10 11:29 ` [bpf-next 1/2] bpf: Add flag to continue " Florian Lehner
2024-11-10 11:29 ` Florian Lehner [this message]
2024-11-11 14:15 ` [bpf-next 0/2] bpf: Add flag for " Hou Tao
2024-11-12  3:01   ` Alexei Starovoitov
2024-11-12 19:13     ` dev
2024-11-12 19:47       ` Alexei Starovoitov

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=20241110112905.64616-3-dev@der-flo.net \
    --to=dev@der-flo.net \
    --cc=andrii@kernel.org \
    --cc=aspsk@isovalent.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kees@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=martin.kelly@crowdstrike.com \
    --cc=martin.lau@linux.dev \
    --cc=mykolal@fb.com \
    --cc=quic_abchauha@quicinc.com \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=yikai.lin@vivo.com \
    --cc=yonghong.song@linux.dev \
    /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