From: Martin KaFai Lau <martin.lau@linux.dev>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
kernel-team@meta.com
Subject: Re: [PATCH bpf-next 14/16] selftests/bpf: Replace CHECK with ASSERT in test_local_storage
Date: Tue, 7 Mar 2023 17:24:58 -0800 [thread overview]
Message-ID: <8854d3ae-3288-3e98-33fd-9bd015a78173@linux.dev> (raw)
In-Reply-To: <CAEf4BzYn4CMhNLko5E1HmhP5BeeeVWeUqWzbOjuDcbSgo4nBTA@mail.gmail.com>
On 3/7/23 5:15 PM, Andrii Nakryiko wrote:
>> @@ -60,36 +58,32 @@ static bool check_syscall_operations(int map_fd, int obj_fd)
>>
>> /* Looking up an existing element should fail initially */
>> err = bpf_map_lookup_elem_flags(map_fd, &obj_fd, &lookup_val, 0);
>> - if (CHECK(!err || errno != ENOENT, "bpf_map_lookup_elem",
>> - "err:%d errno:%d\n", err, errno))
>> + if (!ASSERT_ERR(err, "bpf_map_lookup_elem") ||
>> + !ASSERT_EQ(errno, ENOENT, "errno"))
>
> all libbpf APIs since v1.0 always return actual error number directly,
> so no need to check errno anymore, you can simplify this further
>
>> return false;
>>
>> /* Create a new element */
>> err = bpf_map_update_elem(map_fd, &obj_fd, &val, BPF_NOEXIST);
>> - if (CHECK(err < 0, "bpf_map_update_elem", "err:%d errno:%d\n", err,
>> - errno))
>> + if (!ASSERT_OK(err, "bpf_map_update_elem"))
>> return false;
>>
>> /* Lookup the newly created element */
>> err = bpf_map_lookup_elem_flags(map_fd, &obj_fd, &lookup_val, 0);
>> - if (CHECK(err < 0, "bpf_map_lookup_elem", "err:%d errno:%d", err,
>> - errno))
>> + if (!ASSERT_OK(err, "bpf_map_lookup_elem"))
>> return false;
>>
>> /* Check the value of the newly created element */
>> - if (CHECK(lookup_val.value != val.value, "bpf_map_lookup_elem",
>> - "value got = %x errno:%d", lookup_val.value, val.value))
>> + if (!ASSERT_EQ(lookup_val.value, val.value, "bpf_map_lookup_elem"))
>> return false;
>>
>> err = bpf_map_delete_elem(map_fd, &obj_fd);
>> - if (CHECK(err, "bpf_map_delete_elem()", "err:%d errno:%d\n", err,
>> - errno))
>> + if (!ASSERT_OK(err, "bpf_map_delete_elem()"))
>> return false;
>>
>> /* The lookup should fail, now that the element has been deleted */
>> err = bpf_map_lookup_elem_flags(map_fd, &obj_fd, &lookup_val, 0);
>> - if (CHECK(!err || errno != ENOENT, "bpf_map_lookup_elem",
>> - "err:%d errno:%d\n", err, errno))
>> + if (!ASSERT_ERR(err, "bpf_map_lookup_elem") ||
>> + !ASSERT_EQ(errno, ENOENT, "errno"))
>
> same here and probably in other places (I haven't checked everything)
Ack. will simplify.
next prev parent reply other threads:[~2023-03-08 1:25 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-06 8:42 [PATCH bpf-next 00/16] bpf: Use bpf_mem_cache_alloc/free in bpf_local_storage Martin KaFai Lau
2023-03-06 8:42 ` [PATCH bpf-next 01/16] bpf: Move a few bpf_local_storage functions to static scope Martin KaFai Lau
2023-03-06 8:42 ` [PATCH bpf-next 02/16] bpf: Refactor codes into bpf_local_storage_destroy Martin KaFai Lau
2023-03-06 8:42 ` [PATCH bpf-next 03/16] bpf: Remove __bpf_local_storage_map_alloc Martin KaFai Lau
2023-03-06 8:42 ` [PATCH bpf-next 04/16] bpf: Remove the preceding __ from __bpf_selem_unlink_storage Martin KaFai Lau
2023-03-06 8:42 ` [PATCH bpf-next 05/16] bpf: Remember smap in bpf_local_storage Martin KaFai Lau
2023-03-06 8:42 ` [PATCH bpf-next 06/16] bpf: Repurpose use_trace_rcu to reuse_now " Martin KaFai Lau
2023-03-06 8:42 ` [PATCH bpf-next 07/16] bpf: Remove bpf_selem_free_fields*_rcu Martin KaFai Lau
2023-03-07 1:35 ` Kumar Kartikeya Dwivedi
2023-03-06 8:42 ` [PATCH bpf-next 08/16] bpf: Add bpf_selem_free_rcu callback Martin KaFai Lau
2023-03-06 8:42 ` [PATCH bpf-next 09/16] bpf: Add bpf_selem_free() Martin KaFai Lau
2023-03-06 8:53 ` Martin KaFai Lau
2023-03-06 8:42 ` [PATCH bpf-next 10/16] bpf: Add bpf_local_storage_rcu callback Martin KaFai Lau
2023-03-06 8:42 ` [PATCH bpf-next 11/16] bpf: Add bpf_local_storage_free() Martin KaFai Lau
2023-03-06 8:42 ` [PATCH bpf-next 12/16] bpf: Use bpf_mem_cache_alloc/free in bpf_selem_alloc/free Martin KaFai Lau
2023-03-07 3:47 ` Alexei Starovoitov
2023-03-08 0:38 ` Martin KaFai Lau
2023-03-06 8:42 ` [PATCH bpf-next 13/16] bpf: Use bpf_mem_cache_alloc/free for bpf_local_storage Martin KaFai Lau
2023-03-06 8:42 ` [PATCH bpf-next 14/16] selftests/bpf: Replace CHECK with ASSERT in test_local_storage Martin KaFai Lau
2023-03-08 1:15 ` Andrii Nakryiko
2023-03-08 1:24 ` Martin KaFai Lau [this message]
2023-03-06 8:42 ` [PATCH bpf-next 15/16] selftests/bpf: Check freeing sk->sk_local_storage with sk_local_storage->smap is NULL Martin KaFai Lau
2023-03-06 8:42 ` [PATCH bpf-next 16/16] selftests/bpf: Add local-storage-create benchmark Martin KaFai Lau
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=8854d3ae-3288-3e98-33fd-9bd015a78173@linux.dev \
--to=martin.lau@linux.dev \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@meta.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